diff options
Diffstat (limited to 'extensions/renderer/guest_view')
-rw-r--r-- | extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc | 30 | ||||
-rw-r--r-- | extensions/renderer/guest_view/guest_view_internal_custom_bindings.h | 4 |
2 files changed, 34 insertions, 0 deletions
diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc index ff18e04..a57f454 100644 --- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc +++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc @@ -14,6 +14,8 @@ #include "extensions/common/guest_view/guest_view_constants.h" #include "extensions/renderer/guest_view/extensions_guest_view_container.h" #include "extensions/renderer/script_context.h" +#include "third_party/WebKit/public/web/WebFrame.h" +#include "third_party/WebKit/public/web/WebView.h" #include "v8/include/v8.h" using content::V8ValueConverter; @@ -29,6 +31,9 @@ GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( RouteFunction("DetachGuest", base::Bind(&GuestViewInternalCustomBindings::DetachGuest, base::Unretained(this))); + RouteFunction("GetContentWindow", + base::Bind(&GuestViewInternalCustomBindings::GetContentWindow, + base::Unretained(this))); RouteFunction( "RegisterDestructionCallback", base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, @@ -122,6 +127,31 @@ void GuestViewInternalCustomBindings::DetachGuest( args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); } +void GuestViewInternalCustomBindings::GetContentWindow( + const v8::FunctionCallbackInfo<v8::Value>& args) { + // Default to returning null. + args.GetReturnValue().SetNull(); + + if (args.Length() != 1) + return; + + // The routing ID for the RenderView. + if (!args[0]->IsInt32()) + return; + + int view_id = args[0]->Int32Value(); + if (view_id == MSG_ROUTING_NONE) + return; + + content::RenderView* view = content::RenderView::FromRoutingID(view_id); + if (!view) + return; + + blink::WebFrame* frame = view->GetWebView()->mainFrame(); + v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); + args.GetReturnValue().Set(window); +} + void GuestViewInternalCustomBindings::RegisterDestructionCallback( const v8::FunctionCallbackInfo<v8::Value>& args) { // There are two parameters. diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h index 0c29435..2c19137 100644 --- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h +++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h @@ -40,6 +40,10 @@ class GuestViewInternalCustomBindings : public ObjectBackedNativeHandler { // been detached. void DetachGuest(const v8::FunctionCallbackInfo<v8::Value>& args); + // GetContentWindow takes in a RenderView routing ID and returns the + // Window JavaScript object for that RenderView. + void GetContentWindow(const v8::FunctionCallbackInfo<v8::Value>& args); + // RegisterDestructionCallback registers a JavaScript callback function to be // called when the guestview's container is destroyed. // RegisterDestructionCallback takes in a single paramater, |callback|. |