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

Offer google translate installation in translate bubbles #3103

Merged
merged 10 commits into from
Aug 9, 2019

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Aug 6, 2019

Fix brave/brave-browser#5561

Below is the gif of how this PR looks like and it's easier to go through each commit when reviewing.
gtranslate

This PR repurposed TranslateBubbleView and TranslateIconView to offer google translate installation in translate bubbles when ENABLE_BRAVE_TRANSLATE (go-translate) is disabled.
This UI is expected to be used in all desktop channels, and the prompt of translate bubbles could be disabled through language settings by toggling Offer to translate pages that aren't in a language you read as below.
Screen Shot 2019-08-06 at 11 04 26 AM

Submitter Checklist:

Test Plan:

  1. Open brave://settings
  2. Toggle off the Offer to translate pages that aren't in a language you read setting in Languages -> Language.
  3. Visit https://www.deutschland.de/de, translate bubble should not be shown.
  4. Right click and Translate to _your_language_ should not be shown in the context menu.
  5. Toggle on the Offer to translate pages that aren't in a language you read setting in Languages -> Language.
  6. Visit https://www.deutschland.de/de, the translate bubble should be shown to offer google translate installation.
  7. After installation, both the icon & bubble in the location bar should be hidden and the page could be translated through Google Translate extension.
  8. Open a new tab and visit https://www.deutschland.de/de again, translate bubble should not be shown.

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.

@yrliou yrliou added this to the 0.70.x - Nightly milestone Aug 6, 2019
@yrliou yrliou self-assigned this Aug 6, 2019
@yrliou yrliou force-pushed the offer_google_translate branch 3 times, most recently from 42ccc16 to 0657843 Compare August 6, 2019 23:10
@yrliou yrliou changed the title [WIP] Offer google translate installation in translate bubbles Offer google translate installation in translate bubbles Aug 6, 2019
@yrliou yrliou marked this pull request as ready for review August 6, 2019 23:30
@yrliou yrliou requested a review from bridiver as a code owner August 6, 2019 23:30
@yrliou yrliou requested review from mkarolin, simonhong, emerick and bbondy and removed request for emerick August 6, 2019 23:30
mkarolin
mkarolin previously approved these changes Aug 8, 2019
Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

LGTM, works as described.

#endif

private:
#if !BUILDFLAG(ENABLE_BRAVE_TRANSLATE) && BUILDFLAG(ENABLE_EXTENSIONS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we want ENABLE_EXTENSIONS here. If translate is dependent on extensions then we should set enable_brave_translate = enable_extensions in gn

Copy link
Member Author

Choose a reason for hiding this comment

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

separate the build flags in 6acee43

void BraveTranslateBubbleView::Init() {
TranslateBubbleView::Init();
RemoveChildView(before_translate_view_);
before_translate_view_ = AddChildView(BraveCreateViewBeforeTranslate());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is going to fail on android because it has a guard above

Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems like in general this needs to work differently for android

Copy link
Member Author

Choose a reason for hiding this comment

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

this google extension approach won't work in android unless we have extensions supported, so this code block shouldn't be built on android atm.

std::unique_ptr<TranslateBubbleModel> model(
new TranslateBubbleModelImpl(step, std::move(ui_delegate)));
- TranslateBubbleView* view = new TranslateBubbleView(
+ TranslateBubbleView* view = new BraveTranslateBubbleView(
Copy link
Collaborator

Choose a reason for hiding this comment

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

rather than change this line, I think it's better to add BRAVE_SHOW_BUBBLE_ after it. Then if ENABLE_BRAVE_TRANSLATE is false BRAVE_SHOW_BUBBLE_ does nothing. If it's true then it replaces view with BraveTranslateBubbleView. This also eliminates all the guards inside BraveTranslateBubbleView and any issues with android. brave_translate_bubble_view.h/.cc should also go inside enable_brave_translate guards in gn

Copy link
Member Author

@yrliou yrliou Aug 8, 2019

Choose a reason for hiding this comment

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

Could we keep this patch line but replace BraveTranslateBubbleView back to TranslateBubbleView in the chromium_src override instead if ENABLE_BRAVE_TRANSLATE_EXTENSION is false?
This would also eliminates the guards inside BraveTranslateBubbleView and guard brave_translate_bubble_view.h/.cc inside gn.
Currently did this in 6acee43, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated as suggested in 60e70de

- Move adding Open Link with Tor into InitMenu and remove AppendBraveLinkItems
- Fix bug when removing IDC_CONTENT_CONTEXT_TRANSLATE since it is not always existed
- Define BRAVE_RENDER_VIEW_CONTEXT_MENU_H_ and BRAVE_TRANSLATE_BUBBLE_VIEW_H_ to be extensible in the header
private: \
friend class BraveTranslateBubbleView; \
public:
class BraveTranslateBubbleView;
Copy link
Collaborator

Choose a reason for hiding this comment

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

just for readability please leave a space after the multiline macro

Copy link
Member Author

Choose a reason for hiding this comment

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

addresses in 352251d

- Separate translate build flags for go-translate and google translate extension approaches
- Guard translate_bubble_view and translate_icon_view subclasses files in gn

declare_args() {
enable_brave_translate = !is_release_channel
enable_brave_translate_go = false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit - you only need one declare_args section here

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually getting below build error when doing enable_brave_translate_extension = !enable_brave_translate_go && enable_extensions if using one declare_args.
ERROR at //brave/browser/translate/buildflags/buildflags.gni:7:39: Reading a variable defined in the same declare_args() call.

const Browser* browser = GetBrowser();
const bool is_app = browser && browser->is_app();

index = menu_model_.GetIndexOfCommandId(
Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @petemill - anything else she should do here? Did you find a good way to test?

return was_visible != GetVisible();
}

return TranslateIconView::Update();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this right? Won't ChromeTranslateClient::FromWebContents(GetWebContents()) return nullptr in TranslateIconView::Update? Either way does it ever make sense to call the superclass method here?

Copy link
Member Author

@yrliou yrliou Aug 8, 2019

Choose a reason for hiding this comment

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

It won't be nullptr when doing ChromeTranslateClient::FromWebContents(GetWebContents()) in TranslateIconView::Update, the client still exists in our case.
What I planned to achieve here is just to behave the same way as superclass before google translate is installed, and make sure we won't still show the icon right after google translate is already installed.

@@ -0,0 +1,138 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this stuff maybe be in browser/ui/views/translate/extension?

@yrliou
Copy link
Member Author

yrliou commented Aug 9, 2019

Added unit tests for translate bubble, latest CI test failure was only in win-x64's Copy file to S3 step.

@yrliou yrliou merged commit 4efa8ef into master Aug 9, 2019
@yrliou yrliou deleted the offer_google_translate branch August 9, 2019 20:55
yrliou added a commit that referenced this pull request Aug 14, 2019
Offer google translate installation in translate bubbles
@kjozwiak
Copy link
Member

Using 0.71.21 Chromium: 76.0.3809.100, went through the following cases to ensure the above was working as expected so we can uplift into 0.69.x via #3177:

  • went through the original issues outlined under Offer google translate installation in translate bubbles #3103 (comment)
  • ensured that you can uninstall/reinstall multiple times without any issues
  • ensured that the translation model appears once you visit a website that can be translated even though you've uninstalled/installed several times
  • ensured that "Translate this Page" via the extension worked without issues
  • ensured that the translate context menu feature worked without issues
  • ensured that you can translate to different languages using the "Translate to:" feature
  • ensured that "Sow original" displays the original language without any issues
  • ensured that "Turn off translations for for this site" worked as expected

Used the following websites:

Examples of the feature:

Screen Shot 2019-08-20 at 8 01 53 PM

Screen Shot 2019-08-20 at 8 02 10 PM

Screen Shot 2019-08-20 at 8 02 25 PM

Screen Shot 2019-08-20 at 8 02 54 PM

Screen Shot 2019-08-20 at 8 05 35 PM

Screen Shot 2019-08-20 at 8 05 45 PM

Screen Shot 2019-08-20 at 8 15 27 PM

Screen Shot 2019-08-20 at 8 16 52 PM

@jost-s
Copy link

jost-s commented Oct 11, 2019

Guys, is there a way to disable the offer to install the extension? I don't want to install it and it constantly pops up.

@bsclifton
Copy link
Member

@jost-s yes, there is 😄

Visit brave://settings/languages and click the down chevron under languages. There should be an option: Offer to translate pages that aren't in a language you read
Screen Shot 2019-10-11 at 9 28 56 AM

We're rolling out a fix soon (today) that offers a Don't ask me again in this popup also 😄

@jost-s
Copy link

jost-s commented Oct 11, 2019

@bsclifton Brilliant, cheers man! 😃

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.

Offer to install Google Translate extension in translate bubble
6 participants