| 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/chrome_browser_application_mac.h" | 5 #import "chrome/browser/chrome_browser_application_mac.h" |
| 6 | 6 |
| 7 #include <objc/objc-exception.h> | 7 #include <objc/objc-exception.h> |
| 8 | 8 |
| 9 #import "base/auto_reset.h" | 9 #import "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void Terminate() { | 124 void Terminate() { |
| 125 [NSApp terminate:nil]; | 125 [NSApp terminate:nil]; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void CancelTerminate() { | 128 void CancelTerminate() { |
| 129 [NSApp cancelTerminate:nil]; | 129 [NSApp cancelTerminate:nil]; |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace chrome_browser_application_mac | 132 } // namespace chrome_browser_application_mac |
| 133 | 133 |
| 134 // These methods are being exposed for the purposes of overriding. | 134 // Method exposed for the purposes of overriding. |
| 135 // Used to determine when a Panel window can become the key window. | 135 // Used to determine when a Panel window can become the key window. |
| 136 @interface NSApplication (PanelsCanBecomeKey) | 136 @interface NSApplication (PanelsCanBecomeKey) |
| 137 - (void)_cycleWindowsReversed:(BOOL)arg1; | 137 - (void)_cycleWindowsReversed:(BOOL)arg1; |
| 138 - (id)_removeWindow:(NSWindow*)window; | |
| 139 - (id)_setKeyWindow:(NSWindow*)window; | |
| 140 @end | |
| 141 | |
| 142 @interface BrowserCrApplication (PrivateInternal) | |
| 143 | |
| 144 // This must be called under the protection of previousKeyWindowsLock_. | |
| 145 - (void)removePreviousKeyWindow:(NSWindow*)window; | |
| 146 | |
| 147 @end | 138 @end |
| 148 | 139 |
| 149 @implementation BrowserCrApplication | 140 @implementation BrowserCrApplication |
| 150 | 141 |
| 151 + (void)initialize { | 142 + (void)initialize { |
| 152 // Turn all deallocated Objective-C objects into zombies, keeping | 143 // Turn all deallocated Objective-C objects into zombies, keeping |
| 153 // the most recent 10,000 of them on the treadmill. | 144 // the most recent 10,000 of them on the treadmill. |
| 154 ObjcEvilDoers::ZombieEnable(true, 10000); | 145 ObjcEvilDoers::ZombieEnable(true, 10000); |
| 155 | 146 |
| 156 if (!chrome_browser_application_mac::g_next_preprocessor) { | 147 if (!chrome_browser_application_mac::g_next_preprocessor) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 361 |
| 371 - (void)_cycleWindowsReversed:(BOOL)arg1 { | 362 - (void)_cycleWindowsReversed:(BOOL)arg1 { |
| 372 base::AutoReset<BOOL> pin(&cyclingWindows_, YES); | 363 base::AutoReset<BOOL> pin(&cyclingWindows_, YES); |
| 373 [super _cycleWindowsReversed:arg1]; | 364 [super _cycleWindowsReversed:arg1]; |
| 374 } | 365 } |
| 375 | 366 |
| 376 - (BOOL)isCyclingWindows { | 367 - (BOOL)isCyclingWindows { |
| 377 return cyclingWindows_; | 368 return cyclingWindows_; |
| 378 } | 369 } |
| 379 | 370 |
| 380 - (id)_removeWindow:(NSWindow*)window { | |
| 381 // Note _removeWindow is called from -[NSWindow dealloc], which can happen at | |
| 382 // unpredictable times due to reference counting. Just update state. | |
| 383 { | |
| 384 base::AutoLock lock(previousKeyWindowsLock_); | |
| 385 [self removePreviousKeyWindow:window]; | |
| 386 } | |
| 387 return [super _removeWindow:window]; | |
| 388 } | |
| 389 | |
| 390 - (id)_setKeyWindow:(NSWindow*)window { | |
| 391 // |window| is nil when the current key window is being closed. | |
| 392 // A separate call follows with a new value when a new key window is set. | |
| 393 // Closed windows are not tracked in previousKeyWindows_. | |
| 394 if (window != nil) { | |
| 395 base::AutoLock lock(previousKeyWindowsLock_); | |
| 396 [self removePreviousKeyWindow:window]; | |
| 397 NSWindow* currentKeyWindow = [self keyWindow]; | |
| 398 if (currentKeyWindow != nil && currentKeyWindow != window) | |
| 399 previousKeyWindows_.push_back(currentKeyWindow); | |
| 400 } | |
| 401 | |
| 402 return [super _setKeyWindow:window]; | |
| 403 } | |
| 404 | |
| 405 - (NSWindow*)previousKeyWindow { | |
| 406 base::AutoLock lock(previousKeyWindowsLock_); | |
| 407 return previousKeyWindows_.empty() ? nil : previousKeyWindows_.back(); | |
| 408 } | |
| 409 | |
| 410 - (void)removePreviousKeyWindow:(NSWindow*)window { | |
| 411 previousKeyWindowsLock_.AssertAcquired(); | |
| 412 std::vector<NSWindow*>::iterator window_iterator = | |
| 413 std::find(previousKeyWindows_.begin(), | |
| 414 previousKeyWindows_.end(), | |
| 415 window); | |
| 416 if (window_iterator != previousKeyWindows_.end()) { | |
| 417 previousKeyWindows_.erase(window_iterator); | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 @end | 371 @end |
| OLD | NEW |