Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Unified Diff: content/public/renderer/render_frame.h

Issue 2310563002: Adds routed interface support between RenderFrameHost and RenderFrame (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/renderer/BUILD.gn ('k') | content/public/renderer/render_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/renderer/render_frame.h
diff --git a/content/public/renderer/render_frame.h b/content/public/renderer/render_frame.h
index 0ac29c8eecdab5aaa8ebc77b1f0e2422197520f6..da0b809abe8b5f2407fecc494a1e7c2d9c5010a1 100644
--- a/content/public/renderer/render_frame.h
+++ b/content/public/renderer/render_frame.h
@@ -13,8 +13,12 @@
#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "content/public/common/console_message_level.h"
+#include "content/public/renderer/render_thread.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
+#include "ipc/ipc_sync_channel.h"
+#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
+#include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
@@ -155,6 +159,23 @@ class CONTENT_EXPORT RenderFrame : public IPC::Listener,
// interfaces exposed to it by the application running in this frame.
virtual shell::InterfaceProvider* GetRemoteInterfaces() = 0;
+ using GenericRoutedInterfaceFactory =
+ base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
+
+ // Adds an associated interface factory to this frame, allowing the remote
+ // RenderFrameHost to acquire a proxy to the interface on this specific frame.
+ virtual void AddRoutedInterface(
tibell 2016/09/05 00:32:13 It's a bit unfortunate that we couldn't instead ha
+ const base::StringPiece& name,
+ const GenericRoutedInterfaceFactory& factory) = 0;
+
+ virtual void RemoveRoutedInterface(const base::StringPiece& name) = 0;
+
+ // Binds an interface proxy to be associated with the remote RenderFrameHost
+ // in the browser process.
+ virtual void GetRemoteRoutedInterface(
+ const base::StringPiece& name,
+ mojo::ScopedInterfaceEndpointHandle handle) = 0;
+
#if defined(ENABLE_PLUGINS)
// Registers a plugin that has been marked peripheral. If the origin
// whitelist is later updated and includes |content_origin|, then
@@ -229,13 +250,50 @@ class CONTENT_EXPORT RenderFrame : public IPC::Listener,
// Returns the current visibility of the frame.
virtual blink::WebPageVisibilityState GetVisibilityState() const = 0;
+ template <typename Interface>
+ void GetRemoteRoutedInterface(
+ mojo::AssociatedInterfacePtr<Interface>* proxy) {
+ IPC::ChannelProxy* channel = RenderThread::Get()->GetChannel();
+
+ // Tests may not have a channel set up. Since they clearly don't expect IPC
+ // to work, we can bind these interface requests to dead-ends.
+ if (!channel) {
+ mojo::GetDummyProxy(proxy);
+ return;
+ }
+
+ mojo::AssociatedInterfaceRequest<Interface> request = mojo::GetProxy(
+ proxy, channel->GetAssociatedGroup());
+ GetRemoteRoutedInterface(Interface::Name_, request.PassHandle());
+ }
+
+ template <typename Interface>
+ using RoutedInterfaceFactory =
+ base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>;
+
+ template <typename Interface>
+ void AddRoutedInterface(const RoutedInterfaceFactory<Interface>& factory) {
+ AddRoutedInterface(Interface::Name_,
+ base::Bind(&BindRoutedInterface<Interface>, factory));
+ }
+
protected:
~RenderFrame() override {}
private:
// This interface should only be implemented inside content.
friend class RenderFrameImpl;
+
RenderFrame() {}
+
+ template <typename Interface>
+ static void BindRoutedInterface(
+ const RoutedInterfaceFactory<Interface>& factory,
+ mojo::ScopedInterfaceEndpointHandle handle) {
+ mojo::AssociatedInterfaceRequest<Interface> request;
+ request.Bind(std::move(handle));
+ factory.Run(std::move(request));
+ }
};
} // namespace content
« no previous file with comments | « content/public/renderer/BUILD.gn ('k') | content/public/renderer/render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698