Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 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>( |
| 96 host()->render_view_host()) == details) | 103 host()->render_view_host()) == details) |
| 97 GetWidget()->Close(); | 104 GetWidget()->Close(); |
| 98 break; | 105 break; |
| 106 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: | |
| 107 // First check that the devtools are being opened on this popup. | |
| 108 if (content::Details<RenderViewHost>( | |
| 109 host()->render_view_host()) == details) { | |
|
not at google - send to devlin
2012/01/23 05:43:51
<- 2 indent
benwells
2012/01/23 06:42:23
OK, I think I've fixed it and the similar code abo
| |
| 110 // Set inspect_with_devtools_ so the popup will be kept open while | |
| 111 // the devtools are open. | |
| 112 inspect_with_devtools_ = true; | |
| 113 // Listen for the devtools being closed so the popup can be closed. | |
| 114 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | |
| 115 content::Source<content::BrowserContext>(host()->profile())); | |
| 116 } | |
| 117 break; | |
| 99 default: | 118 default: |
| 100 NOTREACHED() << L"Received unexpected notification"; | 119 NOTREACHED() << L"Received unexpected notification"; |
| 101 } | 120 } |
| 102 } | 121 } |
| 103 | 122 |
| 104 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 123 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
| 105 SizeToContents(); | 124 SizeToContents(); |
| 106 } | 125 } |
| 107 | 126 |
| 108 gfx::Size ExtensionPopup::GetPreferredSize() { | 127 gfx::Size ExtensionPopup::GetPreferredSize() { |
| (...skipping 42 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 | 170 // 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. | 171 // and not show. This seems to happen in single-process mode. |
| 153 if (host->did_stop_loading()) { | 172 if (host->did_stop_loading()) { |
| 154 popup->Show(); | 173 popup->Show(); |
| 155 // Focus on the host contents when the bubble is first shown. | 174 // Focus on the host contents when the bubble is first shown. |
| 156 host->host_contents()->Focus(); | 175 host->host_contents()->Focus(); |
| 157 } | 176 } |
| 158 | 177 |
| 159 return popup; | 178 return popup; |
| 160 } | 179 } |
| OLD | NEW |