OLD | NEW |
---|---|
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" |
21 #include "third_party/WebKit/public/web/WebBindings.h" | |
22 #include "third_party/WebKit/public/web/WebElement.h" | |
17 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
25 #include "third_party/WebKit/public/web/WebNode.h" | |
26 #include "third_party/WebKit/public/web/WebRemoteFrame.h" | |
18 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 27 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
19 #include "third_party/WebKit/public/web/WebView.h" | 28 #include "third_party/WebKit/public/web/WebView.h" |
20 #include "v8/include/v8.h" | 29 #include "v8/include/v8.h" |
21 | 30 |
22 using content::V8ValueConverter; | 31 using content::V8ValueConverter; |
23 | 32 |
24 namespace extensions { | 33 namespace extensions { |
25 | 34 |
26 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( | 35 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( |
27 ScriptContext* context) | 36 ScriptContext* context) |
(...skipping 13 matching lines...) Expand all Loading... | |
41 base::Unretained(this))); | 50 base::Unretained(this))); |
42 RouteFunction( | 51 RouteFunction( |
43 "RegisterElementResizeCallback", | 52 "RegisterElementResizeCallback", |
44 base::Bind( | 53 base::Bind( |
45 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, | 54 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, |
46 base::Unretained(this))); | 55 base::Unretained(this))); |
47 RouteFunction( | 56 RouteFunction( |
48 "RunWithGesture", | 57 "RunWithGesture", |
49 base::Bind(&GuestViewInternalCustomBindings::RunWithGesture, | 58 base::Bind(&GuestViewInternalCustomBindings::RunWithGesture, |
50 base::Unretained(this))); | 59 base::Unretained(this))); |
60 RouteFunction("AttachIframeGuest", | |
61 base::Bind(&GuestViewInternalCustomBindings::AttachIframeGuest, | |
62 base::Unretained(this))); | |
63 // TODO(lazyboy): There must be a better way to query command line from JS. | |
64 RouteFunction("IsSitePerProcess", | |
65 base::Bind(&GuestViewInternalCustomBindings::IsSitePerProcess, | |
66 base::Unretained(this))); | |
51 } | 67 } |
52 | 68 |
53 void GuestViewInternalCustomBindings::AttachGuest( | 69 void GuestViewInternalCustomBindings::AttachGuest( |
54 const v8::FunctionCallbackInfo<v8::Value>& args) { | 70 const v8::FunctionCallbackInfo<v8::Value>& args) { |
55 // Allow for an optional callback parameter. | 71 // Allow for an optional callback parameter. |
56 CHECK(args.Length() >= 3 && args.Length() <= 4); | 72 CHECK(args.Length() >= 3 && args.Length() <= 4); |
57 // Element Instance ID. | 73 // Element Instance ID. |
58 CHECK(args[0]->IsInt32()); | 74 CHECK(args[0]->IsInt32()); |
59 // Guest Instance ID. | 75 // Guest Instance ID. |
60 CHECK(args[1]->IsInt32()); | 76 CHECK(args[1]->IsInt32()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 void GuestViewInternalCustomBindings::RunWithGesture( | 222 void GuestViewInternalCustomBindings::RunWithGesture( |
207 const v8::FunctionCallbackInfo<v8::Value>& args) { | 223 const v8::FunctionCallbackInfo<v8::Value>& args) { |
208 // Gesture is required to request fullscreen. | 224 // Gesture is required to request fullscreen. |
209 blink::WebScopedUserGesture user_gesture; | 225 blink::WebScopedUserGesture user_gesture; |
210 CHECK_EQ(args.Length(), 1); | 226 CHECK_EQ(args.Length(), 1); |
211 CHECK(args[0]->IsFunction()); | 227 CHECK(args[0]->IsFunction()); |
212 v8::Handle<v8::Value> no_args; | 228 v8::Handle<v8::Value> no_args; |
213 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 0, &no_args); | 229 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 0, &no_args); |
214 } | 230 } |
215 | 231 |
232 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.
| |
233 NPVariant result; | |
234 blink::WebBindings::toNPVariant(value, NULL, &result); | |
235 if (result.type != NPVariantType_Object) { | |
236 return false; | |
237 } | |
238 NPObject* obj = result.value.objectValue; | |
239 return blink::WebBindings::getNode(obj, node); | |
240 } | |
241 | |
242 void GuestViewInternalCustomBindings::AttachIframeGuest( | |
243 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
244 // Allow for an optional callback parameter. | |
245 CHECK(args.Length() >= 4 && args.Length() <= 5); | |
246 // Element Instance ID. | |
247 CHECK(args[0]->IsInt32()); | |
248 // Guest Instance ID. | |
249 CHECK(args[1]->IsInt32()); | |
250 // Node. | |
251 CHECK(args[2]->IsObject()); | |
252 // Optional Callback Function. | |
253 CHECK(args.Length() < 4 || args[3]->IsFunction()); | |
254 LOG(WARNING) << "has_callback: " << (args.Length() >= 4); | |
255 | |
256 int element_instance_id = args[0]->Int32Value(); | |
257 int guest_instance_id = args[1]->Int32Value(); | |
258 LOG(WARNING) << "guest_instance_id: " << guest_instance_id << | |
259 "element_instance_id: " << element_instance_id; | |
260 | |
261 blink::WebNode node; | |
262 bool got_webnode = GetWebNodeFromValue(args[2], &node); | |
263 CHECK(got_webnode); | |
264 blink::WebElement element = node.to<blink::WebElement>(); | |
265 blink::WebLocalFrame* frame = | |
266 blink::WebLocalFrame::fromFrameOwnerElement(element); | |
267 DCHECK(frame); | |
268 content::RenderFrame* render_frame = | |
269 content::RenderFrame::FromWebFrame(frame); | |
270 | |
271 // Parent must exist. | |
272 blink::WebFrame* parent_frame = frame->parent(); | |
273 DCHECK(parent_frame); | |
274 DCHECK(parent_frame->isWebLocalFrame()); | |
275 | |
276 render_frame->Send( | |
277 new ExtensionsGuestViewHostMsg_AttachLocalFrameToGuest( | |
278 render_frame->GetRoutingID(), | |
279 element_instance_id, | |
280 guest_instance_id)); | |
281 content::RenderFrame* embedder_parent_frame = | |
282 content::RenderFrame::FromWebFrame(parent_frame); | |
283 | |
284 // Create a GuestViewContainer if it does not exist. | |
285 ExtensionsGuestViewContainer* guest_view_container = | |
286 ExtensionsGuestViewContainer::FromID(element_instance_id); | |
287 // This is the first time we hear about the |element_instance_id|. | |
288 DCHECK(!guest_view_container); | |
289 // TODO(lazyboy): Leaked, make this render_frame observer and destruct. | |
290 guest_view_container = new extensions::ExtensionsGuestViewContainer( | |
291 embedder_parent_frame); | |
292 guest_view_container->SetElementInstanceID(element_instance_id); | |
293 | |
294 linked_ptr<ExtensionsGuestViewContainer::Request> request( | |
295 new ExtensionsGuestViewContainer::AttachIframeRequest( | |
296 guest_view_container, | |
297 guest_instance_id, | |
298 args.Length() == 4 ? args[3].As<v8::Function>() : | |
299 v8::Handle<v8::Function>(), | |
300 args.GetIsolate())); | |
301 guest_view_container->IssueRequest(request); | |
302 | |
303 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | |
304 | |
305 LOG(WARNING) << "AttachLocalFrameToGuest complete"; | |
306 } | |
307 | |
308 void GuestViewInternalCustomBindings::IsSitePerProcess( | |
309 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
310 bool is_site_per_process = | |
311 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
312 switches::kSitePerProcess); | |
313 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), | |
314 is_site_per_process)); | |
315 } | |
316 | |
216 } // namespace extensions | 317 } // namespace extensions |
OLD | NEW |