OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/app_context_menu.h" | 5 #include "chrome/browser/ui/app_list/app_context_menu.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/extensions/context_menu_matcher.h" | 8 #include "chrome/browser/extensions/context_menu_matcher.h" |
9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
10 #include "chrome/browser/extensions/menu_manager.h" | 10 #include "chrome/browser/extensions/menu_manager.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 } | 174 } |
175 | 175 |
176 return menu_model_.get(); | 176 return menu_model_.get(); |
177 } | 177 } |
178 | 178 |
179 bool AppContextMenu::IsItemForCommandIdDynamic(int command_id) const { | 179 bool AppContextMenu::IsItemForCommandIdDynamic(int command_id) const { |
180 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; | 180 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; |
181 } | 181 } |
182 | 182 |
183 base::string16 AppContextMenu::GetLabelForCommandId(int command_id) const { | 183 base::string16 AppContextMenu::GetLabelForCommandId(int command_id) const { |
184 if (command_id == TOGGLE_PIN) { | 184 // If streamlined hosted apps are enabled, then we do not need to consider |
185 return controller_->IsAppPinned(app_id_) ? | 185 // the case when command_id == TOGGLE_PIN (see AppContextMenu::GetMenuModel). |
186 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : | 186 if (extensions::util::IsStreamlinedHostedAppsEnabled()) { |
187 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN); | 187 if (command_id == LAUNCH_NEW) { |
tapted
2015/01/05 23:10:32
nit: instead of the if/else-NOTREACHED, you can ju
mitchellj
2015/01/06 01:41:14
Done.
| |
188 } else if (command_id == LAUNCH_NEW) { | 188 return IsCommandIdChecked(USE_LAUNCH_TYPE_REGULAR) ? |
189 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : | |
190 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); | |
191 } else { | |
192 NOTREACHED(); | |
193 return base::string16(); | |
194 } | |
195 } else { | |
tapted
2015/01/05 23:10:32
"Don't use else after return" : http://www.chromiu
mitchellj
2015/01/06 01:41:14
Done.
| |
196 if (command_id == TOGGLE_PIN) { | |
197 return controller_->IsAppPinned(app_id_) ? | |
198 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : | |
199 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN); | |
200 } else if (command_id == LAUNCH_NEW) { | |
189 #if defined(OS_MACOSX) | 201 #if defined(OS_MACOSX) |
190 // Even fullscreen windows launch in a browser tab on Mac. | 202 // Even fullscreen windows launch in a browser tab on Mac. |
191 const bool launches_in_tab = true; | 203 const bool launches_in_tab = true; |
192 #else | 204 #else |
193 const bool launches_in_tab = IsCommandIdChecked(USE_LAUNCH_TYPE_PINNED) || | 205 const bool launches_in_tab = |
194 IsCommandIdChecked(USE_LAUNCH_TYPE_REGULAR); | 206 IsCommandIdChecked(USE_LAUNCH_TYPE_PINNED) || |
207 IsCommandIdChecked(USE_LAUNCH_TYPE_REGULAR); | |
195 #endif | 208 #endif |
196 return launches_in_tab ? | 209 return launches_in_tab ? |
197 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : | 210 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : |
198 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); | 211 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); |
199 } else { | 212 } else { |
200 NOTREACHED(); | 213 NOTREACHED(); |
201 return base::string16(); | 214 return base::string16(); |
215 } | |
202 } | 216 } |
203 } | 217 } |
204 | 218 |
205 bool AppContextMenu::IsCommandIdChecked(int command_id) const { | 219 bool AppContextMenu::IsCommandIdChecked(int command_id) const { |
206 if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && | 220 if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && |
207 command_id < USE_LAUNCH_TYPE_COMMAND_END) { | 221 command_id < USE_LAUNCH_TYPE_COMMAND_END) { |
208 return static_cast<int>(controller_->GetExtensionLaunchType( | 222 return static_cast<int>(controller_->GetExtensionLaunchType( |
209 profile_, app_id_)) + USE_LAUNCH_TYPE_COMMAND_START == command_id; | 223 profile_, app_id_)) + USE_LAUNCH_TYPE_COMMAND_START == command_id; |
210 } else if (extensions::ContextMenuMatcher::IsExtensionsCustomCommandId( | 224 } else if (extensions::ContextMenuMatcher::IsExtensionsCustomCommandId( |
211 command_id)) { | 225 command_id)) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 extension_menu_items_->ExecuteCommand(command_id, NULL, | 292 extension_menu_items_->ExecuteCommand(command_id, NULL, |
279 content::ContextMenuParams()); | 293 content::ContextMenuParams()); |
280 } else if (command_id == MENU_NEW_WINDOW) { | 294 } else if (command_id == MENU_NEW_WINDOW) { |
281 controller_->CreateNewWindow(profile_, false); | 295 controller_->CreateNewWindow(profile_, false); |
282 } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { | 296 } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { |
283 controller_->CreateNewWindow(profile_, true); | 297 controller_->CreateNewWindow(profile_, true); |
284 } | 298 } |
285 } | 299 } |
286 | 300 |
287 } // namespace app_list | 301 } // namespace app_list |
OLD | NEW |