OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include "base/ref_counted.h" |
9 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
10 #include "chrome/browser/ui/views/browser_bubble.h" | 11 #include "chrome/browser/ui/views/browser_bubble.h" |
11 #include "chrome/browser/ui/views/bubble_border.h" | 12 #include "chrome/browser/ui/views/bubble_border.h" |
12 #include "chrome/browser/ui/views/extensions/extension_view.h" | 13 #include "chrome/browser/ui/views/extensions/extension_view.h" |
13 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
14 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
15 #include "gfx/native_widget_types.h" | 16 #include "gfx/native_widget_types.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 | 18 |
18 | 19 |
19 class Browser; | 20 class Browser; |
20 class ExtensionHost; | 21 class ExtensionHost; |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace views { | 24 namespace views { |
24 class Widget; | 25 class Widget; |
25 } | 26 } |
26 | 27 |
27 class ExtensionPopup : public BrowserBubble, | 28 class ExtensionPopup : public BrowserBubble, |
28 public BrowserBubble::Delegate, | 29 public BrowserBubble::Delegate, |
| 30 public ExtensionView::Container, |
29 public NotificationObserver, | 31 public NotificationObserver, |
30 public ExtensionView::Container { | 32 public base::RefCounted<ExtensionPopup> { |
31 public: | 33 public: |
32 // Observer to ExtensionPopup events. | 34 // Observer to ExtensionPopup events. |
33 class Observer { | 35 class Observer { |
34 public: | 36 public: |
35 // Called when the ExtensionPopup is closing. Note that it | 37 // Called when the ExtensionPopup is closing. Note that it |
36 // is ref-counted, and thus will be released shortly after | 38 // is ref-counted, and thus will be released shortly after |
37 // making this delegate call. | 39 // making this delegate call. |
38 virtual void ExtensionPopupIsClosing(ExtensionPopup* popup) {} | 40 virtual void ExtensionPopupIsClosing(ExtensionPopup* popup) {} |
39 | 41 |
40 // Called after the ExtensionPopup has been closed and deleted. | |
41 // |popup_token| is the address of the deleted ExtensionPopup. | |
42 virtual void ExtensionPopupClosed(void* popup_token) {} | |
43 | |
44 // Called when the ExtensionHost is first created for the pop-up view. | |
45 // Note that this is invoked BEFORE the ExtensionPopup is created, and can | |
46 // be used to provide extra configuration of the host before it is pushed | |
47 // into the popup. An example use is for automation resource routing in | |
48 // Chrome-Frame. See extension_popup_api.cc. | |
49 virtual void ExtensionHostCreated(ExtensionHost* host) {} | |
50 | |
51 // Called immediately after a popup is created, but before the hosted | |
52 // extension has loaded and before the popup has been displayed. Use to | |
53 // finalize configuration of |popup|. | |
54 virtual void ExtensionPopupCreated(ExtensionPopup* popup) {} | |
55 | |
56 // Called when the ExtensionPopup is resized. Note that the popup may have | 42 // Called when the ExtensionPopup is resized. Note that the popup may have |
57 // an empty bounds, if a popup is repositioned before the hosted content | 43 // an empty bounds, if a popup is repositioned before the hosted content |
58 // has loaded. | 44 // has loaded. |
59 virtual void ExtensionPopupResized(ExtensionPopup* popup) {} | 45 virtual void ExtensionPopupResized(ExtensionPopup* popup) {} |
60 }; | 46 }; |
61 | 47 |
62 enum PopupChrome { | |
63 BUBBLE_CHROME, | |
64 RECTANGLE_CHROME | |
65 }; | |
66 | |
67 virtual ~ExtensionPopup(); | 48 virtual ~ExtensionPopup(); |
68 | 49 |
69 // Create and show a popup with |url| positioned adjacent to |relative_to| in | 50 // Create and show a popup with |url| positioned adjacent to |relative_to| in |
70 // screen coordinates. | 51 // screen coordinates. |
71 // |browser| is the browser to which the pop-up will be attached. NULL is a | 52 // |browser| is the browser to which the pop-up will be attached. NULL is a |
72 // valid parameter for pop-ups not associated with a browser. | 53 // valid parameter for pop-ups not associated with a browser. |
73 // |profile| is the user profile instance associated with the popup. A | 54 // |profile| is the user profile instance associated with the popup. A |
74 // non NULL value must be given. | 55 // non NULL value must be given. |
75 // |frame_window| is the native window that hosts the view inside which the | 56 // |frame_window| is the native window that hosts the view inside which the |
76 // popup will be anchored. | 57 // popup will be anchored. |
77 // The positioning of the pop-up is determined by |arrow_location| according | 58 // The positioning of the pop-up is determined by |arrow_location| according |
78 // to the following logic: The popup is anchored so that the corner indicated | 59 // to the following logic: The popup is anchored so that the corner indicated |
79 // by value of |arrow_location| remains fixed during popup resizes. | 60 // by value of |arrow_location| remains fixed during popup resizes. |
80 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise | 61 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise |
81 // the popup 'drops down'. | 62 // the popup 'drops down'. |
82 // Pass |activate_on_show| as true to activate the popup window. | |
83 // Pass |inspect_with_devtools| as true to pin the popup open and show the | 63 // Pass |inspect_with_devtools| as true to pin the popup open and show the |
84 // devtools window for it. | 64 // devtools window for it. |
85 // The |chrome| argument controls the chrome that surrounds the pop-up. | |
86 // Passing BUBBLE_CHROME will give the pop-up a bubble-like appearance, | |
87 // including the arrow mentioned above. Passing RECTANGLE_CHROME will give | |
88 // the popup a rectangular, black border with a drop-shadow with no arrow. | |
89 // The positioning of the popup is still governed by the arrow-location | |
90 // parameter. | |
91 // | |
92 // The actual display of the popup is delayed until the page contents | 65 // The actual display of the popup is delayed until the page contents |
93 // finish loading in order to minimize UI flashing and resizing. | 66 // finish loading in order to minimize UI flashing and resizing. |
94 static ExtensionPopup* Show(const GURL& url, Browser* browser, | 67 static ExtensionPopup* Show(const GURL& url, Browser* browser, |
95 Profile* profile, | 68 Profile* profile, |
96 gfx::NativeWindow frame_window, | 69 gfx::NativeWindow frame_window, |
97 const gfx::Rect& relative_to, | 70 const gfx::Rect& relative_to, |
98 BubbleBorder::ArrowLocation arrow_location, | 71 BubbleBorder::ArrowLocation arrow_location, |
99 bool activate_on_show, | |
100 bool inspect_with_devtools, | 72 bool inspect_with_devtools, |
101 PopupChrome chrome, | |
102 Observer* observer); | 73 Observer* observer); |
103 | 74 |
104 // Assigns the maximal width and height, respectively, to which the popup | 75 // Assigns the maximal width and height, respectively, to which the popup |
105 // may expand. If these routines are not called, the popup will resize to | 76 // may expand. If these routines are not called, the popup will resize to |
106 // no larger than |kMaxWidth| x |kMaxHeight|. Note that the popup will | 77 // no larger than |kMaxWidth| x |kMaxHeight|. Note that the popup will |
107 // never expand to larger than the dimensions of the screen. | 78 // never expand to larger than the dimensions of the screen. |
108 void set_max_width(int width) { max_size_.set_width(width); } | 79 void set_max_width(int width) { max_size_.set_width(width); } |
109 void set_max_height(int height) { max_size_.set_height(height); } | 80 void set_max_height(int height) { max_size_.set_height(height); } |
110 | 81 |
111 // Closes the ExtensionPopup (this will cause the delegate | 82 // Closes the ExtensionPopup. |
112 // ExtensionPopupIsClosing and ExtensionPopupClosed to fire. | |
113 void Close(); | 83 void Close(); |
114 | 84 |
115 // Some clients wish to do their own custom focus change management. If this | 85 // Some clients wish to do their own custom focus change management. If this |
116 // is set to false, then the ExtensionPopup will not do anything in response | 86 // is set to false, then the ExtensionPopup will not do anything in response |
117 // to the BubbleLostFocus() calls it gets from the BrowserBubble. | 87 // to the BubbleLostFocus() calls it gets from the BrowserBubble. |
118 void set_close_on_lost_focus(bool close_on_lost_focus) { | 88 void set_close_on_lost_focus(bool close_on_lost_focus) { |
119 close_on_lost_focus_ = close_on_lost_focus; | 89 close_on_lost_focus_ = close_on_lost_focus; |
120 } | 90 } |
121 | 91 |
122 ExtensionHost* host() const { return extension_host_.get(); } | 92 ExtensionHost* host() const { return extension_host_.get(); } |
(...skipping 25 matching lines...) Expand all Loading... |
148 // NotificationObserver overrides. | 118 // NotificationObserver overrides. |
149 virtual void Observe(NotificationType type, | 119 virtual void Observe(NotificationType type, |
150 const NotificationSource& source, | 120 const NotificationSource& source, |
151 const NotificationDetails& details); | 121 const NotificationDetails& details); |
152 | 122 |
153 // ExtensionView::Container overrides. | 123 // ExtensionView::Container overrides. |
154 virtual void OnExtensionMouseMove(ExtensionView* view) { } | 124 virtual void OnExtensionMouseMove(ExtensionView* view) { } |
155 virtual void OnExtensionMouseLeave(ExtensionView* view) { } | 125 virtual void OnExtensionMouseLeave(ExtensionView* view) { } |
156 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); | 126 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); |
157 | 127 |
158 // Export the refrence-counted interface required for use as template | |
159 // arguments for RefCounted. ExtensionPopup does not inherit from RefCounted | |
160 // because it must override the behaviour of Release. | |
161 void AddRef() { instance_lifetime_->AddRef(); } | |
162 static bool ImplementsThreadSafeReferenceCounting() { | |
163 return InternalRefCounter::ImplementsThreadSafeReferenceCounting(); | |
164 } | |
165 | |
166 // Implements the standard RefCounted<T>::Release behaviour, except | |
167 // signals Observer::ExtensionPopupClosed after final release. | |
168 void Release(); | |
169 | |
170 // The min/max height of popups. | 128 // The min/max height of popups. |
171 static const int kMinWidth; | 129 static const int kMinWidth; |
172 static const int kMinHeight; | 130 static const int kMinHeight; |
173 static const int kMaxWidth; | 131 static const int kMaxWidth; |
174 static const int kMaxHeight; | 132 static const int kMaxHeight; |
175 | 133 |
176 private: | 134 private: |
177 ExtensionPopup(ExtensionHost* host, | 135 ExtensionPopup(ExtensionHost* host, |
178 views::Widget* frame, | 136 views::Widget* frame, |
179 const gfx::Rect& relative_to, | 137 const gfx::Rect& relative_to, |
180 BubbleBorder::ArrowLocation arrow_location, | 138 BubbleBorder::ArrowLocation arrow_location, |
181 bool activate_on_show, | |
182 bool inspect_with_devtools, | 139 bool inspect_with_devtools, |
183 PopupChrome chrome, | |
184 Observer* observer); | 140 Observer* observer); |
185 | 141 |
186 // The area on the screen that the popup should be positioned relative to. | 142 // The area on the screen that the popup should be positioned relative to. |
187 gfx::Rect relative_to_; | 143 gfx::Rect relative_to_; |
188 | 144 |
189 // The contained host for the view. | 145 // The contained host for the view. |
190 scoped_ptr<ExtensionHost> extension_host_; | 146 scoped_ptr<ExtensionHost> extension_host_; |
191 | 147 |
192 // Flag used to indicate if the pop-up should be activated upon first display. | |
193 bool activate_on_show_; | |
194 | |
195 // Flag used to indicate if the pop-up should open a devtools window once | 148 // Flag used to indicate if the pop-up should open a devtools window once |
196 // it is shown inspecting it. | 149 // it is shown inspecting it. |
197 bool inspect_with_devtools_; | 150 bool inspect_with_devtools_; |
198 | 151 |
199 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls. | 152 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls. |
200 bool close_on_lost_focus_; | 153 bool close_on_lost_focus_; |
201 | 154 |
202 // Whether the ExtensionPopup is current going about closing itself. | 155 // Whether the ExtensionPopup is current going about closing itself. |
203 bool closing_; | 156 bool closing_; |
204 | 157 |
205 NotificationRegistrar registrar_; | 158 NotificationRegistrar registrar_; |
206 | 159 |
207 // A separate widget and associated pieces to draw a border behind the | 160 // A separate widget and associated pieces to draw a border behind the |
208 // popup. This has to be a separate window in order to support transparency. | 161 // popup. This has to be a separate window in order to support transparency. |
209 // Layered windows can't contain native child windows, so we wouldn't be | 162 // Layered windows can't contain native child windows, so we wouldn't be |
210 // able to have the ExtensionView child. | 163 // able to have the ExtensionView child. |
211 views::Widget* border_widget_; | 164 views::Widget* border_widget_; |
212 BubbleBorder* border_; | 165 BubbleBorder* border_; |
213 views::View* border_view_; | 166 views::View* border_view_; |
214 | 167 |
215 // The type of chrome associated with the popup window. | |
216 PopupChrome popup_chrome_; | |
217 | |
218 // The maximal size to which the popup may expand. | 168 // The maximal size to which the popup may expand. |
219 gfx::Size max_size_; | 169 gfx::Size max_size_; |
220 | 170 |
221 // The observer of this popup. | 171 // The observer of this popup. |
222 Observer* observer_; | 172 Observer* observer_; |
223 | 173 |
224 // A cached copy of the arrow-position for the bubble chrome. | 174 // A cached copy of the arrow-position for the bubble chrome. |
225 // If a black-border was requested, we still need this value to determine | 175 // If a black-border was requested, we still need this value to determine |
226 // the position of the pop-up in relation to |relative_to_|. | 176 // the position of the pop-up in relation to |relative_to_|. |
227 BubbleBorder::ArrowLocation anchor_position_; | 177 BubbleBorder::ArrowLocation anchor_position_; |
228 | 178 |
229 // ExtensionPopup's lifetime is managed via reference counting, but it does | |
230 // not expose the RefCounted interface. Instead, the lifetime is tied to | |
231 // this member variable. | |
232 class InternalRefCounter : public base::RefCounted<InternalRefCounter> { | |
233 }; | |
234 InternalRefCounter* instance_lifetime_; | |
235 | |
236 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); | 179 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); |
237 }; | 180 }; |
238 | 181 |
239 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ | 182 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
OLD | NEW |