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

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::IsResourceWebAccessible(const std::string& relative_path)
373 const {
374 if (web_accessible_resources_.find(relative_path) !=
375 web_accessible_resources_.end())
376 return true;
377
378 return false;
379 }
380
381 bool Extension::HasWebAccessibleResources() const {
382 if (web_accessible_resources_.size())
383 return true;
384
385 return false;
386 }
387
372 bool Extension::GenerateId(const std::string& input, std::string* output) { 388 bool Extension::GenerateId(const std::string& input, std::string* output) {
373 DCHECK(output); 389 DCHECK(output);
374 uint8 hash[Extension::kIdSize]; 390 uint8 hash[Extension::kIdSize];
375 crypto::SHA256HashString(input, hash, sizeof(hash)); 391 crypto::SHA256HashString(input, hash, sizeof(hash));
376 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); 392 *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
377 ConvertHexadecimalToIDAlphabet(output); 393 ConvertHexadecimalToIDAlphabet(output);
378 394
379 return true; 395 return true;
380 } 396 }
381 397
(...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 return false; // Failed to parse script context definition. 1836 return false; // Failed to parse script context definition.
1821 script.set_extension_id(id()); 1837 script.set_extension_id(id());
1822 if (converted_from_user_script_) { 1838 if (converted_from_user_script_) {
1823 script.set_emulate_greasemonkey(true); 1839 script.set_emulate_greasemonkey(true);
1824 script.set_match_all_frames(true); // Greasemonkey matches all frames. 1840 script.set_match_all_frames(true); // Greasemonkey matches all frames.
1825 } 1841 }
1826 content_scripts_.push_back(script); 1842 content_scripts_.push_back(script);
1827 } 1843 }
1828 } 1844 }
1829 1845
1846 // Initialize web accessible resources (optional).
1847 if (manifest->HasKey(keys::kWebAccessibleResources)) {
1848 ListValue* list_value;
1849 if (!manifest->GetList(keys::kWebAccessibleResources, &list_value)) {
1850 *error = errors::kInvalidWebAccessibleResourcesList;
1851 return false;
1852 }
1853 for (size_t i = 0; i < list_value->GetSize(); ++i) {
1854 std::string relative_path;
1855 if (!list_value->GetString(i, &relative_path)) {
1856 *error = ExtensionErrorUtils::FormatErrorMessage(
1857 errors::kInvalidWebAccessibleResource, base::IntToString(i));
1858 return false;
1859 }
1860 if (relative_path[0] != '/')
1861 relative_path = '/' + relative_path;
1862 web_accessible_resources_.insert(relative_path);
1863 }
1864 }
1865
1830 // Initialize page action (optional). 1866 // Initialize page action (optional).
1831 DictionaryValue* page_action_value = NULL; 1867 DictionaryValue* page_action_value = NULL;
1832 1868
1833 if (manifest->HasKey(keys::kPageActions)) { 1869 if (manifest->HasKey(keys::kPageActions)) {
1834 ListValue* list_value = NULL; 1870 ListValue* list_value = NULL;
1835 if (!manifest->GetList(keys::kPageActions, &list_value)) { 1871 if (!manifest->GetList(keys::kPageActions, &list_value)) {
1836 *error = errors::kInvalidPageActionsList; 1872 *error = errors::kInvalidPageActionsList;
1837 return false; 1873 return false;
1838 } 1874 }
1839 1875
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 already_disabled(false), 3035 already_disabled(false),
3000 extension(extension) {} 3036 extension(extension) {}
3001 3037
3002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3038 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3003 const Extension* extension, 3039 const Extension* extension,
3004 const ExtensionPermissionSet* permissions, 3040 const ExtensionPermissionSet* permissions,
3005 Reason reason) 3041 Reason reason)
3006 : reason(reason), 3042 : reason(reason),
3007 extension(extension), 3043 extension(extension),
3008 permissions(permissions) {} 3044 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698