| 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_POPUP_HOST_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_POPUP_HOST_H_ |
| 7 |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "build/build_config.h" |
| 10 #if defined(TOOLKIT_VIEWS) |
| 11 #include "chrome/browser/views/browser_bubble.h" |
| 12 #endif |
| 13 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/notification_registrar.h" |
| 15 |
| 16 #if defined(TOOLKIT_VIEWS) |
| 17 class ExtensionPopup; |
| 18 #endif |
| 19 |
| 20 class Browser; |
| 21 class Profile; |
| 22 class RenderViewHost; |
| 23 |
| 24 // ExtensionPopupHost objects implement the environment necessary to host |
| 25 // ExtensionPopup views. This class manages the creation and life-time |
| 26 // of extension pop-up views. |
| 27 class ExtensionPopupHost : // NOLINT |
| 28 #if defined(TOOLKIT_VIEWS) |
| 29 public BrowserBubble::Delegate, |
| 30 #endif |
| 31 public NotificationObserver { |
| 32 public: |
| 33 // Classes wishing to host pop-ups should inherit from this class, and |
| 34 // implement the virtual methods below. This class manages the lifetime |
| 35 // of an ExtensionPopupHost instance. |
| 36 class PopupDelegate { |
| 37 public: |
| 38 PopupDelegate() {} |
| 39 virtual ~PopupDelegate() {} |
| 40 virtual Browser* GetBrowser() = 0; |
| 41 virtual RenderViewHost* GetRenderViewHost() = 0; |
| 42 |
| 43 // Constructs, or returns the existing ExtensionPopupHost instance. |
| 44 ExtensionPopupHost* popup_host(); |
| 45 private: |
| 46 scoped_ptr<ExtensionPopupHost> popup_host_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(PopupDelegate); |
| 49 }; |
| 50 |
| 51 explicit ExtensionPopupHost(PopupDelegate* delegate); |
| 52 virtual ~ExtensionPopupHost(); |
| 53 |
| 54 // Dismiss the hosted pop-up, if one is present. |
| 55 void DismissPopup(); |
| 56 |
| 57 #if defined(TOOLKIT_VIEWS) |
| 58 ExtensionPopup* child_popup() const { return child_popup_; } |
| 59 void set_child_popup(ExtensionPopup* popup) { |
| 60 // An extension may only have one popup active at a given time. |
| 61 DismissPopup(); |
| 62 child_popup_ = popup; |
| 63 } |
| 64 |
| 65 // BrowserBubble::Delegate implementation. |
| 66 // Called when the Browser Window that this bubble is attached to moves. |
| 67 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); |
| 68 |
| 69 // Called with the Browser Window that this bubble is attached to is |
| 70 // about to close. |
| 71 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); |
| 72 |
| 73 // Called when the bubble became active / got focus. |
| 74 virtual void BubbleGotFocus(BrowserBubble* bubble); |
| 75 |
| 76 // Called when the bubble became inactive / lost focus. |
| 77 virtual void BubbleLostFocus(BrowserBubble* bubble); |
| 78 #endif // defined(TOOLKIT_VIEWS) |
| 79 |
| 80 // NotificationObserver implementation. |
| 81 virtual void Observe(NotificationType type, |
| 82 const NotificationSource& source, |
| 83 const NotificationDetails& details); |
| 84 |
| 85 private: |
| 86 #if defined(TOOLKIT_VIEWS) |
| 87 // A popup view that is anchored to and owned by this ExtensionHost. However, |
| 88 // the popup contains its own separate ExtensionHost |
| 89 ExtensionPopup* child_popup_; |
| 90 #endif |
| 91 |
| 92 NotificationRegistrar registrar_; |
| 93 |
| 94 // Non-owning pointer to the delegate for this host. |
| 95 PopupDelegate* delegate_; |
| 96 |
| 97 // Boolean value used to ensure that the host only registers for event |
| 98 // notifications once. |
| 99 bool listeners_registered_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupHost); |
| 102 }; |
| 103 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_POPUP_HOST_H_ |
| OLD | NEW |