| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 // Wait to show the popup until the contained host finishes loading. | 53 // Wait to show the popup until the contained host finishes loading. |
| 54 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 54 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 55 content::Source<WebContents>(host->host_contents())); | 55 content::Source<WebContents>(host->host_contents())); |
| 56 | 56 |
| 57 // Listen for the containing view calling window.close(); | 57 // Listen for the containing view calling window.close(); |
| 58 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 58 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 59 content::Source<Profile>(host->profile())); | 59 content::Source<Profile>(host->profile())); |
| 60 | 60 |
| 61 if (!inspect_with_devtools_) { |
| 62 // Listen for the dev tools opening on this popup, so we can stop it going |
| 63 // away when the dev tools get focus. |
| 64 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING, |
| 65 content::Source<Profile>(host->profile())); |
| 66 } |
| 67 |
| 61 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | 68 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); |
| 62 } | 69 } |
| 63 | 70 |
| 64 ExtensionPopup::~ExtensionPopup() { | 71 ExtensionPopup::~ExtensionPopup() { |
| 65 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 72 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
| 66 } | 73 } |
| 67 | 74 |
| 68 void ExtensionPopup::Observe(int type, | 75 void ExtensionPopup::Observe(int type, |
| 69 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) { | 77 const content::NotificationDetails& details) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 85 break; | 92 break; |
| 86 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 93 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 87 // If we aren't the host of the popup, then disregard the notification. | 94 // If we aren't the host of the popup, then disregard the notification. |
| 88 if (content::Details<ExtensionHost>(host()) == details) | 95 if (content::Details<ExtensionHost>(host()) == details) |
| 89 GetWidget()->Close(); | 96 GetWidget()->Close(); |
| 90 break; | 97 break; |
| 91 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: | 98 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: |
| 92 // Make sure its the devtools window that inspecting our popup. | 99 // Make sure its the devtools window that inspecting our popup. |
| 93 // Widget::Close posts a task, which should give the devtools window a | 100 // Widget::Close posts a task, which should give the devtools window a |
| 94 // chance to finish detaching from the inspected RenderViewHost. | 101 // chance to finish detaching from the inspected RenderViewHost. |
| 95 if (content::Details<RenderViewHost>( | 102 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
| 96 host()->render_view_host()) == details) | 103 details) { |
| 97 GetWidget()->Close(); | 104 GetWidget()->Close(); |
| 105 } |
| 106 break; |
| 107 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: |
| 108 // First check that the devtools are being opened on this popup. |
| 109 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
| 110 details) { |
| 111 // Set inspect_with_devtools_ so the popup will be kept open while |
| 112 // the devtools are open. |
| 113 inspect_with_devtools_ = true; |
| 114 // Listen for the devtools being closed so the popup can be closed. |
| 115 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, |
| 116 content::Source<content::BrowserContext>(host()->profile())); |
| 117 } |
| 98 break; | 118 break; |
| 99 default: | 119 default: |
| 100 NOTREACHED() << L"Received unexpected notification"; | 120 NOTREACHED() << L"Received unexpected notification"; |
| 101 } | 121 } |
| 102 } | 122 } |
| 103 | 123 |
| 104 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 124 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
| 105 SizeToContents(); | 125 SizeToContents(); |
| 106 } | 126 } |
| 107 | 127 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // If the host had somehow finished loading, then we'd miss the notification | 171 // If the host had somehow finished loading, then we'd miss the notification |
| 152 // and not show. This seems to happen in single-process mode. | 172 // and not show. This seems to happen in single-process mode. |
| 153 if (host->did_stop_loading()) { | 173 if (host->did_stop_loading()) { |
| 154 popup->Show(); | 174 popup->Show(); |
| 155 // Focus on the host contents when the bubble is first shown. | 175 // Focus on the host contents when the bubble is first shown. |
| 156 host->host_contents()->Focus(); | 176 host->host_contents()->Focus(); |
| 157 } | 177 } |
| 158 | 178 |
| 159 return popup; | 179 return popup; |
| 160 } | 180 } |
| OLD | NEW |