-
Notifications
You must be signed in to change notification settings - Fork 921
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
Create site hacks network delegate helper #68
Conversation
I'm still working on a test for the above, you can review before but I'll do the test before merging. |
Test pushed, ready for review. |
This re-uses the static network redirect helper class for both the profile network delegate and the system network delegate.
Allows a list of hosts to be redirected to empty data URLs. The list is initially: - sp1.nypost.com - sp.nasdaq.com
Matches requests for Google tag manager and Google tag services, and uses our polyfill instead.
Creates a different network delegate helper so the system one is not re-used. This is for 2 reasons: 1) To avoid accidentally leaking things like geolocation redirects to the profile network context. 2) To not need to slow down the system network context with other site hacks meant for the profile network context.
Allows the SiteHacks delegate to block things. These should eventually be moved to the ad-block lists, but for now I'm just porting things 1:1 from browser-laptop.
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 we discussed on Slack, this needed a rebase to pick up some of the recent rename-related changes. With the rebase, I am able to run yarn test brave_unit_tests
successfully.
The code looks good and the new tests look great. LGTM, I mentioned some concerns/nits in line comments but they do not need to block merge.
str.append(": noopthisfn, updateCorrelator: noopfn }; var SizeMappingBuilder = function() { }; p = SizeMappingBuilder.prototype; p.addSize = noopthisfn; p.build = noopnullfn; var Slot = function() { }; p = Slot.prototype; p.addService = noopthisfn; p.clearCategoryExclusions = noopthisfn; p.clearTargeting = noopthisfn; p.defineSizeMapping = noopthisfn; p.get = noopnullfn; p.getAdUnitPath = nooparrayfn; p.getAttributeKeys = nooparrayfn; p.getCategoryExclusions = nooparrayfn; p.getDomId = noopstrfn; p.getSlot"); | ||
str.append("ElementId = noopstrfn; p.getSlotId = noopthisfn; p.getTargeting = nooparrayfn; p.getTargetingKeys = nooparrayfn; p.set = noopthisfn; p.setCategoryExclusion = noopthisfn; p.setClickUrl = noopthisfn; p.setCollapseEmptyDiv = noopthisfn; p.setTargeting = noopthisfn; var gpt = window.googletag || {}; window.googletag.destroySlots = function () { }; var cmd = gpt.cmd || []; gpt.apiReady = true; gpt.cmd = []; gpt.cmd.push = function(a) { try { a(); } catch (ex) { } return 1; }; gpt.companionAds = func"); | ||
str.append("tion() { return companionAdsService; }; gpt.content = function() { return contentService; }; gpt.defineOutOfPageSlot = function() { return new Slot(); }; gpt.defineSlot = function() { return new Slot(); }; gpt.disablePublisherConsole = noopfn; gpt.display = noopfn; gpt.enableServices = noopfn; gpt.getVersion = noopstrfn; gpt.pubads = function() { return pubAdsService; }; gpt.pubadsReady = true; gpt.sizeMapping = function() { return new SizeMappingBuilder(); }; window.googletag = gpt; while ( cm"); | ||
str.append("d.length !== 0 ) { gpt.cmd.push(cmd.shift()); } })();"); |
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.
It's too bad C++ doesn't have something akin to Rust's include_str!
(as far as I know). Perhaps GN has something that can help us out with including large strings like this. I think all these str.append
s are fine for now, but may be difficult to maintain over time.
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 getting this script from file in resource pak?
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.
That's a great idea. I won't block on it but I"ll do it in this new issue I just posted:
brave/brave-browser#128
str.append("d.length !== 0 ) { gpt.cmd.push(cmd.shift()); } })();"); | ||
base64_output.reserve(4668); | ||
Base64UrlEncode(str, base::Base64UrlEncodePolicy::OMIT_PADDING, &base64_output); | ||
base64_output= std::string(kJSDataURLPrefix) + base64_output; |
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: space before =
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.
will fix before landing, thx.
Thanks for the review.
The old branch was also runnable on its own, but I rebased for ease of testing. As long as it's buildable in general though on its own with init and build, rebases are not required because otherwise it'll take up everyone's time constantly rebasing with scale. |
We probably have some more work to do on the tooling, because I think the sync that you did didn't reset things properly. Maybe because using the different repo name in DEPS, it probably doesn't have proper support for that. |
#ifndef BRAVE_BROWSER_NET_BRAVE_SITE_HACKS_NETWORK_DELEGATE_H_ | ||
#define BRAVE_BROWSER_NET_BRAVE_SITE_HACKS_NETWORK_DELEGATE_H_ | ||
|
||
#include "chrome/browser/net/chrome_network_delegate.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.
nit: this header can be removed
#include "extensions/common/url_pattern.h" | ||
#include "net/url_request/url_request.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.
nit: two blank lines
Or did you add one more line intentionally?
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.
We need to introduce .cc linting soon. Ya I did it intentionally but I see now most chromium files do not do that. I'll update before merging this.
Add scope to methods which modify content settings
Implements some of the needed site-hacks from browser-laptop.
Implements these site hacks as a new network delegate helper.
This partially implements the following issue: brave/brave-browser#84.
An alternate strategy for this task using an extension was considered and partially implemented in this branch:
site-hacks-extension
, but we aren't sure if we'll have support for extensions in Android yet, and it seemed easy enough to do these via C++.In this PR:
www.googletagservices.com/tag/js/gpt.js
http://www.googletagmanager.com/gtm.js
https://www.lesechos.fr/xtcore.js
https://*.y8.com/js/sdkloader/outstream.js
In a follow up PRs: