OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/extensions/extension_popup_host.h" | 5 #include "chrome/browser/extensions/extension_popup_host.h" |
6 | 6 |
7 #if defined(TOOLKIT_VIEWS) | 7 #if defined(TOOLKIT_VIEWS) |
8 #include "chrome/browser/extensions/extension_popup_api.h" | 8 #include "chrome/browser/extensions/extension_popup_api.h" |
9 #endif | 9 #endif |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
12 #include "chrome/browser/renderer_host/render_view_host.h" | 12 #include "chrome/browser/renderer_host/render_view_host.h" |
13 #if defined(TOOLKIT_VIEWS) | 13 #if defined(TOOLKIT_VIEWS) |
14 #include "chrome/browser/views/extensions/extension_popup.h" | 14 #include "chrome/browser/views/extensions/extension_popup.h" |
15 #endif | 15 #endif |
16 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
17 #include "chrome/common/notification_source.h" | 17 #include "chrome/common/notification_source.h" |
18 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
19 | 19 |
20 | 20 |
| 21 ExtensionPopupHost::PopupDelegate::~PopupDelegate() { |
| 22 // If the PopupDelegate is being torn down, then make sure to reset the |
| 23 // cached pointer in the host to prevent access to a stale pointer. |
| 24 if (popup_host_.get()) |
| 25 popup_host_->RevokeDelegate(); |
| 26 } |
| 27 |
21 ExtensionPopupHost* ExtensionPopupHost::PopupDelegate::popup_host() { | 28 ExtensionPopupHost* ExtensionPopupHost::PopupDelegate::popup_host() { |
22 if (!popup_host_.get()) | 29 if (!popup_host_.get()) |
23 popup_host_.reset(new ExtensionPopupHost(this)); | 30 popup_host_.reset(new ExtensionPopupHost(this)); |
24 | 31 |
25 return popup_host_.get(); | 32 return popup_host_.get(); |
26 } | 33 } |
27 | 34 |
| 35 Profile* ExtensionPopupHost::PopupDelegate::GetProfile() { |
| 36 // If there is a browser present, return the profile associated with it. |
| 37 // When hosting a view in an ExternalTabContainer, it is possible to have |
| 38 // no Browser instance. |
| 39 Browser* browser = GetBrowser(); |
| 40 if (browser) { |
| 41 return browser->profile(); |
| 42 } |
| 43 |
| 44 return NULL; |
| 45 } |
| 46 |
28 ExtensionPopupHost::ExtensionPopupHost(PopupDelegate* delegate) | 47 ExtensionPopupHost::ExtensionPopupHost(PopupDelegate* delegate) |
29 : // NO LINT | 48 : // NO LINT |
30 #if defined(TOOLKIT_VIEWS) | 49 #if defined(TOOLKIT_VIEWS) |
31 child_popup_(NULL), | 50 child_popup_(NULL), |
32 #endif | 51 #endif |
33 delegate_(delegate) { | 52 delegate_(delegate) { |
34 DCHECK(delegate_); | 53 DCHECK(delegate_); |
35 | 54 |
36 // Listen for view close requests, so that we can dismiss a hosted pop-up | 55 // Listen for view close requests, so that we can dismiss a hosted pop-up |
37 // view, if necessary. | 56 // view, if necessary. |
| 57 Profile* profile = delegate_->GetProfile(); |
| 58 DCHECK(profile); |
38 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 59 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
39 Source<Profile>(delegate_->GetBrowser()->profile())); | 60 Source<Profile>(profile)); |
40 } | 61 } |
41 | 62 |
42 ExtensionPopupHost::~ExtensionPopupHost() { | 63 ExtensionPopupHost::~ExtensionPopupHost() { |
43 DismissPopup(); | 64 DismissPopup(); |
44 } | 65 } |
45 | 66 |
46 #if defined(TOOLKIT_VIEWS) | 67 #if defined(TOOLKIT_VIEWS) |
47 void ExtensionPopupHost::BubbleBrowserWindowMoved(BrowserBubble* bubble) { | 68 void ExtensionPopupHost::BubbleBrowserWindowMoved(BrowserBubble* bubble) { |
48 DismissPopup(); | 69 DismissPopup(); |
49 } | 70 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 102 } |
82 | 103 |
83 void ExtensionPopupHost::DismissPopup() { | 104 void ExtensionPopupHost::DismissPopup() { |
84 #if defined(TOOLKIT_VIEWS) | 105 #if defined(TOOLKIT_VIEWS) |
85 if (child_popup_) { | 106 if (child_popup_) { |
86 child_popup_->Hide(); | 107 child_popup_->Hide(); |
87 child_popup_->DetachFromBrowser(); | 108 child_popup_->DetachFromBrowser(); |
88 delete child_popup_; | 109 delete child_popup_; |
89 child_popup_ = NULL; | 110 child_popup_ = NULL; |
90 | 111 |
91 PopupEventRouter::OnPopupClosed( | 112 if (delegate_) { |
92 delegate_->GetBrowser()->profile(), | 113 PopupEventRouter::OnPopupClosed( |
93 delegate_->GetRenderViewHost()->routing_id()); | 114 delegate_->GetProfile(), |
| 115 delegate_->GetRenderViewHost()->routing_id()); |
| 116 } |
94 } | 117 } |
95 #endif // defined(TOOLKIT_VIEWS) | 118 #endif // defined(TOOLKIT_VIEWS) |
96 } | 119 } |
OLD | NEW |