Chromium Code Reviews| 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 v8::Local<v8::Value> window; |
|
Fady Samuel
2015/09/14 15:42:46
nit: comment would be helpful
| |
| 319 if (frame->isWebLocalFrame()) { | |
| 320 window = frame->mainWorldScriptContext()->Global(); | |
| 321 } else { | |
| 322 window = | |
| 323 frame->toWebRemoteFrame()->deprecatedMainWorldScriptContext()->Global(); | |
| 324 } | |
| 318 args.GetReturnValue().Set(window); | 325 args.GetReturnValue().Set(window); |
| 319 } | 326 } |
| 320 | 327 |
| 321 void GuestViewInternalCustomBindings::GetViewFromID( | 328 void GuestViewInternalCustomBindings::GetViewFromID( |
| 322 const v8::FunctionCallbackInfo<v8::Value>& args) { | 329 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 323 // Default to returning null. | 330 // Default to returning null. |
| 324 args.GetReturnValue().SetNull(); | 331 args.GetReturnValue().SetNull(); |
| 325 // There is one argument. | 332 // There is one argument. |
| 326 CHECK(args.Length() == 1); | 333 CHECK(args.Length() == 1); |
| 327 // The view ID. | 334 // The view ID. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 const v8::FunctionCallbackInfo<v8::Value>& args) { | 427 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 421 // Gesture is required to request fullscreen. | 428 // Gesture is required to request fullscreen. |
| 422 blink::WebScopedUserGesture user_gesture; | 429 blink::WebScopedUserGesture user_gesture; |
| 423 CHECK_EQ(args.Length(), 1); | 430 CHECK_EQ(args.Length(), 1); |
| 424 CHECK(args[0]->IsFunction()); | 431 CHECK(args[0]->IsFunction()); |
| 425 v8::Local<v8::Value> no_args; | 432 v8::Local<v8::Value> no_args; |
| 426 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); | 433 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); |
| 427 } | 434 } |
| 428 | 435 |
| 429 } // namespace extensions | 436 } // namespace extensions |
| OLD | NEW |