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

Unified Diff: chrome/browser/extensions/extension_popup_host.cc

Issue 434046: Support for chrome.experimental.popup API in ExternalTabContainer views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_popup_host.cc
===================================================================
--- chrome/browser/extensions/extension_popup_host.cc (revision 34039)
+++ chrome/browser/extensions/extension_popup_host.cc (working copy)
@@ -18,6 +18,13 @@
#include "chrome/common/notification_type.h"
+ExtensionPopupHost::PopupDelegate::~PopupDelegate() {
+ // If the PopupDelegate is being torn down, then make sure to reset the
+ // cached pointer in the host to prevent access to a stale pointer.
+ if (popup_host_.get())
+ popup_host_->RevokeDelegate();
+}
+
ExtensionPopupHost* ExtensionPopupHost::PopupDelegate::popup_host() {
if (!popup_host_.get())
popup_host_.reset(new ExtensionPopupHost(this));
@@ -25,6 +32,18 @@
return popup_host_.get();
}
+Profile* ExtensionPopupHost::PopupDelegate::GetProfile() {
+ // If there is a browser present, return the profile associated with it.
+ // When hosting a view in an ExternalTabContainer, it is possible to have
+ // no Browser instance.
+ Browser* browser = GetBrowser();
+ if (browser) {
+ return browser->profile();
+ }
+
+ return NULL;
+}
+
ExtensionPopupHost::ExtensionPopupHost(PopupDelegate* delegate)
: // NO LINT
#if defined(TOOLKIT_VIEWS)
@@ -35,8 +54,10 @@
// Listen for view close requests, so that we can dismiss a hosted pop-up
// view, if necessary.
+ Profile* profile = delegate_->GetProfile();
+ DCHECK(profile);
registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE,
- Source<Profile>(delegate_->GetBrowser()->profile()));
+ Source<Profile>(profile));
}
ExtensionPopupHost::~ExtensionPopupHost() {
@@ -88,9 +109,11 @@
delete child_popup_;
child_popup_ = NULL;
- PopupEventRouter::OnPopupClosed(
- delegate_->GetBrowser()->profile(),
- delegate_->GetRenderViewHost()->routing_id());
+ if (delegate_) {
+ PopupEventRouter::OnPopupClosed(
+ delegate_->GetProfile(),
+ delegate_->GetRenderViewHost()->routing_id());
+ }
}
#endif // defined(TOOLKIT_VIEWS)
}

Powered by Google App Engine
This is Rietveld 408576698