Skip to content

Commit

Permalink
Eliminate RenderFrame::GetInterfaceRegistry()'
Browse files Browse the repository at this point in the history
R=rockot@chromium.org

Change-Id: Ice65be679658f544f46e1906b79642de5f337d67
Reviewed-on: https://chromium-review.googlesource.com/580789
Commit-Queue: Ben Goodger <ben@chromium.org>
Reviewed-by: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#489127}
  • Loading branch information
Ben Goodger authored and Commit Bot committed Jul 24, 2017
1 parent 471aa60 commit d5ee3cc
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 45 deletions.
10 changes: 8 additions & 2 deletions chrome/renderer/chrome_render_frame_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ ChromeRenderFrameObserver::ChromeRenderFrameObserver(
: content::RenderFrameObserver(render_frame),
translate_helper_(nullptr),
phishing_classifier_(nullptr) {
render_frame->GetInterfaceRegistry()->AddInterface(
registry_.AddInterface(
base::Bind(&ChromeRenderFrameObserver::OnImageContextMenuRendererRequest,
base::Unretained(this)));
render_frame->GetInterfaceRegistry()->AddInterface(
registry_.AddInterface(
base::Bind(&ChromeRenderFrameObserver::OnThumbnailCapturerRequest,
base::Unretained(this)));

Expand All @@ -145,6 +145,12 @@ ChromeRenderFrameObserver::ChromeRenderFrameObserver(
ChromeRenderFrameObserver::~ChromeRenderFrameObserver() {
}

void ChromeRenderFrameObserver::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

bool ChromeRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
// Filter only.
bool handled = true;
Expand Down
6 changes: 6 additions & 0 deletions chrome/renderer/chrome_render_frame_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "chrome/common/thumbnail_capturer.mojom.h"
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"

namespace gfx {
class Size;
Expand Down Expand Up @@ -39,6 +40,9 @@ class ChromeRenderFrameObserver
enum TextCaptureType { PRELIMINARY_CAPTURE, FINAL_CAPTURE };

// RenderFrameObserver implementation.
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
bool OnMessageReceived(const IPC::Message& message) override;
void DidStartProvisionalLoad(blink::WebDataSource* data_source) override;
void DidFinishLoad() override;
Expand Down Expand Up @@ -93,6 +97,8 @@ class ChromeRenderFrameObserver
mojo::BindingSet<chrome::mojom::ThumbnailCapturer>
thumbnail_capturer_bindings_;

service_manager::BinderRegistry registry_;

DISALLOW_COPY_AND_ASSIGN(ChromeRenderFrameObserver);
};

Expand Down
8 changes: 7 additions & 1 deletion chrome/renderer/content_settings_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ContentSettingsObserver::ContentSettingsObserver(
ClearBlockedContentSettings();
render_frame->GetWebFrame()->SetContentSettingsClient(this);

render_frame->GetInterfaceRegistry()->AddInterface(
registry_.AddInterface(
base::Bind(&ContentSettingsObserver::OnInsecureContentRendererRequest,
base::Unretained(this)));

Expand Down Expand Up @@ -160,6 +160,12 @@ void ContentSettingsObserver::DidBlockContentType(
}
}

void ContentSettingsObserver::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
Expand Down
6 changes: 6 additions & 0 deletions chrome/renderer/content_settings_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "content/public/renderer/render_frame_observer_tracker.h"
#include "extensions/features/features.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/platform/WebContentSettingsClient.h"
#include "url/gurl.h"

Expand Down Expand Up @@ -95,6 +96,9 @@ class ContentSettingsObserver
FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, PluginsTemporarilyAllowed);

// RenderFrameObserver implementation.
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
bool OnMessageReceived(const IPC::Message& message) override;
void DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_document_navigation) override;
Expand Down Expand Up @@ -170,6 +174,8 @@ class ContentSettingsObserver
mojo::BindingSet<chrome::mojom::InsecureContentRenderer>
insecure_content_renderer_bindings_;

service_manager::BinderRegistry registry_;

DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
};

Expand Down
9 changes: 7 additions & 2 deletions components/autofill/content/renderer/autofill_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ AutofillAgent::AutofillAgent(content::RenderFrame* render_frame,
render_frame->GetWebFrame()->SetAutofillClient(this);
password_autofill_agent->SetAutofillAgent(this);

// AutofillAgent is guaranteed to outlive |render_frame|.
render_frame->GetInterfaceRegistry()->AddInterface(
registry_.AddInterface(
base::Bind(&AutofillAgent::BindRequest, base::Unretained(this)));
}

Expand All @@ -178,6 +177,12 @@ bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs,
std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag);
}

void AutofillAgent::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_document_navigation) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
Expand Down
6 changes: 6 additions & 0 deletions components/autofill/content/renderer/autofill_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "components/autofill/content/renderer/page_click_tracker.h"
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebAutofillClient.h"
#include "third_party/WebKit/public/web/WebFormControlElement.h"
#include "third_party/WebKit/public/web/WebFormElement.h"
Expand Down Expand Up @@ -131,6 +132,9 @@ class AutofillAgent : public content::RenderFrameObserver,
};

// content::RenderFrameObserver:
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_document_navigation) override;
void DidFinishDocumentLoad() override;
Expand Down Expand Up @@ -292,6 +296,8 @@ class AutofillAgent : public content::RenderFrameObserver,

mojom::AutofillDriverPtr autofill_driver_;

service_manager::BinderRegistry registry_;

base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,7 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame)
checked_safe_browsing_reputation_(false),
binding_(this),
form_element_observer_(nullptr) {
// PasswordAutofillAgent is guaranteed to outlive |render_frame|.
render_frame->GetInterfaceRegistry()->AddInterface(
registry_.AddInterface(
base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this)));
}

Expand Down Expand Up @@ -1282,6 +1281,12 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
}
}

void PasswordAutofillAgent::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void PasswordAutofillAgent::DidFinishDocumentLoad() {
// The |frame| contents have been parsed, but not yet rendered. Let the
// PasswordManager know that forms are loaded, even though we can't yet tell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_view_observer.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebInputElement.h"

namespace blink {
Expand Down Expand Up @@ -201,6 +202,9 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
};

// RenderFrameObserver:
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void DidFinishDocumentLoad() override;
void DidFinishLoad() override;
void FrameDetached() override;
Expand Down Expand Up @@ -312,6 +316,8 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,

blink::WebFormElementObserver* form_element_observer_;

service_manager::BinderRegistry registry_;

DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ PasswordGenerationAgent::PasswordGenerationAgent(
password_agent_(password_agent),
binding_(this) {
LogBoolean(Logger::STRING_GENERATION_RENDERER_ENABLED, enabled_);
// PasswordGenerationAgent is guaranteed to outlive |render_frame|.
render_frame->GetInterfaceRegistry()->AddInterface(base::Bind(
&PasswordGenerationAgent::BindRequest, base::Unretained(this)));
registry_.AddInterface(base::Bind(&PasswordGenerationAgent::BindRequest,
base::Unretained(this)));
}
PasswordGenerationAgent::~PasswordGenerationAgent() {}

Expand All @@ -178,6 +177,12 @@ void PasswordGenerationAgent::BindRequest(
binding_.Bind(std::move(request));
}

void PasswordGenerationAgent::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void PasswordGenerationAgent::DidFinishDocumentLoad() {
// Update stats for main frame navigation.
if (!render_frame()->GetWebFrame()->Parent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "components/autofill/content/renderer/renderer_save_password_progress_logger.h"
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "url/gurl.h"

Expand Down Expand Up @@ -87,6 +88,9 @@ class PasswordGenerationAgent : public content::RenderFrameObserver,
typedef std::vector<AccountCreationFormData> AccountCreationFormDataList;

// RenderFrameObserver:
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void DidFinishDocumentLoad() override;
void DidFinishLoad() override;
void OnDestruct() override;
Expand Down Expand Up @@ -193,6 +197,8 @@ class PasswordGenerationAgent : public content::RenderFrameObserver,

mojo::Binding<mojom::PasswordGenerationAgent> binding_;

service_manager::BinderRegistry registry_;

DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ OverlayJsRenderFrameObserver::OverlayJsRenderFrameObserver(

OverlayJsRenderFrameObserver::~OverlayJsRenderFrameObserver() {}

void OverlayJsRenderFrameObserver::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void OverlayJsRenderFrameObserver::DidStartProvisionalLoad(
blink::WebDataSource* data_source) {
RegisterMojoInterface();
}

void OverlayJsRenderFrameObserver::RegisterMojoInterface() {
render_frame()->GetInterfaceRegistry()->AddInterface(base::Bind(
registry_.AddInterface(base::Bind(
&OverlayJsRenderFrameObserver::CreateOverlayPageNotifierService,
weak_factory_.GetWeakPtr()));
}
Expand Down Expand Up @@ -62,11 +68,7 @@ void OverlayJsRenderFrameObserver::DidFinishLoad() {
}

void OverlayJsRenderFrameObserver::DestroyOverlayPageNotifierService() {
if (render_frame()) {
render_frame()
->GetInterfaceRegistry()
->RemoveInterface<mojom::OverlayPageNotifierService>();
}
registry_.RemoveInterface<mojom::OverlayPageNotifierService>();
}

void OverlayJsRenderFrameObserver::OnDestruct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "components/contextual_search/common/overlay_page_notifier_service.mojom.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "v8/include/v8.h"

Expand All @@ -25,6 +26,9 @@ class OverlayJsRenderFrameObserver : public content::RenderFrameObserver {
~OverlayJsRenderFrameObserver() override;

// RenderFrameObserver implementation.
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void DidStartProvisionalLoad(blink::WebDataSource* data_source) override;
void DidClearWindowObject() override;
void DidFinishLoad() override;
Expand All @@ -49,6 +53,8 @@ class OverlayJsRenderFrameObserver : public content::RenderFrameObserver {
// Track if the current page is presented in the contextual search overlay.
bool is_contextual_search_overlay_;

service_manager::BinderRegistry registry_;

base::WeakPtrFactory<OverlayJsRenderFrameObserver> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(OverlayJsRenderFrameObserver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ DistillerJsRenderFrameObserver::DistillerJsRenderFrameObserver(

DistillerJsRenderFrameObserver::~DistillerJsRenderFrameObserver() {}

void DistillerJsRenderFrameObserver::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void DistillerJsRenderFrameObserver::DidStartProvisionalLoad(
blink::WebDataSource* data_source) {
RegisterMojoInterface();
Expand All @@ -36,9 +42,7 @@ void DistillerJsRenderFrameObserver::DidFinishLoad() {
// If no message about the distilled page was received at this point, there
// will not be one; remove the mojom::DistillerPageNotifierService from the
// registry.
render_frame()
->GetInterfaceRegistry()
->RemoveInterface<mojom::DistillerPageNotifierService>();
registry_.RemoveInterface<mojom::DistillerPageNotifierService>();
}

void DistillerJsRenderFrameObserver::DidCreateScriptContext(
Expand All @@ -54,7 +58,7 @@ void DistillerJsRenderFrameObserver::DidCreateScriptContext(
}

void DistillerJsRenderFrameObserver::RegisterMojoInterface() {
render_frame()->GetInterfaceRegistry()->AddInterface(base::Bind(
registry_.AddInterface(base::Bind(
&DistillerJsRenderFrameObserver::CreateDistillerPageNotifierService,
weak_factory_.GetWeakPtr()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "components/dom_distiller/content/renderer/distiller_page_notifier_service_impl.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "v8/include/v8.h"

Expand All @@ -27,6 +28,9 @@ class DistillerJsRenderFrameObserver : public content::RenderFrameObserver {
~DistillerJsRenderFrameObserver() override;

// RenderFrameObserver implementation.
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void DidStartProvisionalLoad(blink::WebDataSource* data_source) override;
void DidFinishLoad() override;
void DidCreateScriptContext(v8::Local<v8::Context> context,
Expand All @@ -51,6 +55,8 @@ class DistillerJsRenderFrameObserver : public content::RenderFrameObserver {
// Track if the current page is distilled. This is needed for testing.
bool is_distiller_page_;

service_manager::BinderRegistry registry_;

// Handle to "distiller" JavaScript object functionality.
std::unique_ptr<DistillerNativeJavaScript> native_javascript_handle_;
base::WeakPtrFactory<DistillerJsRenderFrameObserver> weak_factory_;
Expand Down
10 changes: 8 additions & 2 deletions components/spellcheck/renderer/spellcheck_panel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ SpellCheckPanel::SpellCheckPanel(content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame),
spelling_panel_visible_(false) {
DCHECK(render_frame);
render_frame->GetInterfaceRegistry()->AddInterface(base::Bind(
&SpellCheckPanel::SpellCheckPanelRequest, base::Unretained(this)));
registry_.AddInterface(base::Bind(&SpellCheckPanel::SpellCheckPanelRequest,
base::Unretained(this)));
render_frame->GetWebFrame()->SetSpellCheckPanelHostClient(this);
}

SpellCheckPanel::~SpellCheckPanel() = default;

void SpellCheckPanel::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void SpellCheckPanel::OnDestruct() {
delete this;
}
Expand Down
Loading

0 comments on commit d5ee3cc

Please sign in to comment.