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 "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_messages.h" | 13 #include "extensions/common/extension_messages.h" |
14 #include "extensions/common/guest_view/guest_view_constants.h" | 14 #include "extensions/common/guest_view/guest_view_constants.h" |
15 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" | 15 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" |
16 #include "extensions/renderer/script_context.h" | 16 #include "extensions/renderer/script_context.h" |
| 17 #include "third_party/WebKit/public/web/WebFrame.h" |
| 18 #include "third_party/WebKit/public/web/WebView.h" |
17 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
18 | 20 |
19 using content::V8ValueConverter; | 21 using content::V8ValueConverter; |
20 | 22 |
21 namespace extensions { | 23 namespace extensions { |
22 | 24 |
23 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( | 25 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( |
24 ScriptContext* context) | 26 ScriptContext* context) |
25 : ObjectBackedNativeHandler(context) { | 27 : ObjectBackedNativeHandler(context) { |
26 RouteFunction("AttachGuest", | 28 RouteFunction("AttachGuest", |
27 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, | 29 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, |
28 base::Unretained(this))); | 30 base::Unretained(this))); |
29 RouteFunction("DetachGuest", | 31 RouteFunction("DetachGuest", |
30 base::Bind(&GuestViewInternalCustomBindings::DetachGuest, | 32 base::Bind(&GuestViewInternalCustomBindings::DetachGuest, |
31 base::Unretained(this))); | 33 base::Unretained(this))); |
| 34 RouteFunction("GetContentWindow", |
| 35 base::Bind(&GuestViewInternalCustomBindings::GetContentWindow, |
| 36 base::Unretained(this))); |
32 RouteFunction( | 37 RouteFunction( |
33 "RegisterDestructionCallback", | 38 "RegisterDestructionCallback", |
34 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, | 39 base::Bind(&GuestViewInternalCustomBindings::RegisterDestructionCallback, |
35 base::Unretained(this))); | 40 base::Unretained(this))); |
36 RouteFunction( | 41 RouteFunction( |
37 "RegisterElementResizeCallback", | 42 "RegisterElementResizeCallback", |
38 base::Bind( | 43 base::Bind( |
39 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, | 44 &GuestViewInternalCustomBindings::RegisterElementResizeCallback, |
40 base::Unretained(this))); | 45 base::Unretained(this))); |
41 } | 46 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 new ExtensionsGuestViewContainer::DetachRequest( | 120 new ExtensionsGuestViewContainer::DetachRequest( |
116 guest_view_container, | 121 guest_view_container, |
117 args.Length() == 2 ? args[1].As<v8::Function>() : | 122 args.Length() == 2 ? args[1].As<v8::Function>() : |
118 v8::Handle<v8::Function>(), | 123 v8::Handle<v8::Function>(), |
119 args.GetIsolate())); | 124 args.GetIsolate())); |
120 guest_view_container->IssueRequest(request); | 125 guest_view_container->IssueRequest(request); |
121 | 126 |
122 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | 127 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); |
123 } | 128 } |
124 | 129 |
| 130 void GuestViewInternalCustomBindings::GetContentWindow( |
| 131 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 132 // Default to returning null. |
| 133 args.GetReturnValue().SetNull(); |
| 134 |
| 135 if (args.Length() != 1) |
| 136 return; |
| 137 |
| 138 // The routing ID for the RenderView. |
| 139 if (!args[0]->IsInt32()) |
| 140 return; |
| 141 |
| 142 int view_id = args[0]->Int32Value(); |
| 143 if (view_id == MSG_ROUTING_NONE) |
| 144 return; |
| 145 |
| 146 content::RenderView* view = content::RenderView::FromRoutingID(view_id); |
| 147 if (!view) |
| 148 return; |
| 149 |
| 150 blink::WebFrame* frame = view->GetWebView()->mainFrame(); |
| 151 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); |
| 152 args.GetReturnValue().Set(window); |
| 153 } |
| 154 |
125 void GuestViewInternalCustomBindings::RegisterDestructionCallback( | 155 void GuestViewInternalCustomBindings::RegisterDestructionCallback( |
126 const v8::FunctionCallbackInfo<v8::Value>& args) { | 156 const v8::FunctionCallbackInfo<v8::Value>& args) { |
127 // There are two parameters. | 157 // There are two parameters. |
128 CHECK(args.Length() == 2); | 158 CHECK(args.Length() == 2); |
129 // Element Instance ID. | 159 // Element Instance ID. |
130 CHECK(args[0]->IsInt32()); | 160 CHECK(args[0]->IsInt32()); |
131 // Callback function. | 161 // Callback function. |
132 CHECK(args[1]->IsFunction()); | 162 CHECK(args[1]->IsFunction()); |
133 | 163 |
134 int element_instance_id = args[0]->Int32Value(); | 164 int element_instance_id = args[0]->Int32Value(); |
(...skipping 27 matching lines...) Expand all Loading... |
162 if (!guest_view_container) | 192 if (!guest_view_container) |
163 return; | 193 return; |
164 | 194 |
165 guest_view_container->RegisterElementResizeCallback( | 195 guest_view_container->RegisterElementResizeCallback( |
166 args[1].As<v8::Function>(), args.GetIsolate()); | 196 args[1].As<v8::Function>(), args.GetIsolate()); |
167 | 197 |
168 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | 198 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); |
169 } | 199 } |
170 | 200 |
171 } // namespace extensions | 201 } // namespace extensions |
OLD | NEW |