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/views/extensions/extension_popup.h" | 5 #include "chrome/browser/views/extensions/extension_popup.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_list.h" |
8 #include "chrome/browser/browser_window.h" | 9 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
11 #include "chrome/browser/views/frame/browser_view.h" | 12 #include "chrome/browser/views/frame/browser_view.h" |
12 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/notification_details.h" | 14 #include "chrome/common/notification_details.h" |
14 #include "chrome/common/notification_source.h" | 15 #include "chrome/common/notification_source.h" |
15 #include "chrome/common/notification_type.h" | 16 #include "chrome/common/notification_type.h" |
16 #include "views/widget/root_view.h" | 17 #include "views/widget/root_view.h" |
17 #include "views/window/window.h" | 18 #include "views/window/window.h" |
18 | 19 |
19 using views::Widget; | 20 using views::Widget; |
20 | 21 |
21 // The minimum/maximum dimensions of the popup. | 22 // The minimum/maximum dimensions of the popup. |
22 // The minimum is just a little larger than the size of the button itself. | 23 // The minimum is just a little larger than the size of the button itself. |
23 // The maximum is an arbitrary number that should be smaller than most screens. | 24 // The maximum is an arbitrary number that should be smaller than most screens. |
24 const int ExtensionPopup::kMinWidth = 25; | 25 const int ExtensionPopup::kMinWidth = 25; |
25 const int ExtensionPopup::kMinHeight = 25; | 26 const int ExtensionPopup::kMinHeight = 25; |
26 const int ExtensionPopup::kMaxWidth = 800; | 27 const int ExtensionPopup::kMaxWidth = 800; |
27 const int ExtensionPopup::kMaxHeight = 600; | 28 const int ExtensionPopup::kMaxHeight = 600; |
28 | 29 |
29 ExtensionPopup::ExtensionPopup(ExtensionHost* host, | 30 ExtensionPopup::ExtensionPopup(ExtensionHost* host, |
30 Widget* frame, | 31 views::Widget* frame, |
31 const gfx::Rect& relative_to, | 32 const gfx::Rect& relative_to, |
32 BubbleBorder::ArrowLocation arrow_location, | 33 BubbleBorder::ArrowLocation arrow_location, |
33 bool activate_on_show) | 34 bool activate_on_show) |
34 : BrowserBubble(host->view(), | 35 : BrowserBubble(host->view(), |
35 frame, | 36 frame, |
36 gfx::Point()), | 37 gfx::Point()), |
37 relative_to_(relative_to), | 38 relative_to_(relative_to), |
38 extension_host_(host), | 39 extension_host_(host), |
39 activate_on_show_(activate_on_show) { | 40 activate_on_show_(activate_on_show) { |
40 host->view()->SetContainer(this); | 41 host->view()->SetContainer(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 void ExtensionPopup::Hide() { | 73 void ExtensionPopup::Hide() { |
73 BrowserBubble::Hide(); | 74 BrowserBubble::Hide(); |
74 border_widget_->Hide(); | 75 border_widget_->Hide(); |
75 } | 76 } |
76 | 77 |
77 void ExtensionPopup::Show(bool activate) { | 78 void ExtensionPopup::Show(bool activate) { |
78 if (visible()) | 79 if (visible()) |
79 return; | 80 return; |
80 | 81 |
81 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
82 frame_->GetWindow()->DisableInactiveRendering(); | 83 if (frame_->GetWindow()) |
| 84 frame_->GetWindow()->DisableInactiveRendering(); |
83 #endif | 85 #endif |
84 | 86 |
85 ResizeToView(); | 87 ResizeToView(); |
86 | 88 |
87 // Show the border first, then the popup overlaid on top. | 89 // Show the border first, then the popup overlaid on top. |
88 border_widget_->Show(); | 90 border_widget_->Show(); |
89 BrowserBubble::Show(activate); | 91 BrowserBubble::Show(activate); |
90 } | 92 } |
91 | 93 |
92 void ExtensionPopup::ResizeToView() { | 94 void ExtensionPopup::ResizeToView() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 gfx::Size sz = view->GetPreferredSize(); | 137 gfx::Size sz = view->GetPreferredSize(); |
136 view->SetBounds(view->x(), view->y(), | 138 view->SetBounds(view->x(), view->y(), |
137 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), | 139 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), |
138 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); | 140 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); |
139 | 141 |
140 ResizeToView(); | 142 ResizeToView(); |
141 } | 143 } |
142 | 144 |
143 // static | 145 // static |
144 ExtensionPopup* ExtensionPopup::Show( | 146 ExtensionPopup* ExtensionPopup::Show( |
145 const GURL& url, Browser* browser, | 147 const GURL& url, |
| 148 Browser* browser, |
| 149 Profile* profile, |
| 150 gfx::NativeWindow frame_window, |
146 const gfx::Rect& relative_to, | 151 const gfx::Rect& relative_to, |
147 BubbleBorder::ArrowLocation arrow_location, | 152 BubbleBorder::ArrowLocation arrow_location, |
148 bool activate_on_show) { | 153 bool activate_on_show) { |
149 ExtensionProcessManager* manager = | 154 DCHECK(profile); |
150 browser->profile()->GetExtensionProcessManager(); | 155 DCHECK(frame_window); |
| 156 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); |
151 DCHECK(manager); | 157 DCHECK(manager); |
152 if (!manager) | 158 if (!manager) |
153 return NULL; | 159 return NULL; |
154 | 160 |
| 161 // If no Browser instance was given, attempt to look up one matching the given |
| 162 // profile. |
| 163 if (!browser) |
| 164 browser = BrowserList::FindBrowserWithProfile(profile); |
| 165 |
| 166 Widget* frame_widget = Widget::GetWidgetFromNativeWindow(frame_window); |
| 167 DCHECK(frame_widget); |
| 168 if (!frame_widget) |
| 169 return NULL; |
| 170 |
155 ExtensionHost* host = manager->CreatePopup(url, browser); | 171 ExtensionHost* host = manager->CreatePopup(url, browser); |
156 views::Widget* frame = BrowserView::GetBrowserViewForNativeWindow( | 172 ExtensionPopup* popup = new ExtensionPopup(host, frame_widget, relative_to, |
157 browser->window()->GetNativeHandle())->GetWidget(); | |
158 ExtensionPopup* popup = new ExtensionPopup(host, frame, relative_to, | |
159 arrow_location, activate_on_show); | 173 arrow_location, activate_on_show); |
160 | 174 |
161 // If the host had somehow finished loading, then we'd miss the notification | 175 // If the host had somehow finished loading, then we'd miss the notification |
162 // and not show. This seems to happen in single-process mode. | 176 // and not show. This seems to happen in single-process mode. |
163 if (host->did_stop_loading()) | 177 if (host->did_stop_loading()) |
164 popup->Show(activate_on_show); | 178 popup->Show(activate_on_show); |
165 | 179 |
166 return popup; | 180 return popup; |
167 } | 181 } |
OLD | NEW |