| 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 "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/devtools/devtools_window.h" | 10 #include "chrome/browser/devtools/devtools_window.h" |
| 11 #include "chrome/browser/extensions/extension_view_host.h" | 11 #include "chrome/browser/extensions/extension_view_host.h" |
| 12 #include "chrome/browser/extensions/extension_view_host_factory.h" | 12 #include "chrome/browser/extensions/extension_view_host_factory.h" |
| 13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/host_desktop.h" | 17 #include "chrome/browser/ui/host_desktop.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "content/public/browser/devtools_agent_host.h" | 20 #include "content/public/browser/devtools_agent_host.h" |
| 20 #include "content/public/browser/devtools_manager.h" | 21 #include "content/public/browser/devtools_manager.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_view.h" | 26 #include "content/public/browser/web_contents_view.h" |
| 26 #include "ui/gfx/insets.h" | 27 #include "ui/gfx/insets.h" |
| 27 #include "ui/views/layout/fill_layout.h" | 28 #include "ui/views/layout/fill_layout.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 88 |
| 88 // Wait to show the popup until the contained host finishes loading. | 89 // Wait to show the popup until the contained host finishes loading. |
| 89 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 90 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 90 content::Source<WebContents>(host->host_contents())); | 91 content::Source<WebContents>(host->host_contents())); |
| 91 | 92 |
| 92 // Listen for the containing view calling window.close(); | 93 // Listen for the containing view calling window.close(); |
| 93 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 94 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 94 content::Source<BrowserContext>(host->browser_context())); | 95 content::Source<BrowserContext>(host->browser_context())); |
| 95 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 96 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
| 96 devtools_callback_); | 97 devtools_callback_); |
| 98 |
| 99 host_->view()->browser()->tab_strip_model()->AddObserver(this); |
| 97 } | 100 } |
| 98 | 101 |
| 99 ExtensionPopup::~ExtensionPopup() { | 102 ExtensionPopup::~ExtensionPopup() { |
| 100 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 103 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
| 101 devtools_callback_); | 104 devtools_callback_); |
| 105 |
| 106 host_->view()->browser()->tab_strip_model()->RemoveObserver(this); |
| 102 } | 107 } |
| 103 | 108 |
| 104 void ExtensionPopup::Observe(int type, | 109 void ExtensionPopup::Observe(int type, |
| 105 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
| 106 const content::NotificationDetails& details) { | 111 const content::NotificationDetails& details) { |
| 107 switch (type) { | 112 switch (type) { |
| 108 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 113 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 109 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); | 114 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); |
| 110 // Show when the content finishes loading and its width is computed. | 115 // Show when the content finishes loading and its width is computed. |
| 111 ShowBubble(); | 116 ShowBubble(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 chrome::HostDesktopType host_desktop_type = | 190 chrome::HostDesktopType host_desktop_type = |
| 186 chrome::GetHostDesktopTypeForNativeWindow(this_window); | 191 chrome::GetHostDesktopTypeForNativeWindow(this_window); |
| 187 if (!inspect_with_devtools_ && anchor_window == gained_active && | 192 if (!inspect_with_devtools_ && anchor_window == gained_active && |
| 188 host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH && | 193 host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH && |
| 189 this_window->GetRootWindow() == anchor_window->GetRootWindow() && | 194 this_window->GetRootWindow() == anchor_window->GetRootWindow() && |
| 190 gained_active->transient_parent() != this_window) | 195 gained_active->transient_parent() != this_window) |
| 191 GetWidget()->Close(); | 196 GetWidget()->Close(); |
| 192 } | 197 } |
| 193 #endif | 198 #endif |
| 194 | 199 |
| 200 void ExtensionPopup::ActiveTabChanged(content::WebContents* old_contents, |
| 201 content::WebContents* new_contents, |
| 202 int index, |
| 203 int reason) { |
| 204 GetWidget()->Close(); |
| 205 } |
| 206 |
| 195 // static | 207 // static |
| 196 ExtensionPopup* ExtensionPopup::ShowPopup(const GURL& url, | 208 ExtensionPopup* ExtensionPopup::ShowPopup(const GURL& url, |
| 197 Browser* browser, | 209 Browser* browser, |
| 198 views::View* anchor_view, | 210 views::View* anchor_view, |
| 199 views::BubbleBorder::Arrow arrow, | 211 views::BubbleBorder::Arrow arrow, |
| 200 ShowAction show_action) { | 212 ShowAction show_action) { |
| 201 extensions::ExtensionViewHost* host = | 213 extensions::ExtensionViewHost* host = |
| 202 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser); | 214 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser); |
| 203 ExtensionPopup* popup = new ExtensionPopup(host, anchor_view, arrow, | 215 ExtensionPopup* popup = new ExtensionPopup(host, anchor_view, arrow, |
| 204 show_action); | 216 show_action); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 234 | 246 |
| 235 // Focus on the host contents when the bubble is first shown. | 247 // Focus on the host contents when the bubble is first shown. |
| 236 host()->host_contents()->GetView()->Focus(); | 248 host()->host_contents()->GetView()->Focus(); |
| 237 | 249 |
| 238 if (inspect_with_devtools_) { | 250 if (inspect_with_devtools_) { |
| 239 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), | 251 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), |
| 240 true, | 252 true, |
| 241 DevToolsToggleAction::ShowConsole()); | 253 DevToolsToggleAction::ShowConsole()); |
| 242 } | 254 } |
| 243 } | 255 } |
| OLD | NEW |