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

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

Powered by Google App Engine
This is Rietveld 408576698