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

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

Issue 12213093: Remove ImageLoadingTracker class (Closed) Base URL: https://git.chromium.org/chromium/src.git@Issue_163929
Patch Set: Fix merge conflict Created 7 years, 10 months 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_resource.h » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 *target = 0; 182 *target = 0;
183 *error = ErrorUtils::FormatErrorMessageUTF16( 183 *error = ErrorUtils::FormatErrorMessageUTF16(
184 errors::kInvalidLaunchValue, 184 errors::kInvalidLaunchValue,
185 key); 185 key);
186 return false; 186 return false;
187 } 187 }
188 } 188 }
189 return true; 189 return true;
190 } 190 }
191 191
192 std::string SizeToString(const gfx::Size& max_size) {
193 return base::IntToString(max_size.width()) + "x" +
194 base::IntToString(max_size.height());
195 }
196
197 bool ContainsManifestForbiddenPermission(const APIPermissionSet& apis, 192 bool ContainsManifestForbiddenPermission(const APIPermissionSet& apis,
198 string16* error) { 193 string16* error) {
199 CHECK(error); 194 CHECK(error);
200 for (APIPermissionSet::const_iterator i = apis.begin(); 195 for (APIPermissionSet::const_iterator i = apis.begin();
201 i != apis.end(); ++i) { 196 i != apis.end(); ++i) {
202 if ((*i)->ManifestEntryForbidden()) { 197 if ((*i)->ManifestEntryForbidden()) {
203 *error = ErrorUtils::FormatErrorMessageUTF16( 198 *error = ErrorUtils::FormatErrorMessageUTF16(
204 errors::kPermissionNotAllowedInManifest, 199 errors::kPermissionNotAllowedInManifest,
205 (*i)->info()->name()); 200 (*i)->info()->name());
206 return true; 201 return true;
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 ExtensionIconSet::MatchType match_type) const { 859 ExtensionIconSet::MatchType match_type) const {
865 std::string path = icons().Get(size, match_type); 860 std::string path = icons().Get(size, match_type);
866 return path.empty() ? GURL() : GetResourceURL(path); 861 return path.empty() ? GURL() : GetResourceURL(path);
867 } 862 }
868 863
869 GURL Extension::GetFullLaunchURL() const { 864 GURL Extension::GetFullLaunchURL() const {
870 return launch_local_path().empty() ? GURL(launch_web_url()) : 865 return launch_local_path().empty() ? GURL(launch_web_url()) :
871 url().Resolve(launch_local_path()); 866 url().Resolve(launch_local_path());
872 } 867 }
873 868
874 void Extension::SetCachedImage(const ExtensionResource& source,
875 const SkBitmap& image,
876 const gfx::Size& original_size) const {
877 DCHECK(source.extension_root() == path()); // The resource must come from
878 // this extension.
879 const base::FilePath& path = source.relative_path();
880 gfx::Size actual_size(image.width(), image.height());
881 std::string location;
882 if (actual_size != original_size)
883 location = SizeToString(actual_size);
884 image_cache_[ImageCacheKey(path, location)] = image;
885 }
886
887 bool Extension::HasCachedImage(const ExtensionResource& source,
888 const gfx::Size& max_size) const {
889 DCHECK(source.extension_root() == path()); // The resource must come from
890 // this extension.
891 return GetCachedImageImpl(source, max_size) != NULL;
892 }
893
894 SkBitmap Extension::GetCachedImage(const ExtensionResource& source,
895 const gfx::Size& max_size) const {
896 DCHECK(source.extension_root() == path()); // The resource must come from
897 // this extension.
898 SkBitmap* image = GetCachedImageImpl(source, max_size);
899 return image ? *image : SkBitmap();
900 }
901
902 bool Extension::CanExecuteScriptOnPage(const GURL& document_url, 869 bool Extension::CanExecuteScriptOnPage(const GURL& document_url,
903 const GURL& top_frame_url, 870 const GURL& top_frame_url,
904 int tab_id, 871 int tab_id,
905 const UserScript* script, 872 const UserScript* script,
906 std::string* error) const { 873 std::string* error) const {
907 base::AutoLock auto_lock(runtime_data_lock_); 874 base::AutoLock auto_lock(runtime_data_lock_);
908 // The gallery is special-cased as a restricted URL for scripting to prevent 875 // The gallery is special-cased as a restricted URL for scripting to prevent
909 // access to special JS bindings we expose to the gallery (and avoid things 876 // access to special JS bindings we expose to the gallery (and avoid things
910 // like extensions removing the "report abuse" link). 877 // like extensions removing the "report abuse" link).
911 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing 878 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 // TODO(abarth): Should we continue to let extensions override the 2414 // TODO(abarth): Should we continue to let extensions override the
2448 // default Content-Security-Policy? 2415 // default Content-Security-Policy?
2449 content_security_policy_ = is_platform_app() ? 2416 content_security_policy_ = is_platform_app() ?
2450 kDefaultPlatformAppContentSecurityPolicy : 2417 kDefaultPlatformAppContentSecurityPolicy :
2451 kDefaultContentSecurityPolicy; 2418 kDefaultContentSecurityPolicy;
2452 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); 2419 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType()));
2453 } 2420 }
2454 return true; 2421 return true;
2455 } 2422 }
2456 2423
2457 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source,
2458 const gfx::Size& max_size) const {
2459 const base::FilePath& path = source.relative_path();
2460
2461 // Look for exact size match.
2462 ImageCache::iterator i = image_cache_.find(
2463 ImageCacheKey(path, SizeToString(max_size)));
2464 if (i != image_cache_.end())
2465 return &(i->second);
2466
2467 // If we have the original size version cached, return that if it's small
2468 // enough.
2469 i = image_cache_.find(ImageCacheKey(path, std::string()));
2470 if (i != image_cache_.end()) {
2471 const SkBitmap& image = i->second;
2472 if (image.width() <= max_size.width() &&
2473 image.height() <= max_size.height()) {
2474 return &(i->second);
2475 }
2476 }
2477
2478 return NULL;
2479 }
2480
2481 // Helper method that loads a UserScript object from a dictionary in the 2424 // Helper method that loads a UserScript object from a dictionary in the
2482 // content_script list of the manifest. 2425 // content_script list of the manifest.
2483 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, 2426 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
2484 int definition_index, 2427 int definition_index,
2485 string16* error, 2428 string16* error,
2486 UserScript* result) { 2429 UserScript* result) {
2487 // run_at 2430 // run_at
2488 if (content_script->HasKey(keys::kRunAt)) { 2431 if (content_script->HasKey(keys::kRunAt)) {
2489 std::string run_location; 2432 std::string run_location;
2490 if (!content_script->GetString(keys::kRunAt, &run_location)) { 2433 if (!content_script->GetString(keys::kRunAt, &run_location)) {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 2835
2893 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 2836 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2894 const Extension* extension, 2837 const Extension* extension,
2895 const PermissionSet* permissions, 2838 const PermissionSet* permissions,
2896 Reason reason) 2839 Reason reason)
2897 : reason(reason), 2840 : reason(reason),
2898 extension(extension), 2841 extension(extension),
2899 permissions(permissions) {} 2842 permissions(permissions) {}
2900 2843
2901 } // namespace extensions 2844 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698