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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "components/guest_view/common/guest_view_constants.h" | 11 #include "components/guest_view/common/guest_view_constants.h" |
12 #include "components/guest_view/common/guest_view_messages.h" | 12 #include "components/guest_view/common/guest_view_messages.h" |
13 #include "components/guest_view/renderer/guest_view_request.h" | 13 #include "components/guest_view/renderer/guest_view_request.h" |
14 #include "components/guest_view/renderer/iframe_guest_view_container.h" | 14 #include "components/guest_view/renderer/iframe_guest_view_container.h" |
15 #include "components/guest_view/renderer/iframe_guest_view_request.h" | 15 #include "components/guest_view/renderer/iframe_guest_view_request.h" |
16 #include "content/public/child/v8_value_converter.h" | 16 #include "content/public/child/v8_value_converter.h" |
17 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
18 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
19 #include "content/public/renderer/render_view.h" | 19 #include "content/public/renderer/render_view.h" |
20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_messages.h" | 21 #include "extensions/common/extension_messages.h" |
22 #include "extensions/common/guest_view/extensions_guest_view_messages.h" | 22 #include "extensions/common/guest_view/extensions_guest_view_messages.h" |
23 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" | 23 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" |
24 #include "extensions/renderer/script_context.h" | 24 #include "extensions/renderer/script_context.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
27 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 28 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
28 #include "third_party/WebKit/public/web/WebView.h" | 29 #include "third_party/WebKit/public/web/WebView.h" |
29 #include "v8/include/v8.h" | 30 #include "v8/include/v8.h" |
30 | 31 |
31 using content::V8ValueConverter; | 32 using content::V8ValueConverter; |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // A map from view instance ID to view object (stored via weak V8 reference). | 36 // A map from view instance ID to view object (stored via weak V8 reference). |
36 // Views are registered into this map via | 37 // Views are registered into this map via |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 308 |
308 int view_id = args[0]->Int32Value(); | 309 int view_id = args[0]->Int32Value(); |
309 if (view_id == MSG_ROUTING_NONE) | 310 if (view_id == MSG_ROUTING_NONE) |
310 return; | 311 return; |
311 | 312 |
312 content::RenderView* view = content::RenderView::FromRoutingID(view_id); | 313 content::RenderView* view = content::RenderView::FromRoutingID(view_id); |
313 if (!view) | 314 if (!view) |
314 return; | 315 return; |
315 | 316 |
316 blink::WebFrame* frame = view->GetWebView()->mainFrame(); | 317 blink::WebFrame* frame = view->GetWebView()->mainFrame(); |
317 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); | 318 // TODO(lazyboy,nasko): The WebLocalFrame branch is not used when running |
| 319 // on top of out-of-process iframes. Remove it once the code is converted. |
| 320 v8::Local<v8::Value> window; |
| 321 if (frame->isWebLocalFrame()) { |
| 322 window = frame->mainWorldScriptContext()->Global(); |
| 323 } else { |
| 324 window = |
| 325 frame->toWebRemoteFrame()->deprecatedMainWorldScriptContext()->Global(); |
| 326 } |
318 args.GetReturnValue().Set(window); | 327 args.GetReturnValue().Set(window); |
319 } | 328 } |
320 | 329 |
321 void GuestViewInternalCustomBindings::GetViewFromID( | 330 void GuestViewInternalCustomBindings::GetViewFromID( |
322 const v8::FunctionCallbackInfo<v8::Value>& args) { | 331 const v8::FunctionCallbackInfo<v8::Value>& args) { |
323 // Default to returning null. | 332 // Default to returning null. |
324 args.GetReturnValue().SetNull(); | 333 args.GetReturnValue().SetNull(); |
325 // There is one argument. | 334 // There is one argument. |
326 CHECK(args.Length() == 1); | 335 CHECK(args.Length() == 1); |
327 // The view ID. | 336 // The view ID. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 const v8::FunctionCallbackInfo<v8::Value>& args) { | 429 const v8::FunctionCallbackInfo<v8::Value>& args) { |
421 // Gesture is required to request fullscreen. | 430 // Gesture is required to request fullscreen. |
422 blink::WebScopedUserGesture user_gesture; | 431 blink::WebScopedUserGesture user_gesture; |
423 CHECK_EQ(args.Length(), 1); | 432 CHECK_EQ(args.Length(), 1); |
424 CHECK(args[0]->IsFunction()); | 433 CHECK(args[0]->IsFunction()); |
425 v8::Local<v8::Value> no_args; | 434 v8::Local<v8::Value> no_args; |
426 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); | 435 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); |
427 } | 436 } |
428 | 437 |
429 } // namespace extensions | 438 } // namespace extensions |
OLD | NEW |