Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc

Issue 1143333008: Getting rid of more webview memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 two parameters.
lazyboy 2015/06/05 23:09:56 three
paulmeyer 2015/06/08 17:53:59 Done.
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
lazyboy 2015/06/05 23:09:55 nit: |view_instance_id|
paulmeyer 2015/06/08 17:53:59 Done.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698