summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-29 23:14:02 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-29 23:14:02 +0000
commit9adb9693e8a90bb63be325dbb5d3391f47f839ba (patch)
tree555765afd7bc851de6f3a2bf4a35151435d58d77 /chrome/common/extensions
parent5b5a5c976aead85a87ced0847c068012d3979cae (diff)
downloadchromium_src-9adb9693e8a90bb63be325dbb5d3391f47f839ba.zip
chromium_src-9adb9693e8a90bb63be325dbb5d3391f47f839ba.tar.gz
chromium_src-9adb9693e8a90bb63be325dbb5d3391f47f839ba.tar.bz2
Part 3 of immutable Extension refactor.
Make ExtensionsService hold const Extension pointers only. This ensures that extensions can't be modified after they're created, and lets us share them between threads. BUG=56558 TEST=no functional change Review URL: http://codereview.chromium.org/4138006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/extension.cc47
-rw-r--r--chrome/common/extensions/extension.h48
2 files changed, 49 insertions, 46 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 8bf9938..dc11856 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -299,7 +299,7 @@ int Extension::GetPermissionMessageId(const std::string& permission) {
return ExtensionConfig::GetSingleton()->GetPermissionMessageId(permission);
}
-std::vector<string16> Extension::GetPermissionMessages() {
+std::vector<string16> Extension::GetPermissionMessages() const {
std::vector<string16> messages;
if (!plugins().empty()) {
messages.push_back(
@@ -317,7 +317,7 @@ std::vector<string16> Extension::GetPermissionMessages() {
return messages;
}
-std::set<string16> Extension::GetSimplePermissionMessages() {
+std::set<string16> Extension::GetSimplePermissionMessages() const {
std::set<string16> messages;
std::set<std::string>::const_iterator i;
for (i = api_permissions().begin(); i != api_permissions().end(); ++i) {
@@ -328,7 +328,7 @@ std::set<string16> Extension::GetSimplePermissionMessages() {
return messages;
}
-std::vector<std::string> Extension::GetDistinctHosts() {
+std::vector<std::string> Extension::GetDistinctHosts() const {
return GetDistinctHosts(GetEffectiveHostPermissions().patterns());
}
@@ -359,7 +359,7 @@ std::vector<std::string> Extension::GetDistinctHosts(
return distinct_hosts;
}
-string16 Extension::GetHostPermissionMessage() {
+string16 Extension::GetHostPermissionMessage() const {
if (HasEffectiveAccessToAllHosts())
return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT2_WARNING_ALL_HOSTS);
@@ -447,7 +447,7 @@ std::string Extension::GenerateIdForPath(const FilePath& path) {
return id;
}
-Extension::HistogramType Extension::GetHistogramType() {
+Extension::HistogramType Extension::GetHistogramType() const {
if (is_theme())
return TYPE_THEME;
if (converted_from_user_script())
@@ -782,7 +782,7 @@ ExtensionAction* Extension::LoadExtensionActionHelper(
return result.release();
}
-bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) {
+bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) const {
for (DictionaryValue::key_iterator key = source.begin_keys();
key != source.end_keys(); ++key) {
if (!IsBaseCrxKey(*key) && *key != keys::kTheme)
@@ -1019,7 +1019,8 @@ Extension::Extension(const FilePath& path, Location location)
Extension::~Extension() {
}
-ExtensionResource Extension::GetResource(const std::string& relative_path) {
+ExtensionResource Extension::GetResource(
+ const std::string& relative_path) const {
#if defined(OS_POSIX)
FilePath relative_file_path(relative_path);
#elif defined(OS_WIN)
@@ -1028,7 +1029,8 @@ ExtensionResource Extension::GetResource(const std::string& relative_path) {
return ExtensionResource(id(), path(), relative_file_path);
}
-ExtensionResource Extension::GetResource(const FilePath& relative_file_path) {
+ExtensionResource Extension::GetResource(
+ const FilePath& relative_file_path) const {
return ExtensionResource(id(), path(), relative_file_path);
}
@@ -1108,8 +1110,8 @@ bool Extension::FormatPEMForFileOutput(const std::string input,
// extensions that require less permissions than the current version, but then
// we don't silently allow them to go back. In order to fix this, we would need
// to remember the max set of permissions we ever granted a single extension.
-bool Extension::IsPrivilegeIncrease(Extension* old_extension,
- Extension* new_extension) {
+bool Extension::IsPrivilegeIncrease(const Extension* old_extension,
+ const Extension* new_extension) {
// If the old extension had native code access, we don't need to go any
// further. Things can't get any worse.
if (old_extension->plugins().size() > 0)
@@ -1156,7 +1158,7 @@ bool Extension::IsPrivilegeIncrease(Extension* old_extension,
}
// static
-void Extension::DecodeIcon(Extension* extension,
+void Extension::DecodeIcon(const Extension* extension,
Icons icon_size,
scoped_ptr<SkBitmap>* result) {
FilePath icon_path = extension->GetIconResource(
@@ -1899,7 +1901,7 @@ GURL Extension::GetHomepageURL() const {
return url;
}
-std::set<FilePath> Extension::GetBrowserImages() {
+std::set<FilePath> Extension::GetBrowserImages() const {
std::set<FilePath> image_paths;
// TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())|
// indicate that we're doing something wrong.
@@ -1949,12 +1951,12 @@ GURL Extension::GetFullLaunchURL() const {
return GURL(launch_web_url());
}
-bool Extension::GetBackgroundPageReady() {
+bool Extension::GetBackgroundPageReady() const {
return (GetRuntimeData()->background_page_ready ||
background_url().is_empty());
}
-void Extension::SetBackgroundPageReady() {
+void Extension::SetBackgroundPageReady() const {
DCHECK(!background_url().is_empty());
GetRuntimeData()->background_page_ready = true;
NotificationService::current()->Notify(
@@ -1982,7 +1984,7 @@ void Extension::SetScriptingWhitelist(
void Extension::SetCachedImage(const ExtensionResource& source,
const SkBitmap& image,
- const gfx::Size& original_size) {
+ const gfx::Size& original_size) const {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
const FilePath& path = source.relative_path();
@@ -1997,14 +1999,14 @@ void Extension::SetCachedImage(const ExtensionResource& source,
}
bool Extension::HasCachedImage(const ExtensionResource& source,
- const gfx::Size& max_size) {
+ const gfx::Size& max_size) const {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
return GetCachedImageImpl(source, max_size) != NULL;
}
SkBitmap Extension::GetCachedImage(const ExtensionResource& source,
- const gfx::Size& max_size) {
+ const gfx::Size& max_size) const {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
SkBitmap* image = GetCachedImageImpl(source, max_size);
@@ -2012,7 +2014,7 @@ SkBitmap Extension::GetCachedImage(const ExtensionResource& source,
}
SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source,
- const gfx::Size& max_size) {
+ const gfx::Size& max_size) const {
const FilePath& path = source.relative_path();
// Look for exact size match.
@@ -2036,14 +2038,15 @@ SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source,
}
ExtensionResource Extension::GetIconResource(
- int size, ExtensionIconSet::MatchType match_type) {
+ int size, ExtensionIconSet::MatchType match_type) const {
std::string path = icons().Get(size, match_type);
if (path.empty())
return ExtensionResource();
return GetResource(path);
}
-GURL Extension::GetIconURL(int size, ExtensionIconSet::MatchType match_type) {
+GURL Extension::GetIconURL(int size,
+ ExtensionIconSet::MatchType match_type) const {
std::string path = icons().Get(size, match_type);
if (path.empty())
return GURL();
@@ -2064,7 +2067,7 @@ bool Extension::CanSpecifyHostPermission(const URLPattern& pattern) const {
return true;
}
-// static.
+// static
bool Extension::HasApiPermission(
const std::set<std::string>& api_permissions,
const std::string& function_name) {
@@ -2204,7 +2207,7 @@ bool Extension::HasEffectiveAccessToAllHosts() const {
return false;
}
-bool Extension::IsAPIPermission(const std::string& str) {
+bool Extension::IsAPIPermission(const std::string& str) const {
for (size_t i = 0; i < Extension::kNumPermissions; ++i) {
if (str == Extension::kPermissions[i].name) {
// Only allow the experimental API permission if the command line
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 82c007b..08e4bbb 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -285,7 +285,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Returns the full list of permission messages that this extension
// should display at install time.
- std::vector<string16> GetPermissionMessages();
+ std::vector<string16> GetPermissionMessages() const;
// Returns the distinct hosts that should be displayed in the install UI. This
// discards some of the detail that is present in the manifest to make it as
@@ -293,7 +293,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// and path components of URLPatterns and de-dupe the result.
static std::vector<std::string> GetDistinctHosts(
const URLPatternList& host_patterns);
- std::vector<std::string> GetDistinctHosts();
+ std::vector<std::string> GetDistinctHosts() const;
// Icon sizes used by the extension system.
static const int kIconSizes[];
@@ -378,7 +378,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
}
// See HistogramType definition above.
- HistogramType GetHistogramType();
+ HistogramType GetHistogramType() const;
// Returns an absolute url to a resource inside of an extension. The
// |extension_url| argument should be the url() from an Extension object. The
@@ -393,10 +393,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Returns an extension resource object. |relative_path| should be UTF8
// encoded.
- ExtensionResource GetResource(const std::string& relative_path);
+ ExtensionResource GetResource(const std::string& relative_path) const;
// As above, but with |relative_path| following the file system's encoding.
- ExtensionResource GetResource(const FilePath& relative_path);
+ ExtensionResource GetResource(const FilePath& relative_path) const;
// |input| is expected to be the text of an rsa public or private key. It
// tolerates the presence or absence of bracking header/footer like this:
@@ -418,14 +418,14 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Determine whether |new_extension| has increased privileges compared to
// |old_extension|.
- static bool IsPrivilegeIncrease(Extension* old_extension,
- Extension* new_extension);
+ static bool IsPrivilegeIncrease(const Extension* old_extension,
+ const Extension* new_extension);
// Given an extension and icon size, read it if present and decode it into
// result. In the browser process, this will DCHECK if not called on the
// file thread. To easily load extension images on the UI thread, see
// ImageLoadingTracker.
- static void DecodeIcon(Extension* extension,
+ static void DecodeIcon(const Extension* extension,
Icons icon_size,
scoped_ptr<SkBitmap>* result);
@@ -560,12 +560,12 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Returns a list of paths (relative to the extension dir) for images that
// the browser might load (like themes and page action icons).
- std::set<FilePath> GetBrowserImages();
+ std::set<FilePath> GetBrowserImages() const;
// Get an extension icon as a resource or URL.
- ExtensionResource GetIconResource(int size,
- ExtensionIconSet::MatchType match_type);
- GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type);
+ ExtensionResource GetIconResource(
+ int size, ExtensionIconSet::MatchType match_type) const;
+ GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
const DictionaryValue* manifest_value() const {
return static_data_->manifest_value.get();
@@ -609,13 +609,13 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Whether the background page, if any, is ready. We don't load other
// components until then. If there is no background page, we consider it to
// be ready.
- bool GetBackgroundPageReady();
- void SetBackgroundPageReady();
+ bool GetBackgroundPageReady() const;
+ void SetBackgroundPageReady() const;
// Getter and setter for the flag that specifies whether the extension is
// being upgraded.
bool being_upgraded() const { return GetRuntimeData()->being_upgraded; }
- void set_being_upgraded(bool value) {
+ void set_being_upgraded(bool value) const {
GetRuntimeData()->being_upgraded = value;
}
@@ -625,11 +625,11 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// before any scaling may have been done to produce the pixels in |image|.
void SetCachedImage(const ExtensionResource& source,
const SkBitmap& image,
- const gfx::Size& original_size);
+ const gfx::Size& original_size) const;
bool HasCachedImage(const ExtensionResource& source,
- const gfx::Size& max_size);
+ const gfx::Size& max_size) const;
SkBitmap GetCachedImage(const ExtensionResource& source,
- const gfx::Size& max_size);
+ const gfx::Size& max_size) const;
bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); }
bool is_packaged_app() const { return is_app() && web_extent().is_empty(); }
@@ -658,7 +658,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// value of NULL means there is no matching image cached (we allow caching an
// empty SkBitmap).
SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
- const gfx::Size& max_size);
+ const gfx::Size& max_size) const;
// Helper method that loads a UserScript object from a
// dictionary in the content_script list of the manifest.
@@ -700,21 +700,21 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// Figures out if a source contains keys not associated with themes - we
// don't want to allow scripts and such to be bundled with themes.
- bool ContainsNonThemeKeys(const DictionaryValue& source);
+ bool ContainsNonThemeKeys(const DictionaryValue& source) const;
// Returns true if the string is one of the known api permissions (see
// kPermissions).
- bool IsAPIPermission(const std::string& permission);
+ bool IsAPIPermission(const std::string& permission) const;
// The set of unique API install messages that the extension has.
// NOTE: This only includes messages related to permissions declared in the
// "permissions" key in the manifest. Permissions implied from other features
// of the manifest, like plugins and content scripts are not included.
- std::set<string16> GetSimplePermissionMessages();
+ std::set<string16> GetSimplePermissionMessages() const;
// The permission message displayed related to the host permissions for
// this extension.
- string16 GetHostPermissionMessage();
+ string16 GetHostPermissionMessage() const;
// Returns a mutable pointer to our runtime data. Can only be called on
// the UI thread.
@@ -739,7 +739,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
DISALLOW_COPY_AND_ASSIGN(Extension);
};
-typedef std::vector< scoped_refptr<Extension> > ExtensionList;
+typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
typedef std::set<std::string> ExtensionIdSet;
// Handy struct to pass core extension info around.