| 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/app_list/extension_app_item.h" | 5 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 8 #include "chrome/browser/extensions/extension_prefs.h" | 10 #include "chrome/browser/extensions/extension_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 12 #include "chrome/browser/extensions/management_policy.h" | 14 #include "chrome/browser/extensions/management_policy.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/app_list/app_list_controller.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller.h" |
| 15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_icon_set.h" | 23 #include "chrome/common/extensions/extension_icon_set.h" |
| 24 #include "content/public/common/context_menu_params.h" |
| 22 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 26 | 29 |
| 27 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h" | 31 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h" |
| 29 #endif | 32 #endif |
| 30 | 33 |
| 31 using extensions::Extension; | 34 using extensions::Extension; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 profile->GetExtensionService()->extension_prefs()->SetLaunchType( | 116 profile->GetExtensionService()->extension_prefs()->SetLaunchType( |
| 114 extension_id, launch_type); | 117 extension_id, launch_type); |
| 115 } | 118 } |
| 116 | 119 |
| 117 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) { | 120 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) { |
| 118 ExtensionService* service = profile->GetExtensionService(); | 121 ExtensionService* service = profile->GetExtensionService(); |
| 119 return service->IsExtensionEnabled(extension_id) && | 122 return service->IsExtensionEnabled(extension_id) && |
| 120 !service->GetTerminatedExtension(extension_id); | 123 !service->GetTerminatedExtension(extension_id); |
| 121 } | 124 } |
| 122 | 125 |
| 126 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { |
| 127 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); |
| 128 } |
| 129 |
| 123 } // namespace | 130 } // namespace |
| 124 | 131 |
| 125 ExtensionAppItem::ExtensionAppItem(Profile* profile, | 132 ExtensionAppItem::ExtensionAppItem(Profile* profile, |
| 126 const Extension* extension, | 133 const Extension* extension, |
| 127 AppListController* controller) | 134 AppListController* controller) |
| 128 : ChromeAppListItem(TYPE_APP), | 135 : ChromeAppListItem(TYPE_APP), |
| 129 profile_(profile), | 136 profile_(profile), |
| 130 extension_id_(extension->id()), | 137 extension_id_(extension->id()), |
| 131 controller_(controller) { | 138 controller_(controller) { |
| 132 SetTitle(extension->name()); | 139 SetTitle(extension->name()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } else { | 214 } else { |
| 208 NOTREACHED(); | 215 NOTREACHED(); |
| 209 return string16(); | 216 return string16(); |
| 210 } | 217 } |
| 211 } | 218 } |
| 212 | 219 |
| 213 bool ExtensionAppItem::IsCommandIdChecked(int command_id) const { | 220 bool ExtensionAppItem::IsCommandIdChecked(int command_id) const { |
| 214 if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) { | 221 if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) { |
| 215 return static_cast<int>(GetExtensionLaunchType(profile_, extension_id_)) + | 222 return static_cast<int>(GetExtensionLaunchType(profile_, extension_id_)) + |
| 216 LAUNCH_TYPE_START == command_id; | 223 LAUNCH_TYPE_START == command_id; |
| 224 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 225 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 226 return extension_menu_items_->IsCommandIdChecked(command_id); |
| 217 } | 227 } |
| 218 return false; | 228 return false; |
| 219 } | 229 } |
| 220 | 230 |
| 221 bool ExtensionAppItem::IsCommandIdEnabled(int command_id) const { | 231 bool ExtensionAppItem::IsCommandIdEnabled(int command_id) const { |
| 222 if (command_id == TOGGLE_PIN) { | 232 if (command_id == TOGGLE_PIN) { |
| 223 return controller_->CanPin(); | 233 return controller_->CanPin(); |
| 224 } else if (command_id == OPTIONS) { | 234 } else if (command_id == OPTIONS) { |
| 225 const Extension* extension = GetExtension(); | 235 const Extension* extension = GetExtension(); |
| 226 return IsExtensionEnabled(profile_, extension_id_) && extension && | 236 return IsExtensionEnabled(profile_, extension_id_) && extension && |
| 227 !extension->options_url().is_empty(); | 237 !extension->options_url().is_empty(); |
| 228 } else if (command_id == UNINSTALL) { | 238 } else if (command_id == UNINSTALL) { |
| 229 const Extension* extension = GetExtension(); | 239 const Extension* extension = GetExtension(); |
| 230 const extensions::ManagementPolicy* policy = | 240 const extensions::ManagementPolicy* policy = |
| 231 extensions::ExtensionSystem::Get(profile_)->management_policy(); | 241 extensions::ExtensionSystem::Get(profile_)->management_policy(); |
| 232 return extension && | 242 return extension && |
| 233 policy->UserMayModifySettings(extension, NULL); | 243 policy->UserMayModifySettings(extension, NULL); |
| 234 } else if (command_id == DETAILS) { | 244 } else if (command_id == DETAILS) { |
| 235 const Extension* extension = GetExtension(); | 245 const Extension* extension = GetExtension(); |
| 236 return extension && extension->from_webstore(); | 246 return extension && extension->from_webstore(); |
| 247 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 248 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 249 return extension_menu_items_->IsCommandIdEnabled(command_id); |
| 237 } | 250 } |
| 238 return true; | 251 return true; |
| 239 } | 252 } |
| 240 | 253 |
| 241 bool ExtensionAppItem::GetAcceleratorForCommandId( | 254 bool ExtensionAppItem::GetAcceleratorForCommandId( |
| 242 int command_id, | 255 int command_id, |
| 243 ui::Accelerator* acclelrator) { | 256 ui::Accelerator* acclelrator) { |
| 244 return false; | 257 return false; |
| 245 } | 258 } |
| 246 | 259 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 257 SetExtensionLaunchType(profile_, | 270 SetExtensionLaunchType(profile_, |
| 258 extension_id_, | 271 extension_id_, |
| 259 static_cast<extensions::ExtensionPrefs::LaunchType>( | 272 static_cast<extensions::ExtensionPrefs::LaunchType>( |
| 260 command_id - LAUNCH_TYPE_START)); | 273 command_id - LAUNCH_TYPE_START)); |
| 261 } else if (command_id == OPTIONS) { | 274 } else if (command_id == OPTIONS) { |
| 262 ShowExtensionOptions(); | 275 ShowExtensionOptions(); |
| 263 } else if (command_id == UNINSTALL) { | 276 } else if (command_id == UNINSTALL) { |
| 264 StartExtensionUninstall(); | 277 StartExtensionUninstall(); |
| 265 } else if (command_id == DETAILS) { | 278 } else if (command_id == DETAILS) { |
| 266 ShowExtensionDetails(); | 279 ShowExtensionDetails(); |
| 280 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 281 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 282 extension_menu_items_->ExecuteCommand(command_id, |
| 283 content::ContextMenuParams()); |
| 267 } | 284 } |
| 268 } | 285 } |
| 269 | 286 |
| 270 void ExtensionAppItem::Activate(int event_flags) { | 287 void ExtensionAppItem::Activate(int event_flags) { |
| 271 const Extension* extension = GetExtension(); | 288 const Extension* extension = GetExtension(); |
| 272 if (!extension) | 289 if (!extension) |
| 273 return; | 290 return; |
| 274 | 291 |
| 275 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 276 // Talk extension isn't an app, send special rtcPrivate API message to | 293 // Talk extension isn't an app, send special rtcPrivate API message to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 287 controller_->ActivateApp(profile_, extension->id(), event_flags); | 304 controller_->ActivateApp(profile_, extension->id(), event_flags); |
| 288 } | 305 } |
| 289 | 306 |
| 290 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() { | 307 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() { |
| 291 // No context menu for Chrome app. | 308 // No context menu for Chrome app. |
| 292 if (extension_id_ == extension_misc::kChromeAppId) | 309 if (extension_id_ == extension_misc::kChromeAppId) |
| 293 return NULL; | 310 return NULL; |
| 294 | 311 |
| 295 if (!context_menu_model_.get()) { | 312 if (!context_menu_model_.get()) { |
| 296 context_menu_model_.reset(new ui::SimpleMenuModel(this)); | 313 context_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 314 extension_menu_items_.reset(new extensions::ContextMenuMatcher( |
| 315 profile_, this, context_menu_model_.get(), |
| 316 base::Bind(MenuItemHasLauncherContext))); |
| 317 |
| 297 context_menu_model_->AddItem(LAUNCH, UTF8ToUTF16(title())); | 318 context_menu_model_->AddItem(LAUNCH, UTF8ToUTF16(title())); |
| 298 // Talk extension isn't an app and so doesn't support most launch options. | 319 // Talk extension isn't an app and so doesn't support most launch options. |
| 299 if (!IsTalkExtension()) { | 320 if (!IsTalkExtension()) { |
| 321 int index = 0; |
| 322 extension_menu_items_->AppendExtensionItems(extension_id_, string16(), |
| 323 &index); |
| 300 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 324 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 301 context_menu_model_->AddItemWithStringId( | 325 context_menu_model_->AddItemWithStringId( |
| 302 TOGGLE_PIN, | 326 TOGGLE_PIN, |
| 303 controller_->IsAppPinned(extension_id_) ? | 327 controller_->IsAppPinned(extension_id_) ? |
| 304 IDS_APP_LIST_CONTEXT_MENU_UNPIN : | 328 IDS_APP_LIST_CONTEXT_MENU_UNPIN : |
| 305 IDS_APP_LIST_CONTEXT_MENU_PIN); | 329 IDS_APP_LIST_CONTEXT_MENU_PIN); |
| 306 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 330 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 307 context_menu_model_->AddCheckItemWithStringId( | 331 context_menu_model_->AddCheckItemWithStringId( |
| 308 LAUNCH_TYPE_REGULAR_TAB, | 332 LAUNCH_TYPE_REGULAR_TAB, |
| 309 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); | 333 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 321 } | 345 } |
| 322 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 346 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 323 context_menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); | 347 context_menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); |
| 324 context_menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); | 348 context_menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); |
| 325 context_menu_model_->AddItemWithStringId(UNINSTALL, | 349 context_menu_model_->AddItemWithStringId(UNINSTALL, |
| 326 IDS_EXTENSIONS_UNINSTALL); | 350 IDS_EXTENSIONS_UNINSTALL); |
| 327 } | 351 } |
| 328 | 352 |
| 329 return context_menu_model_.get(); | 353 return context_menu_model_.get(); |
| 330 } | 354 } |
| OLD | NEW |