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

[WIP] Publisher access pass #3565

Closed
wants to merge 12 commits into from
Closed

[WIP] Publisher access pass #3565

wants to merge 12 commits into from

Conversation

petemill
Copy link
Member

Demo purposes. Not marked as draft in order to get CI builds.

petemill and others added 12 commits September 30, 2019 13:29
- Run some code when the page is loaded (now or future)
- Run some code when the URL changes via history.pushState / replaceState
- Run some code only when the page first becomes visible (in case the tab is loaded in the background)
- Generate random / semi-unique ID for inter-script communication
- Inject some code from content script to a document
- Wait for and get some global variable from the document to the content script
…ll, only use publisher-site-specific on-paywall-shown 'event'
…ss status between content-script and background script

For some reason I'm still keeping around content-script-paywall-bypass possibility, maybe we will have to do that in the future. Otherwise the reload could be done in background script immediately after doing the background-script-paywall-bypass.
@petemill petemill force-pushed the publisher-access-pass branch from ffda0bb to bf94520 Compare September 30, 2019 20:29
@petemill petemill added CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS CI/skip-linux labels Sep 30, 2019
petemill added a commit that referenced this pull request Oct 10, 2019
Introduces `chrome.{ braveRewards, braveShields }.openBrowserActionUI(optional tabId, 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 tab, which only works when called from a WebUI page. When called from a background script, a tabId 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.

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

Open chrome://inspect, switch to the Extensions tab, and inspect either the Rewards or Brave extension. Then use the following API calls:
```
const tabId = (await chrome.tabs.queryAsync({ active: true }))[0].id
chrome.braveShields.openBrowserActionUI(tabId)
```

```
const tabId = (await chrome.tabs.queryAsync({ active: true }))[0].id
chrome.braveShields.openBrowserActionUI(tabId, 'fake-page.html')
```
petemill added a commit to petemill/brave-core that referenced this pull request Oct 24, 2019
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 brave#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.
petemill added a commit that referenced this pull request Oct 24, 2019
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.
@NejcZdovc
Copy link
Contributor

@petemill do we still need this one can we close it and reopen it later if needed?

@bsclifton
Copy link
Member

bsclifton commented Nov 18, 2019

@NejcZdovc I think it's safe to close 😄

I'll leave the branch as-is, just in case!

@bsclifton bsclifton closed this Nov 18, 2019
@bsclifton bsclifton deleted the publisher-access-pass branch November 10, 2023 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants