Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 4132005: Kill Extension::RuntimeData and move its guts to ExtensionsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Extension::kUnlimitedStoragePermission, 242 Extension::kUnlimitedStoragePermission,
243 Extension::kWebstorePrivatePermission, 243 Extension::kWebstorePrivatePermission,
244 }; 244 };
245 const size_t Extension::kNumHostedAppPermissions = 245 const size_t Extension::kNumHostedAppPermissions =
246 arraysize(Extension::kHostedAppPermissionNames); 246 arraysize(Extension::kHostedAppPermissionNames);
247 247
248 // We purposefully don't put this into kPermissionNames. 248 // We purposefully don't put this into kPermissionNames.
249 const char Extension::kOldUnlimitedStoragePermission[] = "unlimited_storage"; 249 const char Extension::kOldUnlimitedStoragePermission[] = "unlimited_storage";
250 250
251 // 251 //
252 // Extension::RuntimeData 252 // Extension
253 // 253 //
254 254
255 Extension::RuntimeData::RuntimeData() 255 // static
256 : background_page_ready(false),
257 being_upgraded(false) {
258 }
259
260 Extension::RuntimeData::~RuntimeData() {
261 } 256 }
262 257
263 // 258 //
264 // Extension 259 // Extension
265 // 260 //
266 261
267 // static 262 // static
268 scoped_refptr<Extension> Extension::Create(const FilePath& path, 263 scoped_refptr<Extension> Extension::Create(const FilePath& path,
269 Location location, 264 Location location,
270 const DictionaryValue& value, 265 const DictionaryValue& value,
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 return image_paths; 1917 return image_paths;
1923 } 1918 }
1924 1919
1925 GURL Extension::GetFullLaunchURL() const { 1920 GURL Extension::GetFullLaunchURL() const {
1926 if (!launch_local_path().empty()) 1921 if (!launch_local_path().empty())
1927 return url().Resolve(launch_local_path()); 1922 return url().Resolve(launch_local_path());
1928 else 1923 else
1929 return GURL(launch_web_url()); 1924 return GURL(launch_web_url());
1930 } 1925 }
1931 1926
1932 bool Extension::GetBackgroundPageReady() const {
1933 return (GetRuntimeData()->background_page_ready ||
1934 background_url().is_empty());
1935 }
1936
1937 void Extension::SetBackgroundPageReady() const {
1938 DCHECK(!background_url().is_empty());
1939 GetRuntimeData()->background_page_ready = true;
1940 NotificationService::current()->Notify(
1941 NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
1942 Source<Extension>(this),
1943 NotificationService::NoDetails());
1944 }
1945
1946 static std::string SizeToString(const gfx::Size& max_size) { 1927 static std::string SizeToString(const gfx::Size& max_size) {
1947 return base::IntToString(max_size.width()) + "x" + 1928 return base::IntToString(max_size.width()) + "x" +
1948 base::IntToString(max_size.height()); 1929 base::IntToString(max_size.height());
1949 } 1930 }
1950 1931
1951 // static 1932 // static
1952 void Extension::SetScriptingWhitelist( 1933 void Extension::SetScriptingWhitelist(
1953 const std::vector<std::string>& whitelist) { 1934 const std::vector<std::string>& whitelist) {
1954 ScriptingWhitelist* current_whitelist = 1935 ScriptingWhitelist* current_whitelist =
1955 ExtensionConfig::GetSingleton()->whitelist(); 1936 ExtensionConfig::GetSingleton()->whitelist();
1956 current_whitelist->clear(); 1937 current_whitelist->clear();
1957 for (ScriptingWhitelist::const_iterator it = whitelist.begin(); 1938 for (ScriptingWhitelist::const_iterator it = whitelist.begin();
1958 it != whitelist.end(); ++it) { 1939 it != whitelist.end(); ++it) {
1959 current_whitelist->push_back(*it); 1940 current_whitelist->push_back(*it);
1960 } 1941 }
1961 } 1942 }
1962 1943
1963 void Extension::SetCachedImage(const ExtensionResource& source, 1944 void Extension::SetCachedImage(const ExtensionResource& source,
1964 const SkBitmap& image, 1945 const SkBitmap& image,
1965 const gfx::Size& original_size) const { 1946 const gfx::Size& original_size) const {
1966 DCHECK(source.extension_root() == path()); // The resource must come from 1947 DCHECK(source.extension_root() == path()); // The resource must come from
1967 // this extension. 1948 // this extension.
1968 const FilePath& path = source.relative_path(); 1949 const FilePath& path = source.relative_path();
1969 gfx::Size actual_size(image.width(), image.height()); 1950 gfx::Size actual_size(image.width(), image.height());
1970 if (actual_size == original_size) { 1951 if (actual_size == original_size) {
1971 GetRuntimeData()->image_cache_[ 1952 image_cache_[ImageCacheKey(path, std::string())] = image;
1972 RuntimeData::ImageCacheKey(path, std::string())] = image;
1973 } else { 1953 } else {
1974 GetRuntimeData()->image_cache_[ 1954 image_cache_[ImageCacheKey(path, SizeToString(actual_size))] = image;
1975 RuntimeData::ImageCacheKey(path, SizeToString(actual_size))] = image;
1976 } 1955 }
1977 } 1956 }
1978 1957
1979 bool Extension::HasCachedImage(const ExtensionResource& source, 1958 bool Extension::HasCachedImage(const ExtensionResource& source,
1980 const gfx::Size& max_size) const { 1959 const gfx::Size& max_size) const {
1981 DCHECK(source.extension_root() == path()); // The resource must come from 1960 DCHECK(source.extension_root() == path()); // The resource must come from
1982 // this extension. 1961 // this extension.
1983 return GetCachedImageImpl(source, max_size) != NULL; 1962 return GetCachedImageImpl(source, max_size) != NULL;
1984 } 1963 }
1985 1964
1986 SkBitmap Extension::GetCachedImage(const ExtensionResource& source, 1965 SkBitmap Extension::GetCachedImage(const ExtensionResource& source,
1987 const gfx::Size& max_size) const { 1966 const gfx::Size& max_size) const {
1988 DCHECK(source.extension_root() == path()); // The resource must come from 1967 DCHECK(source.extension_root() == path()); // The resource must come from
1989 // this extension. 1968 // this extension.
1990 SkBitmap* image = GetCachedImageImpl(source, max_size); 1969 SkBitmap* image = GetCachedImageImpl(source, max_size);
1991 return image ? *image : SkBitmap(); 1970 return image ? *image : SkBitmap();
1992 } 1971 }
1993 1972
1994 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, 1973 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source,
1995 const gfx::Size& max_size) const { 1974 const gfx::Size& max_size) const {
1996 const FilePath& path = source.relative_path(); 1975 const FilePath& path = source.relative_path();
1997 1976
1998 // Look for exact size match. 1977 // Look for exact size match.
1999 RuntimeData::ImageCache::iterator i = GetRuntimeData()->image_cache_.find( 1978 ImageCache::iterator i = image_cache_.find(
2000 RuntimeData::ImageCacheKey(path, SizeToString(max_size))); 1979 ImageCacheKey(path, SizeToString(max_size)));
2001 if (i != GetRuntimeData()->image_cache_.end()) 1980 if (i != image_cache_.end())
2002 return &(i->second); 1981 return &(i->second);
2003 1982
2004 // If we have the original size version cached, return that if it's small 1983 // If we have the original size version cached, return that if it's small
2005 // enough. 1984 // enough.
2006 i = GetRuntimeData()->image_cache_.find( 1985 i = image_cache_.find(ImageCacheKey(path, std::string()));
2007 RuntimeData::ImageCacheKey(path, std::string())); 1986 if (i != image_cache_.end()) {
2008 if (i != GetRuntimeData()->image_cache_.end()) {
2009 SkBitmap& image = i->second; 1987 SkBitmap& image = i->second;
2010 if (image.width() <= max_size.width() && 1988 if (image.width() <= max_size.width() &&
2011 image.height() <= max_size.height()) 1989 image.height() <= max_size.height())
2012 return &(i->second); 1990 return &(i->second);
2013 } 1991 }
2014 1992
2015 return NULL; 1993 return NULL;
2016 } 1994 }
2017 1995
2018 ExtensionResource Extension::GetIconResource( 1996 ExtensionResource Extension::GetIconResource(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); 2195 for (ScriptingWhitelist::const_iterator it = whitelist->begin();
2218 it != whitelist->end(); ++it) { 2196 it != whitelist->end(); ++it) {
2219 if (id() == *it) { 2197 if (id() == *it) {
2220 return true; 2198 return true;
2221 } 2199 }
2222 } 2200 }
2223 2201
2224 return false; 2202 return false;
2225 } 2203 }
2226 2204
2227 Extension::RuntimeData* Extension::GetRuntimeData() const {
2228 // TODO(mpcomplete): it would be nice if I could verify we were on the UI
2229 // thread, but we're in common and don't have access to BrowserThread.
2230 return const_cast<Extension::RuntimeData*>(&runtime_data_);
2231 }
2232
2233 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, 2205 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
2234 const std::string& id, 2206 const std::string& id,
2235 const FilePath& path, 2207 const FilePath& path,
2236 Extension::Location location) 2208 Extension::Location location)
2237 : extension_id(id), 2209 : extension_id(id),
2238 extension_path(path), 2210 extension_path(path),
2239 extension_location(location) { 2211 extension_location(location) {
2240 if (manifest) 2212 if (manifest)
2241 extension_manifest.reset( 2213 extension_manifest.reset(
2242 static_cast<DictionaryValue*>(manifest->DeepCopy())); 2214 static_cast<DictionaryValue*>(manifest->DeepCopy()));
2243 } 2215 }
2244 2216
2245 ExtensionInfo::~ExtensionInfo() {} 2217 ExtensionInfo::~ExtensionInfo() {}
2246 2218
2247 UninstalledExtensionInfo::UninstalledExtensionInfo( 2219 UninstalledExtensionInfo::UninstalledExtensionInfo(
2248 const Extension& extension) 2220 const Extension& extension)
2249 : extension_id(extension.id()), 2221 : extension_id(extension.id()),
2250 extension_api_permissions(extension.api_permissions()), 2222 extension_api_permissions(extension.api_permissions()),
2251 is_theme(extension.is_theme()), 2223 is_theme(extension.is_theme()),
2252 is_app(extension.is_app()), 2224 is_app(extension.is_app()),
2253 converted_from_user_script(extension.converted_from_user_script()), 2225 converted_from_user_script(extension.converted_from_user_script()),
2254 update_url(extension.update_url()) {} 2226 update_url(extension.update_url()) {}
2255 2227
2256 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2228 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698