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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 AddChildView(GetExtensionView(host)); | 58 AddChildView(GetExtensionView(host)); |
59 GetExtensionView(host)->set_container(this); | 59 GetExtensionView(host)->set_container(this); |
60 // ExtensionPopup closes itself on very specific de-activation conditions. | 60 // ExtensionPopup closes itself on very specific de-activation conditions. |
61 set_close_on_deactivate(false); | 61 set_close_on_deactivate(false); |
62 | 62 |
63 // Wait to show the popup until the contained host finishes loading. | 63 // Wait to show the popup until the contained host finishes loading. |
64 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 64 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
65 content::Source<content::WebContents>(host->host_contents())); | 65 content::Source<content::WebContents>(host->host_contents())); |
66 | 66 |
67 // Listen for the containing view calling window.close(); | 67 // Listen for the containing view calling window.close(); |
68 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 68 registrar_.Add( |
| 69 this, |
| 70 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
69 content::Source<content::BrowserContext>(host->browser_context())); | 71 content::Source<content::BrowserContext>(host->browser_context())); |
70 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 72 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
71 devtools_callback_); | 73 devtools_callback_); |
72 | 74 |
73 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); | 75 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); |
74 } | 76 } |
75 | 77 |
76 ExtensionPopup::~ExtensionPopup() { | 78 ExtensionPopup::~ExtensionPopup() { |
77 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 79 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
78 devtools_callback_); | 80 devtools_callback_); |
79 | 81 |
80 GetExtensionView( | 82 GetExtensionView( |
81 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); | 83 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); |
82 } | 84 } |
83 | 85 |
84 void ExtensionPopup::Observe(int type, | 86 void ExtensionPopup::Observe(int type, |
85 const content::NotificationSource& source, | 87 const content::NotificationSource& source, |
86 const content::NotificationDetails& details) { | 88 const content::NotificationDetails& details) { |
87 switch (type) { | 89 switch (type) { |
88 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 90 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
89 DCHECK_EQ(host()->host_contents(), | 91 DCHECK_EQ(host()->host_contents(), |
90 content::Source<content::WebContents>(source).ptr()); | 92 content::Source<content::WebContents>(source).ptr()); |
91 // Show when the content finishes loading and its width is computed. | 93 // Show when the content finishes loading and its width is computed. |
92 ShowBubble(); | 94 ShowBubble(); |
93 break; | 95 break; |
94 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 96 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
95 // If we aren't the host of the popup, then disregard the notification. | 97 // If we aren't the host of the popup, then disregard the notification. |
96 if (content::Details<extensions::ExtensionHost>(host()) == details) | 98 if (content::Details<extensions::ExtensionHost>(host()) == details) |
97 GetWidget()->Close(); | 99 GetWidget()->Close(); |
98 break; | 100 break; |
99 default: | 101 default: |
100 NOTREACHED() << L"Received unexpected notification"; | 102 NOTREACHED() << L"Received unexpected notification"; |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 void ExtensionPopup::OnDevToolsStateChanged( | 106 void ExtensionPopup::OnDevToolsStateChanged( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 GetWidget()->Show(); | 222 GetWidget()->Show(); |
221 | 223 |
222 // Focus on the host contents when the bubble is first shown. | 224 // Focus on the host contents when the bubble is first shown. |
223 host()->host_contents()->Focus(); | 225 host()->host_contents()->Focus(); |
224 | 226 |
225 if (inspect_with_devtools_) { | 227 if (inspect_with_devtools_) { |
226 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), | 228 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), |
227 DevToolsToggleAction::ShowConsole()); | 229 DevToolsToggleAction::ShowConsole()); |
228 } | 230 } |
229 } | 231 } |
OLD | NEW |