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" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/chrome_to_mobile_service.h" | 10 #include "chrome/browser/chrome_to_mobile_service.h" |
11 #include "chrome/browser/chrome_to_mobile_service_factory.h" | 11 #include "chrome/browser/chrome_to_mobile_service_factory.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 14 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 16 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
19 #include "chrome/browser/ui/browser_command_controller.h" | 19 #include "chrome/browser/ui/browser_command_controller.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/extensions/api/extension_action/action_info.h" |
21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 | 26 |
| 27 using extensions::ActionInfo; |
| 28 |
26 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
27 // ActionBoxMenuModel | 30 // ActionBoxMenuModel |
28 | 31 |
29 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, | 32 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, |
30 ui::SimpleMenuModel::Delegate* delegate) | 33 ui::SimpleMenuModel::Delegate* delegate) |
31 : ui::SimpleMenuModel(delegate), | 34 : ui::SimpleMenuModel(delegate), |
32 browser_(browser) { | 35 browser_(browser) { |
33 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 36 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
34 // TODO(msw): Show the item as disabled for chrome: and file: scheme pages? | 37 // TODO(msw): Show the item as disabled for chrome: and file: scheme pages? |
35 if (ChromeToMobileService::UpdateAndGetCommandState(browser_)) { | 38 if (ChromeToMobileService::UpdateAndGetCommandState(browser_)) { |
(...skipping 13 matching lines...) Expand all Loading... |
49 } | 52 } |
50 | 53 |
51 ActionBoxMenuModel::~ActionBoxMenuModel() { | 54 ActionBoxMenuModel::~ActionBoxMenuModel() { |
52 } | 55 } |
53 | 56 |
54 void ActionBoxMenuModel::AddExtension(const extensions::Extension& extension, | 57 void ActionBoxMenuModel::AddExtension(const extensions::Extension& extension, |
55 int command_id) { | 58 int command_id) { |
56 if (extension_ids_.empty()) | 59 if (extension_ids_.empty()) |
57 AddSeparator(ui::NORMAL_SEPARATOR); | 60 AddSeparator(ui::NORMAL_SEPARATOR); |
58 extension_ids_.push_back(extension.id()); | 61 extension_ids_.push_back(extension.id()); |
59 AddItem(command_id, UTF8ToUTF16(extension.name())); | 62 const ActionInfo* page_launcher_info = |
| 63 ActionInfo::GetPageLauncherInfo(&extension); |
| 64 AddItem(command_id, UTF8ToUTF16(page_launcher_info->default_title)); |
60 } | 65 } |
61 | 66 |
62 bool ActionBoxMenuModel::IsItemExtension(int index) { | 67 bool ActionBoxMenuModel::IsItemExtension(int index) { |
63 // The extensions are always at the end of the model. | 68 // The extensions are always at the end of the model. |
64 CHECK(index < GetItemCount()); | 69 CHECK(index < GetItemCount()); |
65 return index >= GetFirstExtensionIndex(); | 70 return index >= GetFirstExtensionIndex(); |
66 } | 71 } |
67 | 72 |
68 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { | 73 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { |
69 if (!IsItemExtension(index)) | 74 if (!IsItemExtension(index)) |
(...skipping 10 matching lines...) Expand all Loading... |
80 extension_ids_[index_in_extension_ids]); | 85 extension_ids_[index_in_extension_ids]); |
81 } | 86 } |
82 | 87 |
83 void ActionBoxMenuModel::ExecuteCommand(int command_id) { | 88 void ActionBoxMenuModel::ExecuteCommand(int command_id) { |
84 delegate()->ExecuteCommand(command_id); | 89 delegate()->ExecuteCommand(command_id); |
85 } | 90 } |
86 | 91 |
87 int ActionBoxMenuModel::GetFirstExtensionIndex() { | 92 int ActionBoxMenuModel::GetFirstExtensionIndex() { |
88 return GetItemCount() - extension_ids_.size(); | 93 return GetItemCount() - extension_ids_.size(); |
89 } | 94 } |
OLD | NEW |