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

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: not using NPAPI bindings anymore, yay! Created 5 years, 7 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 "base/command_line.h"
10 #include "content/public/child/v8_value_converter.h" 11 #include "content/public/child/v8_value_converter.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/renderer/render_frame.h"
11 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
12 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_messages.h" 16 #include "extensions/common/extension_messages.h"
17 #include "extensions/common/guest_view/extensions_guest_view_messages.h"
14 #include "extensions/common/guest_view/guest_view_constants.h" 18 #include "extensions/common/guest_view/guest_view_constants.h"
15 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" 19 #include "extensions/renderer/guest_view/extensions_guest_view_container.h"
16 #include "extensions/renderer/script_context.h" 20 #include "extensions/renderer/script_context.h"
17 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 23 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
19 #include "third_party/WebKit/public/web/WebView.h" 24 #include "third_party/WebKit/public/web/WebView.h"
20 #include "v8/include/v8.h" 25 #include "v8/include/v8.h"
21 26
22 using content::V8ValueConverter; 27 using content::V8ValueConverter;
23 28
24 namespace extensions { 29 namespace extensions {
25 30
31 namespace {
32
33 content::RenderFrame* GetRenderFrame(v8::Handle<v8::Value> value) {
34 v8::Local<v8::Context> context =
35 v8::Local<v8::Object>::Cast(value)->CreationContext();
36 if (context.IsEmpty())
37 return nullptr;
38 blink::WebLocalFrame* frame = blink::WebLocalFrame::frameForContext(context);
39 if (!frame)
40 return nullptr;
41 return content::RenderFrame::FromWebFrame(frame);
42 }
43
44 } // namespace
45
26 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( 46 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings(
27 ScriptContext* context) 47 ScriptContext* context)
28 : ObjectBackedNativeHandler(context) { 48 : ObjectBackedNativeHandler(context) {
29 RouteFunction("AttachGuest", 49 RouteFunction("AttachGuest",
30 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, 50 base::Bind(&GuestViewInternalCustomBindings::AttachGuest,
31 base::Unretained(this))); 51 base::Unretained(this)));
32 RouteFunction("DetachGuest", 52 RouteFunction("DetachGuest",
33 base::Bind(&GuestViewInternalCustomBindings::DetachGuest, 53 base::Bind(&GuestViewInternalCustomBindings::DetachGuest,
34 base::Unretained(this))); 54 base::Unretained(this)));
35 RouteFunction("GetContentWindow", 55 RouteFunction("GetContentWindow",
36 base::Bind(&GuestViewInternalCustomBindings::GetContentWindow, 56 base::Bind(&GuestViewInternalCustomBindings::GetContentWindow,
37 base::Unretained(this))); 57 base::Unretained(this)));
38 RouteFunction( 58 RouteFunction(
39 "RegisterDestructionCallback", 59 "RegisterDestructionCallback",
40 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, 60 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback,
41 base::Unretained(this))); 61 base::Unretained(this)));
42 RouteFunction( 62 RouteFunction(
43 "RegisterElementResizeCallback", 63 "RegisterElementResizeCallback",
44 base::Bind( 64 base::Bind(
45 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, 65 &GuestViewInternalCustomBindings::RegisterElementResizeCallback,
46 base::Unretained(this))); 66 base::Unretained(this)));
47 RouteFunction( 67 RouteFunction(
48 "RunWithGesture", 68 "RunWithGesture",
49 base::Bind(&GuestViewInternalCustomBindings::RunWithGesture, 69 base::Bind(&GuestViewInternalCustomBindings::RunWithGesture,
50 base::Unretained(this))); 70 base::Unretained(this)));
71 RouteFunction("AttachIframeGuest",
72 base::Bind(&GuestViewInternalCustomBindings::AttachIframeGuest,
73 base::Unretained(this)));
74 // TODO(lazyboy): There must be a better way to query command line from JS.
75 RouteFunction("IsSitePerProcess",
76 base::Bind(&GuestViewInternalCustomBindings::IsSitePerProcess,
77 base::Unretained(this)));
51 } 78 }
52 79
53 void GuestViewInternalCustomBindings::AttachGuest( 80 void GuestViewInternalCustomBindings::AttachGuest(
54 const v8::FunctionCallbackInfo<v8::Value>& args) { 81 const v8::FunctionCallbackInfo<v8::Value>& args) {
55 // Allow for an optional callback parameter. 82 // Allow for an optional callback parameter.
56 CHECK(args.Length() >= 3 && args.Length() <= 4); 83 CHECK(args.Length() >= 3 && args.Length() <= 4);
57 // Element Instance ID. 84 // Element Instance ID.
58 CHECK(args[0]->IsInt32()); 85 CHECK(args[0]->IsInt32());
59 // Guest Instance ID. 86 // Guest Instance ID.
60 CHECK(args[1]->IsInt32()); 87 CHECK(args[1]->IsInt32());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void GuestViewInternalCustomBindings::RunWithGesture( 230 void GuestViewInternalCustomBindings::RunWithGesture(
204 const v8::FunctionCallbackInfo<v8::Value>& args) { 231 const v8::FunctionCallbackInfo<v8::Value>& args) {
205 // Gesture is required to request fullscreen. 232 // Gesture is required to request fullscreen.
206 blink::WebScopedUserGesture user_gesture; 233 blink::WebScopedUserGesture user_gesture;
207 CHECK_EQ(args.Length(), 1); 234 CHECK_EQ(args.Length(), 1);
208 CHECK(args[0]->IsFunction()); 235 CHECK(args[0]->IsFunction());
209 v8::Local<v8::Value> no_args; 236 v8::Local<v8::Value> no_args;
210 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); 237 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args);
211 } 238 }
212 239
240 void GuestViewInternalCustomBindings::AttachIframeGuest(
241 const v8::FunctionCallbackInfo<v8::Value>& args) {
242 // Allow for an optional callback parameter.
243 const int num_required_params = 3;
244 CHECK(args.Length() >= num_required_params &&
245 args.Length() <= (num_required_params + 1));
246 // Element Instance ID.
247 CHECK(args[0]->IsInt32());
248 // Guest Instance ID.
249 CHECK(args[1]->IsInt32());
250 // <iframe>.contentWindow.
251 CHECK(args[2]->IsObject());
252 // Optional Callback Function.
253 CHECK(args.Length() <= num_required_params ||
254 args[num_required_params]->IsFunction());
255 LOG(WARNING) << "has_callback: "
256 << (args.Length() >= (num_required_params + 1));
257
258 int element_instance_id = args[0]->Int32Value();
259 int guest_instance_id = args[1]->Int32Value();
260 LOG(WARNING) << "guest_instance_id: " << guest_instance_id
261 << "element_instance_id: " << element_instance_id;
262
263 content::RenderFrame* render_frame = GetRenderFrame(args[2]);
264 blink::WebLocalFrame* frame = render_frame->GetWebFrame();
265
266 // Parent must exist.
267 blink::WebFrame* parent_frame = frame->parent();
268 DCHECK(parent_frame);
269 DCHECK(parent_frame->isWebLocalFrame());
270
271 render_frame->Send(new ExtensionsGuestViewHostMsg_AttachToEmbedderFrame(
272 render_frame->GetRoutingID(), element_instance_id, guest_instance_id));
273 content::RenderFrame* embedder_parent_frame =
274 content::RenderFrame::FromWebFrame(parent_frame);
275
276 // Create a GuestViewContainer if it does not exist.
277 ExtensionsGuestViewContainer* guest_view_container =
278 ExtensionsGuestViewContainer::FromID(element_instance_id);
279 // This is the first time we hear about the |element_instance_id|.
280 DCHECK(!guest_view_container);
281 // TODO(lazyboy): Leaked, make this render_frame observer and destruct.
282 guest_view_container =
283 new extensions::ExtensionsGuestViewContainer(embedder_parent_frame);
284 guest_view_container->SetElementInstanceID(element_instance_id);
285
286 linked_ptr<ExtensionsGuestViewContainer::Request> request(
287 new ExtensionsGuestViewContainer::AttachIframeRequest(
288 guest_view_container, guest_instance_id,
289 args.Length() == 4 ? args[3].As<v8::Function>()
290 : v8::Handle<v8::Function>(),
291 args.GetIsolate()));
292 guest_view_container->IssueRequest(request);
293
294 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
295
296 LOG(WARNING) << "AttachLocalFrameToGuest complete";
297 }
298
299 void GuestViewInternalCustomBindings::IsSitePerProcess(
300 const v8::FunctionCallbackInfo<v8::Value>& args) {
301 bool is_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch(
302 switches::kSitePerProcess);
303 args.GetReturnValue().Set(
304 v8::Boolean::New(context()->isolate(), is_site_per_process));
305 }
306
213 } // namespace extensions 307 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698