OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
12 #include "chrome/browser/browser_init.h" | 12 #include "chrome/browser/browser_init.h" |
13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
15 #import "chrome/browser/cocoa/about_window_controller.h" | 15 #import "chrome/browser/cocoa/about_window_controller.h" |
16 #import "chrome/browser/cocoa/bookmark_menu_bridge.h" | 16 #import "chrome/browser/cocoa/bookmark_menu_bridge.h" |
| 17 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
17 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" | 18 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" |
18 #import "chrome/browser/cocoa/menu_localizer.h" | 19 #import "chrome/browser/cocoa/menu_localizer.h" |
19 #import "chrome/browser/cocoa/preferences_window_controller.h" | 20 #import "chrome/browser/cocoa/preferences_window_controller.h" |
20 #import "chrome/browser/cocoa/tab_strip_controller.h" | 21 #import "chrome/browser/cocoa/tab_strip_controller.h" |
21 #import "chrome/browser/cocoa/tab_window_controller.h" | 22 #import "chrome/browser/cocoa/tab_window_controller.h" |
22 #include "chrome/browser/command_updater.h" | 23 #include "chrome/browser/command_updater.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/pref_service.h" | 25 #include "chrome/common/pref_service.h" |
25 #include "chrome/browser/profile_manager.h" | 26 #include "chrome/browser/profile_manager.h" |
26 #include "chrome/common/temp_scaffolding_stubs.h" | 27 #include "chrome/common/temp_scaffolding_stubs.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 enable = YES; | 283 enable = YES; |
283 } | 284 } |
284 return enable; | 285 return enable; |
285 } | 286 } |
286 | 287 |
287 // Called when the user picks a menu item when there are no key windows. Calls | 288 // Called when the user picks a menu item when there are no key windows. Calls |
288 // through to the browser object to execute the command. This assumes that the | 289 // through to the browser object to execute the command. This assumes that the |
289 // command is supported and doesn't check, otherwise it would have been disabled | 290 // command is supported and doesn't check, otherwise it would have been disabled |
290 // in the UI in validateUserInterfaceItem:. | 291 // in the UI in validateUserInterfaceItem:. |
291 - (void)commandDispatch:(id)sender { | 292 - (void)commandDispatch:(id)sender { |
292 Profile* default_profile = [self defaultProfile]; | 293 Profile* defaultProfile = [self defaultProfile]; |
293 | 294 |
294 NSInteger tag = [sender tag]; | 295 NSInteger tag = [sender tag]; |
295 switch (tag) { | 296 switch (tag) { |
296 case IDC_NEW_WINDOW: | 297 case IDC_NEW_WINDOW: |
297 Browser::OpenEmptyWindow(default_profile); | 298 Browser::OpenEmptyWindow(defaultProfile); |
298 break; | 299 break; |
299 case IDC_NEW_INCOGNITO_WINDOW: | 300 case IDC_NEW_INCOGNITO_WINDOW: |
300 Browser::OpenURLOffTheRecord(default_profile, GURL()); | 301 Browser::OpenURLOffTheRecord(defaultProfile, GURL()); |
301 break; | 302 break; |
302 case IDC_OPEN_FILE: | 303 case IDC_OPEN_FILE: |
303 Browser::OpenEmptyWindow(default_profile); | 304 Browser::OpenEmptyWindow(defaultProfile); |
304 BrowserList::GetLastActive()-> | 305 BrowserList::GetLastActive()-> |
305 ExecuteCommandWithDisposition(IDC_OPEN_FILE, CURRENT_TAB); | 306 ExecuteCommandWithDisposition(IDC_OPEN_FILE, CURRENT_TAB); |
306 break; | 307 break; |
| 308 case IDC_CLEAR_BROWSING_DATA: |
| 309 // There may not be a browser open, so use the default profile. |
| 310 scoped_nsobject<ClearBrowsingDataController> controller( |
| 311 [[ClearBrowsingDataController alloc] |
| 312 initWithProfile:defaultProfile]); |
| 313 [controller runModalDialog]; |
| 314 break; |
307 }; | 315 }; |
308 } | 316 } |
309 | 317 |
310 // NSApplication delegate method called when someone clicks on the | 318 // NSApplication delegate method called when someone clicks on the |
311 // dock icon and there are no open windows. To match standard mac | 319 // dock icon and there are no open windows. To match standard mac |
312 // behavior, we should open a new window. | 320 // behavior, we should open a new window. |
313 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication | 321 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication |
314 hasVisibleWindows:(BOOL)flag { | 322 hasVisibleWindows:(BOOL)flag { |
315 // Don't do anything if there are visible windows. This will cause | 323 // Don't do anything if there are visible windows. This will cause |
316 // AppKit to unminimize the most recently minimized window. | 324 // AppKit to unminimize the most recently minimized window. |
317 if (flag) | 325 if (flag) |
318 return YES; | 326 return YES; |
319 | 327 |
320 // Otherwise open a new window. | 328 // Otherwise open a new window. |
321 Browser::OpenEmptyWindow([self defaultProfile]); | 329 Browser::OpenEmptyWindow([self defaultProfile]); |
322 | 330 |
323 // We've handled the reopen event, so return NO to tell AppKit not | 331 // We've handled the reopen event, so return NO to tell AppKit not |
324 // to do anything. | 332 // to do anything. |
325 return NO; | 333 return NO; |
326 } | 334 } |
327 | 335 |
328 - (void)initMenuState { | 336 - (void)initMenuState { |
329 menuState_.reset(new CommandUpdater(NULL)); | 337 menuState_.reset(new CommandUpdater(NULL)); |
330 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 338 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
331 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); | 339 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); |
332 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true); | 340 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true); |
| 341 menuState_->UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true); |
333 // TODO(pinkerton): ...more to come... | 342 // TODO(pinkerton): ...more to come... |
334 } | 343 } |
335 | 344 |
336 - (Profile*)defaultProfile { | 345 - (Profile*)defaultProfile { |
337 // TODO(jrg): Find a better way to get the "default" profile. | 346 // TODO(jrg): Find a better way to get the "default" profile. |
338 if (g_browser_process->profile_manager()) | 347 if (g_browser_process->profile_manager()) |
339 return* g_browser_process->profile_manager()->begin(); | 348 return* g_browser_process->profile_manager()->begin(); |
340 | 349 |
341 return NULL; | 350 return NULL; |
342 } | 351 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 name:kUserClosedAboutNotification | 486 name:kUserClosedAboutNotification |
478 object:aboutController_.get()]; | 487 object:aboutController_.get()]; |
479 } | 488 } |
480 if (![[aboutController_ window] isVisible]) | 489 if (![[aboutController_ window] isVisible]) |
481 [[aboutController_ window] center]; | 490 [[aboutController_ window] center]; |
482 [aboutController_ showWindow:self]; | 491 [aboutController_ showWindow:self]; |
483 #endif | 492 #endif |
484 } | 493 } |
485 | 494 |
486 @end | 495 @end |
OLD | NEW |