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

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

Issue 8849010: Add 'web_accessible_resource" keyword for version 2 extension manifests. This makes extension res... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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') | chrome/common/extensions/extension_constants.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 const std::string& relative_path) { 369 const std::string& relative_path) {
370 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); 370 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme));
371 DCHECK_EQ("/", extension_url.path()); 371 DCHECK_EQ("/", extension_url.path());
372 372
373 GURL ret_val = GURL(extension_url.spec() + relative_path); 373 GURL ret_val = GURL(extension_url.spec() + relative_path);
374 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); 374 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false));
375 375
376 return ret_val; 376 return ret_val;
377 } 377 }
378 378
379 bool Extension::IsResourceWebAccessible(const std::string& relative_path)
380 const {
381 // For old manifest versions which do not specify web_accessible_resources
382 // we always allow resource loads.
383 if (manifest_version() < 2 && !HasWebAccessibleResources())
384 return true;
385
386 if (web_accessible_resources_.find(relative_path) !=
387 web_accessible_resources_.end())
388 return true;
389
390 return false;
391 }
392
393 bool Extension::HasWebAccessibleResources() const {
394 if (web_accessible_resources_.size())
395 return true;
396
397 return false;
398 }
399
379 bool Extension::GenerateId(const std::string& input, std::string* output) { 400 bool Extension::GenerateId(const std::string& input, std::string* output) {
380 DCHECK(output); 401 DCHECK(output);
381 uint8 hash[Extension::kIdSize]; 402 uint8 hash[Extension::kIdSize];
382 crypto::SHA256HashString(input, hash, sizeof(hash)); 403 crypto::SHA256HashString(input, hash, sizeof(hash));
383 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); 404 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
384 ConvertHexadecimalToIDAlphabet(output); 405 ConvertHexadecimalToIDAlphabet(output);
385 406
386 return true; 407 return true;
387 } 408 }
388 409
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 return false; // Failed to parse script context definition. 1846 return false; // Failed to parse script context definition.
1826 script.set_extension_id(id()); 1847 script.set_extension_id(id());
1827 if (converted_from_user_script_) { 1848 if (converted_from_user_script_) {
1828 script.set_emulate_greasemonkey(true); 1849 script.set_emulate_greasemonkey(true);
1829 script.set_match_all_frames(true); // Greasemonkey matches all frames. 1850 script.set_match_all_frames(true); // Greasemonkey matches all frames.
1830 } 1851 }
1831 content_scripts_.push_back(script); 1852 content_scripts_.push_back(script);
1832 } 1853 }
1833 } 1854 }
1834 1855
1856 // Initialize web accessible resources (optional).
1857 if (manifest->HasKey(keys::kWebAccessibleResources)) {
1858 ListValue* list_value;
1859 if (!manifest->GetList(keys::kWebAccessibleResources, &list_value)) {
1860 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList);
1861 return false;
1862 }
1863 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1864 std::string relative_path;
1865 if (!list_value->GetString(i, &relative_path)) {
1866 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1867 errors::kInvalidWebAccessibleResource, base::IntToString(i));
1868 return false;
1869 }
1870 if (relative_path[0] != '/')
1871 relative_path = '/' + relative_path;
1872 web_accessible_resources_.insert(relative_path);
1873 }
1874 }
1875
1835 // Initialize page action (optional). 1876 // Initialize page action (optional).
1836 DictionaryValue* page_action_value = NULL; 1877 DictionaryValue* page_action_value = NULL;
1837 1878
1838 if (manifest->HasKey(keys::kPageActions)) { 1879 if (manifest->HasKey(keys::kPageActions)) {
1839 ListValue* list_value = NULL; 1880 ListValue* list_value = NULL;
1840 if (!manifest->GetList(keys::kPageActions, &list_value)) { 1881 if (!manifest->GetList(keys::kPageActions, &list_value)) {
1841 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); 1882 *error = ASCIIToUTF16(errors::kInvalidPageActionsList);
1842 return false; 1883 return false;
1843 } 1884 }
1844 1885
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2975 already_disabled(false), 3016 already_disabled(false),
2976 extension(extension) {} 3017 extension(extension) {}
2977 3018
2978 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3019 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2979 const Extension* extension, 3020 const Extension* extension,
2980 const ExtensionPermissionSet* permissions, 3021 const ExtensionPermissionSet* permissions,
2981 Reason reason) 3022 Reason reason)
2982 : reason(reason), 3023 : reason(reason),
2983 extension(extension), 3024 extension(extension),
2984 permissions(permissions) {} 3025 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698