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

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
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const std::string& relative_path) { 362 const std::string& relative_path) {
363 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); 363 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme));
364 DCHECK_EQ("/", extension_url.path()); 364 DCHECK_EQ("/", extension_url.path());
365 365
366 GURL ret_val = GURL(extension_url.spec() + relative_path); 366 GURL ret_val = GURL(extension_url.spec() + relative_path);
367 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); 367 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false));
368 368
369 return ret_val; 369 return ret_val;
370 } 370 }
371 371
372 bool Extension::CanWebAccessResource(const std::string& relative_path) const {
373 if (web_accessible_resources_.find(relative_path) !=
374 web_accessible_resources_.end())
375 return true;
376
377 return false;
378 }
379
372 bool Extension::GenerateId(const std::string& input, std::string* output) { 380 bool Extension::GenerateId(const std::string& input, std::string* output) {
373 DCHECK(output); 381 DCHECK(output);
374 uint8 hash[Extension::kIdSize]; 382 uint8 hash[Extension::kIdSize];
375 crypto::SHA256HashString(input, hash, sizeof(hash)); 383 crypto::SHA256HashString(input, hash, sizeof(hash));
376 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); 384 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
377 ConvertHexadecimalToIDAlphabet(output); 385 ConvertHexadecimalToIDAlphabet(output);
378 386
379 return true; 387 return true;
380 } 388 }
381 389
(...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 return false; // Failed to parse script context definition. 1828 return false; // Failed to parse script context definition.
1821 script.set_extension_id(id()); 1829 script.set_extension_id(id());
1822 if (converted_from_user_script_) { 1830 if (converted_from_user_script_) {
1823 script.set_emulate_greasemonkey(true); 1831 script.set_emulate_greasemonkey(true);
1824 script.set_match_all_frames(true); // Greasemonkey matches all frames. 1832 script.set_match_all_frames(true); // Greasemonkey matches all frames.
1825 } 1833 }
1826 content_scripts_.push_back(script); 1834 content_scripts_.push_back(script);
1827 } 1835 }
1828 } 1836 }
1829 1837
1838 // Initialize web accessible resources (optional).
1839 if (manifest->HasKey(keys::kWebAccessibleResources)) {
1840 ListValue* list_value;
1841 if (!manifest->GetList(keys::kWebAccessibleResources, &list_value)) {
1842 *error = errors::kInvalidWebAccessibleResourcesList;
1843 return false;
1844 }
1845 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1846 std::string relative_path;
1847 if (!list_value->GetString(i, &relative_path)) {
1848 *error = ExtensionErrorUtils::FormatErrorMessage(
1849 errors::kInvalidWebAccessibleResource, base::IntToString(i));
1850 return false;
1851 }
1852 if (relative_path[0] != '/')
1853 relative_path = '/' + relative_path;
1854 web_accessible_resources_.insert(relative_path);
1855 }
1856 }
1857
1830 // Initialize page action (optional). 1858 // Initialize page action (optional).
1831 DictionaryValue* page_action_value = NULL; 1859 DictionaryValue* page_action_value = NULL;
1832 1860
1833 if (manifest->HasKey(keys::kPageActions)) { 1861 if (manifest->HasKey(keys::kPageActions)) {
1834 ListValue* list_value = NULL; 1862 ListValue* list_value = NULL;
1835 if (!manifest->GetList(keys::kPageActions, &list_value)) { 1863 if (!manifest->GetList(keys::kPageActions, &list_value)) {
1836 *error = errors::kInvalidPageActionsList; 1864 *error = errors::kInvalidPageActionsList;
1837 return false; 1865 return false;
1838 } 1866 }
1839 1867
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 already_disabled(false), 3027 already_disabled(false),
3000 extension(extension) {} 3028 extension(extension) {}
3001 3029
3002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3030 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3003 const Extension* extension, 3031 const Extension* extension,
3004 const ExtensionPermissionSet* permissions, 3032 const ExtensionPermissionSet* permissions,
3005 Reason reason) 3033 Reason reason)
3006 : reason(reason), 3034 : reason(reason),
3007 extension(extension), 3035 extension(extension),
3008 permissions(permissions) {} 3036 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698