| 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 web_modal::PopupManager* popup_manager = |
| 213 if (modalDialogManager && | 214 web_modal::PopupManager::FromWebContents(host_->host_contents()); |
| 214 modalDialogManager->IsDialogActive()) { | 215 if (popup_manager && popup_manager->IsWebModalDialogActive( |
| 216 host_->host_contents())) { |
| 215 return; | 217 return; |
| 216 } | 218 } |
| 219 |
| 217 // We must shutdown host_ immediately, and it will notify RendererProcess | 220 // We must shutdown host_ immediately, and it will notify RendererProcess |
| 218 // right away. We can't wait to do it in | 221 // right away. We can't wait to do it in |
| 219 // -[ExtensionPopController windowWillClose:...] | 222 // -[ExtensionPopController windowWillClose:...] |
| 220 if (host_->view()) | 223 if (host_->view()) |
| 221 host_->view()->set_container(NULL); | 224 host_->view()->set_container(NULL); |
| 222 host_.reset(); | 225 host_.reset(); |
| 223 } | 226 } |
| 224 [super close]; | 227 [super close]; |
| 225 } | 228 } |
| 226 | 229 |
| 227 - (void)windowWillClose:(NSNotification*)notification { | 230 - (void)windowWillClose:(NSNotification*)notification { |
| 228 [super windowWillClose:notification]; | 231 [super windowWillClose:notification]; |
| 229 if (gPopup == self) | 232 if (gPopup == self) |
| 230 gPopup = nil; | 233 gPopup = nil; |
| 231 } | 234 } |
| 232 | 235 |
| 233 - (void)windowDidResignKey:(NSNotification*)notification { | 236 - (void)windowDidResignKey:(NSNotification*)notification { |
| 234 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 237 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
| 235 if (host_) { | 238 if (host_) { |
| 236 // When a modal dialog is opened on top of the popup and when it's closed, | 239 // 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 | 240 // it steals key-ness from the popup. Don't close the popup when this |
| 238 // happens. There's an extra windowDidResignKey: notification after the | 241 // happens. There's an extra windowDidResignKey: notification after the |
| 239 // modal dialog closes that should also be ignored. | 242 // modal dialog closes that should also be ignored. |
| 240 web_modal::WebContentsModalDialogManager* modalDialogManager = | 243 web_modal::PopupManager* popupManager = |
| 241 web_modal::WebContentsModalDialogManager::FromWebContents( | 244 web_modal::PopupManager::FromWebContents( |
| 242 host_->host_contents()); | 245 host_->host_contents()); |
| 243 if (modalDialogManager && | 246 if (popupManager && |
| 244 modalDialogManager->IsDialogActive()) { | 247 popupManager->IsWebModalDialogActive(host_->host_contents())) { |
| 245 ignoreWindowDidResignKey_ = YES; | 248 ignoreWindowDidResignKey_ = YES; |
| 246 return; | 249 return; |
| 247 } | 250 } |
| 248 if (ignoreWindowDidResignKey_) { | 251 if (ignoreWindowDidResignKey_) { |
| 249 ignoreWindowDidResignKey_ = NO; | 252 ignoreWindowDidResignKey_ = NO; |
| 250 return; | 253 return; |
| 251 } | 254 } |
| 252 } | 255 } |
| 253 if (!beingInspected_) | 256 if (!beingInspected_) |
| 254 [super windowDidResignKey:notification]; | 257 [super windowDidResignKey:notification]; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return minSize; | 416 return minSize; |
| 414 } | 417 } |
| 415 | 418 |
| 416 // Private (TestingAPI) | 419 // Private (TestingAPI) |
| 417 + (NSSize)maxPopupSize { | 420 + (NSSize)maxPopupSize { |
| 418 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 421 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 419 return maxSize; | 422 return maxSize; |
| 420 } | 423 } |
| 421 | 424 |
| 422 @end | 425 @end |
| OLD | NEW |