diff options
author | Torne (Richard Coles) <torne@google.com> | 2013-08-23 16:39:15 +0100 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2013-08-23 16:39:15 +0100 |
commit | 3551c9c881056c480085172ff9840cab31610854 (patch) | |
tree | 23660320f5f4c279966609cf9da7491b96d10ca8 /extensions | |
parent | 4e9d9adbbb6cf287125ca44a0823791a570472f5 (diff) | |
download | chromium_org-3551c9c881056c480085172ff9840cab31610854.tar.gz |
Merge from Chromium at DEPS revision r219274
This commit was generated by merge_to_master.py.
Change-Id: Ibb7f41396cadf4071e89153e1913c986d126f65d
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/common/features/feature.cc | 43 | ||||
-rw-r--r-- | extensions/common/features/feature.h | 155 | ||||
-rw-r--r-- | extensions/common/install_warning.cc | 28 | ||||
-rw-r--r-- | extensions/common/install_warning.h | 38 | ||||
-rw-r--r-- | extensions/common/manifest.cc | 257 | ||||
-rw-r--r-- | extensions/common/manifest.h | 177 | ||||
-rw-r--r-- | extensions/common/manifest_constants.cc | 151 | ||||
-rw-r--r-- | extensions/common/manifest_constants.h | 157 | ||||
-rw-r--r-- | extensions/common/matcher/regex_set_matcher.cc | 1 | ||||
-rw-r--r-- | extensions/common/matcher/url_matcher.cc | 16 |
10 files changed, 988 insertions, 35 deletions
diff --git a/extensions/common/features/feature.cc b/extensions/common/features/feature.cc new file mode 100644 index 0000000000..705f3e5ab8 --- /dev/null +++ b/extensions/common/features/feature.cc @@ -0,0 +1,43 @@ +// 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/features/feature.h" + +#include <map> + +#include "base/command_line.h" +#include "base/lazy_instance.h" +#include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" + +namespace extensions { + +// static +Feature::Platform Feature::GetCurrentPlatform() { +#if defined(OS_CHROMEOS) + return CHROMEOS_PLATFORM; +#else + return UNSPECIFIED_PLATFORM; +#endif +} + +// static +Feature::Location Feature::ConvertLocation(Manifest::Location location) { + if (location == Manifest::COMPONENT) + return COMPONENT_LOCATION; + else + return UNSPECIFIED_LOCATION; +} + +// static +Feature::Availability Feature::CreateAvailability(AvailabilityResult result, + const std::string& message) { + return Availability(result, message); +} + +Feature::Feature() : no_parent_(false) {} + +Feature::~Feature() {} + +} // namespace extensions diff --git a/extensions/common/features/feature.h b/extensions/common/features/feature.h new file mode 100644 index 0000000000..036fc725ed --- /dev/null +++ b/extensions/common/features/feature.h @@ -0,0 +1,155 @@ +// 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_FEATURES_FEATURE_H_ +#define EXTENSIONS_COMMON_FEATURES_FEATURE_H_ + +#include <set> +#include <string> + +#include "base/values.h" +#include "extensions/common/manifest.h" + +class GURL; + +namespace extensions { + +class Extension; + +// Represents a single feature accessible to an extension developer, such as a +// top-level manifest key, a permission, or a programmatic API. A feature can +// express requirements for where it can be accessed, and supports testing +// support for those requirements. +class Feature { + public: + // The JavaScript contexts the feature is supported in. + enum Context { + UNSPECIFIED_CONTEXT, + + // A context in a privileged extension process. + BLESSED_EXTENSION_CONTEXT, + + // A context in an unprivileged extension process. + UNBLESSED_EXTENSION_CONTEXT, + + // A context from a content script. + CONTENT_SCRIPT_CONTEXT, + + // A normal web page. This should have an associated URL matching pattern. + WEB_PAGE_CONTEXT, + }; + + // The location required of extensions the feature is supported in. + enum Location { + UNSPECIFIED_LOCATION, + COMPONENT_LOCATION + }; + + // The platforms the feature is supported in. + enum Platform { + UNSPECIFIED_PLATFORM, + CHROMEOS_PLATFORM + }; + + // Whether a feature is available in a given situation or not, and if not, + // why not. + enum AvailabilityResult { + IS_AVAILABLE, + NOT_FOUND_IN_WHITELIST, + INVALID_URL, + INVALID_TYPE, + INVALID_CONTEXT, + INVALID_LOCATION, + INVALID_PLATFORM, + INVALID_MIN_MANIFEST_VERSION, + INVALID_MAX_MANIFEST_VERSION, + NOT_PRESENT, + UNSUPPORTED_CHANNEL, + }; + + // Container for AvailabiltyResult that also exposes a user-visible error + // message in cases where the feature is not available. + class Availability { + public: + AvailabilityResult result() const { return result_; } + bool is_available() const { return result_ == IS_AVAILABLE; } + const std::string& message() const { return message_; } + + private: + friend class SimpleFeature; + friend class Feature; + + // Instances should be created via Feature::CreateAvailability. + Availability(AvailabilityResult result, const std::string& message) + : result_(result), message_(message) { } + + const AvailabilityResult result_; + const std::string message_; + }; + + Feature(); + virtual ~Feature(); + + // Used by ChromeV8Context until the feature system is fully functional. + static Availability CreateAvailability(AvailabilityResult result, + const std::string& message); + + const std::string& name() const { return name_; } + void set_name(const std::string& name) { name_ = name; } + const std::set<std::string>& dependencies() { return dependencies_; } + bool no_parent() const { return no_parent_; } + + // Gets the platform the code is currently running on. + static Platform GetCurrentPlatform(); + + // Gets the Feature::Location value for the specified Manifest::Location. + static Location ConvertLocation(Manifest::Location extension_location); + + virtual std::set<Context>* GetContexts() = 0; + + // Tests whether this is an internal API or not. + virtual bool IsInternal() const = 0; + + // Returns true if the feature is available to be parsed into a new extension + // manifest. + Availability IsAvailableToManifest(const std::string& extension_id, + Manifest::Type type, + Location location, + int manifest_version) const { + return IsAvailableToManifest(extension_id, type, location, manifest_version, + GetCurrentPlatform()); + } + virtual Availability IsAvailableToManifest(const std::string& extension_id, + Manifest::Type type, + Location location, + int manifest_version, + Platform platform) const = 0; + + // Returns true if the feature is available to be used in the specified + // extension and context. + Availability IsAvailableToContext(const Extension* extension, + Context context, + const GURL& url) const { + return IsAvailableToContext(extension, context, url, GetCurrentPlatform()); + } + virtual Availability IsAvailableToContext(const Extension* extension, + Context context, + const GURL& url, + Platform platform) const = 0; + + virtual std::string GetAvailabilityMessage(AvailabilityResult result, + Manifest::Type type, + const GURL& url) const = 0; + + virtual bool IsIdInWhitelist(const std::string& extension_id) const = 0; + + protected: + std::string name_; + std::set<std::string> dependencies_; + bool no_parent_; +}; + +} // namespace extensions + +#endif // EXTENSIONS_COMMON_FEATURES_FEATURE_H_ diff --git a/extensions/common/install_warning.cc b/extensions/common/install_warning.cc index c632a71ae0..3db5a5be07 100644 --- a/extensions/common/install_warning.cc +++ b/extensions/common/install_warning.cc @@ -6,19 +6,27 @@ namespace extensions { +InstallWarning::InstallWarning(const std::string& message) : message(message) { +} + +InstallWarning::InstallWarning(const std::string& message, + const std::string& key) + : message(message), key(key) { +} + +InstallWarning::InstallWarning(const std::string& message, + const std::string& key, + const std::string& specific) + : message(message), key(key), specific(specific) { +} + +InstallWarning::~InstallWarning() { +} + void PrintTo(const InstallWarning& warning, ::std::ostream* os) { - *os << "InstallWarning("; - switch (warning.format) { - case InstallWarning::FORMAT_TEXT: - *os << "FORMAT_TEXT, \""; - break; - case InstallWarning::FORMAT_HTML: - *os << "FORMAT_HTML, \""; - break; - } // This is just for test error messages, so no need to escape '"' // characters inside the message. - *os << warning.message << "\")"; + *os << "InstallWarning(\"" << warning.message << "\")"; } } // namespace extensions diff --git a/extensions/common/install_warning.h b/extensions/common/install_warning.h index fb3fccb29b..88dd0a1aa2 100644 --- a/extensions/common/install_warning.h +++ b/extensions/common/install_warning.h @@ -10,24 +10,34 @@ namespace extensions { +// A struct to describe a non-fatal issue discovered in the installation of an +// extension. struct InstallWarning { - enum Format { - // IMPORTANT: Do not build HTML strings from user or developer-supplied - // input. - FORMAT_TEXT, - FORMAT_HTML, - }; - static InstallWarning Text(const std::string& message) { - return InstallWarning(FORMAT_TEXT, message); - } - InstallWarning(Format format, const std::string& message) - : format(format), message(message) { - } + InstallWarning(const std::string& message); + InstallWarning(const std::string& message, + const std::string& key); + InstallWarning(const std::string& message, + const std::string& key, + const std::string& specific); + ~InstallWarning(); + bool operator==(const InstallWarning& other) const { - return format == other.format && message == other.message; + // We don't have to look at |key| or |specific| here, because they are each + // used in the the message itself. + // For example, a full message would be "Permission 'foo' is unknown or URL + // pattern is malformed." |key| here is "permissions", and |specific| is + // "foo", but these are redundant with the message. + return message == other.message; } - Format format; + + // The warning's message (human-friendly). std::string message; + // Optional - for specifying the incorrect key in the manifest (e.g., + // "permissions"). + std::string key; + // Optional - for specifying the incorrect portion of a key in the manifest + // (e.g., an unrecognized permission "foo" in "permissions"). + std::string specific; }; // Let gtest print InstallWarnings. diff --git a/extensions/common/manifest.cc b/extensions/common/manifest.cc new file mode 100644 index 0000000000..eaaaf76061 --- /dev/null +++ b/extensions/common/manifest.cc @@ -0,0 +1,257 @@ +// 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/manifest.h" + +#include "base/basictypes.h" +#include "base/lazy_instance.h" +#include "base/logging.h" +#include "base/strings/string_split.h" +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" +#include "extensions/common/error_utils.h" +#include "extensions/common/features/feature.h" +#include "extensions/common/features/feature_provider.h" +#include "extensions/common/install_warning.h" +#include "extensions/common/manifest_constants.h" + +namespace extensions { + +namespace keys = manifest_keys; + +namespace { + +// Rank extension locations in a way that allows +// Manifest::GetHigherPriorityLocation() to compare locations. +// An extension installed from two locations will have the location +// with the higher rank, as returned by this function. The actual +// integer values may change, and should never be persisted. +int GetLocationRank(Manifest::Location location) { + const int kInvalidRank = -1; + int rank = kInvalidRank; // Will CHECK that rank is not kInvalidRank. + + switch (location) { + // Component extensions can not be overriden by any other type. + case Manifest::COMPONENT: + rank = 7; + break; + + // Policy controlled extensions may not be overridden by any type + // that is not part of chrome. + case Manifest::EXTERNAL_POLICY_DOWNLOAD: + rank = 6; + break; + + // A developer-loaded extension should override any installed type + // that a user can disable. Anything specified on the command-line should + // override one loaded via the extensions UI. + case Manifest::COMMAND_LINE: + rank = 5; + break; + + case Manifest::UNPACKED: + rank = 4; + break; + + // The relative priority of various external sources is not important, + // but having some order ensures deterministic behavior. + case Manifest::EXTERNAL_REGISTRY: + rank = 3; + break; + + case Manifest::EXTERNAL_PREF: + rank = 2; + break; + + case Manifest::EXTERNAL_PREF_DOWNLOAD: + rank = 1; + break; + + // User installed extensions are overridden by any external type. + case Manifest::INTERNAL: + rank = 0; + break; + + default: + NOTREACHED() << "Need to add new extension location " << location; + } + + CHECK(rank != kInvalidRank); + return rank; +} + +} // namespace + +// static +Manifest::Location Manifest::GetHigherPriorityLocation( + Location loc1, Location loc2) { + if (loc1 == loc2) + return loc1; + + int loc1_rank = GetLocationRank(loc1); + int loc2_rank = GetLocationRank(loc2); + + // If two different locations have the same rank, then we can not + // deterministicly choose a location. + CHECK(loc1_rank != loc2_rank); + + // Highest rank has highest priority. + return (loc1_rank > loc2_rank ? loc1 : loc2 ); +} + +Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value) + : location_(location), + value_(value.Pass()), + type_(TYPE_UNKNOWN) { + if (value_->HasKey(keys::kTheme)) { + type_ = TYPE_THEME; + } else if (value_->HasKey(keys::kExport)) { + type_ = TYPE_SHARED_MODULE; + } else if (value_->HasKey(keys::kApp)) { + if (value_->Get(keys::kWebURLs, NULL) || + value_->Get(keys::kLaunchWebURL, NULL)) { + type_ = TYPE_HOSTED_APP; + } else if (value_->Get(keys::kPlatformAppBackground, NULL)) { + type_ = TYPE_PLATFORM_APP; + } else { + type_ = TYPE_LEGACY_PACKAGED_APP; + } + } else { + type_ = TYPE_EXTENSION; + } + CHECK_NE(type_, TYPE_UNKNOWN); +} + +Manifest::~Manifest() { +} + +bool Manifest::ValidateManifest( + std::string* error, + std::vector<InstallWarning>* warnings) const { + *error = ""; + + // Check every feature to see if its in the manifest. Note that this means + // we will ignore keys that are not features; we do this for forward + // compatibility. + // TODO(aa): Consider having an error here in the case of strict error + // checking to let developers know when they screw up. + + FeatureProvider* provider = FeatureProvider::GetByName("manifest"); + const std::vector<std::string>& feature_names = + provider->GetAllFeatureNames(); + for (std::vector<std::string>::const_iterator feature_name = + feature_names.begin(); + feature_name != feature_names.end(); ++feature_name) { + // Use Get instead of HasKey because the former uses path expansion. + if (!value_->Get(*feature_name, NULL)) + continue; + + Feature* feature = provider->GetFeature(*feature_name); + Feature::Availability result = feature->IsAvailableToManifest( + extension_id_, type_, Feature::ConvertLocation(location_), + GetManifestVersion()); + if (!result.is_available()) + warnings->push_back(InstallWarning(result.message(), *feature_name)); + } + + // Also generate warnings for keys that are not features. + for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); + it.Advance()) { + if (!provider->GetFeature(it.key())) { + warnings->push_back(InstallWarning( + base::StringPrintf("Unrecognized manifest key '%s'.", + it.key().c_str()), + it.key())); + } + } + return true; +} + +bool Manifest::HasKey(const std::string& key) const { + return CanAccessKey(key) && value_->HasKey(key); +} + +bool Manifest::HasPath(const std::string& path) const { + base::Value* ignored = NULL; + return CanAccessPath(path) && value_->Get(path, &ignored); +} + +bool Manifest::Get( + const std::string& path, const base::Value** out_value) const { + return CanAccessPath(path) && value_->Get(path, out_value); +} + +bool Manifest::GetBoolean( + const std::string& path, bool* out_value) const { + return CanAccessPath(path) && value_->GetBoolean(path, out_value); +} + +bool Manifest::GetInteger( + const std::string& path, int* out_value) const { + return CanAccessPath(path) && value_->GetInteger(path, out_value); +} + +bool Manifest::GetString( + const std::string& path, std::string* out_value) const { + return CanAccessPath(path) && value_->GetString(path, out_value); +} + +bool Manifest::GetString( + const std::string& path, string16* out_value) const { + return CanAccessPath(path) && value_->GetString(path, out_value); +} + +bool Manifest::GetDictionary( + const std::string& path, const base::DictionaryValue** out_value) const { + return CanAccessPath(path) && value_->GetDictionary(path, out_value); +} + +bool Manifest::GetList( + const std::string& path, const base::ListValue** out_value) const { + return CanAccessPath(path) && value_->GetList(path, out_value); +} + +Manifest* Manifest::DeepCopy() const { + Manifest* manifest = new Manifest( + location_, scoped_ptr<base::DictionaryValue>(value_->DeepCopy())); + manifest->set_extension_id(extension_id_); + return manifest; +} + +bool Manifest::Equals(const Manifest* other) const { + return other && value_->Equals(other->value()); +} + +int Manifest::GetManifestVersion() const { + // Platform apps were launched after manifest version 2 was the preferred + // version, so they default to that. + int manifest_version = type_ == TYPE_PLATFORM_APP ? 2 : 1; + value_->GetInteger(keys::kManifestVersion, &manifest_version); + return manifest_version; +} + +bool Manifest::CanAccessPath(const std::string& path) const { + std::vector<std::string> components; + base::SplitString(path, '.', &components); + std::string key; + for (size_t i = 0; i < components.size(); ++i) { + key += components[i]; + if (!CanAccessKey(key)) + return false; + key += '.'; + } + return true; +} + +bool Manifest::CanAccessKey(const std::string& key) const { + Feature* feature = FeatureProvider::GetByName("manifest")->GetFeature(key); + if (!feature) + return true; + + return feature->IsAvailableToManifest( + extension_id_, type_, Feature::ConvertLocation(location_), + GetManifestVersion()).is_available(); +} + +} // namespace extensions diff --git a/extensions/common/manifest.h b/extensions/common/manifest.h new file mode 100644 index 0000000000..c4ceb3870c --- /dev/null +++ b/extensions/common/manifest.h @@ -0,0 +1,177 @@ +// 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_MANIFEST_H_ +#define EXTENSIONS_COMMON_MANIFEST_H_ + +#include <map> +#include <set> +#include <string> + +#include "base/memory/scoped_ptr.h" +#include "base/strings/string16.h" +#include "base/values.h" + +namespace extensions { +struct InstallWarning; + +// Wraps the DictionaryValue form of extension's manifest. Enforces access to +// properties of the manifest using ManifestFeatureProvider. +class Manifest { + public: + // What an extension was loaded from. + // NOTE: These values are stored as integers in the preferences and used + // in histograms so don't remove or reorder existing items. Just append + // to the end. + enum Location { + INVALID_LOCATION, + INTERNAL, // A crx file from the internal Extensions directory. + EXTERNAL_PREF, // A crx file from an external directory (via prefs). + EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the + // registry on Windows). + UNPACKED, // From loading an unpacked extension from the + // extensions settings page. + COMPONENT, // An integral component of Chrome itself, which + // happens to be implemented as an extension. We don't + // show these in the management UI. + EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via + // prefs), installed from an update URL. + EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via + // admin policies), installed from an update URL. + COMMAND_LINE, // --load-extension. + + NUM_LOCATIONS + }; + + // Do not change the order of entries or remove entries in this list + // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. + enum Type { + TYPE_UNKNOWN = 0, + TYPE_EXTENSION, + TYPE_THEME, + TYPE_USER_SCRIPT, + TYPE_HOSTED_APP, + // This is marked legacy because platform apps are preferred. For + // backwards compatibility, we can't remove support for packaged apps + TYPE_LEGACY_PACKAGED_APP, + TYPE_PLATFORM_APP, + TYPE_SHARED_MODULE + }; + + // Given two install sources, return the one which should take priority + // over the other. If an extension is installed from two sources A and B, + // its install source should be set to GetHigherPriorityLocation(A, B). + static Location GetHigherPriorityLocation(Location loc1, Location loc2); + + // Whether the |location| is external or not. + static inline bool IsExternalLocation(Location location) { + return location == EXTERNAL_PREF || + location == EXTERNAL_REGISTRY || + location == EXTERNAL_PREF_DOWNLOAD || + location == EXTERNAL_POLICY_DOWNLOAD; + } + + // Whether the |location| is unpacked (no CRX) or not. + static inline bool IsUnpackedLocation(Location location) { + return location == UNPACKED || location == COMMAND_LINE; + } + + // Whether extensions with |location| are auto-updatable or not. + static inline bool IsAutoUpdateableLocation(Location location) { + // Only internal and external extensions can be autoupdated. + return location == INTERNAL || + IsExternalLocation(location); + } + + // Unpacked extensions start off with file access since they are a developer + // feature. + static inline bool ShouldAlwaysAllowFileAccess(Location location) { + return IsUnpackedLocation(location); + } + + Manifest(Location location, scoped_ptr<base::DictionaryValue> value); + virtual ~Manifest(); + + const std::string& extension_id() const { return extension_id_; } + void set_extension_id(const std::string& id) { extension_id_ = id; } + + Location location() const { return location_; } + + // Returns false and |error| will be non-empty if the manifest is malformed. + // |warnings| will be populated if there are keys in the manifest that cannot + // be specified by the extension type. + bool ValidateManifest(std::string* error, + std::vector<InstallWarning>* warnings) const; + + // The version of this extension's manifest. We increase the manifest + // version when making breaking changes to the extension system. If the + // manifest contains no explicit manifest version, this returns the current + // system default. + int GetManifestVersion() const; + + // Returns the manifest type. + Type type() const { return type_; } + + bool is_theme() const { return type_ == TYPE_THEME; } + bool is_app() const { + return is_legacy_packaged_app() || is_hosted_app() || is_platform_app(); + } + bool is_platform_app() const { return type_ == TYPE_PLATFORM_APP; } + bool is_hosted_app() const { return type_ == TYPE_HOSTED_APP; } + bool is_legacy_packaged_app() const { + return type_ == TYPE_LEGACY_PACKAGED_APP; + } + bool is_extension() const { return type_ == TYPE_EXTENSION; } + bool is_shared_module() const { return type_ == TYPE_SHARED_MODULE; } + + // These access the wrapped manifest value, returning false when the property + // does not exist or if the manifest type can't access it. + bool HasKey(const std::string& key) const; + bool HasPath(const std::string& path) const; + bool Get(const std::string& path, const base::Value** out_value) const; + bool GetBoolean(const std::string& path, bool* out_value) const; + bool GetInteger(const std::string& path, int* out_value) const; + bool GetString(const std::string& path, std::string* out_value) const; + bool GetString(const std::string& path, string16* out_value) const; + bool GetDictionary(const std::string& path, + const base::DictionaryValue** out_value) const; + bool GetList(const std::string& path, + const base::ListValue** out_value) const; + + // Returns a new Manifest equal to this one, passing ownership to + // the caller. + Manifest* DeepCopy() const; + + // Returns true if this equals the |other| manifest. + bool Equals(const Manifest* other) const; + + // Gets the underlying DictionaryValue representing the manifest. + // Note: only use this when you KNOW you don't need the validation. + const base::DictionaryValue* value() const { return value_.get(); } + + private: + // Returns true if the extension can specify the given |path|. + bool CanAccessPath(const std::string& path) const; + bool CanAccessKey(const std::string& key) const; + + // A persistent, globally unique ID. An extension's ID is used in things + // like directory structures and URLs, and is expected to not change across + // versions. It is generated as a SHA-256 hash of the extension's public + // key, or as a hash of the path in the case of unpacked extensions. + std::string extension_id_; + + // The location the extension was loaded from. + Location location_; + + // The underlying dictionary representation of the manifest. + scoped_ptr<base::DictionaryValue> value_; + + Type type_; + + DISALLOW_COPY_AND_ASSIGN(Manifest); +}; + +} // namespace extensions + +#endif // EXTENSIONS_COMMON_MANIFEST_H_ diff --git a/extensions/common/manifest_constants.cc b/extensions/common/manifest_constants.cc new file mode 100644 index 0000000000..fcdf6e99fc --- /dev/null +++ b/extensions/common/manifest_constants.cc @@ -0,0 +1,151 @@ +// 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/manifest_constants.h" + +namespace extensions { + +namespace manifest_keys { + +const char kAllFrames[] = "all_frames"; +const char kAltKey[] = "altKey"; +const char kApp[] = "app"; +const char kAudio[] = "audio"; +const char kBackgroundAllowJsAccess[] = "background.allow_js_access"; +const char kBackgroundPage[] = "background.page"; +const char kBackgroundPageLegacy[] = "background_page"; +const char kBackgroundPersistent[] = "background.persistent"; +const char kBackgroundScripts[] = "background.scripts"; +const char kBrowserAction[] = "browser_action"; +const char kChromeURLOverrides[] = "chrome_url_overrides"; +const char kCommands[] = "commands"; +const char kContentPack[] = "content_pack"; +const char kContentPackSites[] = "sites"; +const char kContentScripts[] = "content_scripts"; +const char kContentSecurityPolicy[] = "content_security_policy"; +const char kConvertedFromUserScript[] = "converted_from_user_script"; +const char kCss[] = "css"; +const char kCtrlKey[] = "ctrlKey"; +const char kCurrentLocale[] = "current_locale"; +const char kDefaultLocale[] = "default_locale"; +const char kDescription[] = "description"; +const char kDevToolsPage[] = "devtools_page"; +const char kDisplayInLauncher[] = "display_in_launcher"; +const char kDisplayInNewTabPage[] = "display_in_new_tab_page"; +const char kEventName[] = "event_name"; +const char kExcludeGlobs[] = "exclude_globs"; +const char kExcludeMatches[] = "exclude_matches"; +const char kExport[] = "export"; +const char kExternallyConnectable[] = "externally_connectable"; +const char kFileAccessList[] = "file_access"; +const char kFileFilters[] = "file_filters"; +const char kFileBrowserHandlers[] = "file_browser_handlers"; +const char kMediaGalleriesHandlers[] = "media_galleries_handlers"; +const char kFileHandlers[] = "file_handlers"; +const char kFileHandlerExtensions[] = "extensions"; +const char kFileHandlerTitle[] = "title"; +const char kFileHandlerTypes[] = "types"; +const char kHomepageURL[] = "homepage_url"; +const char kIcons[] = "icons"; +const char kId[] = "id"; +const char kImport[] = "import"; +const char kIncognito[] = "incognito"; +const char kIncludeGlobs[] = "include_globs"; +const char kInputComponents[] = "input_components"; +const char kIsolation[] = "app.isolation"; +const char kJs[] = "js"; +const char kKey[] = "key"; +const char kKeycode[] = "keyCode"; +const char kKioskEnabled[] = "kiosk_enabled"; +const char kLanguage[] = "language"; +const char kLaunch[] = "app.launch"; +const char kLaunchContainer[] = "app.launch.container"; +const char kLaunchHeight[] = "app.launch.height"; +const char kLaunchLocalPath[] = "app.launch.local_path"; +const char kLaunchWebURL[] = "app.launch.web_url"; +const char kLaunchWidth[] = "app.launch.width"; +const char kLayouts[] = "layouts"; +const char kManifestVersion[] = "manifest_version"; +const char kMatches[] = "matches"; +const char kMinimumChromeVersion[] = "minimum_chrome_version"; +const char kMinimumVersion[] = "minimum_version"; +const char kMIMETypes[] = "mime_types"; +const char kMimeTypesHandler[] = "mime_types_handler"; +const char kName[] = "name"; +const char kNaClModules[] = "nacl_modules"; +const char kNaClModulesMIMEType[] = "mime_type"; +const char kNaClModulesPath[] = "path"; +const char kOAuth2[] = "oauth2"; +const char kOAuth2AutoApprove[] = "oauth2.auto_approve"; +const char kOAuth2ClientId[] = "oauth2.client_id"; +const char kOAuth2Scopes[] = "oauth2.scopes"; +const char kOfflineEnabled[] = "offline_enabled"; +const char kOmnibox[] = "omnibox"; +const char kOmniboxKeyword[] = "omnibox.keyword"; +const char kOptionalPermissions[] = "optional_permissions"; +const char kOptionsPage[] = "options_page"; +const char kPageAction[] = "page_action"; +const char kPageActionDefaultIcon[] = "default_icon"; +const char kPageActionDefaultPopup[] = "default_popup"; +const char kPageActionDefaultTitle[] = "default_title"; +const char kPageActionIcons[] = "icons"; +const char kPageActionId[] = "id"; +const char kPageActionPopup[] = "popup"; +const char kPageActionPopupPath[] = "path"; +const char kPageActions[] = "page_actions"; +const char kPermissions[] = "permissions"; +const char kPlatformAppBackground[] = "app.background"; +const char kPlatformAppBackgroundPage[] = "app.background.page"; +const char kPlatformAppBackgroundScripts[] = "app.background.scripts"; +const char kPlatformAppContentSecurityPolicy[] = "app.content_security_policy"; +const char kPlugins[] = "plugins"; +const char kPluginsPath[] = "path"; +const char kPluginsPublic[] = "public"; +const char kPublicKey[] = "key"; +const char kResources[] = "resources"; +const char kRequirements[] = "requirements"; +const char kRunAt[] = "run_at"; +const char kSandboxedPages[] = "sandbox.pages"; +const char kSandboxedPagesCSP[] = "sandbox.content_security_policy"; +const char kScriptBadge[] = "script_badge"; +const char kShiftKey[] = "shiftKey"; +const char kShortcutKey[] = "shortcutKey"; +const char kSignature[] = "signature"; +const char kSpellcheck[] = "spellcheck"; +const char kSpellcheckDictionaryFormat[] = "dictionary_format"; +const char kSpellcheckDictionaryLanguage[] = "dictionary_language"; +const char kSpellcheckDictionaryLocale[] = "dictionary_locale"; +const char kSpellcheckDictionaryPath[] = "dictionary_path"; +const char kStorageManagedSchema[] = "storage.managed_schema"; +const char kSuggestedKey[] = "suggested_key"; +const char kSystemIndicator[] = "system_indicator"; +const char kSystemInfoDisplay[] = "systemInfo.display"; +const char kTheme[] = "theme"; +const char kThemeColors[] = "colors"; +const char kThemeDisplayProperties[] = "properties"; +const char kThemeImages[] = "images"; +const char kThemeTints[] = "tints"; +const char kTtsEngine[] = "tts_engine"; +const char kTtsGenderFemale[] = "female"; +const char kTtsGenderMale[] = "male"; +const char kTtsVoices[] = "voices"; +const char kTtsVoicesEventTypeEnd[] = "end"; +const char kTtsVoicesEventTypeError[] = "error"; +const char kTtsVoicesEventTypeMarker[] = "marker"; +const char kTtsVoicesEventTypeSentence[] = "sentence"; +const char kTtsVoicesEventTypeStart[] = "start"; +const char kTtsVoicesEventTypeWord[] = "word"; +const char kTtsVoicesEventTypes[] = "event_types"; +const char kTtsVoicesGender[] = "gender"; +const char kTtsVoicesLang[] = "lang"; +const char kTtsVoicesVoiceName[] = "voice_name"; +const char kType[] = "type"; +const char kUpdateURL[] = "update_url"; +const char kVersion[] = "version"; +const char kWebAccessibleResources[] = "web_accessible_resources"; +const char kWebURLs[] = "app.urls"; + +} // namespace manifest_keys + +} // namespace extensions diff --git a/extensions/common/manifest_constants.h b/extensions/common/manifest_constants.h new file mode 100644 index 0000000000..ce31f7c688 --- /dev/null +++ b/extensions/common/manifest_constants.h @@ -0,0 +1,157 @@ +// 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_MANIFEST_CONSTANTS_H_ +#define EXTENSIONS_COMMON_MANIFEST_CONSTANTS_H_ + +// Keys used in JSON representation of extensions. +namespace extensions { +namespace manifest_keys { + extern const char kAllFrames[]; + extern const char kAltKey[]; + extern const char kApp[]; + extern const char kBackgroundAllowJsAccess[]; + extern const char kBackgroundPage[]; + extern const char kBackgroundPageLegacy[]; + extern const char kBackgroundPersistent[]; + extern const char kBackgroundScripts[]; + extern const char kBrowserAction[]; + extern const char kBrowseURLs[]; + extern const char kChromeURLOverrides[]; + extern const char kCommands[]; + extern const char kContentPack[]; + extern const char kContentPackSites[]; + extern const char kContentScripts[]; + extern const char kContentSecurityPolicy[]; + extern const char kConvertedFromUserScript[]; + extern const char kCss[]; + extern const char kCtrlKey[]; + extern const char kCurrentLocale[]; + extern const char kDefaultLocale[]; + extern const char kDescription[]; + extern const char kDevToolsPage[]; + extern const char kDisplayInLauncher[]; + extern const char kDisplayInNewTabPage[]; + extern const char kEventName[]; + extern const char kExcludeGlobs[]; + extern const char kExcludeMatches[]; + extern const char kExport[]; + extern const char kExternallyConnectable[]; + extern const char kFileAccessList[]; + extern const char kFileHandlers[]; + extern const char kFileHandlerExtensions[]; + extern const char kFileHandlerTitle[]; + extern const char kFileHandlerTypes[]; + extern const char kFileFilters[]; + extern const char kFileBrowserHandlers[]; + extern const char kMediaGalleriesHandlers[]; + extern const char kHomepageURL[]; + extern const char kIcons[]; + extern const char kId[]; + extern const char kImport[]; + extern const char kIncognito[]; + extern const char kIncludeGlobs[]; + extern const char kInputComponents[]; + extern const char kIntentDisposition[]; + extern const char kIntentHref[]; + extern const char kIntentPath[]; + extern const char kIntents[]; + extern const char kIntentTitle[]; + extern const char kIntentType[]; + extern const char kIsolation[]; + extern const char kJs[]; + extern const char kKey[]; + extern const char kKeycode[]; + extern const char kKioskEnabled[]; + extern const char kLanguage[]; + extern const char kLaunch[]; + extern const char kLaunchContainer[]; + extern const char kLaunchHeight[]; + extern const char kLaunchLocalPath[]; + extern const char kLaunchWebURL[]; + extern const char kLaunchWidth[]; + extern const char kLayouts[]; + extern const char kManifestVersion[]; + extern const char kMatches[]; + extern const char kMIMETypes[]; + extern const char kMimeTypesHandler[]; + extern const char kMinimumChromeVersion[]; + extern const char kMinimumVersion[]; + extern const char kNaClModules[]; + extern const char kNaClModulesMIMEType[]; + extern const char kNaClModulesPath[]; + extern const char kName[]; + extern const char kOAuth2[]; + extern const char kOAuth2AutoApprove[]; + extern const char kOAuth2ClientId[]; + extern const char kOAuth2Scopes[]; + extern const char kOfflineEnabled[]; + extern const char kOmnibox[]; + extern const char kOmniboxKeyword[]; + extern const char kOptionalPermissions[]; + extern const char kOptionsPage[]; + extern const char kPageAction[]; + extern const char kPageActionDefaultIcon[]; + extern const char kPageActionDefaultPopup[]; + extern const char kPageActionDefaultTitle[]; + extern const char kPageActionIcons[]; + extern const char kPageActionId[]; + extern const char kPageActionPopup[]; + extern const char kPageActionPopupPath[]; + extern const char kPageActions[]; + extern const char kPermissions[]; + extern const char kPlatformAppBackground[]; + extern const char kPlatformAppBackgroundPage[]; + extern const char kPlatformAppBackgroundScripts[]; + extern const char kPlatformAppContentSecurityPolicy[]; + extern const char kPlugins[]; + extern const char kPluginsPath[]; + extern const char kPluginsPublic[]; + extern const char kPublicKey[]; + extern const char kResources[]; + extern const char kRequirements[]; + extern const char kRunAt[]; + extern const char kSandboxedPages[]; + extern const char kSandboxedPagesCSP[]; + extern const char kScriptBadge[]; + extern const char kShiftKey[]; + extern const char kShortcutKey[]; + extern const char kSignature[]; + extern const char kSpellcheck[]; + extern const char kSpellcheckDictionaryFormat[]; + extern const char kSpellcheckDictionaryLanguage[]; + extern const char kSpellcheckDictionaryLocale[]; + extern const char kSpellcheckDictionaryPath[]; + extern const char kStorageManagedSchema[]; + extern const char kSuggestedKey[]; + extern const char kSystemIndicator[]; + extern const char kTheme[]; + extern const char kThemeColors[]; + extern const char kThemeDisplayProperties[]; + extern const char kThemeImages[]; + extern const char kThemeTints[]; + extern const char kTtsEngine[]; + extern const char kTtsGenderFemale[]; + extern const char kTtsGenderMale[]; + extern const char kTtsVoices[]; + extern const char kTtsVoicesEventTypeEnd[]; + extern const char kTtsVoicesEventTypeError[]; + extern const char kTtsVoicesEventTypeMarker[]; + extern const char kTtsVoicesEventTypeSentence[]; + extern const char kTtsVoicesEventTypeStart[]; + extern const char kTtsVoicesEventTypeWord[]; + extern const char kTtsVoicesEventTypes[]; + extern const char kTtsVoicesGender[]; + extern const char kTtsVoicesLang[]; + extern const char kTtsVoicesVoiceName[]; + extern const char kType[]; + extern const char kUpdateURL[]; + extern const char kVersion[]; + extern const char kWebAccessibleResources[]; + extern const char kWebURLs[]; +} // namespace manifest_keys + +} // namespace extensions + +#endif // EXTENSIONS_COMMON_MANIFEST_CONSTANTS_H_ diff --git a/extensions/common/matcher/regex_set_matcher.cc b/extensions/common/matcher/regex_set_matcher.cc index af8027cdd3..24d99efa3f 100644 --- a/extensions/common/matcher/regex_set_matcher.cc +++ b/extensions/common/matcher/regex_set_matcher.cc @@ -53,7 +53,6 @@ bool RegexSetMatcher::Match(const std::string& text, std::vector<RE2ID> re2_ids; filtered_re2_->AllMatches(text, atoms, &re2_ids); - std::set<StringPattern::ID> matched_ids; for (size_t i = 0; i < re2_ids.size(); ++i) { StringPattern::ID id = re2_id_map_[re2_ids[i]]; matches->insert(id); diff --git a/extensions/common/matcher/url_matcher.cc b/extensions/common/matcher/url_matcher.cc index be3057a26b..5a1d876cc6 100644 --- a/extensions/common/matcher/url_matcher.cc +++ b/extensions/common/matcher/url_matcher.cc @@ -752,19 +752,15 @@ void URLMatcher::UpdateSubstringSetMatcher(bool full_url_conditions) { : registered_url_component_patterns_; // Add all patterns that are in new_patterns but not in registered_patterns. - std::vector<const StringPattern*> patterns_to_register; - std::set_difference( - new_patterns.begin(), new_patterns.end(), - registered_patterns.begin(), registered_patterns.end(), - std::back_inserter(patterns_to_register)); + std::vector<const StringPattern*> patterns_to_register = + base::STLSetDifference<std::vector<const StringPattern*> >( + new_patterns, registered_patterns); // Remove all patterns that are in registered_patterns but not in // new_patterns. - std::vector<const StringPattern*> patterns_to_unregister; - std::set_difference( - registered_patterns.begin(), registered_patterns.end(), - new_patterns.begin(), new_patterns.end(), - std::back_inserter(patterns_to_unregister)); + std::vector<const StringPattern*> patterns_to_unregister = + base::STLSetDifference<std::vector<const StringPattern*> >( + registered_patterns, new_patterns); // Update the SubstringSetMatcher. SubstringSetMatcher& url_matcher = |