-
Notifications
You must be signed in to change notification settings - Fork 887
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
API to open Shields and Rewards dialog UI #3664
Conversation
2111317
to
1ad4d45
Compare
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.
Please check CI for build/browser test errors
I think the problem here is a dependency violation in calling code in |
#include "brave/browser/ui/views/brave_actions/brave_actions_container.h" | ||
#include "brave/browser/ui/views/location_bar/brave_location_bar_view.h" | ||
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" | ||
#include "chrome/browser/ui/views/frame/browser_view.h" |
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.
As discussed in DM, these views header files should not be included here.
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.
Changed, now using an obserer pattern
1ad4d45
to
1fc2597
Compare
This is ready for review. Now using the Observer pattern, modeled on ExtensionActionAPI and ExtensionActionAPI::Observer. Interestingly enough there already is an API to open popups from an extension itself (we're not using that here since we want to open the popup from other contexts, specifying which extension to open). The pattern for that API is to store a reference on the BrowserWindow to the UI model which contains the ExtensionActions, and for the ExtensionActionAPI to go through the browser UI layer and call ExecuteAction directly. I much prefer the observer pattern here so that the UI project looks at the Extension project. Plus, it doesn't need a new patch or chromium_src override, which adding a property to BrowserWindow would require. |
1fc2597
to
9723cda
Compare
One question concerning the Likewise I haven't called Let me know if you have any thoughts @bridiver @simonhong. |
@@ -53,6 +56,26 @@ ExtensionFunction::ResponseAction BraveRewardsCreateWalletFunction::Run() { | |||
return RespondNow(NoArguments()); | |||
} | |||
|
|||
BraveRewardsOpenBrowserActionUIFunction:: |
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: Not sure if this effects lint, but can you format definitions that need to break like: https://github.com/brave/brave-core/blob/9723cdad5bb75b84d6ccdaac55fbc1d137181fd7/browser/extensions/api/brave_rewards_api.cc#L955
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
) { | ||
} | ||
|
||
ExtensionFunction::ResponseAction BraveRewardsOpenBrowserActionUIFunction::Run( |
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.
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
return; | ||
} | ||
if (actions_[extension_id].view_controller_) { | ||
// auto view_controller = static_cast<BraveActionViewController*>( |
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.
Can this comment be removed or does it indicate needed code?
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.
Thanks for the spot - removed
9723cda
to
31ba47a
Compare
} | ||
} | ||
// Don't support showing action popups in a popup window. | ||
if (!browser->SupportsWindowFeature(Browser::FEATURE_TOOLBAR)) { |
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 using BrowserWindow::IsToolbarVisible()
seems more robust.
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 I think I'll remove this part. It was there from the first implementation, where we called methods directly on the toolbar. Now, the subscriber for that Browser will either be there or it won't. Plus, the subscriber can decide to still show the popup even if the toolbar is hidden, like what happens in full screen windows when permission bubbles appear.
I think we don't need to have |
return false; | ||
} | ||
// Pass event to correct observer | ||
for (auto& observer : observers_) { |
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 using Browser*
and observers map?
I think it should be a little bit efficient than iterating all every time.
@@ -379,6 +379,24 @@ | |||
} | |||
], | |||
"functions": [ | |||
{ |
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.
if this is a utility function that can be used from any internal extension it should go in it's own api config instead of being duplicated in rewards and shields
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.
as discussed, it's specific to each API (each API opens the UI related to that API)
As discussed with @bridiver, we'll attempt to make a |
bdbf9a7
to
c8ecffa
Compare
This is ready for re-review @simonhong @bridiver now that I've converted from |
c8ecffa
to
c6921d9
Compare
@@ -10,6 +10,7 @@ | |||
#include <memory> | |||
#include <string> | |||
|
|||
#include "brave/browser/extensions/api/brave_action_api.h" |
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 you might be missing a dep for 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.
fixed
463fb09
to
76d045e
Compare
202f3f3
to
194a65f
Compare
Introduces `chrome.{ braveRewards, braveShields }.openBrowserActionUI(optional windowId, optional relativePath)`. Several upcoming features require being able to summon a dialog attached to Shields or Rewards icons from some other user action that is not clicking on the icon buttons (the only current way to open the dialogs). These features include: • Offering to bypass paywalls (Publisher Access Pass) • Offering to turn shields off (Webcompat detection) • Offering to opt-in to Rewards or complete a Rewards captcha The API allows a custom path to be sent to open a specific HTML page other than the one configured for the active tab, e.g. offer-paywall.html, solve-captcha.html etc The API will default to the current window for the profile, which only works when called from a WebUI page. When called from a background script, a windowId will need to be provided so that the popup is shown on a compatible active or recently-active window (and not, e.g., a devtools window). This was prototyped for the Publisher Access Pass concept at #3565 and modified for this PR to use the Observer pattern. If there is a webui page which has access to chrome.braveShields or chrome.braveRewards API, then simply call `chrome.brave{Shields | Rewards}.openBrowserActionUI()` and `chrome.brave{Shields | Rewards}.openBrowserActionUI('fake-page.html)` to test. A popup should open on the current window Test Plan: Open chrome://inspect, switch to the Extensions tab, and inspect either the Rewards or Brave extension. Then use the following API calls, one at a time (uncomment the line you wish to run): ``` chrome.windows.getAll(wins => { // test that we can open in a specified window // chrome.braveShields.openBrowserActionUI(wins[0].id) // test that we can specify a page (should be 404 though!) // chrome.braveShields.openBrowserActionUI(wins[0].id, 'another.html) }) // Test that we can call in the 'active' window (e.g. if the call is made from NTP, which is the intention for rewards). Run this command then switch focus to an actual browser window for the profile. // setTimeout(() => chrome.braveShields.openBrowserActionUI('popup.html?grant-id=42'), 2000) // And with the default popup html // setTimeout(() => chrome.braveShields.openBrowserActionUI(), 2000) ``` Then create or open another profile at the same time, and verify that calling the API from one profile cannot open a popup in a window id from another profile. Also check that the API works for the other profile.
194a65f
to
73e30e9
Compare
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.
rewards code looks good
CI still shows all tests passed even though ultimate status is the grey circle. Merging. |
Any uplifts should also include:
Introduces
chrome.{ braveRewards, braveShields }.openBrowserActionUI(optional windowId, optional relativePath)
.Several upcoming features require being able to summon a dialog attached to Shields or Rewards icons from some other user action that is not clicking on the icon buttons (the only current way to open the dialogs). These features include:
• Offering to bypass paywalls (Publisher Access Pass)
• Offering to turn shields off (Webcompat detection)
• Offering to opt-in to Rewards or complete a Rewards captcha
The API allows a custom path to be sent to open a specific HTML page other than the one configured for the active tab, e.g. offer-paywall.html, solve-captcha.html etc
The API will default to the current window for the profile, which only works when called from a WebUI page. When called from a background script, a windowId will need to be provided so that the popup is shown on a compatible active or recently-active window (and not, e.g., a devtools window).
This was prototyped for the Publisher Access Pass concept at #3565 and modified for this PR to use the Observer pattern.
If there is a webui page which has access to chrome.braveShields or chrome.braveRewards API, then simply call
chrome.brave{Shields | Rewards}.openBrowserActionUI()
andchrome.brave{Shields | Rewards}.openBrowserActionUI('fake-page.html)
to test. A popup should open on the current windowSecurity / Permissions
The use of the target extension ID coming from the
ExtensionFunction
means that only contexts which are granted access to an extension's overall API will have permission to open that extension's popup from code.Test Plan
Open chrome://inspect, switch to the Extensions tab, and inspect either the Rewards or Brave extension. Then use the following API calls, one at a time (uncomment the line you wish to run):
Then create or open another profile at the same time, and verify that calling the API from one profile cannot open a popup in a window id from another profile.
Also check that the API works for the other profile.
Fix brave/brave-browser#6419
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Reviewer Checklist:
After-merge Checklist:
changes has landed on.