| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_popup_host.h" |
| 6 |
| 7 #if defined(TOOLKIT_VIEWS) |
| 8 #include "chrome/browser/extensions/extension_popup_api.h" |
| 9 #endif |
| 10 #include "chrome/browser/profile.h" |
| 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #if defined(TOOLKIT_VIEWS) |
| 14 #include "chrome/browser/views/extensions/extension_popup.h" |
| 15 #endif |
| 16 #include "chrome/common/notification_details.h" |
| 17 #include "chrome/common/notification_source.h" |
| 18 #include "chrome/common/notification_type.h" |
| 19 |
| 20 |
| 21 ExtensionPopupHost* ExtensionPopupHost::PopupDelegate::popup_host() { |
| 22 if (!popup_host_.get()) |
| 23 popup_host_.reset(new ExtensionPopupHost(this)); |
| 24 |
| 25 return popup_host_.get(); |
| 26 } |
| 27 |
| 28 ExtensionPopupHost::ExtensionPopupHost(PopupDelegate* delegate) |
| 29 : // NO LINT |
| 30 #if defined(TOOLKIT_VIEWS) |
| 31 child_popup_(NULL), |
| 32 #endif |
| 33 delegate_(delegate) { |
| 34 DCHECK(delegate_); |
| 35 |
| 36 // Listen for view close requests, so that we can dismiss a hosted pop-up |
| 37 // view, if necessary. |
| 38 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 39 Source<Profile>(delegate_->GetBrowser()->profile())); |
| 40 } |
| 41 |
| 42 ExtensionPopupHost::~ExtensionPopupHost() { |
| 43 DismissPopup(); |
| 44 } |
| 45 |
| 46 #if defined(TOOLKIT_VIEWS) |
| 47 void ExtensionPopupHost::BubbleBrowserWindowMoved(BrowserBubble* bubble) { |
| 48 DismissPopup(); |
| 49 } |
| 50 |
| 51 void ExtensionPopupHost::BubbleBrowserWindowClosing(BrowserBubble* bubble) { |
| 52 DismissPopup(); |
| 53 } |
| 54 |
| 55 void ExtensionPopupHost::BubbleGotFocus(BrowserBubble* bubble) { |
| 56 } |
| 57 |
| 58 void ExtensionPopupHost::BubbleLostFocus(BrowserBubble* bubble) { |
| 59 // TODO(twiz): Dismiss the pop-up upon loss of focus of the bubble, but not |
| 60 // if the focus is transitioning to the host which owns the popup! |
| 61 // DismissPopup(); |
| 62 } |
| 63 #endif // defined(TOOLKIT_VIEWS) |
| 64 |
| 65 void ExtensionPopupHost::Observe(NotificationType type, |
| 66 const NotificationSource& source, |
| 67 const NotificationDetails& details) { |
| 68 if (type == NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE) { |
| 69 #if defined(TOOLKIT_VIEWS) |
| 70 // If we aren't the host of the popup, then disregard the notification. |
| 71 if (!child_popup_ || |
| 72 Details<ExtensionHost>(child_popup_->host()) != details) { |
| 73 return; |
| 74 } |
| 75 DismissPopup(); |
| 76 #endif |
| 77 } else { |
| 78 NOTREACHED(); |
| 79 } |
| 80 } |
| 81 |
| 82 void ExtensionPopupHost::DismissPopup() { |
| 83 #if defined(TOOLKIT_VIEWS) |
| 84 if (child_popup_) { |
| 85 child_popup_->Hide(); |
| 86 child_popup_->DetachFromBrowser(); |
| 87 delete child_popup_; |
| 88 child_popup_ = NULL; |
| 89 |
| 90 PopupEventRouter::OnPopupClosed( |
| 91 delegate_->GetBrowser()->profile(), |
| 92 delegate_->GetRenderViewHost()->routing_id()); |
| 93 } |
| 94 #endif // defined(TOOLKIT_VIEWS) |
| 95 } |
| OLD | NEW |