Commit 947a73c8 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert DistillabilityService client to use BrowserInterfaceBroker

This change converts DistillabilityService mojom interface client in
components to use BrowserInterfaceBroker. Since DistillabilityDriver
is a WebContentsObserver, a static helper function is used to register
its binder.

Bug: 936482,1006361
Change-Id: If92c3a6f3aede131beff7a0f943bb9a2e4df157b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1889275
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712824}
parent fc65dfd9
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "components/autofill/content/common/mojom/autofill_driver.mojom.h" #include "components/autofill/content/common/mojom/autofill_driver.mojom.h"
#include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h" #include "components/contextual_search/content/common/mojom/contextual_search_js_api_service.mojom.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy.mojom.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy.mojom.h"
#include "components/dom_distiller/content/common/mojom/distillability_service.mojom.h"
#include "components/dom_distiller/content/common/mojom/distiller_javascript_service.mojom.h" #include "components/dom_distiller/content/common/mojom/distiller_javascript_service.mojom.h"
#include "components/metrics/public/mojom/call_stack_profile_collector.mojom.h" #include "components/metrics/public/mojom/call_stack_profile_collector.mojom.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h" #include "components/page_load_metrics/common/page_load_metrics.mojom.h"
...@@ -160,7 +159,6 @@ const service_manager::Manifest& GetChromeContentBrowserOverlayManifest() { ...@@ -160,7 +159,6 @@ const service_manager::Manifest& GetChromeContentBrowserOverlayManifest() {
cros::mojom::CameraAppDeviceProvider, cros::mojom::CameraAppDeviceProvider,
#endif #endif
contextual_search::mojom::ContextualSearchJsApiService, contextual_search::mojom::ContextualSearchJsApiService,
dom_distiller::mojom::DistillabilityService,
dom_distiller::mojom::DistillerJavaScriptService, dom_distiller::mojom::DistillerJavaScriptService,
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
extensions::KeepAlive, extensions::KeepAlive,
......
...@@ -81,6 +81,7 @@ include_rules = [ ...@@ -81,6 +81,7 @@ include_rules = [
"+components/device_event_log", "+components/device_event_log",
"+components/domain_reliability", "+components/domain_reliability",
"+components/dom_distiller/content/browser", "+components/dom_distiller/content/browser",
"+components/dom_distiller/content/common",
"+components/dom_distiller/core", "+components/dom_distiller/core",
"+components/dom_distiller/webui", "+components/dom_distiller/webui",
"+components/download/content/factory", "+components/download/content/factory",
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "chrome/browser/navigation_predictor/navigation_predictor.h" #include "chrome/browser/navigation_predictor/navigation_predictor.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h" #include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h"
#include "components/dom_distiller/content/browser/distillability_driver.h"
#include "components/dom_distiller/content/common/mojom/distillability_service.mojom.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -71,6 +73,18 @@ void BindImageAnnotator( ...@@ -71,6 +73,18 @@ void BindImageAnnotator(
->BindImageAnnotator(std::move(receiver)); ->BindImageAnnotator(std::move(receiver));
} }
void BindDistillabilityService(
content::RenderFrameHost* const frame_host,
mojo::PendingReceiver<dom_distiller::mojom::DistillabilityService>
receiver) {
dom_distiller::DistillabilityDriver* driver =
dom_distiller::DistillabilityDriver::FromWebContents(
content::WebContents::FromRenderFrameHost(frame_host));
if (!driver)
return;
driver->CreateDistillabilityService(std::move(receiver));
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
template <typename Interface> template <typename Interface>
void ForwardToJavaWebContents(content::RenderFrameHost* frame_host, void ForwardToJavaWebContents(content::RenderFrameHost* frame_host,
...@@ -102,6 +116,9 @@ void PopulateChromeFrameBinders( ...@@ -102,6 +116,9 @@ void PopulateChromeFrameBinders(
map->Add<blink::mojom::InsecureInputService>( map->Add<blink::mojom::InsecureInputService>(
base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver)); base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver));
map->Add<dom_distiller::mojom::DistillabilityService>(
base::BindRepeating(&BindDistillabilityService));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
map->Add<blink::mojom::InstalledAppProvider>(base::BindRepeating( map->Add<blink::mojom::InstalledAppProvider>(base::BindRepeating(
&ForwardToJavaFrame<blink::mojom::InstalledAppProvider>)); &ForwardToJavaFrame<blink::mojom::InstalledAppProvider>));
......
...@@ -50,9 +50,6 @@ DistillabilityDriver::DistillabilityDriver(content::WebContents* web_contents) ...@@ -50,9 +50,6 @@ DistillabilityDriver::DistillabilityDriver(content::WebContents* web_contents)
latest_result_(base::nullopt) { latest_result_(base::nullopt) {
if (!web_contents) if (!web_contents)
return; return;
frame_interfaces_.AddInterface(
base::BindRepeating(&DistillabilityDriver::CreateDistillabilityService,
base::Unretained(this)));
} }
DistillabilityDriver::~DistillabilityDriver() { DistillabilityDriver::~DistillabilityDriver() {
...@@ -79,13 +76,6 @@ void DistillabilityDriver::OnDistillability( ...@@ -79,13 +76,6 @@ void DistillabilityDriver::OnDistillability(
observer.OnResult(result); observer.OnResult(result);
} }
void DistillabilityDriver::OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
frame_interfaces_.TryBindInterface(interface_name, interface_pipe);
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(DistillabilityDriver) WEB_CONTENTS_USER_DATA_KEY_IMPL(DistillabilityDriver)
} // namespace dom_distiller } // namespace dom_distiller
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace dom_distiller { namespace dom_distiller {
...@@ -34,12 +33,6 @@ class DistillabilityDriver ...@@ -34,12 +33,6 @@ class DistillabilityDriver
return latest_result_; return latest_result_;
} }
// content::WebContentsObserver implementation.
void OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
private: private:
explicit DistillabilityDriver(content::WebContents* web_contents); explicit DistillabilityDriver(content::WebContents* web_contents);
friend class content::WebContentsUserData<DistillabilityDriver>; friend class content::WebContentsUserData<DistillabilityDriver>;
...@@ -55,8 +48,6 @@ class DistillabilityDriver ...@@ -55,8 +48,6 @@ class DistillabilityDriver
// new page, accounting for same-document navigation. // new page, accounting for same-document navigation.
base::Optional<DistillabilityResult> latest_result_; base::Optional<DistillabilityResult> latest_result_;
service_manager::BinderRegistry frame_interfaces_;
base::WeakPtrFactory<DistillabilityDriver> weak_factory_{this}; base::WeakPtrFactory<DistillabilityDriver> weak_factory_{this};
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "components/dom_distiller/core/url_utils.h" #include "components/dom_distiller/core/url_utils.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/web_distillability.h" #include "third_party/blink/public/platform/web_distillability.h"
#include "third_party/blink/public/web/web_document.h" #include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_element.h"
...@@ -259,7 +259,7 @@ void DistillabilityAgent::DidMeaningfulLayout( ...@@ -259,7 +259,7 @@ void DistillabilityAgent::DidMeaningfulLayout(
bool is_last = IsLast(is_loaded); bool is_last = IsLast(is_loaded);
// Connect to Mojo service on browser to notify page distillability. // Connect to Mojo service on browser to notify page distillability.
mojo::Remote<mojom::DistillabilityService> distillability_service; mojo::Remote<mojom::DistillabilityService> distillability_service;
render_frame()->GetRemoteInterfaces()->GetInterface( render_frame()->GetBrowserInterfaceBroker()->GetInterface(
distillability_service.BindNewPipeAndPassReceiver()); distillability_service.BindNewPipeAndPassReceiver());
if (!distillability_service.is_bound()) if (!distillability_service.is_bound())
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment