-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 8416: Introduce speedreader button. #5085
Conversation
The button is not colorful yet - have to do some manual adjustments in the |
I'll take a look tomorrow :) |
@@ -1,5 +1,5 @@ | |||
import("//build/config/features.gni") | |||
|
|||
declare_args() { | |||
enable_speedreader = !is_ios | |||
enable_speedreader = !is_android |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we want to disable it for both ios and android currently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe ios is based on a different codebase...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we do use the flag in various other components, and the CI seems to build some libraries used by ios - there still doesn't seem to be a need to build it for ios, so should be disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think components for ios are manually selected, so we shouldn't explicitly disable - it is never reached. @bsclifton please correct me if I'm wrong?
SpeedreaderButton* button = | ||
static_cast<BraveToolbarView*>(view->toolbar())->speedreader_button(); | ||
if (button) { | ||
button->SetActive(active_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking: the current interaction here will show SpeedReader active icon even on tabs that have not been reloaded since SpeedReader was enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, actually this is a bug. The user could 1) enable speedreader, load a distilled page 2) open another tab 3) turn off speedreader 4) come back to tab#1 5) navigate away to e.g. blank page 6) open tab#2, enable speedreader 7) open tab#1 - speedreader icon is active
@@ -47,6 +49,7 @@ class SpeedReaderBrowserTest : public InProcessBrowserTest { | |||
}; | |||
|
|||
IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, SmokeTest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more than a smoke test would be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll add more test when a component updater stuff is in place
|
||
class SpeedreaderService; | ||
|
||
class SpeedreaderServiceFactory : public BrowserContextKeyedServiceFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this service & factory aren't necessary.
If this is only used for get/set related prefs value, I think just using simple apis seems fine. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree, though I decided to keep it in case we would add a user preference (and would need to keep a pref registrar), or something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok. if service will have registrar
in the future, having service seems reasonable.
namespace speedreader { | ||
|
||
// Updates the speedreader toolbar button state when a tab visibility changes. | ||
class SpeedreaderTabHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever browser ui change needs, BraveToolBarView::Update(content::WebContents*)
is called.
I think we can manage speedreader button's state at there w/o this tab helper.
Also, using views api outside of views modules is layer violation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the toolbar should be aware of speedreader button activation logic, so I propose to keep the helper.
Agree that there is a violation, I'm open for suggestions :) We probably should involve the Browser
object, as bookmarks do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean we can call SpeedReaderButton::Update
from ToolBarView
.
Maybe speedreader button can have the logic that tab helper has?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With tab helper, I think it's hard to remove this layer violation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem is that the "active" state is determined in BraveContentBrowserClient - we should pass it to the toolbar/button somehow. So it seems the only way is to user Browser
- i.e. subclass it, add a method and override it in BraveBrowserView
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - I see. How about this?
Setting active state to tab helper from here and checking that state from SpeedReaderButton::Update()?
With this, I think we don't need to introduce additional api to BrowserView.
I think SpeedReaderButton::Update() can be called whenever toolbar state should be updated like tab changing, loading and etc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a small refactor, so now Tab Helper determines the active state by itself and the toolbar actively queries this state - PTAL :)
@bridiver Please take a look at a tiny patch :) |
SpeedreaderServiceFactory::GetForProfile(profile)->IsEnabled(); | ||
|
||
if (!enabled) { | ||
active_ = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add return false;
here?
I assume active state is always false when preference is off. isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it was caught by the test :D
SpeedreaderTabHelper(const SpeedreaderTabHelper&) = delete; | ||
SpeedreaderTabHelper& operator=(SpeedreaderTabHelper&) = delete; | ||
|
||
void UpdateActiveState(content::NavigationHandle* handle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be private method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -182,14 +206,25 @@ void BraveToolbarView::Update(content::WebContents* tab) { | |||
bookmark_->SetVisible(browser_defaults::bookmarks_enabled && | |||
edit_bookmarks_enabled_.GetValue()); | |||
} | |||
if (speedreader_) { | |||
speedreader_->SetVisible(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View is visible by default.
I think this button's visibility is determined by SpeedreaderService::IsEnabled()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just removed that line, if it exists it is visible
auto* active_contents = GetWebContents(); | ||
if (active_contents) { | ||
auto* tab_helper = | ||
speedreader::SpeedreaderTabHelper::FromWebContents(active_contents); | ||
if (tab_helper) { | ||
speedreader_->SetActive(tab_helper->IsActiveForMainFrame()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic could be moved into SpeedreaderButton::Update(content::WebContents* web_contents)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
browser/ui/browser_commands.cc
Outdated
// TODO(iefremov): We probably should do it with lesser amount of hacks. | ||
BrowserView* view = static_cast<BrowserView*>(browser->window()); | ||
SpeedreaderButton* button = | ||
static_cast<BraveToolbarView*>(view->toolbar())->speedreader_button(); | ||
if (button) { | ||
button->Toggle(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about control button's toggle status by button itself by overriding OnMouseRelease()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command may be executed not only by mouse, so I think it's better as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, accelerator could run it. I'm still thinking about how to delete this code...
Ok - how about update button's on/off state by checking kSpeedreaderEnabled
value in Button::Update()
?
Or monitoring that prefs in the button?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in favor of splitting this logic... Probably we should just patch or inherit Browser
. I've placed a TODO here, mb we can think about it in follow-ups?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, most important thing here is avoiding layer violation. I'm fine both adding new method to BraveBrowserView or letting button handle its on/off status by itself.
If you want to fix this layer violation later, it's fine for me. but why not now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my bad, I didn't notice this is a layering violation as well. OK, I'll push a fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@simonhong ptal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
// IDs for the WebUI-based tab strip. See https://crbug.com/989131. | ||
VIEW_ID_WEBUI_TAB_STRIP_TAB_COUNTER, | ||
VIEW_ID_WEBUI_TAB_STRIP_NEW_TAB_BUTTON, | ||
+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe we don't want blank line to patch file.
691f18d
to
f7227f0
Compare
Yeah, I'm fine with using our new view id file. I think you forgot to add that file in this PR :) |
c1eb716
to
bb5d7c2
Compare
bb5d7c2
to
9b98691
Compare
brave/brave-browser#8416
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
After-merge Checklist:
changes has landed on.