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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 set_close_on_deactivate(!inspect_with_devtools); | 50 set_close_on_deactivate(!inspect_with_devtools); |
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 |
| 61 // Listen for the dev tools closing, so we can close this window if it is |
| 62 // being inspected and the inspector is closed. |
| 63 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, |
| 64 content::Source<content::BrowserContext>(host->profile())); |
| 65 |
| 66 if (!inspect_with_devtools_) { |
| 67 // Listen for the dev tools opening on this popup, so we can stop it going |
| 68 // away when the dev tools get focus. |
| 69 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING, |
| 70 content::Source<Profile>(host->profile())); |
| 71 } |
60 } | 72 } |
61 | 73 |
62 ExtensionPopup::~ExtensionPopup() { | 74 ExtensionPopup::~ExtensionPopup() { |
63 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 75 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
64 } | 76 } |
65 | 77 |
66 void ExtensionPopup::Observe(int type, | 78 void ExtensionPopup::Observe(int type, |
67 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
68 const content::NotificationDetails& details) { | 80 const content::NotificationDetails& details) { |
69 switch (type) { | 81 switch (type) { |
70 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 82 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
71 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); | 83 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); |
72 // Show when the content finishes loading and its width is computed. | 84 // Show when the content finishes loading and its width is computed. |
73 ShowBubble(); | 85 ShowBubble(); |
74 break; | 86 break; |
75 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 87 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
76 // If we aren't the host of the popup, then disregard the notification. | 88 // If we aren't the host of the popup, then disregard the notification. |
77 if (content::Details<ExtensionHost>(host()) == details) | 89 if (content::Details<ExtensionHost>(host()) == details) |
78 GetWidget()->Close(); | 90 GetWidget()->Close(); |
79 break; | 91 break; |
80 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: | 92 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: |
81 // Make sure its the devtools window that inspecting our popup. | 93 // Make sure it's the devtools window that inspecting our popup. |
82 // Widget::Close posts a task, which should give the devtools window a | 94 // Widget::Close posts a task, which should give the devtools window a |
83 // chance to finish detaching from the inspected RenderViewHost. | 95 // chance to finish detaching from the inspected RenderViewHost. |
84 if (content::Details<RenderViewHost>( | 96 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
85 host()->render_view_host()) == details) | 97 details) { |
86 GetWidget()->Close(); | 98 GetWidget()->Close(); |
| 99 } |
| 100 break; |
| 101 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: |
| 102 // First check that the devtools are being opened on this popup. |
| 103 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
| 104 details) { |
| 105 // Set inspect_with_devtools_ so the popup will be kept open while |
| 106 // the devtools are open. |
| 107 inspect_with_devtools_ = true; |
| 108 set_close_on_deactivate(false); |
| 109 } |
87 break; | 110 break; |
88 default: | 111 default: |
89 NOTREACHED() << L"Received unexpected notification"; | 112 NOTREACHED() << L"Received unexpected notification"; |
90 } | 113 } |
91 } | 114 } |
92 | 115 |
93 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 116 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
94 SizeToContents(); | 117 SizeToContents(); |
95 } | 118 } |
96 | 119 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void ExtensionPopup::ShowBubble() { | 169 void ExtensionPopup::ShowBubble() { |
147 Show(); | 170 Show(); |
148 | 171 |
149 // Focus on the host contents when the bubble is first shown. | 172 // Focus on the host contents when the bubble is first shown. |
150 host()->host_contents()->Focus(); | 173 host()->host_contents()->Focus(); |
151 | 174 |
152 // Listen for widget focus changes after showing (used for non-aura win). | 175 // Listen for widget focus changes after showing (used for non-aura win). |
153 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | 176 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); |
154 | 177 |
155 if (inspect_with_devtools_) { | 178 if (inspect_with_devtools_) { |
156 // Listen for the the devtools window closing. | |
157 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | |
158 content::Source<content::BrowserContext>(host()->profile())); | |
159 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), | 179 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), |
160 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); | 180 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
161 } | 181 } |
162 } | 182 } |
OLD | NEW |