| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "chrome/browser/app_menu_model.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/defaults.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/browser/sync/sync_ui_util.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "grit/chromium_strings.h" |
| 16 #include "grit/generated_resources.h" |
| 17 |
| 18 AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate, |
| 19 Browser* browser) |
| 20 : menus::SimpleMenuModel(delegate), |
| 21 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 22 profiles_helper_(new GetProfilesHelper(this))), |
| 23 browser_(browser) { |
| 24 Build(); |
| 25 } |
| 26 |
| 27 AppMenuModel::~AppMenuModel() { |
| 28 profiles_helper_->OnDelegateDeleted(); |
| 29 } |
| 30 |
| 31 void AppMenuModel::Build() { |
| 32 AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); |
| 33 AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); |
| 34 AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); |
| 35 // Enumerate profiles asynchronously and then create the parent menu item. |
| 36 // We will create the child menu items for this once the asynchronous call is |
| 37 // done. See OnGetProfilesDone(). |
| 38 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 39 if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) { |
| 40 if (!profiles_menu_contents_.get()) { |
| 41 profiles_helper_->GetProfiles(NULL); |
| 42 profiles_menu_contents_.reset(new menus::SimpleMenuModel(delegate())); |
| 43 } |
| 44 AddSubMenuWithStringId(IDS_PROFILE_MENU, profiles_menu_contents_.get()); |
| 45 } |
| 46 |
| 47 AddSeparator(); |
| 48 AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR); |
| 49 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); |
| 50 AddSeparator(); |
| 51 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); |
| 52 AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER); |
| 53 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); |
| 54 |
| 55 // Create the manage extensions menu item. |
| 56 AddItemWithStringId(IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS); |
| 57 |
| 58 AddSeparator(); |
| 59 if (ProfileSyncService::IsSyncEnabled()) { |
| 60 string16 label; |
| 61 string16 link; |
| 62 // TODO(akalin): use sync_ui_util::GetStatus instead. |
| 63 sync_ui_util::MessageType type = sync_ui_util::GetStatusLabels( |
| 64 browser_->profile()->GetOriginalProfile()->GetProfileSyncService(), |
| 65 &label, &link); |
| 66 if (type == sync_ui_util::SYNCED) { |
| 67 label = l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL); |
| 68 } else if (type == sync_ui_util::SYNC_ERROR) { |
| 69 label = l10n_util::GetStringUTF16( |
| 70 IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL); |
| 71 } else { |
| 72 label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); |
| 73 } |
| 74 AddItem(IDC_SYNC_BOOKMARKS, label); |
| 75 AddSeparator(); |
| 76 } |
| 77 #if defined(OS_MACOSX) |
| 78 AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC); |
| 79 #else |
| 80 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); |
| 81 #endif |
| 82 if (browser_defaults::kShowAboutMenuItem) { |
| 83 AddItem(IDC_ABOUT, |
| 84 l10n_util::GetStringFUTF16( |
| 85 IDS_ABOUT, |
| 86 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 87 } |
| 88 AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); |
| 89 if (browser_defaults::kShowExitMenuItem) { |
| 90 AddSeparator(); |
| 91 AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
| 92 } |
| 93 } |
| 94 |
| 95 void AppMenuModel::OnGetProfilesDone( |
| 96 const std::vector<std::wstring>& profiles) { |
| 97 // Nothing to do if the menu has gone away. |
| 98 if (!profiles_menu_contents_.get()) |
| 99 return; |
| 100 |
| 101 // Store the latest list of profiles in the browser. |
| 102 browser_->set_user_data_dir_profiles(profiles); |
| 103 |
| 104 // Add direct submenu items for profiles. |
| 105 std::vector<std::wstring>::const_iterator iter = profiles.begin(); |
| 106 for (int i = IDC_NEW_WINDOW_PROFILE_0; |
| 107 i <= IDC_NEW_WINDOW_PROFILE_LAST && iter != profiles.end(); |
| 108 ++i, ++iter) |
| 109 profiles_menu_contents_->AddItem(i, WideToUTF16Hack(*iter)); |
| 110 |
| 111 // If there are more profiles then show "Other" link. |
| 112 if (iter != profiles.end()) { |
| 113 profiles_menu_contents_->AddSeparator(); |
| 114 profiles_menu_contents_->AddItemWithStringId(IDC_SELECT_PROFILE, |
| 115 IDS_SELECT_PROFILE); |
| 116 } |
| 117 |
| 118 // Always show a link to select a new profile. |
| 119 profiles_menu_contents_->AddSeparator(); |
| 120 profiles_menu_contents_->AddItemWithStringId( |
| 121 IDC_NEW_PROFILE, |
| 122 IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY); |
| 123 } |
| OLD | NEW |