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

Move Greaselion handling into Brave extension #6978

Merged
merged 2 commits into from
Nov 11, 2020

Conversation

emerick
Copy link
Contributor

@emerick emerick commented Oct 28, 2020

Resolves brave/brave-browser#12307
Resolves brave/brave-browser#6462

Related Greaselion PR: brave/brave-site-specific-scripts#25

Submitter Checklist:

Test Plan:

Rewards panel test

  • Clean profile
  • Start the browser
  • Verify that you have the latest Greaselion scripts installed (brave://components)
  • Visit a publisher (e.g., http://twitter.com/emerick)
  • Verify that Rewards panel shows expected publisher info
  • Verify that tipping from panel works

Tipping test

  • Clean profile
  • Start the browser
  • Verify that you have the latest Greaselion scripts installed (brave://components)
  • Visit a publisher (e.g., http://twitter.com/emerick)
  • Verify that inline tipping works as expected

Extension test

  • Clean profile
  • Start the browser
  • Verify that only Brave extension is running (brave://inspect -> Extensions)
  • Visit a publisher (e.g., http://twitter.com/emerick)
  • Still only Brave extension running
  • Verify that showing panel or clicking inline tip starts the Rewards extension

Ideally, this should be tested for all of our supported publishers. In addition, we should verify that this works with YouTube on 1.16.

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.

@emerick emerick self-assigned this Oct 28, 2020
@emerick emerick force-pushed the rewards-greaselion-brave-extension branch 3 times, most recently from 057ec27 to 43d7afe Compare October 29, 2020 21:10
@emerick emerick marked this pull request as ready for review October 30, 2020 12:26
@emerick emerick requested a review from a team as a code owner October 30, 2020 12:26
@emerick emerick force-pushed the rewards-greaselion-brave-extension branch 5 times, most recently from e0e044c to a35628d Compare November 2, 2020 22:47
Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

inline tipping is not shown

@emerick emerick requested a review from NejcZdovc November 3, 2020 15:24
@emerick
Copy link
Contributor Author

emerick commented Nov 3, 2020

@NejcZdovc Fixed problem with Twitter inline tips not showing up (scripts need to handle readystatechange event, probably an oversight from splitting them out). Should be good for review again.

@emerick emerick force-pushed the rewards-greaselion-brave-extension branch 2 times, most recently from 86a8ee3 to cbb4d99 Compare November 6, 2020 19:52
@@ -400,8 +400,6 @@ void RewardsServiceImpl::OnPreferenceChanged(const std::string& key) {
return;
}

EnableGreaseLion();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be dangerous to do this in response to a preference change, as this currently ends up unloading and reinstalling the Greaselion extension yet leaves the related content script injected and in a non-functional state. It seemed odd that this preference callback was being called at all, but it's due to StateMigration::FreshInstall which sets the three inline tip preferences to true.

I think not calling this here is the safest way forward until/unless Greaselion is changed to be a bit smarter about how it handles this scenario. For the time being, we may want to suggest to the user that a browser restart is required when updating these settings.

@emerick
Copy link
Contributor Author

emerick commented Nov 6, 2020

@NejcZdovc Should be ready for review again. I left a comment regarding the fix I made. Open to other suggestions too, of course; it just seemed like the most expedient approach for 1.18.

@emerick emerick force-pushed the rewards-greaselion-brave-extension branch 3 times, most recently from 19a2739 to 220739b Compare November 10, 2020 17:42
Comment on lines +26 to +28
"ids": [
"*"
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't specify this, no extensions/apps will be able to communicate with the Brave extension per https://developer.chrome.com/extensions/manifest/externally_connectable

@emerick emerick force-pushed the rewards-greaselion-brave-extension branch from 220739b to 7755775 Compare November 10, 2020 19:46

chrome.runtime.onMessageExternal.addListener(
function (msg: any, sender: chrome.runtime.MessageSender, sendResponse: any) {
if (!msg) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to filter extensions here (e.g. filter for rewards extension or greaselion extensions), for security reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean similar to what we do in the onConnectExternal listener?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right - given that we have externally_connectable opened up, is there any way that some random extension could send a message through this listener?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will enter a follow-up issue to address this.

Copy link
Member

Choose a reason for hiding this comment

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

This will absolutely be required and needs to be uplifted to wherever this PR is ASAP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, will get it in tomorrow.

@emerick emerick force-pushed the rewards-greaselion-brave-extension branch from 3ca3764 to dbd5a2d Compare November 10, 2020 23:06
@emerick emerick added CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS CI/skip-linux CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Nov 11, 2020
@emerick
Copy link
Contributor Author

emerick commented Nov 11, 2020

CI had expected test failures on Mac and passed on all other platforms but Windows. Will restart for Windows.

@emerick emerick force-pushed the rewards-greaselion-brave-extension branch from dbd5a2d to 8c8562c Compare November 11, 2020 00:41
@emerick
Copy link
Contributor Author

emerick commented Nov 11, 2020

Windows CI passed.

@emerick emerick merged commit 6a02303 into master Nov 11, 2020
@emerick emerick deleted the rewards-greaselion-brave-extension branch November 11, 2020 04:04
@emerick emerick added this to the 1.18.x - Nightly milestone Nov 11, 2020
@emerick emerick removed CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS CI/skip-linux CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Nov 11, 2020
@@ -19,9 +19,13 @@
"web_accessible_resources": [
],
"background": {
"scripts": ["out/brave_extension_background.bundle.js"]
"scripts": ["out/brave_extension_background.bundle.js"],
"persistent": true
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? If it uses an API that needs the background script to be alive won't that just happen automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed by the webRequest API. I'm not sure if it will stay alive automatically, it's called out in the docs to make it persisent here: https://developers.chrome.com/extensions/background_pages ("The webRequest API is incompatible with non-persistent background pages.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publisher not obtained until rewards extension starts Make Brave Rewards extension non-persistent
4 participants