OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | |
10 #include "chrome/browser/chrome_to_mobile_service.h" | |
11 #include "chrome/browser/chrome_to_mobile_service_factory.h" | |
12 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 11 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/profiles/profile.h" | |
16 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | |
17 #include "chrome/browser/ui/browser.h" | |
18 #include "chrome/browser/ui/browser_commands.h" | |
19 #include "chrome/browser/ui/browser_command_controller.h" | |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
21 #include "chrome/common/extensions/api/extension_action/action_info.h" | 12 #include "chrome/common/extensions/api/extension_action/action_info.h" |
22 #include "chrome/common/url_constants.h" | 13 |
23 #include "grit/generated_resources.h" | |
24 #include "grit/theme_resources.h" | |
25 #include "ui/base/resource/resource_bundle.h" | |
26 | 14 |
27 using extensions::ActionInfo; | 15 using extensions::ActionInfo; |
28 | 16 |
29 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
30 // ActionBoxMenuModel | 18 // ActionBoxMenuModel |
31 | 19 |
32 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, | 20 ActionBoxMenuModel::ActionBoxMenuModel(Profile* profile, |
33 ui::SimpleMenuModel::Delegate* delegate) | 21 ui::SimpleMenuModel::Delegate* delegate) |
34 : ui::SimpleMenuModel(delegate), | 22 : ui::SimpleMenuModel(delegate), |
35 browser_(browser) { | 23 profile_(profile) { |
36 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
37 // TODO(msw): Show the item as disabled for chrome: and file: scheme pages? | |
38 if (ChromeToMobileService::UpdateAndGetCommandState(browser_)) { | |
39 AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE, | |
40 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP); | |
41 SetIcon(GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE), | |
42 rb.GetNativeImageNamed(IDR_MOBILE)); | |
43 } | |
44 | 24 |
45 // In some unit tests, GetActiveWebContents can return NULL. | |
46 bool starred = browser_->tab_strip_model()->GetActiveWebContents() && | |
47 BookmarkTabHelper::FromWebContents(browser_->tab_strip_model()-> | |
48 GetActiveWebContents())->is_starred(); | |
49 | |
50 AddItemWithStringId(IDC_BOOKMARK_PAGE_FROM_STAR, | |
51 starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); | |
52 SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE_FROM_STAR), | |
53 rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); | |
54 | |
55 AddItemWithStringId(IDC_PRINT, IDS_PRINT); | |
56 } | 25 } |
57 | 26 |
58 ActionBoxMenuModel::~ActionBoxMenuModel() { | 27 ActionBoxMenuModel::~ActionBoxMenuModel() { |
59 } | 28 } |
60 | 29 |
61 void ActionBoxMenuModel::AddExtension(const extensions::Extension& extension, | 30 void ActionBoxMenuModel::AddExtension(const extensions::Extension& extension, |
62 int command_id) { | 31 int command_id) { |
63 if (extension_ids_.empty()) | 32 if (extension_ids_.empty()) |
64 AddSeparator(ui::NORMAL_SEPARATOR); | 33 AddSeparator(ui::NORMAL_SEPARATOR); |
65 extension_ids_.push_back(extension.id()); | 34 extension_ids_.push_back(extension.id()); |
(...skipping 11 matching lines...) Expand all Loading... |
77 | 46 |
78 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { | 47 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { |
79 if (!IsItemExtension(index)) | 48 if (!IsItemExtension(index)) |
80 return NULL; | 49 return NULL; |
81 | 50 |
82 int index_in_extension_ids = index - GetFirstExtensionIndex(); | 51 int index_in_extension_ids = index - GetFirstExtensionIndex(); |
83 CHECK_GE(index_in_extension_ids, 0); | 52 CHECK_GE(index_in_extension_ids, 0); |
84 CHECK_LT(index_in_extension_ids, static_cast<int>(extension_ids_.size())); | 53 CHECK_LT(index_in_extension_ids, static_cast<int>(extension_ids_.size())); |
85 | 54 |
86 ExtensionService* extension_service = | 55 ExtensionService* extension_service = |
87 extensions::ExtensionSystem::Get(browser_->profile())-> | 56 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
88 extension_service(); | |
89 return extension_service->extensions()->GetByID( | 57 return extension_service->extensions()->GetByID( |
90 extension_ids_[index_in_extension_ids]); | 58 extension_ids_[index_in_extension_ids]); |
91 } | 59 } |
92 | 60 |
93 void ActionBoxMenuModel::ExecuteCommand(int command_id) { | 61 void ActionBoxMenuModel::ExecuteCommand(int command_id) { |
94 delegate()->ExecuteCommand(command_id, 0); | 62 delegate()->ExecuteCommand(command_id, 0); |
95 } | 63 } |
96 | 64 |
97 int ActionBoxMenuModel::GetFirstExtensionIndex() { | 65 int ActionBoxMenuModel::GetFirstExtensionIndex() { |
98 return GetItemCount() - extension_ids_.size(); | 66 return GetItemCount() - extension_ids_.size(); |
99 } | 67 } |
OLD | NEW |