| 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/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | |
| 18 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 19 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 18 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 21 #include "components/web_modal/popup_manager.h" | 20 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 22 #include "content/public/browser/devtools_agent_host.h" | 21 #include "content/public/browser/devtools_agent_host.h" |
| 23 #include "content/public/browser/devtools_manager.h" | 22 #include "content/public/browser/devtools_manager.h" |
| 24 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 26 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 27 #include "ui/base/cocoa/window_size_constants.h" | 26 #include "ui/base/cocoa/window_size_constants.h" |
| 28 | 27 |
| 29 using content::BrowserContext; | 28 using content::BrowserContext; |
| 30 using content::RenderViewHost; | 29 using content::RenderViewHost; |
| 31 using content::WebContents; | 30 using content::WebContents; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 [super dealloc]; | 207 [super dealloc]; |
| 209 } | 208 } |
| 210 | 209 |
| 211 - (void)showDevTools { | 210 - (void)showDevTools { |
| 212 DevToolsWindow::OpenDevToolsWindow(host_->host_contents()); | 211 DevToolsWindow::OpenDevToolsWindow(host_->host_contents()); |
| 213 } | 212 } |
| 214 | 213 |
| 215 - (void)close { | 214 - (void)close { |
| 216 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 215 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
| 217 if (host_) { | 216 if (host_) { |
| 218 // TODO(gbillock): Change this API to say directly if the current popup | 217 web_modal::WebContentsModalDialogManager* modalDialogManager = |
| 219 // should block tab close? This is a bit over-reaching. | 218 web_modal::WebContentsModalDialogManager::FromWebContents( |
| 220 web_modal::PopupManager* popup_manager = | 219 host_->host_contents()); |
| 221 web_modal::PopupManager::FromWebContents(host_->host_contents()); | 220 if (modalDialogManager && |
| 222 if (popup_manager && popup_manager->IsWebModalDialogActive( | 221 modalDialogManager->IsDialogActive()) { |
| 223 host_->host_contents())) { | |
| 224 return; | 222 return; |
| 225 } | 223 } |
| 226 } | 224 } |
| 227 [super close]; | 225 [super close]; |
| 228 } | 226 } |
| 229 | 227 |
| 230 - (void)windowWillClose:(NSNotification *)notification { | 228 - (void)windowWillClose:(NSNotification *)notification { |
| 231 [super windowWillClose:notification]; | 229 [super windowWillClose:notification]; |
| 232 if (gPopup == self) | 230 if (gPopup == self) |
| 233 gPopup = nil; | 231 gPopup = nil; |
| 234 if (host_->view()) | 232 if (host_->view()) |
| 235 static_cast<ExtensionViewMac*>(host_->view())->set_container(NULL); | 233 static_cast<ExtensionViewMac*>(host_->view())->set_container(NULL); |
| 236 host_.reset(); | 234 host_.reset(); |
| 237 } | 235 } |
| 238 | 236 |
| 239 - (void)windowDidResignKey:(NSNotification*)notification { | 237 - (void)windowDidResignKey:(NSNotification*)notification { |
| 240 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 238 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
| 241 if (host_) { | 239 if (host_) { |
| 242 // When a modal dialog is opened on top of the popup and when it's closed, | 240 // When a modal dialog is opened on top of the popup and when it's closed, |
| 243 // it steals key-ness from the popup. Don't close the popup when this | 241 // it steals key-ness from the popup. Don't close the popup when this |
| 244 // happens. There's an extra windowDidResignKey: notification after the | 242 // happens. There's an extra windowDidResignKey: notification after the |
| 245 // modal dialog closes that should also be ignored. | 243 // modal dialog closes that should also be ignored. |
| 246 web_modal::PopupManager* popupManager = | 244 web_modal::WebContentsModalDialogManager* modalDialogManager = |
| 247 web_modal::PopupManager::FromWebContents( | 245 web_modal::WebContentsModalDialogManager::FromWebContents( |
| 248 host_->host_contents()); | 246 host_->host_contents()); |
| 249 if (popupManager && | 247 if (modalDialogManager && |
| 250 popupManager->IsWebModalDialogActive(host_->host_contents())) { | 248 modalDialogManager->IsDialogActive()) { |
| 251 ignoreWindowDidResignKey_ = YES; | 249 ignoreWindowDidResignKey_ = YES; |
| 252 return; | 250 return; |
| 253 } | 251 } |
| 254 if (ignoreWindowDidResignKey_) { | 252 if (ignoreWindowDidResignKey_) { |
| 255 ignoreWindowDidResignKey_ = NO; | 253 ignoreWindowDidResignKey_ = NO; |
| 256 return; | 254 return; |
| 257 } | 255 } |
| 258 } | 256 } |
| 259 if (!beingInspected_) | 257 if (!beingInspected_) |
| 260 [super windowDidResignKey:notification]; | 258 [super windowDidResignKey:notification]; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 return minSize; | 430 return minSize; |
| 433 } | 431 } |
| 434 | 432 |
| 435 // Private (TestingAPI) | 433 // Private (TestingAPI) |
| 436 + (NSSize)maxPopupSize { | 434 + (NSSize)maxPopupSize { |
| 437 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 435 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 438 return maxSize; | 436 return maxSize; |
| 439 } | 437 } |
| 440 | 438 |
| 441 @end | 439 @end |
| OLD | NEW |