diff --git a/app/DEPS b/app/DEPS index cd14d0934dda..59cadf9818bb 100644 --- a/app/DEPS +++ b/app/DEPS @@ -28,7 +28,6 @@ include_rules = [ "+components/sync/base/command_line_switches.h", "+components/translate/core/browser/translate_prefs.h", "+components/variations/variations_switches.h", - "+components/dom_distiller/core/dom_distiller_switches.h", "+google_apis/gaia", "+gpu/config", "+media/base/media_switches.h", diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index 53f425707f9f..a3afbc159be9 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -29,7 +29,6 @@ #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_switches.h" #include "components/component_updater/component_updater_switches.h" -#include "components/dom_distiller/core/dom_distiller_switches.h" #include "components/embedder_support/switches.h" #include "components/sync/base/command_line_switches.h" #include "components/variations/variations_switches.h" diff --git a/browser/brave_ads/ads_service_factory.cc b/browser/brave_ads/ads_service_factory.cc index 40d4a5140ca7..b148ebfe33d4 100644 --- a/browser/brave_ads/ads_service_factory.cc +++ b/browser/brave_ads/ads_service_factory.cc @@ -17,7 +17,6 @@ #include "brave/components/brave_federated/brave_federated_service.h" #include "brave/components/brave_federated/data_store_service.h" #include "brave/components/brave_federated/notification_ad_task_constants.h" -#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/notifications/notification_display_service_factory.h" #include "chrome/browser/profiles/incognito_helpers.h" @@ -47,7 +46,6 @@ AdsServiceFactory::AdsServiceFactory() "AdsService", BrowserContextDependencyManager::GetInstance()) { DependsOn(NotificationDisplayServiceFactory::GetInstance()); - DependsOn(dom_distiller::DomDistillerServiceFactory::GetInstance()); DependsOn(brave_rewards::RewardsServiceFactory::GetInstance()); DependsOn(HistoryServiceFactory::GetInstance()); DependsOn(brave_federated::BraveFederatedServiceFactory::GetInstance()); diff --git a/browser/brave_ads/ads_tab_helper.cc b/browser/brave_ads/ads_tab_helper.cc index 18f222ef34cb..aab358d9c8fa 100644 --- a/browser/brave_ads/ads_tab_helper.cc +++ b/browser/brave_ads/ads_tab_helper.cc @@ -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[] = + 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(*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) { diff --git a/browser/brave_ads/ads_tab_helper.h b/browser/brave_ads/ads_tab_helper.h index 88c28f9be70e..bb05bc72c666 100644 --- a/browser/brave_ads/ads_tab_helper.h +++ b/browser/brave_ads/ads_tab_helper.h @@ -23,16 +23,6 @@ class Browser; class GURL; -namespace dom_distiller { - -class DistillerPage; - -namespace proto { -class DomDistillerResult; -} // namespace proto - -} // namespace dom_distiller - namespace brave_ads { class AdsService; diff --git a/browser/brave_ads/sources.gni b/browser/brave_ads/sources.gni index 470a9f7b92f0..eaa06e47ed97 100644 --- a/browser/brave_ads/sources.gni +++ b/browser/brave_ads/sources.gni @@ -39,7 +39,6 @@ brave_browser_brave_ads_deps = [ "//chrome/browser/profiles", "//chrome/browser/profiles:profile", "//chrome/browser/ui", - "//components/dom_distiller/content/browser", "//components/history/core/browser", "//components/keyed_service/content", "//components/sessions", diff --git a/browser/sources.gni b/browser/sources.gni index 7d55f2323b0b..a3d61f8d29c2 100644 --- a/browser/sources.gni +++ b/browser/sources.gni @@ -197,7 +197,6 @@ brave_chrome_browser_deps = [ "//components/content_settings/browser", "//components/content_settings/core/browser", "//components/content_settings/core/common", - "//components/dom_distiller/core", "//components/embedder_support", "//components/feed/core/shared_prefs:feed_shared_prefs", "//components/gcm_driver:gcm_buildflags", diff --git a/chromium_src/chrome/app/BUILD.gn b/chromium_src/chrome/app/BUILD.gn index 8c84d523038a..83ad81f582c0 100644 --- a/chromium_src/chrome/app/BUILD.gn +++ b/chromium_src/chrome/app/BUILD.gn @@ -6,6 +6,7 @@ group("app") { deps = [ "//brave/components/update_client:buildflags", + "//components/dom_distiller/content/browser", "//google_apis", "//media", ] diff --git a/chromium_src/chrome/app/DEPS b/chromium_src/chrome/app/DEPS index a5120c9cdd35..ca4730af0363 100644 --- a/chromium_src/chrome/app/DEPS +++ b/chromium_src/chrome/app/DEPS @@ -11,6 +11,7 @@ specific_include_rules = { "+brave/build/android/jni_headers/BraveQAPreferences_jni.h", "+brave/components/brave_sync/buildflags.h", "+brave/components/variations/buildflags.h", + "+components/dom_distiller/core/dom_distiller_switches.h", "+components/signin/public/base/account_consistency_method.h", "+components/sync/base/command_line_switches.h", ], diff --git a/chromium_src/chrome/app/chrome_main_delegate.cc b/chromium_src/chrome/app/chrome_main_delegate.cc index 1f1e3cdb7233..653900af06cf 100644 --- a/chromium_src/chrome/app/chrome_main_delegate.cc +++ b/chromium_src/chrome/app/chrome_main_delegate.cc @@ -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 ChromeMainDelegate::BasicStartupComplete() { BraveCommandLineHelper command_line(base::CommandLine::ForCurrentProcess()); command_line.AppendSwitch(switches::kDisableDomainReliability); diff --git a/patches/components-dom_distiller-content-browser-distiller_page_web_contents.cc.patch b/patches/components-dom_distiller-content-browser-distiller_page_web_contents.cc.patch deleted file mode 100644 index d6ae444f3cb4..000000000000 --- a/patches/components-dom_distiller-content-browser-distiller_page_web_contents.cc.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/components/dom_distiller/content/browser/distiller_page_web_contents.cc b/components/dom_distiller/content/browser/distiller_page_web_contents.cc -index e4025f7bc94c0ecaac4032900200a8caef39079b..6302a7a8cc28fa14d42ae04d1c8b734fc0991494 100644 ---- a/components/dom_distiller/content/browser/distiller_page_web_contents.cc -+++ b/components/dom_distiller/content/browser/distiller_page_web_contents.cc -@@ -164,7 +164,9 @@ void DistillerPageWebContents::ExecuteJavaScript() { - content::WebContentsObserver::Observe(nullptr); - // Stop any pending navigation since the intent is to distill the current - // page. -+ if (source_page_handle_->web_contents()->GetDelegate() == this) - source_page_handle_->web_contents()->Stop(); -+ - DVLOG(1) << "Beginning distillation"; - RunIsolatedJavaScript( - &TargetRenderFrameHost(), script_,