| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; | 60 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; |
| 61 // Adjust the margin so that contents fit better. | 61 // Adjust the margin so that contents fit better. |
| 62 const int margin = views::BubbleBorder::GetCornerRadius() / 2; | 62 const int margin = views::BubbleBorder::GetCornerRadius() / 2; |
| 63 set_margins(gfx::Insets(margin, margin, margin, margin)); | 63 set_margins(gfx::Insets(margin, margin, margin, margin)); |
| 64 SetLayoutManager(new views::FillLayout()); | 64 SetLayoutManager(new views::FillLayout()); |
| 65 AddChildView(GetExtensionView(host)); | 65 AddChildView(GetExtensionView(host)); |
| 66 GetExtensionView(host)->set_container(this); | 66 GetExtensionView(host)->set_container(this); |
| 67 // ExtensionPopup closes itself on very specific de-activation conditions. | 67 // ExtensionPopup closes itself on very specific de-activation conditions. |
| 68 set_close_on_deactivate(false); | 68 set_close_on_deactivate(false); |
| 69 | 69 |
| 70 // Wait to show the popup until the contained host finishes loading. | |
| 71 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 72 content::Source<content::WebContents>(host->host_contents())); | |
| 73 | 70 |
| 74 // Listen for the containing view calling window.close(); | 71 // Listen for the containing view calling window.close(); |
| 75 registrar_.Add( | 72 registrar_.Add( |
| 76 this, | 73 this, |
| 77 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 74 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 78 content::Source<content::BrowserContext>(host->browser_context())); | 75 content::Source<content::BrowserContext>(host->browser_context())); |
| 79 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); | 76 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); |
| 80 | 77 |
| 81 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); | 78 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); |
| 79 |
| 80 // If the host had somehow finished loading, then we'd miss the notification |
| 81 // and not show. This seems to happen in single-process mode. |
| 82 if (host_->has_loaded_once()) { |
| 83 ShowBubble(); |
| 84 } else { |
| 85 // Wait to show the popup until the contained host finishes loading. |
| 86 registrar_.Add(this, |
| 87 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 88 content::Source<content::WebContents>( |
| 89 host_->host_contents())); |
| 90 } |
| 82 } | 91 } |
| 83 | 92 |
| 84 ExtensionPopup::~ExtensionPopup() { | 93 ExtensionPopup::~ExtensionPopup() { |
| 85 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); | 94 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); |
| 86 | 95 |
| 87 GetExtensionView( | 96 GetExtensionView( |
| 88 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); | 97 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); |
| 89 } | 98 } |
| 90 | 99 |
| 91 void ExtensionPopup::Observe(int type, | 100 void ExtensionPopup::Observe(int type, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // TODO(msw): Find any remaining crashes related to http://crbug.com/327776 | 172 // TODO(msw): Find any remaining crashes related to http://crbug.com/327776 |
| 164 // No calls are expected if the widget isn't initialized or no longer exists. | 173 // No calls are expected if the widget isn't initialized or no longer exists. |
| 165 CHECK(widget_initialized_); | 174 CHECK(widget_initialized_); |
| 166 CHECK(GetWidget()); | 175 CHECK(GetWidget()); |
| 167 | 176 |
| 168 if (!inspect_with_devtools_) | 177 if (!inspect_with_devtools_) |
| 169 GetWidget()->Close(); | 178 GetWidget()->Close(); |
| 170 } | 179 } |
| 171 | 180 |
| 172 // static | 181 // static |
| 173 ExtensionPopup* ExtensionPopup::ShowPopup(const GURL& url, | 182 ExtensionPopup* ExtensionPopup::ShowPopup( |
| 174 Browser* browser, | 183 scoped_ptr<extensions::ExtensionViewHost> host, |
| 175 views::View* anchor_view, | 184 views::View* anchor_view, |
| 176 views::BubbleBorder::Arrow arrow, | 185 views::BubbleBorder::Arrow arrow, |
| 177 ShowAction show_action) { | 186 ShowAction show_action) { |
| 178 extensions::ExtensionViewHost* host = | 187 return ExtensionPopup::Create( |
| 179 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser); | 188 host.release(), anchor_view, arrow, show_action); |
| 180 auto popup = ExtensionPopup::Create(host, anchor_view, arrow, show_action); | |
| 181 | |
| 182 // If the host had somehow finished loading, then we'd miss the notification | |
| 183 // and not show. This seems to happen in single-process mode. | |
| 184 if (host->has_loaded_once()) | |
| 185 popup->ShowBubble(); | |
| 186 | |
| 187 return popup; | |
| 188 } | 189 } |
| 189 | 190 |
| 190 void ExtensionPopup::ShowBubble() { | 191 void ExtensionPopup::ShowBubble() { |
| 191 GetWidget()->Show(); | 192 GetWidget()->Show(); |
| 192 | 193 |
| 193 // Focus on the host contents when the bubble is first shown. | 194 // Focus on the host contents when the bubble is first shown. |
| 194 host()->host_contents()->Focus(); | 195 host()->host_contents()->Focus(); |
| 195 | 196 |
| 196 if (inspect_with_devtools_) { | 197 if (inspect_with_devtools_) { |
| 197 DevToolsWindow::OpenDevToolsWindow(host()->host_contents(), | 198 DevToolsWindow::OpenDevToolsWindow(host()->host_contents(), |
| 198 DevToolsToggleAction::ShowConsole()); | 199 DevToolsToggleAction::ShowConsole()); |
| 199 } | 200 } |
| 200 } | 201 } |
| OLD | NEW |