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

Side by Side Diff: extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc

Issue 972313002: Make <webview> use out-of-process iframe architecture. (Closed) Base URL: ssh://saopaulo.wat/mnt/dev/shared/src@testoopif2z-better-chrome
Patch Set: Revert unused changes from previous attempt + more cleanup. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h" 5 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/public/child/v8_value_converter.h" 10 #include "content/public/child/v8_value_converter.h"
11 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_messages.h" 13 #include "extensions/common/extension_messages.h"
14 #include "extensions/common/guest_view/guest_view_messages.h"
14 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" 15 #include "extensions/renderer/guest_view/extensions_guest_view_container.h"
15 #include "extensions/renderer/script_context.h" 16 #include "extensions/renderer/script_context.h"
16 #include "v8/include/v8.h" 17 #include "v8/include/v8.h"
18 #include "third_party/WebKit/public/web/WebBindings.h"
19 #include "third_party/WebKit/public/web/WebElement.h"
20 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebLocalFrame.h"
22 #include "third_party/WebKit/public/web/WebRemoteFrame.h"
23 #include "third_party/WebKit/public/web/WebNode.h"
24 #include "content/public/renderer/render_frame.h"
17 25
18 using content::V8ValueConverter; 26 using content::V8ValueConverter;
19 27
20 namespace extensions { 28 namespace extensions {
21 29
22 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( 30 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings(
23 ScriptContext* context) 31 ScriptContext* context)
24 : ObjectBackedNativeHandler(context) { 32 : ObjectBackedNativeHandler(context) {
25 RouteFunction("AttachGuest", 33 RouteFunction("AttachGuest",
26 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, 34 base::Bind(&GuestViewInternalCustomBindings::AttachGuest,
27 base::Unretained(this))); 35 base::Unretained(this)));
28 RouteFunction("DetachGuest", 36 RouteFunction("DetachGuest",
29 base::Bind(&GuestViewInternalCustomBindings::DetachGuest, 37 base::Bind(&GuestViewInternalCustomBindings::DetachGuest,
30 base::Unretained(this))); 38 base::Unretained(this)));
31 RouteFunction( 39 RouteFunction(
32 "RegisterDestructionCallback", 40 "RegisterDestructionCallback",
33 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, 41 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback,
34 base::Unretained(this))); 42 base::Unretained(this)));
35 RouteFunction( 43 RouteFunction(
36 "RegisterElementResizeCallback", 44 "RegisterElementResizeCallback",
37 base::Bind( 45 base::Bind(
38 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, 46 &GuestViewInternalCustomBindings::RegisterElementResizeCallback,
39 base::Unretained(this))); 47 base::Unretained(this)));
48
49 RouteFunction("AttachIframeGuest",
50 base::Bind(&GuestViewInternalCustomBindings::AttachIframeGuest,
51 base::Unretained(this)));
40 } 52 }
41 53
42 void GuestViewInternalCustomBindings::AttachGuest( 54 void GuestViewInternalCustomBindings::AttachGuest(
43 const v8::FunctionCallbackInfo<v8::Value>& args) { 55 const v8::FunctionCallbackInfo<v8::Value>& args) {
44 // Allow for an optional callback parameter. 56 // Allow for an optional callback parameter.
45 CHECK(args.Length() >= 3 && args.Length() <= 4); 57 CHECK(args.Length() >= 3 && args.Length() <= 4);
46 // Element Instance ID. 58 // Element Instance ID.
47 CHECK(args[0]->IsInt32()); 59 CHECK(args[0]->IsInt32());
48 // Guest Instance ID. 60 // Guest Instance ID.
49 CHECK(args[1]->IsInt32()); 61 CHECK(args[1]->IsInt32());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ExtensionsGuestViewContainer::FromID(element_instance_id); 168 ExtensionsGuestViewContainer::FromID(element_instance_id);
157 if (!guest_view_container) 169 if (!guest_view_container)
158 return; 170 return;
159 171
160 guest_view_container->RegisterElementResizeCallback( 172 guest_view_container->RegisterElementResizeCallback(
161 args[1].As<v8::Function>(), args.GetIsolate()); 173 args[1].As<v8::Function>(), args.GetIsolate());
162 174
163 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); 175 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
164 } 176 }
165 177
178 bool GetWebNodeFromValue(v8::Handle<v8::Value> value, blink::WebNode* node) {
Fady Samuel 2015/03/04 20:44:47 This can't use NPAPI. That code is deprecated. Is
179 NPVariant result;
180 blink::WebBindings::toNPVariant(value, NULL, &result);
181 if (result.type != NPVariantType_Object) {
182 return false;
183 }
184 NPObject* obj = result.value.objectValue;
185 return blink::WebBindings::getNode(obj, node);
186 }
187
188 void GuestViewInternalCustomBindings::AttachIframeGuest(
189 const v8::FunctionCallbackInfo<v8::Value>& args) {
190 // Allow for an optional callback parameter.
191 CHECK(args.Length() >= 4 && args.Length() <= 5);
192 // Element Instance ID.
193 CHECK(args[0]->IsInt32());
194 // Guest Instance ID.
195 CHECK(args[1]->IsInt32());
196 // Node.
197 CHECK(args[2]->IsObject());
198 // Optional Callback Function.
199 CHECK(args.Length() < 4 || args[3]->IsFunction());
200 LOG(INFO) << "has_callback: " << (args.Length() >= 4);
201
202 int element_instance_id = args[0]->Int32Value();
203 int guest_instance_id = args[1]->Int32Value();
204 LOG(INFO) << "guest_instance_id: " << guest_instance_id <<
205 "element_instance_id: " << element_instance_id;
206
207 blink::WebNode node;
208 bool got_webnode = GetWebNodeFromValue(args[2], &node);
209 CHECK(got_webnode);
210 blink::WebElement element = node.to<blink::WebElement>();
211 blink::WebLocalFrame* frame =
212 blink::WebLocalFrame::fromFrameOwnerElement(element);
213 DCHECK(frame);
214 content::RenderFrame* render_frame =
215 content::RenderFrame::FromWebFrame(frame);
216
217 // Parent must exist.
218 blink::WebFrame* parent_frame = frame->parent();
219 DCHECK(parent_frame);
220 DCHECK(parent_frame->isWebLocalFrame());
221
222 render_frame->Send(
223 new GuestViewHostMsg_AttachLocalFrameToGuest(
224 render_frame->GetRoutingID(),
225 element_instance_id,
226 guest_instance_id));
227 content::RenderFrame* embedder_parent_frame =
228 content::RenderFrame::FromWebFrame(parent_frame);
229
230 // Create a GuestViewContainer if it does not exist.
231 ExtensionsGuestViewContainer* guest_view_container =
232 ExtensionsGuestViewContainer::FromID(element_instance_id);
233 // This is the first time we hear about the |element_instance_id|.
234 DCHECK(!guest_view_container);
235 // TODO(lazyboy): Leaked, make this render_frame observer and destruct.
236 guest_view_container = new extensions::ExtensionsGuestViewContainer(
Fady Samuel 2015/03/04 20:44:47 The container should self-destruct.
237 embedder_parent_frame);
238 guest_view_container->SetElementInstanceID(element_instance_id);
239
240 linked_ptr<ExtensionsGuestViewContainer::Request> request(
241 new ExtensionsGuestViewContainer::AttachIframeRequest(
242 guest_view_container,
243 guest_instance_id,
244 args.Length() == 4 ? args[3].As<v8::Function>() :
245 v8::Handle<v8::Function>(),
246 args.GetIsolate()));
247 guest_view_container->IssueRequest(request);
248
249 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
250
251 LOG(INFO) << "AttachLocalFrameToGuest complete";
252 }
253
166 } // namespace extensions 254 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698