Skip to content
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

Merged
merged 14 commits into from
Apr 14, 2020
Merged

Conversation

iefremov
Copy link
Contributor

@iefremov iefremov commented Mar 27, 2020

brave/brave-browser#8416

Submitter Checklist:

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@iefremov
Copy link
Contributor Author

The button is not colorful yet - have to do some manual adjustments in the .icon files :-/

@iefremov iefremov requested a review from bridiver as a code owner March 30, 2020 05:59
@simonhong
Copy link
Member

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

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?

Copy link
Contributor Author

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...

Copy link

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?

Copy link
Contributor Author

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_);

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?

Copy link
Contributor Author

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) {

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

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@simonhong simonhong Apr 2, 2020

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..

Copy link
Contributor Author

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 :)

@iefremov
Copy link
Contributor Author

@bridiver Please take a look at a tiny patch :)

SpeedreaderServiceFactory::GetForProfile(profile)->IsEnabled();

if (!enabled) {
active_ = false;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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().

Copy link
Contributor Author

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

Comment on lines 212 to 210
auto* active_contents = GetWebContents();
if (active_contents) {
auto* tab_helper =
speedreader::SpeedreaderTabHelper::FromWebContents(active_contents);
if (tab_helper) {
speedreader_->SetActive(tab_helper->IsActiveForMainFrame());
}
}
}
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 80 to 86
// 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();
}
Copy link
Member

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()?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@iefremov
Copy link
Contributor Author

iefremov commented Apr 7, 2020

@simonhong ptal

Copy link
Member

@simonhong simonhong left a 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,
+
Copy link
Member

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.

@simonhong
Copy link
Member

Yeah, I'm fine with using our new view id file. I think you forgot to add that file in this PR :)

@iefremov iefremov force-pushed the ie_speedreader_button_2 branch 3 times, most recently from c1eb716 to bb5d7c2 Compare April 10, 2020 15:02
@iefremov iefremov merged commit 5cfd089 into master Apr 14, 2020
@iefremov iefremov deleted the ie_speedreader_button_2 branch April 14, 2020 13:25
@bbondy bbondy added this to the 1.9.x - Release milestone Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants