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