OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/extensions/extension_popup.h" | 5 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
10 #include "chrome/browser/extensions/extension_view_host.h" | 10 #include "chrome/browser/extensions/extension_view_host.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 #include "ui/wm/core/window_animations.h" | 24 #include "ui/wm/core/window_animations.h" |
25 #include "ui/wm/core/window_util.h" | 25 #include "ui/wm/core/window_util.h" |
26 #include "ui/wm/public/activation_client.h" | 26 #include "ui/wm/public/activation_client.h" |
27 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "ui/views/win/hwnd_util.h" | 29 #include "ui/views/win/hwnd_util.h" |
30 #endif | 30 #endif |
31 | 31 |
| 32 namespace { |
| 33 |
| 34 ExtensionViewViews* GetExtensionView(extensions::ExtensionViewHost* host) { |
| 35 return static_cast<ExtensionViewViews*>(host->view()); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
32 // The minimum/maximum dimensions of the popup. | 40 // The minimum/maximum dimensions of the popup. |
33 // The minimum is just a little larger than the size of the button itself. | 41 // The minimum is just a little larger than the size of the button itself. |
34 // The maximum is an arbitrary number that should be smaller than most screens. | 42 // The maximum is an arbitrary number that should be smaller than most screens. |
35 const int ExtensionPopup::kMinWidth = 25; | 43 const int ExtensionPopup::kMinWidth = 25; |
36 const int ExtensionPopup::kMinHeight = 25; | 44 const int ExtensionPopup::kMinHeight = 25; |
37 const int ExtensionPopup::kMaxWidth = 800; | 45 const int ExtensionPopup::kMaxWidth = 800; |
38 const int ExtensionPopup::kMaxHeight = 600; | 46 const int ExtensionPopup::kMaxHeight = 600; |
39 | 47 |
40 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, | 48 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, |
41 views::View* anchor_view, | 49 views::View* anchor_view, |
42 views::BubbleBorder::Arrow arrow, | 50 views::BubbleBorder::Arrow arrow, |
43 ShowAction show_action) | 51 ShowAction show_action) |
44 : BubbleDelegateView(anchor_view, arrow), | 52 : BubbleDelegateView(anchor_view, arrow), |
45 host_(host), | 53 host_(host), |
46 devtools_callback_(base::Bind( | 54 devtools_callback_(base::Bind( |
47 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), | 55 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), |
48 widget_initialized_(false) { | 56 widget_initialized_(false) { |
49 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; | 57 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; |
50 // Adjust the margin so that contents fit better. | 58 // Adjust the margin so that contents fit better. |
51 const int margin = views::BubbleBorder::GetCornerRadius() / 2; | 59 const int margin = views::BubbleBorder::GetCornerRadius() / 2; |
52 set_margins(gfx::Insets(margin, margin, margin, margin)); | 60 set_margins(gfx::Insets(margin, margin, margin, margin)); |
53 SetLayoutManager(new views::FillLayout()); | 61 SetLayoutManager(new views::FillLayout()); |
54 AddChildView(host->view()); | 62 AddChildView(GetExtensionView(host)); |
55 host->view()->set_container(this); | 63 GetExtensionView(host)->set_container(this); |
56 // ExtensionPopup closes itself on very specific de-activation conditions. | 64 // ExtensionPopup closes itself on very specific de-activation conditions. |
57 set_close_on_deactivate(false); | 65 set_close_on_deactivate(false); |
58 | 66 |
59 // Wait to show the popup until the contained host finishes loading. | 67 // Wait to show the popup until the contained host finishes loading. |
60 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 68 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
61 content::Source<content::WebContents>(host->host_contents())); | 69 content::Source<content::WebContents>(host->host_contents())); |
62 | 70 |
63 // Listen for the containing view calling window.close(); | 71 // Listen for the containing view calling window.close(); |
64 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 72 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
65 content::Source<content::BrowserContext>(host->browser_context())); | 73 content::Source<content::BrowserContext>(host->browser_context())); |
66 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 74 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
67 devtools_callback_); | 75 devtools_callback_); |
68 | 76 |
69 host_->view()->browser()->tab_strip_model()->AddObserver(this); | 77 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); |
70 } | 78 } |
71 | 79 |
72 ExtensionPopup::~ExtensionPopup() { | 80 ExtensionPopup::~ExtensionPopup() { |
73 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 81 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
74 devtools_callback_); | 82 devtools_callback_); |
75 | 83 |
76 host_->view()->browser()->tab_strip_model()->RemoveObserver(this); | 84 GetExtensionView( |
| 85 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); |
77 } | 86 } |
78 | 87 |
79 void ExtensionPopup::Observe(int type, | 88 void ExtensionPopup::Observe(int type, |
80 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
81 const content::NotificationDetails& details) { | 90 const content::NotificationDetails& details) { |
82 switch (type) { | 91 switch (type) { |
83 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 92 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
84 DCHECK_EQ(host()->host_contents(), | 93 DCHECK_EQ(host()->host_contents(), |
85 content::Source<content::WebContents>(source).ptr()); | 94 content::Source<content::WebContents>(source).ptr()); |
86 // Show when the content finishes loading and its width is computed. | 95 // Show when the content finishes loading and its width is computed. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 GetWidget()->Show(); | 224 GetWidget()->Show(); |
216 | 225 |
217 // Focus on the host contents when the bubble is first shown. | 226 // Focus on the host contents when the bubble is first shown. |
218 host()->host_contents()->Focus(); | 227 host()->host_contents()->Focus(); |
219 | 228 |
220 if (inspect_with_devtools_) { | 229 if (inspect_with_devtools_) { |
221 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), | 230 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), |
222 DevToolsToggleAction::ShowConsole()); | 231 DevToolsToggleAction::ShowConsole()); |
223 } | 232 } |
224 } | 233 } |
OLD | NEW |