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 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 } | |
60 } | 67 } |
61 | 68 |
62 ExtensionPopup::~ExtensionPopup() { | 69 ExtensionPopup::~ExtensionPopup() { |
63 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 70 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
64 } | 71 } |
65 | 72 |
66 void ExtensionPopup::Observe(int type, | 73 void ExtensionPopup::Observe(int type, |
67 const content::NotificationSource& source, | 74 const content::NotificationSource& source, |
68 const content::NotificationDetails& details) { | 75 const content::NotificationDetails& details) { |
69 switch (type) { | 76 switch (type) { |
70 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 77 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
71 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); | 78 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); |
72 // Show when the content finishes loading and its width is computed. | 79 // Show when the content finishes loading and its width is computed. |
73 ShowBubble(); | 80 ShowBubble(); |
74 break; | 81 break; |
75 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 82 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
76 // If we aren't the host of the popup, then disregard the notification. | 83 // If we aren't the host of the popup, then disregard the notification. |
77 if (content::Details<ExtensionHost>(host()) == details) | 84 if (content::Details<ExtensionHost>(host()) == details) |
78 GetWidget()->Close(); | 85 GetWidget()->Close(); |
79 break; | 86 break; |
80 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: | 87 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: |
81 // Make sure its the devtools window that inspecting our popup. | 88 // Make sure its the devtools window that inspecting our popup. |
82 // Widget::Close posts a task, which should give the devtools window a | 89 // Widget::Close posts a task, which should give the devtools window a |
83 // chance to finish detaching from the inspected RenderViewHost. | 90 // chance to finish detaching from the inspected RenderViewHost. |
84 if (content::Details<RenderViewHost>( | 91 if (content::Details<RenderViewHost>(host()->render_view_host()) == |
85 host()->render_view_host()) == details) | 92 details) { |
msw
2012/02/03 07:57:24
nit: Braces here are optional, not necessary.
benwells
2012/02/06 03:40:46
OK. I think with the if conditional spread over tw
| |
86 GetWidget()->Close(); | 93 GetWidget()->Close(); |
94 } | |
95 break; | |
96 case content::NOTIFICATION_DEVTOOLS_WINDOW_OPENING: | |
97 // First check that the devtools are being opened on this popup. | |
98 if (content::Details<RenderViewHost>(host()->render_view_host()) == | |
99 details) { | |
100 // Set inspect_with_devtools_ so the popup will be kept open while | |
msw
2012/02/03 07:57:24
Does this work? I think you'll need to call set_cl
benwells
2012/02/06 03:40:46
Thanks, it will need that to work on chromeos and
| |
101 // the devtools are open. | |
102 inspect_with_devtools_ = true; | |
103 // Listen for the devtools being closed so the popup can be closed. | |
104 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | |
msw
2012/02/03 07:57:24
optional: consider replacing this statement and th
benwells
2012/02/06 03:40:46
Done.
| |
105 content::Source<content::BrowserContext>(host()->profile())); | |
106 } | |
87 break; | 107 break; |
88 default: | 108 default: |
89 NOTREACHED() << L"Received unexpected notification"; | 109 NOTREACHED() << L"Received unexpected notification"; |
90 } | 110 } |
91 } | 111 } |
92 | 112 |
93 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 113 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
94 SizeToContents(); | 114 SizeToContents(); |
95 } | 115 } |
96 | 116 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); | 173 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); |
154 | 174 |
155 if (inspect_with_devtools_) { | 175 if (inspect_with_devtools_) { |
156 // Listen for the the devtools window closing. | 176 // Listen for the the devtools window closing. |
157 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | 177 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, |
158 content::Source<content::BrowserContext>(host()->profile())); | 178 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 |