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_list.h" | 7 #include "chrome/browser/browser_list.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/debugger/devtools_manager.h" | 9 #include "chrome/browser/debugger/devtools_manager.h" |
10 #include "chrome/browser/debugger/devtools_toggle_action.h" | 10 #include "chrome/browser/debugger/devtools_toggle_action.h" |
11 #include "chrome/browser/extensions/extension_host.h" | 11 #include "chrome/browser/extensions/extension_host.h" |
12 #include "chrome/browser/extensions/extension_process_manager.h" | 12 #include "chrome/browser/extensions/extension_process_manager.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 14 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
15 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/views/frame/browser_view.h" | 17 #include "chrome/browser/views/frame/browser_view.h" |
| 18 #include "chrome/browser/window_sizer.h" |
18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/notification_details.h" | 20 #include "chrome/common/notification_details.h" |
20 #include "chrome/common/notification_source.h" | 21 #include "chrome/common/notification_source.h" |
21 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
23 #include "views/widget/root_view.h" | 24 #include "views/widget/root_view.h" |
24 #include "views/window/window.h" | 25 #include "views/window/window.h" |
25 | 26 |
| 27 |
26 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
27 #include "views/widget/widget_gtk.h" | 29 #include "views/widget/widget_gtk.h" |
28 #endif | 30 #endif |
29 | 31 |
30 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
31 #include "chrome/browser/chromeos/wm_ipc.h" | 33 #include "chrome/browser/chromeos/wm_ipc.h" |
32 #include "cros/chromeos_wm_ipc_enums.h" | 34 #include "cros/chromeos_wm_ipc_enums.h" |
33 #endif | 35 #endif |
34 | 36 |
35 using views::Widget; | 37 using views::Widget; |
36 | 38 |
37 // The minimum/maximum dimensions of the popup. | 39 // The minimum, and default maximum dimensions of the popup. |
38 // The minimum is just a little larger than the size of the button itself. | 40 // The minimum is just a little larger than the size of the button itself. |
39 // The maximum is an arbitrary number that should be smaller than most screens. | 41 // The default maximum is an arbitrary number that should be smaller than most |
| 42 // screens. |
40 const int ExtensionPopup::kMinWidth = 25; | 43 const int ExtensionPopup::kMinWidth = 25; |
41 const int ExtensionPopup::kMinHeight = 25; | 44 const int ExtensionPopup::kMinHeight = 25; |
42 const int ExtensionPopup::kMaxWidth = 800; | 45 const int ExtensionPopup::kMaxWidth = 800; |
43 const int ExtensionPopup::kMaxHeight = 600; | 46 const int ExtensionPopup::kMaxHeight = 600; |
44 | 47 |
45 namespace { | 48 namespace { |
46 | 49 |
47 // The width, in pixels, of the black-border on a popup. | 50 // The width, in pixels, of the black-border on a popup. |
48 const int kPopupBorderWidth = 1; | 51 const int kPopupBorderWidth = 1; |
49 | 52 |
(...skipping 19 matching lines...) Expand all Loading... |
69 relative_to_(relative_to), | 72 relative_to_(relative_to), |
70 extension_host_(host), | 73 extension_host_(host), |
71 activate_on_show_(activate_on_show), | 74 activate_on_show_(activate_on_show), |
72 inspect_with_devtools_(inspect_with_devtools), | 75 inspect_with_devtools_(inspect_with_devtools), |
73 close_on_lost_focus_(true), | 76 close_on_lost_focus_(true), |
74 closing_(false), | 77 closing_(false), |
75 border_widget_(NULL), | 78 border_widget_(NULL), |
76 border_(NULL), | 79 border_(NULL), |
77 border_view_(NULL), | 80 border_view_(NULL), |
78 popup_chrome_(chrome), | 81 popup_chrome_(chrome), |
| 82 max_size_(kMaxWidth, kMaxHeight), |
79 observer_(observer), | 83 observer_(observer), |
80 anchor_position_(arrow_location), | 84 anchor_position_(arrow_location), |
81 instance_lifetime_(new InternalRefCounter()){ | 85 instance_lifetime_(new InternalRefCounter()){ |
82 AddRef(); // Balanced in Close(); | 86 AddRef(); // Balanced in Close(); |
83 set_delegate(this); | 87 set_delegate(this); |
84 host->view()->SetContainer(this); | 88 host->view()->SetContainer(this); |
85 | 89 |
86 // We wait to show the popup until the contained host finishes loading. | 90 // We wait to show the popup until the contained host finishes loading. |
87 registrar_.Add(this, | 91 registrar_.Add(this, |
88 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 92 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 286 |
283 break; | 287 break; |
284 default: | 288 default: |
285 NOTREACHED() << L"Received unexpected notification"; | 289 NOTREACHED() << L"Received unexpected notification"; |
286 } | 290 } |
287 } | 291 } |
288 | 292 |
289 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 293 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
290 // Constrain the size to popup min/max. | 294 // Constrain the size to popup min/max. |
291 gfx::Size sz = view->GetPreferredSize(); | 295 gfx::Size sz = view->GetPreferredSize(); |
| 296 |
| 297 // Enforce that the popup never resizes to larger than the working monitor |
| 298 // bounds. |
| 299 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_provider( |
| 300 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 301 gfx::Rect monitor_bounds( |
| 302 monitor_provider->GetMonitorWorkAreaMatching(relative_to_)); |
| 303 |
| 304 int max_width = std::min(max_size_.width(), monitor_bounds.width()); |
| 305 int max_height = std::min(max_size_.height(), monitor_bounds.height()); |
292 view->SetBounds(view->x(), view->y(), | 306 view->SetBounds(view->x(), view->y(), |
293 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), | 307 std::max(kMinWidth, std::min(max_width, sz.width())), |
294 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); | 308 std::max(kMinHeight, std::min(max_height, sz.height()))); |
295 | 309 |
296 // If popup_chrome_ == RECTANGLE_CHROME, the border is drawn in the client | 310 // If popup_chrome_ == RECTANGLE_CHROME, the border is drawn in the client |
297 // area of the ExtensionView, rather than in a window which sits behind it. | 311 // area of the ExtensionView, rather than in a window which sits behind it. |
298 // In this case, the actual size of the view must be enlarged so that the | 312 // In this case, the actual size of the view must be enlarged so that the |
299 // web contents portion of the view gets its full PreferredSize area. | 313 // web contents portion of the view gets its full PreferredSize area. |
300 if (view->border()) { | 314 if (view->border()) { |
301 gfx::Insets border_insets; | 315 gfx::Insets border_insets; |
302 view->border()->GetInsets(&border_insets); | 316 view->border()->GetInsets(&border_insets); |
303 | 317 |
304 gfx::Rect bounds(view->bounds()); | 318 gfx::Rect bounds(view->bounds()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 394 |
381 ExtensionHost* host = manager->CreatePopup(url, browser); | 395 ExtensionHost* host = manager->CreatePopup(url, browser); |
382 if (observer) | 396 if (observer) |
383 observer->ExtensionHostCreated(host); | 397 observer->ExtensionHostCreated(host); |
384 | 398 |
385 ExtensionPopup* popup = new ExtensionPopup(host, frame_widget, relative_to, | 399 ExtensionPopup* popup = new ExtensionPopup(host, frame_widget, relative_to, |
386 arrow_location, activate_on_show, | 400 arrow_location, activate_on_show, |
387 inspect_with_devtools, chrome, | 401 inspect_with_devtools, chrome, |
388 observer); | 402 observer); |
389 | 403 |
| 404 if (observer) |
| 405 observer->ExtensionPopupCreated(popup); |
| 406 |
390 // If the host had somehow finished loading, then we'd miss the notification | 407 // If the host had somehow finished loading, then we'd miss the notification |
391 // and not show. This seems to happen in single-process mode. | 408 // and not show. This seems to happen in single-process mode. |
392 if (host->did_stop_loading()) | 409 if (host->did_stop_loading()) |
393 popup->Show(activate_on_show); | 410 popup->Show(activate_on_show); |
394 | 411 |
395 return popup; | 412 return popup; |
396 } | 413 } |
397 | 414 |
398 void ExtensionPopup::Close() { | 415 void ExtensionPopup::Close() { |
399 if (closing_) | 416 if (closing_) |
(...skipping 14 matching lines...) Expand all Loading... |
414 DCHECK(closing_) << "ExtensionPopup to be destroyed before being closed."; | 431 DCHECK(closing_) << "ExtensionPopup to be destroyed before being closed."; |
415 ExtensionPopup::Observer* observer = observer_; | 432 ExtensionPopup::Observer* observer = observer_; |
416 delete this; | 433 delete this; |
417 | 434 |
418 // |this| is passed only as a 'cookie'. The observer API explicitly takes a | 435 // |this| is passed only as a 'cookie'. The observer API explicitly takes a |
419 // void* argument to emphasize this. | 436 // void* argument to emphasize this. |
420 if (observer) | 437 if (observer) |
421 observer->ExtensionPopupClosed(this); | 438 observer->ExtensionPopupClosed(this); |
422 } | 439 } |
423 } | 440 } |
OLD | NEW |