| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/mac/bundle_locations.h" | 12 #include "base/mac/bundle_locations.h" |
| 13 #import "base/mac/foundation_util.h" | 13 #import "base/mac/foundation_util.h" |
| 14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #import "base/mac/sdk_forward_declarations.h" | 15 #import "base/mac/sdk_forward_declarations.h" |
| 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/scoped_observer.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/app/chrome_command_ids.h" // IDC_* | 20 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 20 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 22 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 21 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/browser_shutdown.h" | 24 #include "chrome/browser/browser_shutdown.h" |
| 23 #include "chrome/browser/devtools/devtools_window.h" | 25 #include "chrome/browser/devtools/devtools_window.h" |
| 24 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 26 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 25 #include "chrome/browser/permissions/permission_request_manager.h" | 27 #include "chrome/browser/permissions/permission_request_manager.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 59 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 58 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 60 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
| 59 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 61 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 60 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" | 62 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" |
| 61 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" | 63 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" |
| 62 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" | 64 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" |
| 63 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 65 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
| 64 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 66 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 65 #include "chrome/browser/ui/cocoa/l10n_util.h" | 67 #include "chrome/browser/ui/cocoa/l10n_util.h" |
| 66 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 68 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 69 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 67 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" | 70 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
| 68 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 71 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
| 69 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" | 72 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" |
| 70 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" | 73 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" |
| 71 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 74 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 72 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" | 75 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 73 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 76 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 74 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 77 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 75 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 78 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 76 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 79 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 77 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 80 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 78 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" | 81 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" |
| 79 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 82 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 80 #include "chrome/browser/ui/location_bar/location_bar.h" | 83 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 81 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 84 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 82 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 85 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 83 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" | 86 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
| 84 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 87 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 85 #include "chrome/common/chrome_switches.h" | 88 #include "chrome/common/chrome_switches.h" |
| 86 #include "chrome/common/extensions/command.h" | 89 #include "chrome/common/extensions/command.h" |
| 87 #include "chrome/common/pref_names.h" | 90 #include "chrome/common/pref_names.h" |
| 88 #include "components/bookmarks/browser/bookmark_model.h" | 91 #include "components/bookmarks/browser/bookmark_model.h" |
| 89 #include "components/bookmarks/managed/managed_bookmark_service.h" | 92 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 93 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 94 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 95 #include "components/omnibox/browser/omnibox_popup_model_observer.h" |
| 90 #include "components/signin/core/common/profile_management_switches.h" | 96 #include "components/signin/core/common/profile_management_switches.h" |
| 91 #include "components/translate/core/browser/translate_manager.h" | 97 #include "components/translate/core/browser/translate_manager.h" |
| 92 #include "components/translate/core/browser/translate_ui_delegate.h" | 98 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 93 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 99 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 94 #include "content/public/browser/render_view_host.h" | 100 #include "content/public/browser/render_view_host.h" |
| 95 #include "content/public/browser/render_widget_host.h" | 101 #include "content/public/browser/render_widget_host.h" |
| 96 #include "content/public/browser/render_widget_host_view.h" | 102 #include "content/public/browser/render_widget_host_view.h" |
| 97 #include "content/public/browser/web_contents.h" | 103 #include "content/public/browser/web_contents.h" |
| 98 #import "ui/base/cocoa/cocoa_base_utils.h" | 104 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 99 #import "ui/base/cocoa/nsview_additions.h" | 105 #import "ui/base/cocoa/nsview_additions.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // set a flag, and constrain any resize by the allowed amounts. On further | 184 // set a flag, and constrain any resize by the allowed amounts. On further |
| 179 // shrinks, we check the flag (since the size/position of the window will no | 185 // shrinks, we check the flag (since the size/position of the window will no |
| 180 // longer indicate that the window is shrinking from an apparent zoomed state) | 186 // longer indicate that the window is shrinking from an apparent zoomed state) |
| 181 // and if it's set we continue to constrain the resize. | 187 // and if it's set we continue to constrain the resize. |
| 182 | 188 |
| 183 using content::RenderWidgetHostView; | 189 using content::RenderWidgetHostView; |
| 184 using content::WebContents; | 190 using content::WebContents; |
| 185 | 191 |
| 186 namespace { | 192 namespace { |
| 187 | 193 |
| 194 // This class shows or hides the top arrow of the infobar in accordance with the |
| 195 // visibility of the omnibox popup. It hides the top arrow when the omnibox |
| 196 // popup is shown, and vice versa. |
| 197 class OmniboxPopupModelObserverBridge final : public OmniboxPopupModelObserver { |
| 198 public: |
| 199 explicit OmniboxPopupModelObserverBridge(BrowserWindowController* controller) |
| 200 : controller_(controller), |
| 201 omnibox_popup_model_([controller_ locationBarBridge] |
| 202 ->GetOmniboxView() |
| 203 ->model() |
| 204 ->popup_model()), |
| 205 omnibox_popup_model_observer_(this) { |
| 206 DCHECK(omnibox_popup_model_); |
| 207 omnibox_popup_model_observer_.Add(omnibox_popup_model_); |
| 208 } |
| 209 |
| 210 void OnOmniboxPopupShownOrHidden() override { |
| 211 int max_top_arrow_height = 0; |
| 212 if (!omnibox_popup_model_->IsOpen()) { |
| 213 base::scoped_nsobject<BrowserWindowLayout> layout( |
| 214 [[BrowserWindowLayout alloc] init]); |
| 215 [controller_ updateLayoutParameters:layout]; |
| 216 max_top_arrow_height = [layout computeLayout].infoBarMaxTopArrowHeight; |
| 217 } |
| 218 [[controller_ infoBarContainerController] |
| 219 setMaxTopArrowHeight:max_top_arrow_height]; |
| 220 } |
| 221 |
| 222 private: |
| 223 BrowserWindowController* controller_; |
| 224 OmniboxPopupModel* omnibox_popup_model_; |
| 225 ScopedObserver<OmniboxPopupModel, OmniboxPopupModelObserver> |
| 226 omnibox_popup_model_observer_; |
| 227 |
| 228 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupModelObserverBridge); |
| 229 }; |
| 230 |
| 188 void SetUpBrowserWindowCommandHandler(NSWindow* window) { | 231 void SetUpBrowserWindowCommandHandler(NSWindow* window) { |
| 189 // Make the window handle browser window commands. | 232 // Make the window handle browser window commands. |
| 190 [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window) | 233 [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window) |
| 191 setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] | 234 setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] |
| 192 autorelease]]; | 235 autorelease]]; |
| 193 } | 236 } |
| 194 | 237 |
| 195 // Returns true if the Tab Detaching in Fullscreen is enabled. It's enabled by | 238 // Returns true if the Tab Detaching in Fullscreen is enabled. It's enabled by |
| 196 // default. | 239 // default. |
| 197 bool IsTabDetachingInFullscreenEnabled() { | 240 bool IsTabDetachingInFullscreenEnabled() { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // on the window bounds to determine whether to show buttons or not. | 425 // on the window bounds to determine whether to show buttons or not. |
| 383 if ([self hasToolbar]) // Do not create the buttons in popups. | 426 if ([self hasToolbar]) // Do not create the buttons in popups. |
| 384 [toolbarController_ createBrowserActionButtons]; | 427 [toolbarController_ createBrowserActionButtons]; |
| 385 | 428 |
| 386 extensionKeybindingRegistry_.reset( | 429 extensionKeybindingRegistry_.reset( |
| 387 new ExtensionKeybindingRegistryCocoa(browser_->profile(), | 430 new ExtensionKeybindingRegistryCocoa(browser_->profile(), |
| 388 [self window], | 431 [self window], |
| 389 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 432 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 390 windowShim_.get())); | 433 windowShim_.get())); |
| 391 | 434 |
| 435 omniboxPopupModelObserverBridge_ = |
| 436 base::MakeUnique<OmniboxPopupModelObserverBridge>(self); |
| 437 |
| 392 blockLayoutSubviews_ = NO; | 438 blockLayoutSubviews_ = NO; |
| 393 | 439 |
| 394 // We are done initializing now. | 440 // We are done initializing now. |
| 395 initializing_ = NO; | 441 initializing_ = NO; |
| 396 } | 442 } |
| 397 return self; | 443 return self; |
| 398 } | 444 } |
| 399 | 445 |
| 400 - (void)dealloc { | 446 - (void)dealloc { |
| 401 browser_->tab_strip_model()->CloseAllTabs(); | 447 browser_->tab_strip_model()->CloseAllTabs(); |
| 402 | 448 |
| 403 // Explicitly release |fullscreenToolbarController_| here, as it may call | 449 // Explicitly release |fullscreenToolbarController_| here, as it may call |
| 404 // back to this BWC in |-dealloc|. | 450 // back to this BWC in |-dealloc|. |
| 405 [fullscreenToolbarController_ exitFullscreenMode]; | 451 [fullscreenToolbarController_ exitFullscreenMode]; |
| 406 fullscreenToolbarController_.reset(); | 452 fullscreenToolbarController_.reset(); |
| 407 | 453 |
| 408 // Explicitly release |fullscreenTransition_| here since it may call back to | 454 // Explicitly release |fullscreenTransition_| here since it may call back to |
| 409 // this BWC in |-dealloc|. Reset the fullscreen variables. | 455 // this BWC in |-dealloc|. Reset the fullscreen variables. |
| 410 if (fullscreenTransition_) { | 456 if (fullscreenTransition_) { |
| 411 [fullscreenTransition_ browserWillBeDestroyed]; | 457 [fullscreenTransition_ browserWillBeDestroyed]; |
| 412 [self resetCustomAppKitFullscreenVariables]; | 458 [self resetCustomAppKitFullscreenVariables]; |
| 413 } | 459 } |
| 414 | 460 |
| 415 // Under certain testing configurations we may not actually own the browser. | 461 // Under certain testing configurations we may not actually own the browser. |
| 416 if (ownsBrowser_ == NO) | 462 if (ownsBrowser_ == NO) |
| 417 ignore_result(browser_.release()); | 463 ignore_result(browser_.release()); |
| 418 | 464 |
| 419 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 465 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 420 | 466 |
| 467 // Explicitly release |omniboxPopupModelObserverBridge_| before sending |
| 468 // |browserWillBeDestroyed| to prevent it from UAFing OmniboxPopupModel. |
| 469 omniboxPopupModelObserverBridge_.reset(); |
| 470 |
| 421 // Inform reference counted objects that the Browser will be destroyed. This | 471 // Inform reference counted objects that the Browser will be destroyed. This |
| 422 // ensures they invalidate their weak Browser* to prevent use-after-free. | 472 // ensures they invalidate their weak Browser* to prevent use-after-free. |
| 423 // These may outlive the Browser if they are retained by something else. For | 473 // These may outlive the Browser if they are retained by something else. For |
| 424 // example, since 10.10, the Nib loader internally creates an NSDictionary | 474 // example, since 10.10, the Nib loader internally creates an NSDictionary |
| 425 // that retains NSViewControllers and is autoreleased, so there is no way to | 475 // that retains NSViewControllers and is autoreleased, so there is no way to |
| 426 // guarantee that the [super dealloc] call below will also call dealloc on the | 476 // guarantee that the [super dealloc] call below will also call dealloc on the |
| 427 // controllers. | 477 // controllers. |
| 428 [toolbarController_ browserWillBeDestroyed]; | 478 [toolbarController_ browserWillBeDestroyed]; |
| 429 [tabStripController_ browserWillBeDestroyed]; | 479 [tabStripController_ browserWillBeDestroyed]; |
| 430 [findBarCocoaController_ browserWillBeDestroyed]; | 480 [findBarCocoaController_ browserWillBeDestroyed]; |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 | 2083 |
| 2034 - (NSRect)savedRegularWindowFrame { | 2084 - (NSRect)savedRegularWindowFrame { |
| 2035 return savedRegularWindowFrame_; | 2085 return savedRegularWindowFrame_; |
| 2036 } | 2086 } |
| 2037 | 2087 |
| 2038 - (BOOL)isFullscreenTransitionInProgress { | 2088 - (BOOL)isFullscreenTransitionInProgress { |
| 2039 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_; | 2089 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_; |
| 2040 } | 2090 } |
| 2041 | 2091 |
| 2042 @end // @implementation BrowserWindowController(WindowType) | 2092 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |