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" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return; | 260 return; |
261 | 261 |
262 guest_view_container->RegisterElementResizeCallback( | 262 guest_view_container->RegisterElementResizeCallback( |
263 args[1].As<v8::Function>(), args.GetIsolate()); | 263 args[1].As<v8::Function>(), args.GetIsolate()); |
264 | 264 |
265 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | 265 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); |
266 } | 266 } |
267 | 267 |
268 void GuestViewInternalCustomBindings::RegisterView( | 268 void GuestViewInternalCustomBindings::RegisterView( |
269 const v8::FunctionCallbackInfo<v8::Value>& args) { | 269 const v8::FunctionCallbackInfo<v8::Value>& args) { |
270 // There are two parameters. | 270 // There are three parameters. |
271 CHECK(args.Length() == 2); | 271 CHECK(args.Length() == 3); |
272 // View Instance ID. | 272 // View Instance ID. |
273 CHECK(args[0]->IsInt32()); | 273 CHECK(args[0]->IsInt32()); |
274 // View element. | 274 // View element. |
275 CHECK(args[1]->IsObject()); | 275 CHECK(args[1]->IsObject()); |
| 276 // View type (e.g. "webview"). |
| 277 CHECK(args[2]->IsString()); |
276 | 278 |
277 // A reference to the view object is stored in |weak_view_map| using its view | 279 // A reference to the view object is stored in |weak_view_map| using its view |
278 // ID as the key. The reference is made weak so that it will not extend the | 280 // ID as the key. The reference is made weak so that it will not extend the |
279 // lifetime of the object. | 281 // lifetime of the object. |
280 int view_id = args[0]->Int32Value(); | 282 int view_instance_id = args[0]->Int32Value(); |
281 auto object = | 283 auto object = |
282 new v8::Global<v8::Object>(args.GetIsolate(), args[1].As<v8::Object>()); | 284 new v8::Global<v8::Object>(args.GetIsolate(), args[1].As<v8::Object>()); |
283 weak_view_map.Get().insert(std::make_pair(view_id, object)); | 285 weak_view_map.Get().insert(std::make_pair(view_instance_id, object)); |
284 | 286 |
285 // The view_id is given to the SetWeak callback so that that view's entry in | 287 // The |view_instance_id| is given to the SetWeak callback so that that view's |
286 // |weak_view_map| can be cleared when the view object is garbage collected. | 288 // entry in |weak_view_map| can be cleared when the view object is garbage |
287 object->SetWeak(new int(view_id), | 289 // collected. |
| 290 object->SetWeak(new int(view_instance_id), |
288 &GuestViewInternalCustomBindings::ResetMapEntry, | 291 &GuestViewInternalCustomBindings::ResetMapEntry, |
289 v8::WeakCallbackType::kParameter); | 292 v8::WeakCallbackType::kParameter); |
| 293 |
| 294 // Let the GuestViewManager know that a GuestView has been created. |
| 295 const std::string& view_type = *v8::String::Utf8Value(args[2]); |
| 296 content::RenderThread::Get()->Send( |
| 297 new GuestViewHostMsg_ViewCreated(view_instance_id, view_type)); |
290 } | 298 } |
291 | 299 |
292 void GuestViewInternalCustomBindings::RunWithGesture( | 300 void GuestViewInternalCustomBindings::RunWithGesture( |
293 const v8::FunctionCallbackInfo<v8::Value>& args) { | 301 const v8::FunctionCallbackInfo<v8::Value>& args) { |
294 // Gesture is required to request fullscreen. | 302 // Gesture is required to request fullscreen. |
295 blink::WebScopedUserGesture user_gesture; | 303 blink::WebScopedUserGesture user_gesture; |
296 CHECK_EQ(args.Length(), 1); | 304 CHECK_EQ(args.Length(), 1); |
297 CHECK(args[0]->IsFunction()); | 305 CHECK(args[0]->IsFunction()); |
298 v8::Local<v8::Value> no_args; | 306 v8::Local<v8::Value> no_args; |
299 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); | 307 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, &no_args); |
300 } | 308 } |
301 | 309 |
302 } // namespace extensions | 310 } // namespace extensions |
OLD | NEW |