Chromium Code Reviews| Index: extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc | 
| 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 8bc2a2e83174b37f688553f4de785e89dc67f3ec..74d2089b278ba7e9f957b593f0677490859c9e5c 100644 | 
| --- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc | 
| +++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc | 
| @@ -7,14 +7,23 @@ | 
| #include <string> | 
| #include "base/bind.h" | 
| +#include "base/command_line.h" | 
| #include "content/public/child/v8_value_converter.h" | 
| +#include "content/public/common/content_switches.h" | 
| +#include "content/public/renderer/render_frame.h" | 
| #include "content/public/renderer/render_view.h" | 
| #include "extensions/common/extension.h" | 
| #include "extensions/common/extension_messages.h" | 
| +#include "extensions/common/guest_view/extensions_guest_view_messages.h" | 
| #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/WebBindings.h" | 
| +#include "third_party/WebKit/public/web/WebElement.h" | 
| #include "third_party/WebKit/public/web/WebFrame.h" | 
| +#include "third_party/WebKit/public/web/WebLocalFrame.h" | 
| +#include "third_party/WebKit/public/web/WebNode.h" | 
| +#include "third_party/WebKit/public/web/WebRemoteFrame.h" | 
| #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 
| #include "third_party/WebKit/public/web/WebView.h" | 
| #include "v8/include/v8.h" | 
| @@ -48,6 +57,13 @@ GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( | 
| "RunWithGesture", | 
| base::Bind(&GuestViewInternalCustomBindings::RunWithGesture, | 
| base::Unretained(this))); | 
| + RouteFunction("AttachIframeGuest", | 
| + base::Bind(&GuestViewInternalCustomBindings::AttachIframeGuest, | 
| + base::Unretained(this))); | 
| + // TODO(lazyboy): There must be a better way to query command line from JS. | 
| + RouteFunction("IsSitePerProcess", | 
| + base::Bind(&GuestViewInternalCustomBindings::IsSitePerProcess, | 
| + base::Unretained(this))); | 
| } | 
| void GuestViewInternalCustomBindings::AttachGuest( | 
| @@ -213,4 +229,89 @@ void GuestViewInternalCustomBindings::RunWithGesture( | 
| context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 0, &no_args); | 
| } | 
| +bool GetWebNodeFromValue(v8::Handle<v8::Value> value, blink::WebNode* node) { | 
| 
 
Fady Samuel
2015/04/28 17:56:11
This needs to change. This uses NPAPI code.
 
 | 
| + NPVariant result; | 
| + blink::WebBindings::toNPVariant(value, NULL, &result); | 
| + if (result.type != NPVariantType_Object) { | 
| + return false; | 
| + } | 
| + NPObject* obj = result.value.objectValue; | 
| + return blink::WebBindings::getNode(obj, node); | 
| +} | 
| + | 
| +void GuestViewInternalCustomBindings::AttachIframeGuest( | 
| + const v8::FunctionCallbackInfo<v8::Value>& args) { | 
| + // Allow for an optional callback parameter. | 
| + CHECK(args.Length() >= 4 && args.Length() <= 5); | 
| + // Element Instance ID. | 
| + CHECK(args[0]->IsInt32()); | 
| + // Guest Instance ID. | 
| + CHECK(args[1]->IsInt32()); | 
| + // Node. | 
| + CHECK(args[2]->IsObject()); | 
| + // Optional Callback Function. | 
| + CHECK(args.Length() < 4 || args[3]->IsFunction()); | 
| + LOG(WARNING) << "has_callback: " << (args.Length() >= 4); | 
| + | 
| + int element_instance_id = args[0]->Int32Value(); | 
| + int guest_instance_id = args[1]->Int32Value(); | 
| + LOG(WARNING) << "guest_instance_id: " << guest_instance_id << | 
| + "element_instance_id: " << element_instance_id; | 
| + | 
| + blink::WebNode node; | 
| + bool got_webnode = GetWebNodeFromValue(args[2], &node); | 
| + CHECK(got_webnode); | 
| + blink::WebElement element = node.to<blink::WebElement>(); | 
| + blink::WebLocalFrame* frame = | 
| + blink::WebLocalFrame::fromFrameOwnerElement(element); | 
| + DCHECK(frame); | 
| + content::RenderFrame* render_frame = | 
| + content::RenderFrame::FromWebFrame(frame); | 
| + | 
| + // Parent must exist. | 
| + blink::WebFrame* parent_frame = frame->parent(); | 
| + DCHECK(parent_frame); | 
| + DCHECK(parent_frame->isWebLocalFrame()); | 
| + | 
| + render_frame->Send( | 
| + new ExtensionsGuestViewHostMsg_AttachLocalFrameToGuest( | 
| + render_frame->GetRoutingID(), | 
| + element_instance_id, | 
| + guest_instance_id)); | 
| + content::RenderFrame* embedder_parent_frame = | 
| + content::RenderFrame::FromWebFrame(parent_frame); | 
| + | 
| + // Create a GuestViewContainer if it does not exist. | 
| + ExtensionsGuestViewContainer* guest_view_container = | 
| + ExtensionsGuestViewContainer::FromID(element_instance_id); | 
| + // This is the first time we hear about the |element_instance_id|. | 
| + DCHECK(!guest_view_container); | 
| + // TODO(lazyboy): Leaked, make this render_frame observer and destruct. | 
| + guest_view_container = new extensions::ExtensionsGuestViewContainer( | 
| + embedder_parent_frame); | 
| + guest_view_container->SetElementInstanceID(element_instance_id); | 
| + | 
| + linked_ptr<ExtensionsGuestViewContainer::Request> request( | 
| + new ExtensionsGuestViewContainer::AttachIframeRequest( | 
| + guest_view_container, | 
| + guest_instance_id, | 
| + args.Length() == 4 ? args[3].As<v8::Function>() : | 
| + v8::Handle<v8::Function>(), | 
| + args.GetIsolate())); | 
| + guest_view_container->IssueRequest(request); | 
| + | 
| + args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | 
| + | 
| + LOG(WARNING) << "AttachLocalFrameToGuest complete"; | 
| +} | 
| + | 
| +void GuestViewInternalCustomBindings::IsSitePerProcess( | 
| + const v8::FunctionCallbackInfo<v8::Value>& args) { | 
| + bool is_site_per_process = | 
| + base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess); | 
| + args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), | 
| + is_site_per_process)); | 
| +} | 
| + | 
| } // namespace extensions |