// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/wrench_menu_model.h" #include #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/command_line.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/defaults.h" #include "chrome/browser/page_menu_model.h" #include "chrome/browser/profile.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/upgrade_detector.h" #include "chrome/common/chrome_switches.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" //////////////////////////////////////////////////////////////////////////////// // ToolsMenuModel ToolsMenuModel::ToolsMenuModel(menus::SimpleMenuModel::Delegate* delegate, Browser* browser) : SimpleMenuModel(delegate) { Build(browser); } ToolsMenuModel::~ToolsMenuModel() {} void ToolsMenuModel::Build(Browser* browser) { AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR); AddSeparator(); AddItemWithStringId(IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS); AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); AddItemWithStringId(IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA); AddSeparator(); encoding_menu_model_.reset(new EncodingMenuModel(browser)); AddSubMenuWithStringId(IDC_ENCODING_MENU, IDS_ENCODING_MENU, encoding_menu_model_.get()); AddItemWithStringId(IDC_VIEW_SOURCE, IDS_VIEW_SOURCE); if (g_browser_process->have_inspector_files()) { AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS); AddItemWithStringId(IDC_DEV_TOOLS_CONSOLE, IDS_DEV_TOOLS_CONSOLE); } } //////////////////////////////////////////////////////////////////////////////// // WrenchMenuModel WrenchMenuModel::WrenchMenuModel(menus::SimpleMenuModel::Delegate* delegate, Browser* browser) : menus::SimpleMenuModel(delegate), browser_(browser) { Build(); } WrenchMenuModel::~WrenchMenuModel() { } bool WrenchMenuModel::IsLabelDynamicAt(int index) const { return IsDynamicItem(index) || SimpleMenuModel::IsLabelDynamicAt(index); } string16 WrenchMenuModel::GetLabelAt(int index) const { if (!IsDynamicItem(index)) return SimpleMenuModel::GetLabelAt(index); int command_id = GetCommandIdAt(index); switch (command_id) { case IDC_ABOUT: return GetAboutEntryMenuLabel(); case IDC_SYNC_BOOKMARKS: return GetSyncMenuLabel(); default: NOTREACHED(); return string16(); } } bool WrenchMenuModel::GetIconAt(int index, SkBitmap* icon) const { if (GetCommandIdAt(index) == IDC_ABOUT && Singleton::get()->notify_upgrade()) { // Show the exclamation point next to the menu item. ResourceBundle& rb = ResourceBundle::GetSharedInstance(); *icon = *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE); return true; } return false; } void WrenchMenuModel::Build() { AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); AddSeparator(); CreateCutCopyPaste(); AddSeparator(); CreateZoomFullscreen(); AddSeparator(); AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); AddItemWithStringId(IDC_FIND, IDS_FIND); AddItemWithStringId(IDC_PRINT, IDS_PRINT); tools_menu_model_.reset(new ToolsMenuModel(delegate(), browser_)); AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU, tools_menu_model_.get()); AddSeparator(); AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER); AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); AddSeparator(); #if defined(OS_MACOSX) AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC); #else AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); #endif AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); if (browser_defaults::kShowExitMenuItem) { AddSeparator(); #if defined(OS_CHROMEOS) AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT); #else AddItemWithStringId(IDC_EXIT, IDS_EXIT); #endif } } void WrenchMenuModel::CreateCutCopyPaste() { AddItemWithStringId(IDC_CUT, IDS_CUT); AddItemWithStringId(IDC_COPY, IDS_COPY); AddItemWithStringId(IDC_PASTE, IDS_PASTE); } void WrenchMenuModel::CreateZoomFullscreen() { AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); } string16 WrenchMenuModel::GetSyncMenuLabel() const { return sync_ui_util::GetSyncMenuLabel( browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); } string16 WrenchMenuModel::GetAboutEntryMenuLabel() const { if (Singleton::get()->notify_upgrade()) { return l10n_util::GetStringFUTF16( IDS_UPDATE_NOW, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); } return l10n_util::GetStringFUTF16( IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); } bool WrenchMenuModel::IsDynamicItem(int index) const { int command_id = GetCommandIdAt(index); return command_id == IDC_SYNC_BOOKMARKS || command_id == IDC_ABOUT; }