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