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

Side by Side Diff: extensions/browser/guest_view/guest_view_base.cc

Issue 611563002: GuestView: Use Weak Pointers Throughout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed bug where openers become NULL before WillDestroy Created 6 years, 2 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/browser/guest_view/guest_view_base.h" 5 #include "extensions/browser/guest_view/guest_view_base.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/render_frame_host.h" 9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h" 10 #include "content/public/browser/render_process_host.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 delete this; 150 delete this;
151 callback.Run(NULL); 151 callback.Run(NULL);
152 return; 152 return;
153 } 153 }
154 154
155 CreateWebContents(embedder_extension_id, 155 CreateWebContents(embedder_extension_id,
156 embedder_process_id, 156 embedder_process_id,
157 embedder_site_url, 157 embedder_site_url,
158 create_params, 158 create_params,
159 base::Bind(&GuestViewBase::CompleteInit, 159 base::Bind(&GuestViewBase::CompleteInit,
160 AsWeakPtr(), 160 weak_ptr_factory_.GetWeakPtr(),
161 embedder_extension_id, 161 embedder_extension_id,
162 embedder_process_id, 162 embedder_process_id,
163 callback)); 163 callback));
164 } 164 }
165 165
166 void GuestViewBase::InitWithWebContents( 166 void GuestViewBase::InitWithWebContents(
167 const std::string& embedder_extension_id, 167 const std::string& embedder_extension_id,
168 int embedder_render_process_id, 168 int embedder_render_process_id,
169 content::WebContents* guest_web_contents) { 169 content::WebContents* guest_web_contents) {
170 DCHECK(guest_web_contents); 170 DCHECK(guest_web_contents);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return NULL; 263 return NULL;
264 264
265 return GuestViewBase::FromWebContents(guest_web_contents); 265 return GuestViewBase::FromWebContents(guest_web_contents);
266 } 266 }
267 267
268 // static 268 // static
269 bool GuestViewBase::IsGuest(WebContents* web_contents) { 269 bool GuestViewBase::IsGuest(WebContents* web_contents) {
270 return !!GuestViewBase::FromWebContents(web_contents); 270 return !!GuestViewBase::FromWebContents(web_contents);
271 } 271 }
272 272
273 base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() {
274 return weak_ptr_factory_.GetWeakPtr();
275 }
276
277 bool GuestViewBase::IsAutoSizeSupported() const { 273 bool GuestViewBase::IsAutoSizeSupported() const {
278 return false; 274 return false;
279 } 275 }
280 276
281 bool GuestViewBase::IsDragAndDropEnabled() const { 277 bool GuestViewBase::IsDragAndDropEnabled() const {
282 return false; 278 return false;
283 } 279 }
284 280
285 void GuestViewBase::RenderProcessExited(content::RenderProcessHost* host, 281 void GuestViewBase::RenderProcessExited(content::RenderProcessHost* host,
286 base::ProcessHandle handle, 282 base::ProcessHandle handle,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, 316 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size,
321 const gfx::Size& new_size) { 317 const gfx::Size& new_size) {
322 if (!auto_size_enabled_) 318 if (!auto_size_enabled_)
323 return; 319 return;
324 guest_size_ = new_size; 320 guest_size_ = new_size;
325 GuestSizeChangedDueToAutoSize(old_size, new_size); 321 GuestSizeChangedDueToAutoSize(old_size, new_size);
326 } 322 }
327 323
328 void GuestViewBase::Destroy() { 324 void GuestViewBase::Destroy() {
329 DCHECK(web_contents()); 325 DCHECK(web_contents());
326
330 content::RenderProcessHost* host = 327 content::RenderProcessHost* host =
331 content::RenderProcessHost::FromID(embedder_render_process_id()); 328 content::RenderProcessHost::FromID(embedder_render_process_id());
332 if (host) 329 if (host)
333 host->RemoveObserver(this); 330 host->RemoveObserver(this);
334 331
335 // Give the derived class an opportunity to perform some cleanup. 332 // Give the derived class an opportunity to perform some cleanup.
336 WillDestroy(); 333 WillDestroy();
337 334
335 // Invalidate weak pointers now so that bound callbacks cannot be called late
336 // into destruction. We must call this after WillDestroy because derived types
337 // may wish to access their openers.
338 weak_ptr_factory_.InvalidateWeakPtrs();
339
338 // Give the content module an opportunity to perform some cleanup. 340 // Give the content module an opportunity to perform some cleanup.
339 if (!destruction_callback_.is_null()) 341 if (!destruction_callback_.is_null())
340 destruction_callback_.Run(); 342 destruction_callback_.Run();
341 343
342 webcontents_guestview_map.Get().erase(web_contents()); 344 webcontents_guestview_map.Get().erase(web_contents());
343 GuestViewManager::FromBrowserContext(browser_context_)-> 345 GuestViewManager::FromBrowserContext(browser_context_)->
344 RemoveGuest(guest_instance_id_); 346 RemoveGuest(guest_instance_id_);
345 pending_events_.clear(); 347 pending_events_.clear();
346 348
347 delete web_contents(); 349 delete web_contents();
348 } 350 }
349 351
350 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { 352 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) {
351 attach_params_.reset(params.DeepCopy()); 353 attach_params_.reset(params.DeepCopy());
352 attach_params_->GetInteger(guestview::kParameterInstanceId, 354 attach_params_->GetInteger(guestview::kParameterInstanceId,
353 &view_instance_id_); 355 &view_instance_id_);
354 } 356 }
355 357
356 void GuestViewBase::SetOpener(GuestViewBase* guest) { 358 void GuestViewBase::SetOpener(GuestViewBase* guest) {
357 if (guest && guest->IsViewType(GetViewType())) { 359 if (guest && guest->IsViewType(GetViewType())) {
358 opener_ = guest->AsWeakPtr(); 360 opener_ = guest->weak_ptr_factory_.GetWeakPtr();
359 return; 361 return;
360 } 362 }
361 opener_ = base::WeakPtr<GuestViewBase>(); 363 opener_ = base::WeakPtr<GuestViewBase>();
362 } 364 }
363 365
364 void GuestViewBase::RegisterDestructionCallback( 366 void GuestViewBase::RegisterDestructionCallback(
365 const DestructionCallback& callback) { 367 const DestructionCallback& callback) {
366 destruction_callback_ = callback; 368 destruction_callback_ = callback;
367 } 369 }
368 370
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 506
505 // static 507 // static
506 void GuestViewBase::RegisterGuestViewTypes() { 508 void GuestViewBase::RegisterGuestViewTypes() {
507 AppViewGuest::Register(); 509 AppViewGuest::Register();
508 ExtensionOptionsGuest::Register(); 510 ExtensionOptionsGuest::Register();
509 MimeHandlerViewGuest::Register(); 511 MimeHandlerViewGuest::Register();
510 WebViewGuest::Register(); 512 WebViewGuest::Register();
511 } 513 }
512 514
513 } // namespace extensions 515 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/browser/guest_view/web_view/web_view_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698