-
Notifications
You must be signed in to change notification settings - Fork 895
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
Remove dom_distiller dependency from BraveAds #17366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,7 @@ | |
|
||
#include "brave/browser/brave_ads/ads_service_factory.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/dom_distiller/content/browser/distiller_javascript_utils.h" | ||
#include "components/dom_distiller/content/browser/distiller_page_web_contents.h" | ||
#include "chrome/common/chrome_isolated_world_ids.h" | ||
#include "components/sessions/content/session_tab_helper.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
|
@@ -27,6 +26,15 @@ | |
|
||
namespace brave_ads { | ||
|
||
namespace { | ||
|
||
constexpr char16_t kGetDocumentHTMLScript[] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're injecting this into every page? This seems like a probable perf issue, but what exactly are we using this for anyway? If the purpose of this is to get page content, this is definitely not what we should be doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this appears to be happening even if ads is disabled? |
||
u"new XMLSerializer().serializeToString(document)"; | ||
|
||
constexpr char16_t kGetInnerTextScript[] = u"document?.body?.innerText"; | ||
|
||
} // namespace | ||
|
||
AdsTabHelper::AdsTabHelper(content::WebContents* web_contents) | ||
: WebContentsObserver(web_contents), | ||
content::WebContentsUserData<AdsTabHelper>(*web_contents), | ||
|
@@ -67,15 +75,17 @@ void AdsTabHelper::RunIsolatedJavaScript( | |
content::RenderFrameHost* render_frame_host) { | ||
DCHECK(render_frame_host); | ||
|
||
dom_distiller::RunIsolatedJavaScript( | ||
render_frame_host, "new XMLSerializer().serializeToString(document)", | ||
render_frame_host->ExecuteJavaScriptInIsolatedWorld( | ||
kGetDocumentHTMLScript, | ||
base::BindOnce(&AdsTabHelper::OnJavaScriptHtmlResult, | ||
weak_factory_.GetWeakPtr())); | ||
weak_factory_.GetWeakPtr()), | ||
ISOLATED_WORLD_ID_BRAVE_INTERNAL); | ||
|
||
dom_distiller::RunIsolatedJavaScript( | ||
render_frame_host, "document?.body?.innerText", | ||
render_frame_host->ExecuteJavaScriptInIsolatedWorld( | ||
kGetInnerTextScript, | ||
base::BindOnce(&AdsTabHelper::OnJavaScriptTextResult, | ||
weak_factory_.GetWeakPtr())); | ||
weak_factory_.GetWeakPtr()), | ||
ISOLATED_WORLD_ID_BRAVE_INTERNAL); | ||
} | ||
|
||
void AdsTabHelper::OnJavaScriptHtmlResult(base::Value value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#include "brave/components/brave_sync/buildflags.h" | ||
#include "brave/components/variations/buildflags.h" | ||
#include "build/build_config.h" | ||
#include "components/dom_distiller/core/dom_distiller_switches.h" | ||
#include "components/sync/base/command_line_switches.h" | ||
|
||
#if BUILDFLAG(IS_ANDROID) | ||
|
@@ -52,12 +53,6 @@ void AdjustSyncServiceUrlForAndroid(std::string* brave_sync_service_url) { | |
// Because of that, upstream tests won't get BraveMainDelegate instantiated and | ||
// therefore we won't get any of the features below disabled/enabled when | ||
// running those browser tests, which is not what we want. | ||
// | ||
// For instance, on DCHECK-enabled builds, not enabling the DOM distiller will | ||
// get all browser tests crashing when dom_distiller::RunIsolatedJavaScript() | ||
// gets called from AdsTabHelper::RunIsolatedJavaScript() (called via the | ||
// WebContentsObserver machinery), since the JS World ID won't be set yet when | ||
// dom_distiller::RunIsolatedJavaScript() gets called. | ||
absl::optional<int> ChromeMainDelegate::BasicStartupComplete() { | ||
BraveCommandLineHelper command_line(base::CommandLine::ForCurrentProcess()); | ||
command_line.AppendSwitch(switches::kDisableDomainReliability); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried, but removing this line hides the speed-reader icon in Brave. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats because we have |
||
|
This file was deleted.
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.
@boocmp fyi