| 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.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/debugger/devtools_window.h" | 9 #include "chrome/browser/debugger/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Wait to show the popup until the contained host finishes loading. | 84 // Wait to show the popup until the contained host finishes loading. |
| 85 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 85 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 86 content::Source<WebContents>(host->host_contents())); | 86 content::Source<WebContents>(host->host_contents())); |
| 87 | 87 |
| 88 // Listen for the containing view calling window.close(); | 88 // Listen for the containing view calling window.close(); |
| 89 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 89 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 90 content::Source<Profile>(host->profile())); | 90 content::Source<Profile>(host->profile())); |
| 91 | 91 |
| 92 // Listen for the dev tools opening on this popup, so we can stop it going | 92 // Listen for the dev tools opening on this popup, so we can stop it going |
| 93 // away when the dev tools get focus. | 93 // away when the dev tools get focus. |
| 94 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING, | 94 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED, |
| 95 content::Source<Profile>(host->profile())); | 95 content::Source<Profile>(host->profile())); |
| 96 | 96 |
| 97 // Listen for the dev tools closing, so we can close this window if it is | 97 // Listen for the dev tools closing, so we can close this window if it is |
| 98 // being inspected and the inspector is closed. | 98 // being inspected and the inspector is closed. |
| 99 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | 99 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED, |
| 100 content::Source<content::BrowserContext>(host->profile())); | 100 content::Source<content::BrowserContext>(host->profile())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 ExtensionPopup::~ExtensionPopup() { | 103 ExtensionPopup::~ExtensionPopup() { |
| 104 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 104 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ExtensionPopup::Observe(int type, | 107 void ExtensionPopup::Observe(int type, |
| 108 const content::NotificationSource& source, | 108 const content::NotificationSource& source, |
| 109 const content::NotificationDetails& details) { | 109 const content::NotificationDetails& details) { |
| 110 switch (type) { | 110 switch (type) { |
| 111 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 111 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 112 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); | 112 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); |
| 113 // Show when the content finishes loading and its width is computed. | 113 // Show when the content finishes loading and its width is computed. |
| 114 ShowBubble(); | 114 ShowBubble(); |
| 115 break; | 115 break; |
| 116 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 116 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 117 // If we aren't the host of the popup, then disregard the notification. | 117 // If we aren't the host of the popup, then disregard the notification. |
| 118 if (content::Details<extensions::ExtensionHost>(host()) == details) | 118 if (content::Details<extensions::ExtensionHost>(host()) == details) |
| 119 GetWidget()->Close(); | 119 GetWidget()->Close(); |
| 120 break; | 120 break; |
| 121 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: | 121 case content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED: |
| 122 // Make sure it's the devtools window that inspecting our popup. | 122 // Make sure it's the devtools window that inspecting our popup. |
| 123 // Widget::Close posts a task, which should give the devtools window a | 123 // Widget::Close posts a task, which should give the devtools window a |
| 124 // chance to finish detaching from the inspected RenderViewHost. | 124 // chance to finish detaching from the inspected RenderViewHost. |
| 125 if (content::Details<RenderViewHost>(host()->render_view_host()) == | 125 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
| 126 details) { | 126 details) { |
| 127 GetWidget()->Close(); | 127 GetWidget()->Close(); |
| 128 } | 128 } |
| 129 break; | 129 break; |
| 130 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: | 130 case content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED: |
| 131 // First check that the devtools are being opened on this popup. | 131 // First check that the devtools are being opened on this popup. |
| 132 if (content::Details<RenderViewHost>(host()->render_view_host()) == | 132 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
| 133 details) { | 133 details) { |
| 134 // Set inspect_with_devtools_ so the popup will be kept open while | 134 // Set inspect_with_devtools_ so the popup will be kept open while |
| 135 // the devtools are open. | 135 // the devtools are open. |
| 136 inspect_with_devtools_ = true; | 136 inspect_with_devtools_ = true; |
| 137 } | 137 } |
| 138 break; | 138 break; |
| 139 default: | 139 default: |
| 140 NOTREACHED() << L"Received unexpected notification"; | 140 NOTREACHED() << L"Received unexpected notification"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 if (inspect_with_devtools_) { | 214 if (inspect_with_devtools_) { |
| 215 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), | 215 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), |
| 216 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); | 216 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void ExtensionPopup::CloseBubble() { | 220 void ExtensionPopup::CloseBubble() { |
| 221 GetWidget()->Close(); | 221 GetWidget()->Close(); |
| 222 } | 222 } |
| OLD | NEW |