| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/app_menu_model.h" | 5 #include "chrome/browser/app_menu_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 12 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/sync/profile_sync_service.h" | 16 #include "chrome/browser/sync/profile_sync_service.h" |
| 16 #include "chrome/browser/sync/sync_ui_util.h" | 17 #include "chrome/browser/sync/sync_ui_util.h" |
| 18 #include "chrome/browser/upgrade_detector.h" |
| 17 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 18 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" |
| 20 | 23 |
| 21 AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate, | 24 AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate, |
| 22 Browser* browser) | 25 Browser* browser) |
| 23 : menus::SimpleMenuModel(delegate), | 26 : menus::SimpleMenuModel(delegate), |
| 24 browser_(browser) { | 27 browser_(browser) { |
| 25 Build(); | 28 Build(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 AppMenuModel::~AppMenuModel() { | 31 AppMenuModel::~AppMenuModel() { |
| 29 } | 32 } |
| 30 | 33 |
| 31 bool AppMenuModel::IsLabelDynamicAt(int index) const { | 34 bool AppMenuModel::IsLabelDynamicAt(int index) const { |
| 32 return IsSyncItem(index) || SimpleMenuModel::IsLabelDynamicAt(index); | 35 return IsDynamicItem(index) || SimpleMenuModel::IsLabelDynamicAt(index); |
| 33 } | 36 } |
| 34 | 37 |
| 35 string16 AppMenuModel::GetLabelAt(int index) const { | 38 string16 AppMenuModel::GetLabelAt(int index) const { |
| 36 return IsSyncItem(index) ? | 39 if (!IsDynamicItem(index)) |
| 37 GetSyncMenuLabel() : SimpleMenuModel::GetLabelAt(index); | 40 return SimpleMenuModel::GetLabelAt(index); |
| 41 |
| 42 int command_id = GetCommandIdAt(index); |
| 43 |
| 44 switch (command_id) { |
| 45 case IDC_ABOUT: return GetAboutEntryMenuLabel(); break; |
| 46 case IDC_SYNC_BOOKMARKS: return GetSyncMenuLabel(); break; |
| 47 default: |
| 48 NOTREACHED(); |
| 49 return string16(); |
| 50 } |
| 51 } |
| 52 |
| 53 bool AppMenuModel::GetIconAt(int index, SkBitmap* icon) const { |
| 54 if (GetCommandIdAt(index) == IDC_ABOUT && |
| 55 Singleton<UpgradeDetector>::get()->notify_upgrade()) { |
| 56 // Show the exclamation point next to the menu item. |
| 57 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 58 *icon = *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE); |
| 59 return true; |
| 60 } |
| 61 return false; |
| 38 } | 62 } |
| 39 | 63 |
| 40 void AppMenuModel::Build() { | 64 void AppMenuModel::Build() { |
| 41 AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); | 65 AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); |
| 42 AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); | 66 AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); |
| 43 AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); | 67 AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); |
| 44 // Enumerate profiles asynchronously and then create the parent menu item. | 68 // Enumerate profiles asynchronously and then create the parent menu item. |
| 45 // We will create the child menu items for this once the asynchronous call is | 69 // We will create the child menu items for this once the asynchronous call is |
| 46 // done. See OnGetProfilesDone(). | 70 // done. See OnGetProfilesDone(). |
| 47 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 71 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 177 |
| 154 return !std::equal(profiles.begin(), profiles.end(), | 178 return !std::equal(profiles.begin(), profiles.end(), |
| 155 known_profiles_.begin()); | 179 known_profiles_.begin()); |
| 156 } | 180 } |
| 157 | 181 |
| 158 string16 AppMenuModel::GetSyncMenuLabel() const { | 182 string16 AppMenuModel::GetSyncMenuLabel() const { |
| 159 return sync_ui_util::GetSyncMenuLabel( | 183 return sync_ui_util::GetSyncMenuLabel( |
| 160 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); | 184 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); |
| 161 } | 185 } |
| 162 | 186 |
| 163 bool AppMenuModel::IsSyncItem(int index) const { | 187 string16 AppMenuModel::GetAboutEntryMenuLabel() const { |
| 164 return GetCommandIdAt(index) == IDC_SYNC_BOOKMARKS; | 188 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) { |
| 189 return l10n_util::GetStringFUTF16( |
| 190 IDS_UPDATE_NOW, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 191 } |
| 192 return l10n_util::GetStringFUTF16( |
| 193 IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 165 } | 194 } |
| 195 |
| 196 bool AppMenuModel::IsDynamicItem(int index) const { |
| 197 int command_id = GetCommandIdAt(index); |
| 198 return command_id == IDC_SYNC_BOOKMARKS || |
| 199 command_id == IDC_ABOUT; |
| 200 } |
| OLD | NEW |