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 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #import "base/memory/scoped_nsobject.h" | 13 #import "base/memory/scoped_nsobject.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" // IDC_* | 16 #include "chrome/app/chrome_command_ids.h" // IDC_* |
17 #include "chrome/browser/bookmarks/bookmark_editor.h" | 17 #include "chrome/browser/bookmarks/bookmark_editor.h" |
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/managed_mode/managed_mode.h" | 20 #include "chrome/browser/managed_mode/managed_mode.h" |
21 #include "chrome/browser/profiles/avatar_menu_model.h" | 21 #include "chrome/browser/profiles/avatar_menu_model.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/signin/signin_manager.h" | 25 #include "chrome/browser/signin/signin_ui_util.h" |
26 #include "chrome/browser/signin/signin_manager_factory.h" | |
27 #include "chrome/browser/sync/profile_sync_service.h" | |
28 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
29 #include "chrome/browser/sync/sync_global_error.h" | |
30 #include "chrome/browser/sync/sync_ui_util.h" | |
31 #include "chrome/browser/themes/theme_service.h" | 26 #include "chrome/browser/themes/theme_service.h" |
32 #include "chrome/browser/themes/theme_service_factory.h" | 27 #include "chrome/browser/themes/theme_service_factory.h" |
33 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
34 #include "chrome/browser/ui/browser_command_controller.h" | 29 #include "chrome/browser/ui/browser_command_controller.h" |
35 #include "chrome/browser/ui/browser_commands.h" | 30 #include "chrome/browser/ui/browser_commands.h" |
36 #include "chrome/browser/ui/browser_instant_controller.h" | 31 #include "chrome/browser/ui/browser_instant_controller.h" |
37 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
38 #include "chrome/browser/ui/browser_window_state.h" | 33 #include "chrome/browser/ui/browser_window_state.h" |
39 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 34 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
40 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 35 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 NSInteger signinItemIndex = [menu indexOfItem:signinMenuItem]; | 235 NSInteger signinItemIndex = [menu indexOfItem:signinMenuItem]; |
241 DCHECK_NE(signinItemIndex, -1); | 236 DCHECK_NE(signinItemIndex, -1); |
242 if ((signinItemIndex + 1) < [menu numberOfItems]) { | 237 if ((signinItemIndex + 1) < [menu numberOfItems]) { |
243 NSMenuItem* menuItem = [menu itemAtIndex:(signinItemIndex + 1)]; | 238 NSMenuItem* menuItem = [menu itemAtIndex:(signinItemIndex + 1)]; |
244 if ([menuItem isSeparatorItem]) { | 239 if ([menuItem isSeparatorItem]) { |
245 followingSeparator = menuItem; | 240 followingSeparator = menuItem; |
246 } | 241 } |
247 } | 242 } |
248 } | 243 } |
249 | 244 |
250 // Figure out what string to display in the signin menu item - depending on | 245 string16 label = signin_ui_util::GetSigninMenuLabel(profile); |
251 // the state of the signed-in services, this will be one of: | 246 [signinMenuItem setTitle:l10n_util::FixUpWindowsStyleLabel(label)]; |
252 // "Sign in to <product name>" | |
253 // "Signed in as <username>" | |
254 // "Signin Error" | |
255 ProfileSyncService* syncService = profile->IsSyncAccessible() ? | |
256 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
257 profile->GetOriginalProfile()) : NULL; | |
258 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); | |
259 std::string userName = signin->GetAuthenticatedUsername(); | |
260 NSString* title = NULL; | |
261 if (userName.empty() || signin->AuthInProgress() || | |
262 (syncService && !syncService->HasSyncSetupCompleted())) { | |
263 // Not signed in yet - display the default string. | |
264 title = GetNSStringFWithFixup(IDS_SYNC_MENU_PRE_SYNCED_LABEL, | |
265 GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | |
266 } else if (signin->signin_global_error()->HasBadge()) { | |
267 // TODO(atwilson): Change this string to a generic signin error instead of | |
268 // a "Sync error" string once we allow signin without sync. | |
269 title = GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | |
270 } else if (syncService && syncService->sync_global_error() && | |
271 syncService->sync_global_error()->HasBadge()) { | |
272 title = GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | |
273 } else { | |
274 // Signed in. | |
275 title = GetNSStringFWithFixup(IDS_SYNC_MENU_SYNCED_LABEL, | |
276 UTF8ToUTF16(userName)); | |
277 } | |
278 | |
279 [signinMenuItem setTitle:title]; | |
280 [signinMenuItem setHidden:!showSigninMenuItem]; | 247 [signinMenuItem setHidden:!showSigninMenuItem]; |
281 [followingSeparator setHidden:!showSigninMenuItem]; | 248 [followingSeparator setHidden:!showSigninMenuItem]; |
282 } | 249 } |
283 | 250 |
284 // Load the browser window nib and do any Cocoa-specific initialization. | 251 // Load the browser window nib and do any Cocoa-specific initialization. |
285 // Takes ownership of |browser|. Note that the nib also sets this controller | 252 // Takes ownership of |browser|. Note that the nib also sets this controller |
286 // up as the window's delegate. | 253 // up as the window's delegate. |
287 - (id)initWithBrowser:(Browser*)browser { | 254 - (id)initWithBrowser:(Browser*)browser { |
288 return [self initWithBrowser:browser takeOwnership:YES]; | 255 return [self initWithBrowser:browser takeOwnership:YES]; |
289 } | 256 } |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 NSString* menuTitle = l10n_util::GetNSString( | 1083 NSString* menuTitle = l10n_util::GetNSString( |
1117 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : | 1084 [self inPresentationMode] ? IDS_EXIT_PRESENTATION_MAC : |
1118 IDS_ENTER_PRESENTATION_MAC); | 1085 IDS_ENTER_PRESENTATION_MAC); |
1119 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; | 1086 [static_cast<NSMenuItem*>(item) setTitle:menuTitle]; |
1120 } | 1087 } |
1121 break; | 1088 break; |
1122 } | 1089 } |
1123 case IDC_SHOW_SIGNIN: { | 1090 case IDC_SHOW_SIGNIN: { |
1124 Profile* original_profile = | 1091 Profile* original_profile = |
1125 browser_->profile()->GetOriginalProfile(); | 1092 browser_->profile()->GetOriginalProfile(); |
1126 enable &= original_profile->IsSyncAccessible(); | |
1127 [BrowserWindowController updateSigninItem:item | 1093 [BrowserWindowController updateSigninItem:item |
1128 shouldShow:enable | 1094 shouldShow:enable |
1129 currentProfile:original_profile]; | 1095 currentProfile:original_profile]; |
1130 break; | 1096 break; |
1131 } | 1097 } |
1132 default: | 1098 default: |
1133 // Special handling for the contents of the Text Encoding submenu. On | 1099 // Special handling for the contents of the Text Encoding submenu. On |
1134 // Mac OS, instead of enabling/disabling the top-level menu item, we | 1100 // Mac OS, instead of enabling/disabling the top-level menu item, we |
1135 // enable/disable the submenu's contents (per Apple's HIG). | 1101 // enable/disable the submenu's contents (per Apple's HIG). |
1136 EncodingMenuController encoding_controller; | 1102 EncodingMenuController encoding_controller; |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 | 2206 |
2241 - (BOOL)supportsBookmarkBar { | 2207 - (BOOL)supportsBookmarkBar { |
2242 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2208 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2243 } | 2209 } |
2244 | 2210 |
2245 - (BOOL)isTabbedWindow { | 2211 - (BOOL)isTabbedWindow { |
2246 return browser_->is_type_tabbed(); | 2212 return browser_->is_type_tabbed(); |
2247 } | 2213 } |
2248 | 2214 |
2249 @end // @implementation BrowserWindowController(WindowType) | 2215 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |