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 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/devtools/devtools_window.h" | 11 #include "chrome/browser/devtools/devtools_window.h" |
12 #include "chrome/browser/extensions/extension_view_host.h" | 12 #include "chrome/browser/extensions/extension_view_host.h" |
13 #include "chrome/browser/extensions/extension_view_host_factory.h" | 13 #include "chrome/browser/extensions/extension_view_host_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_finder.h" | |
16 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
17 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 18 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
18 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
19 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 20 #include "components/web_modal/popup_manager.h" |
20 #include "content/public/browser/devtools_agent_host.h" | 21 #include "content/public/browser/devtools_agent_host.h" |
21 #include "content/public/browser/devtools_manager.h" | 22 #include "content/public/browser/devtools_manager.h" |
22 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
25 #include "ui/base/cocoa/window_size_constants.h" | 26 #include "ui/base/cocoa/window_size_constants.h" |
26 | 27 |
27 using content::BrowserContext; | 28 using content::BrowserContext; |
28 using content::RenderViewHost; | 29 using content::RenderViewHost; |
29 | 30 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 [super dealloc]; | 201 [super dealloc]; |
201 } | 202 } |
202 | 203 |
203 - (void)showDevTools { | 204 - (void)showDevTools { |
204 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); | 205 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); |
205 } | 206 } |
206 | 207 |
207 - (void)close { | 208 - (void)close { |
208 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 209 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
209 if (host_) { | 210 if (host_) { |
210 web_modal::WebContentsModalDialogManager* modalDialogManager = | 211 // TODO(gbillock): Change this API to say directly if the current popup |
211 web_modal::WebContentsModalDialogManager::FromWebContents( | 212 // should block tab close? This is a bit over-reaching. |
212 host_->host_contents()); | 213 Browser* browser = |
213 if (modalDialogManager && | 214 chrome::FindBrowserWithWebContents(host_->host_contents()); |
214 modalDialogManager->IsDialogActive()) { | 215 if (browser && browser->popup_manager()->IsWebModalDialogActive( |
Mike Wittman
2014/06/25 21:12:44
Can we use PopupManager::FromWebContents() here as
Greg Billock
2014/06/26 00:21:12
Done.
| |
216 host_->host_contents())) { | |
215 return; | 217 return; |
216 } | 218 } |
217 // We must shutdown host_ immediately, and it will notify RendererProcess | 219 // We must shutdown host_ immediately, and it will notify RendererProcess |
218 // right away. We can't wait to do it in | 220 // right away. We can't wait to do it in |
219 // -[ExtensionPopController windowWillClose:...] | 221 // -[ExtensionPopController windowWillClose:...] |
220 if (host_->view()) | 222 if (host_->view()) |
221 host_->view()->set_container(NULL); | 223 host_->view()->set_container(NULL); |
222 host_.reset(); | 224 host_.reset(); |
223 } | 225 } |
224 [super close]; | 226 [super close]; |
225 } | 227 } |
226 | 228 |
227 - (void)windowWillClose:(NSNotification*)notification { | 229 - (void)windowWillClose:(NSNotification*)notification { |
228 [super windowWillClose:notification]; | 230 [super windowWillClose:notification]; |
229 if (gPopup == self) | 231 if (gPopup == self) |
230 gPopup = nil; | 232 gPopup = nil; |
231 } | 233 } |
232 | 234 |
233 - (void)windowDidResignKey:(NSNotification*)notification { | 235 - (void)windowDidResignKey:(NSNotification*)notification { |
234 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 236 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
235 if (host_) { | 237 if (host_) { |
236 // When a modal dialog is opened on top of the popup and when it's closed, | 238 // When a modal dialog is opened on top of the popup and when it's closed, |
237 // it steals key-ness from the popup. Don't close the popup when this | 239 // it steals key-ness from the popup. Don't close the popup when this |
238 // happens. There's an extra windowDidResignKey: notification after the | 240 // happens. There's an extra windowDidResignKey: notification after the |
239 // modal dialog closes that should also be ignored. | 241 // modal dialog closes that should also be ignored. |
240 web_modal::WebContentsModalDialogManager* modalDialogManager = | 242 web_modal::PopupManager* popupManager = |
241 web_modal::WebContentsModalDialogManager::FromWebContents( | 243 web_modal::PopupManager::FromWebContents( |
242 host_->host_contents()); | 244 host_->host_contents()); |
243 if (modalDialogManager && | 245 if (popupManager && |
244 modalDialogManager->IsDialogActive()) { | 246 popupManager->IsWebModalDialogActive(host_->host_contents())) { |
245 ignoreWindowDidResignKey_ = YES; | 247 ignoreWindowDidResignKey_ = YES; |
246 return; | 248 return; |
247 } | 249 } |
248 if (ignoreWindowDidResignKey_) { | 250 if (ignoreWindowDidResignKey_) { |
249 ignoreWindowDidResignKey_ = NO; | 251 ignoreWindowDidResignKey_ = NO; |
250 return; | 252 return; |
251 } | 253 } |
252 } | 254 } |
253 if (!beingInspected_) | 255 if (!beingInspected_) |
254 [super windowDidResignKey:notification]; | 256 [super windowDidResignKey:notification]; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 return minSize; | 415 return minSize; |
414 } | 416 } |
415 | 417 |
416 // Private (TestingAPI) | 418 // Private (TestingAPI) |
417 + (NSSize)maxPopupSize { | 419 + (NSSize)maxPopupSize { |
418 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 420 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
419 return maxSize; | 421 return maxSize; |
420 } | 422 } |
421 | 423 |
422 @end | 424 @end |
OLD | NEW |