Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 6621076: [Mac] Remove native/Cocoa preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/background_application_list_model.h" 15 #include "chrome/browser/background_application_list_model.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/browser_shutdown.h" 17 #include "chrome/browser/browser_shutdown.h"
18 #include "chrome/browser/command_updater.h" 18 #include "chrome/browser/command_updater.h"
19 #include "chrome/browser/download/download_manager.h" 19 #include "chrome/browser/download/download_manager.h"
20 #include "chrome/browser/fonts_languages_window.h"
20 #include "chrome/browser/metrics/user_metrics.h" 21 #include "chrome/browser/metrics/user_metrics.h"
21 #include "chrome/browser/printing/print_job_manager.h" 22 #include "chrome/browser/printing/print_job_manager.h"
22 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/sessions/tab_restore_service.h" 24 #include "chrome/browser/sessions/tab_restore_service.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/sync/sync_ui_util.h" 26 #include "chrome/browser/sync/sync_ui_util.h"
26 #include "chrome/browser/sync/sync_ui_util_mac.h" 27 #include "chrome/browser/sync/sync_ui_util_mac.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_init.h" 29 #include "chrome/browser/ui/browser_init.h"
29 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
31 #import "chrome/browser/ui/cocoa/about_window_controller.h" 32 #import "chrome/browser/ui/cocoa/about_window_controller.h"
32 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" 33 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
33 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 34 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
34 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 35 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
35 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h" 36 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
36 #import "chrome/browser/ui/cocoa/clear_browsing_data_controller.h"
37 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" 37 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
38 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" 38 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h"
39 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" 39 #import "chrome/browser/ui/cocoa/history_menu_bridge.h"
40 #import "chrome/browser/ui/cocoa/importer/import_dialog_cocoa.h" 40 #import "chrome/browser/ui/cocoa/importer/import_dialog_cocoa.h"
41 #import "chrome/browser/ui/cocoa/options/preferences_window_controller.h"
42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
43 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" 42 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
44 #include "chrome/browser/ui/cocoa/task_manager_mac.h" 43 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
45 #include "chrome/browser/ui/options/options_window.h" 44 #include "chrome/browser/ui/options/options_window.h"
46 #include "chrome/common/app_mode_common_mac.h" 45 #include "chrome/common/app_mode_common_mac.h"
47 #include "chrome/common/chrome_paths_internal.h" 46 #include "chrome/common/chrome_paths_internal.h"
48 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/notification_service.h" 48 #include "chrome/common/notification_service.h"
50 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
51 #include "content/browser/browser_thread.h" 50 #include "content/browser/browser_thread.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 @interface AppController(Private) 143 @interface AppController(Private)
145 - (void)initMenuState; 144 - (void)initMenuState;
146 - (void)registerServicesMenuTypesTo:(NSApplication*)app; 145 - (void)registerServicesMenuTypesTo:(NSApplication*)app;
147 - (void)openUrls:(const std::vector<GURL>&)urls; 146 - (void)openUrls:(const std::vector<GURL>&)urls;
148 - (void)getUrl:(NSAppleEventDescriptor*)event 147 - (void)getUrl:(NSAppleEventDescriptor*)event
149 withReply:(NSAppleEventDescriptor*)reply; 148 withReply:(NSAppleEventDescriptor*)reply;
150 - (void)windowLayeringDidChange:(NSNotification*)inNotification; 149 - (void)windowLayeringDidChange:(NSNotification*)inNotification;
151 - (void)checkForAnyKeyWindows; 150 - (void)checkForAnyKeyWindows;
152 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 151 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
153 - (BOOL)shouldQuitWithInProgressDownloads; 152 - (BOOL)shouldQuitWithInProgressDownloads;
154 - (void)showPreferencesWindow:(id)sender
155 page:(OptionsPage)page
156 profile:(Profile*)profile;
157 - (void)executeApplication:(id)sender; 153 - (void)executeApplication:(id)sender;
158 @end 154 @end
159 155
160 @implementation AppController 156 @implementation AppController
161 157
162 @synthesize startupComplete = startupComplete_; 158 @synthesize startupComplete = startupComplete_;
163 159
164 // This method is called very early in application startup (ie, before 160 // This method is called very early in application startup (ie, before
165 // the profile is loaded or any preferences have been registered). Defer any 161 // the profile is loaded or any preferences have been registered). Defer any
166 // user-data initialization until -applicationDidFinishLaunching:. 162 // user-data initialization until -applicationDidFinishLaunching:.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile()); 751 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile());
756 break; 752 break;
757 case IDC_RESTORE_TAB: 753 case IDC_RESTORE_TAB:
758 Browser::OpenWindowWithRestoredTabs(defaultProfile); 754 Browser::OpenWindowWithRestoredTabs(defaultProfile);
759 break; 755 break;
760 case IDC_OPEN_FILE: 756 case IDC_OPEN_FILE:
761 CreateBrowser(defaultProfile)->ExecuteCommand(IDC_OPEN_FILE); 757 CreateBrowser(defaultProfile)->ExecuteCommand(IDC_OPEN_FILE);
762 break; 758 break;
763 case IDC_CLEAR_BROWSING_DATA: { 759 case IDC_CLEAR_BROWSING_DATA: {
764 // There may not be a browser open, so use the default profile. 760 // There may not be a browser open, so use the default profile.
765 if (CommandLine::ForCurrentProcess()->HasSwitch( 761 if (Browser* browser = ActivateBrowser(defaultProfile)) {
766 switches::kDisableTabbedOptions)) { 762 browser->OpenClearBrowsingDataDialog();
767 [ClearBrowsingDataController
768 showClearBrowsingDialogForProfile:defaultProfile];
769 } else { 763 } else {
770 if (Browser* browser = ActivateBrowser(defaultProfile)) { 764 Browser::OpenClearBrowingDataDialogWindow(defaultProfile);
771 browser->OpenClearBrowsingDataDialog();
772 } else {
773 Browser::OpenClearBrowingDataDialogWindow(defaultProfile);
774 }
775 } 765 }
776 break; 766 break;
777 } 767 }
778 case IDC_IMPORT_SETTINGS: { 768 case IDC_IMPORT_SETTINGS: {
779 if (CommandLine::ForCurrentProcess()->HasSwitch( 769 if (Browser* browser = ActivateBrowser(defaultProfile)) {
780 switches::kDisableTabbedOptions)) { 770 browser->OpenImportSettingsDialog();
781 UserMetrics::RecordAction(UserMetricsAction("Import_ShowDlg"),
782 defaultProfile);
783 [ImportDialogController
784 showImportSettingsDialogForProfile:defaultProfile];
785 } else { 771 } else {
786 if (Browser* browser = ActivateBrowser(defaultProfile)) { 772 Browser::OpenImportSettingsDialogWindow(defaultProfile);
787 browser->OpenImportSettingsDialog();
788 } else {
789 Browser::OpenImportSettingsDialogWindow(defaultProfile);
790 }
791 } 773 }
792 break; 774 break;
793 } 775 }
794 case IDC_SHOW_BOOKMARK_MANAGER: 776 case IDC_SHOW_BOOKMARK_MANAGER:
795 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"), 777 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"),
796 defaultProfile); 778 defaultProfile);
797 if (Browser* browser = ActivateBrowser(defaultProfile)) { 779 if (Browser* browser = ActivateBrowser(defaultProfile)) {
798 // Open a bookmark manager tab. 780 // Open a bookmark manager tab.
799 browser->OpenBookmarkManager(); 781 browser->OpenBookmarkManager();
800 } else { 782 } else {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 gurlVector.push_back(gurl); 1008 gurlVector.push_back(gurl);
1027 } 1009 }
1028 if (!gurlVector.empty()) 1010 if (!gurlVector.empty())
1029 [self openUrls:gurlVector]; 1011 [self openUrls:gurlVector];
1030 else 1012 else
1031 NOTREACHED() << "Nothing to open!"; 1013 NOTREACHED() << "Nothing to open!";
1032 1014
1033 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; 1015 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
1034 } 1016 }
1035 1017
1036 // Called when the preferences window is closed. We use this to release the
1037 // window controller.
1038 - (void)prefsWindowClosed:(NSNotification*)notification {
1039 NSWindow* window = [prefsController_ window];
1040 DCHECK_EQ([notification object], window);
1041 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
1042 [defaultCenter removeObserver:self
1043 name:NSWindowWillCloseNotification
1044 object:window];
1045 // PreferencesWindowControllers are autoreleased in
1046 // -[PreferencesWindowController windowWillClose:].
1047 prefsController_ = nil;
1048 }
1049
1050 // Show the preferences window, or bring it to the front if it's already 1018 // Show the preferences window, or bring it to the front if it's already
1051 // visible. 1019 // visible.
1052 - (IBAction)showPreferences:(id)sender { 1020 - (IBAction)showPreferences:(id)sender {
1053 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 1021 if (Browser* browser = ActivateBrowser([self defaultProfile])) {
1054 if (!parsed_command_line.HasSwitch(switches::kDisableTabbedOptions)) { 1022 // Show options tab in the active browser window.
1055 if (Browser* browser = ActivateBrowser([self defaultProfile])) { 1023 browser->OpenOptionsDialog();
1056 // Show options tab in the active browser window.
1057 browser->OpenOptionsDialog();
1058 } else {
1059 // No browser window, so create one for the options tab.
1060 Browser::OpenOptionsWindow([self defaultProfile]);
1061 }
1062 } else { 1024 } else {
1063 [self showPreferencesWindow:sender 1025 // No browser window, so create one for the options tab.
1064 page:OPTIONS_PAGE_DEFAULT 1026 Browser::OpenOptionsWindow([self defaultProfile]);
1065 profile:[self defaultProfile]];
1066 } 1027 }
1067 } 1028 }
1068 1029
1069 - (void)showPreferencesWindow:(id)sender
1070 page:(OptionsPage)page
1071 profile:(Profile*)profile {
1072 if (prefsController_) {
1073 [prefsController_ switchToPage:page animate:YES];
1074 } else {
1075 prefsController_ =
1076 [[PreferencesWindowController alloc] initWithProfile:profile
1077 initialPage:page];
1078 // Watch for a notification of when it goes away so that we can destroy
1079 // the controller.
1080 [[NSNotificationCenter defaultCenter]
1081 addObserver:self
1082 selector:@selector(prefsWindowClosed:)
1083 name:NSWindowWillCloseNotification
1084 object:[prefsController_ window]];
1085 }
1086 [prefsController_ showPreferences:sender];
1087 }
1088
1089 // Called when the about window is closed. We use this to release the 1030 // Called when the about window is closed. We use this to release the
1090 // window controller. 1031 // window controller.
1091 - (void)aboutWindowClosed:(NSNotification*)notification { 1032 - (void)aboutWindowClosed:(NSNotification*)notification {
1092 NSWindow* window = [aboutController_ window]; 1033 NSWindow* window = [aboutController_ window];
1093 DCHECK_EQ([notification object], window); 1034 DCHECK_EQ([notification object], window);
1094 [[NSNotificationCenter defaultCenter] 1035 [[NSNotificationCenter defaultCenter]
1095 removeObserver:self 1036 removeObserver:self
1096 name:NSWindowWillCloseNotification 1037 name:NSWindowWillCloseNotification
1097 object:window]; 1038 object:window];
1098 // AboutWindowControllers are autoreleased in 1039 // AboutWindowControllers are autoreleased in
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 startupUrls_.clear(); 1132 startupUrls_.clear();
1192 } 1133 }
1193 1134
1194 @end // @implementation AppController 1135 @end // @implementation AppController
1195 1136
1196 //--------------------------------------------------------------------------- 1137 //---------------------------------------------------------------------------
1197 1138
1198 void ShowOptionsWindow(OptionsPage page, 1139 void ShowOptionsWindow(OptionsPage page,
1199 OptionsGroup highlight_group, 1140 OptionsGroup highlight_group,
1200 Profile* profile) { 1141 Profile* profile) {
1142 const char* theSwitch = switches::kDisableTabbedOptions;
1143 if (CommandLine::ForCurrentProcess()->HasSwitch(theSwitch)) {
1144 NSRunCriticalAlertPanel(
1145 @"Ooops! No preferences!",
1146 [NSString stringWithFormat:@"You launched chrome with --%s, which "
1147 @"disables the Preferences system. Did you really mean to do that? "
1148 @"You should relaunch without that flag if you want to change "
1149 @"settings.", theSwitch],
1150 @"OK",
1151 nil,
1152 nil);
1153 return;
1154 }
1201 // TODO(akalin): Use highlight_group. 1155 // TODO(akalin): Use highlight_group.
1202 AppController* appController = [NSApp delegate]; 1156 AppController* appController = [NSApp delegate];
1203 [appController showPreferencesWindow:nil page:page profile:profile]; 1157 [appController showPreferences:nil];
1158 }
1159
1160 void ShowFontsLanguagesWindow(gfx::NativeWindow window,
1161 FontsLanguagesPage page,
1162 Profile* profile) {
1163 NOTIMPLEMENTED();
1204 } 1164 }
1205 1165
1206 namespace app_controller_mac { 1166 namespace app_controller_mac {
1207 1167
1208 bool IsOpeningNewWindow() { 1168 bool IsOpeningNewWindow() {
1209 return g_is_opening_new_window; 1169 return g_is_opening_new_window;
1210 } 1170 }
1211 1171
1212 } // namespace app_controller_mac 1172 } // namespace app_controller_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698