#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/values.h"
-#include "chrome/common/chrome_version_info.h" // TODO(finnur): Remove.
-#include "chrome/common/extensions/extension.h"
-#include "chrome/common/extensions/feature_switch.h"
+#include "chrome/grit/generated_resources.h"
#include "extensions/common/error_utils.h"
+#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
-#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace extensions {
bool IsNamedCommand(const std::string& command_name) {
return command_name != values::kPageActionCommandEvent &&
- command_name != values::kBrowserActionCommandEvent &&
- command_name != values::kScriptBadgeCommandEvent;
+ command_name != values::kBrowserActionCommandEvent;
}
bool DoesRequireModifier(const std::string& accelerator) {
const std::string& platform_key,
int index,
bool should_parse_media_keys,
- string16* error) {
+ base::string16* error) {
error->clear();
if (platform_key != values::kKeybindingPlatformWin &&
platform_key != values::kKeybindingPlatformMac &&
key = ui::VKEY_UNKNOWN;
break;
}
+ } else if (tokens[i] == values::kKeySearch) {
+ // Search is a special modifier only on ChromeOS and maps to 'Command'.
+ if (platform_key == values::kKeybindingPlatformChromeOs) {
+ modifiers |= ui::EF_COMMAND_DOWN;
+ } else {
+ // No other platform supports Search.
+ key = ui::VKEY_UNKNOWN;
+ break;
+ }
} else if (tokens[i] == values::kKeyAlt) {
modifiers |= ui::EF_ALT_DOWN;
} else if (tokens[i] == values::kKeyShift) {
Command::Command() : global_(false) {}
Command::Command(const std::string& command_name,
- const string16& description,
+ const base::string16& description,
const std::string& accelerator,
bool global)
: command_name_(command_name),
description_(description),
global_(global) {
- string16 error;
+ base::string16 error;
accelerator_ = ParseImpl(accelerator, CommandPlatform(), 0,
IsNamedCommand(command_name), &error);
}
// static
ui::Accelerator Command::StringToAccelerator(const std::string& accelerator,
const std::string& command_name) {
- string16 error;
+ base::string16 error;
ui::Accelerator parsed =
ParseImpl(accelerator, Command::CommandPlatform(), 0,
IsNamedCommand(command_name), &error);
shortcut += values::kKeySeparator;
if (accelerator.IsCmdDown()) {
+#if defined(OS_CHROMEOS)
+ // Chrome OS treats the Search key like the Command key.
+ shortcut += values::kKeySearch;
+#else
shortcut += values::kKeyCommand;
+#endif
shortcut += values::kKeySeparator;
}
return shortcut;
}
+// static
+bool Command::IsMediaKey(const ui::Accelerator& accelerator) {
+ if (accelerator.modifiers() != 0)
+ return false;
+
+ return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK ||
+ accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK ||
+ accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE ||
+ accelerator.key_code() == ui::VKEY_MEDIA_STOP);
+}
+
bool Command::Parse(const base::DictionaryValue* command,
const std::string& command_name,
int index,
- string16* error) {
+ base::string16* error) {
DCHECK(!command_name.empty());
- string16 description;
+ base::string16 description;
if (IsNamedCommand(command_name)) {
if (!command->GetString(keys::kDescription, &description) ||
description.empty()) {
bool active) const {
base::DictionaryValue* extension_data = new base::DictionaryValue();
- string16 command_description;
+ base::string16 command_description;
bool extension_action = false;
if (command_name() == values::kBrowserActionCommandEvent ||
- command_name() == values::kPageActionCommandEvent ||
- command_name() == values::kScriptBadgeCommandEvent) {
+ command_name() == values::kPageActionCommandEvent) {
command_description =
l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE);
extension_action = true;
extension_data->SetString("extension_id", extension->id());
extension_data->SetBoolean("global", global());
extension_data->SetBoolean("extension_action", extension_action);
-
- if (FeatureSwitch::global_commands()->IsEnabled()) {
- // TODO(finnur): This is to make sure we don't show the config UI beyond
- // dev and will be removed when we launch.
- static bool stable_or_beta =
- chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA;
- extension_data->SetBoolean("scope_ui_visible", !stable_or_beta);
- }
-
return extension_data;
}