summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-08 20:42:57 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-08 20:42:57 +0000
commit5ef835a2c91e112ecf28b589cc5b80ae53e1927f (patch)
treec367bf7148e1e5421beab1478ba1796f4fd9274c /extensions
parentb5a507b2ce386972331f17678b46de4d95d49c02 (diff)
downloadchromium_src-5ef835a2c91e112ecf28b589cc5b80ae53e1927f.zip
chromium_src-5ef835a2c91e112ecf28b589cc5b80ae53e1927f.tar.gz
chromium_src-5ef835a2c91e112ecf28b589cc5b80ae53e1927f.tar.bz2
Move FeatureSwitch to top-level extensions/
Move FeatureSwitch to extensions/common/ Move the switches used in FeatureSwitch to extensions/common/switches.h (when necessary). Update some uses of the switches to use feature switch instead of the commandline BUG=159265 TBR=rdsmith@chromium.org (c/b/download) TBR=sky@chromium.org (c/b/ui/, c/test/ui/) Review URL: https://codereview.chromium.org/47923018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233977 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/common/feature_switch.cc146
-rw-r--r--extensions/common/feature_switch.h79
-rw-r--r--extensions/common/switches.cc23
-rw-r--r--extensions/common/switches.h5
-rw-r--r--extensions/extensions.gyp2
5 files changed, 253 insertions, 2 deletions
diff --git a/extensions/common/feature_switch.cc b/extensions/common/feature_switch.cc
new file mode 100644
index 0000000..0024461
--- /dev/null
+++ b/extensions/common/feature_switch.cc
@@ -0,0 +1,146 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/feature_switch.h"
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "base/metrics/field_trial.h"
+#include "base/strings/string_util.h"
+#include "extensions/common/switches.h"
+
+namespace extensions {
+
+namespace {
+
+class CommonSwitches {
+ public:
+ CommonSwitches()
+ : easy_off_store_install(
+ switches::kEasyOffStoreExtensionInstall,
+ FeatureSwitch::DEFAULT_DISABLED),
+ global_commands(
+ switches::kGlobalCommands,
+ FeatureSwitch::DEFAULT_DISABLED),
+ script_badges(
+ switches::kScriptBadges,
+ FeatureSwitch::DEFAULT_DISABLED),
+ script_bubble(
+ switches::kScriptBubble,
+ FeatureSwitch::DEFAULT_DISABLED),
+ prompt_for_external_extensions(
+ switches::kPromptForExternalExtensions,
+#if defined(OS_WIN)
+ FeatureSwitch::DEFAULT_ENABLED),
+#else
+ FeatureSwitch::DEFAULT_DISABLED),
+#endif
+ error_console(
+ switches::kErrorConsole,
+ FeatureSwitch::DEFAULT_DISABLED) {}
+
+ FeatureSwitch easy_off_store_install;
+ FeatureSwitch global_commands;
+ FeatureSwitch script_badges;
+ FeatureSwitch script_bubble;
+ FeatureSwitch prompt_for_external_extensions;
+ FeatureSwitch error_console;
+};
+
+base::LazyInstance<CommonSwitches> g_common_switches =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+FeatureSwitch* FeatureSwitch::easy_off_store_install() {
+ return &g_common_switches.Get().easy_off_store_install;
+}
+FeatureSwitch* FeatureSwitch::global_commands() {
+ return &g_common_switches.Get().global_commands;
+}
+FeatureSwitch* FeatureSwitch::script_badges() {
+ return &g_common_switches.Get().script_badges;
+}
+FeatureSwitch* FeatureSwitch::script_bubble() {
+ return &g_common_switches.Get().script_bubble;
+}
+FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() {
+ return &g_common_switches.Get().prompt_for_external_extensions;
+}
+FeatureSwitch* FeatureSwitch::error_console() {
+ return &g_common_switches.Get().error_console;
+}
+
+FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature,
+ bool override_value)
+ : feature_(feature),
+ previous_value_(feature->GetOverrideValue()) {
+ feature_->SetOverrideValue(
+ override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED);
+}
+
+FeatureSwitch::ScopedOverride::~ScopedOverride() {
+ feature_->SetOverrideValue(previous_value_);
+}
+
+FeatureSwitch::FeatureSwitch(const char* switch_name,
+ DefaultValue default_value) {
+ Init(CommandLine::ForCurrentProcess(), switch_name, default_value);
+}
+
+FeatureSwitch::FeatureSwitch(const CommandLine* command_line,
+ const char* switch_name,
+ DefaultValue default_value) {
+ Init(command_line, switch_name, default_value);
+}
+
+void FeatureSwitch::Init(const CommandLine* command_line,
+ const char* switch_name,
+ DefaultValue default_value) {
+ command_line_ = command_line;
+ switch_name_ = switch_name;
+ default_value_ = default_value == DEFAULT_ENABLED;
+ override_value_ = OVERRIDE_NONE;
+}
+
+bool FeatureSwitch::IsEnabled() const {
+ if (override_value_ != OVERRIDE_NONE)
+ return override_value_ == OVERRIDE_ENABLED;
+
+ std::string temp = command_line_->GetSwitchValueASCII(switch_name_);
+ std::string switch_value;
+ TrimWhitespaceASCII(temp, TRIM_ALL, &switch_value);
+
+ if (switch_value == "1")
+ return true;
+
+ if (switch_value == "0")
+ return false;
+
+ if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag()))
+ return true;
+
+ if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag()))
+ return false;
+
+ return default_value_;
+}
+
+std::string FeatureSwitch::GetLegacyEnableFlag() const {
+ return std::string("enable-") + switch_name_;
+}
+
+std::string FeatureSwitch::GetLegacyDisableFlag() const {
+ return std::string("disable-") + switch_name_;
+}
+
+void FeatureSwitch::SetOverrideValue(OverrideValue override_value) {
+ override_value_ = override_value;
+}
+
+FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const {
+ return override_value_;
+}
+
+} // namespace extensions
diff --git a/extensions/common/feature_switch.h b/extensions/common/feature_switch.h
new file mode 100644
index 0000000..ece1b01
--- /dev/null
+++ b/extensions/common/feature_switch.h
@@ -0,0 +1,79 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_COMMON_FEATURE_SWITCH_H_
+#define EXTENSIONS_COMMON_FEATURE_SWITCH_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+
+class CommandLine;
+
+namespace extensions {
+
+// A switch that can turn a feature on or off. Typically controlled via
+// command-line switches but can be overridden, e.g., for testing.
+class FeatureSwitch {
+ public:
+ static FeatureSwitch* easy_off_store_install();
+ static FeatureSwitch* global_commands();
+ static FeatureSwitch* script_badges();
+ static FeatureSwitch* script_bubble();
+ static FeatureSwitch* prompt_for_external_extensions();
+ static FeatureSwitch* error_console();
+
+ enum DefaultValue {
+ DEFAULT_ENABLED,
+ DEFAULT_DISABLED
+ };
+
+ enum OverrideValue {
+ OVERRIDE_NONE,
+ OVERRIDE_ENABLED,
+ OVERRIDE_DISABLED
+ };
+
+ // A temporary override for the switch value.
+ class ScopedOverride {
+ public:
+ ScopedOverride(FeatureSwitch* feature, bool override_value);
+ ~ScopedOverride();
+ private:
+ FeatureSwitch* feature_;
+ FeatureSwitch::OverrideValue previous_value_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedOverride);
+ };
+
+ FeatureSwitch(const char* switch_name,
+ DefaultValue default_value);
+ FeatureSwitch(const CommandLine* command_line,
+ const char* switch_name,
+ DefaultValue default_value);
+
+ // Consider using ScopedOverride instead.
+ void SetOverrideValue(OverrideValue value);
+ OverrideValue GetOverrideValue() const;
+
+ bool IsEnabled() const;
+
+ std::string GetLegacyEnableFlag() const;
+ std::string GetLegacyDisableFlag() const;
+
+ private:
+ void Init(const CommandLine* command_line,
+ const char* switch_name,
+ DefaultValue default_value);
+
+ const CommandLine* command_line_;
+ const char* switch_name_;
+ bool default_value_;
+ OverrideValue override_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(FeatureSwitch);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_COMMON_FEATURE_SWITCH_H_
diff --git a/extensions/common/switches.cc b/extensions/common/switches.cc
index 674bb03..451cbc0 100644
--- a/extensions/common/switches.cc
+++ b/extensions/common/switches.cc
@@ -16,7 +16,12 @@ const char kAllowLegacyExtensionManifests[] =
// Allows injecting extensions and user scripts on the extensions gallery
// site. Normally prevented for security reasons, but can be useful for
// automation testing of the gallery.
-const char kAllowScriptingGallery[] = "allow-scripting-gallery";
+const char kAllowScriptingGallery[] = "allow-scripting-gallery";
+
+// Enables extensions to be easily installed from sites other than the web
+// store. Without this flag, they can still be installed, but must be manually
+// dragged onto chrome://extensions/.
+const char kEasyOffStoreExtensionInstall[] = "easy-off-store-extension-install";
// Enables extension APIs that are in development.
const char kEnableExperimentalExtensionApis[] =
@@ -37,7 +42,21 @@ const char kEventPageSuspendingTime[] = "event-page-unloading-time";
// Enables extensions running scripts on chrome:// URLs.
// Extensions still need to explicitly request access to chrome:// URLs in the
// manifest.
-const char kExtensionsOnChromeURLs[] = "extensions-on-chrome-urls";
+const char kExtensionsOnChromeURLs[] = "extensions-on-chrome-urls";
+
+// Enables setting global commands through the Extensions Commands API.
+const char kGlobalCommands[] = "global-commands";
+
+// Should we prompt the user before allowing external extensions to install?
+// Default is yes.
+const char kPromptForExternalExtensions[] = "prompt-for-external-extensions";
+
+// Enables or disables extension scripts badges in the location bar.
+const char kScriptBadges[] = "script-badges";
+
+// Enable or diable the "script bubble" icon in the URL bar that tells you how
+// many extensions are running scripts on a page.
+const char kScriptBubble[] = "script-bubble";
// Makes component extensions appear in chrome://settings/extensions.
const char kShowComponentExtensionOptions[] =
diff --git a/extensions/common/switches.h b/extensions/common/switches.h
index e6ff310..7111d87 100644
--- a/extensions/common/switches.h
+++ b/extensions/common/switches.h
@@ -13,11 +13,16 @@ namespace switches {
extern const char kAllowLegacyExtensionManifests[];
extern const char kAllowScriptingGallery[];
+extern const char kEasyOffStoreExtensionInstall[];
extern const char kEnableExperimentalExtensionApis[];
extern const char kErrorConsole[];
extern const char kEventPageIdleTime[];
extern const char kEventPageSuspendingTime[];
extern const char kExtensionsOnChromeURLs[];
+extern const char kGlobalCommands[];
+extern const char kPromptForExternalExtensions[];
+extern const char kScriptBadges[];
+extern const char kScriptBubble[];
extern const char kShowComponentExtensionOptions[];
} // namespace switches
diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp
index 6cef0ee..be923b6 100644
--- a/extensions/extensions.gyp
+++ b/extensions/extensions.gyp
@@ -47,6 +47,8 @@
'common/extension_urls.h',
'common/extensions_client.cc',
'common/extensions_client.h',
+ 'common/feature_switch.cc',
+ 'common/feature_switch.h',
'common/features/feature.cc',
'common/features/feature.h',
'common/features/feature_provider.cc',