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

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

Issue 9741002: Adding file access permissions to fileBrowserHandler manifest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit_tests Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 2310
2311 // Read the page action title from |default_title| (mandatory). 2311 // Read the page action title from |default_title| (mandatory).
2312 std::string title; 2312 std::string title;
2313 if (!file_browser_handler->HasKey(keys::kPageActionDefaultTitle) || 2313 if (!file_browser_handler->HasKey(keys::kPageActionDefaultTitle) ||
2314 !file_browser_handler->GetString(keys::kPageActionDefaultTitle, &title)) { 2314 !file_browser_handler->GetString(keys::kPageActionDefaultTitle, &title)) {
2315 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle); 2315 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle);
2316 return NULL; 2316 return NULL;
2317 } 2317 }
2318 result->set_title(title); 2318 result->set_title(title);
2319 2319
2320 // Initialize file filters (mandatory). 2320 // Initialize access permissions (optional).
2321 ListValue* list_value = NULL; 2321 ListValue* access_list_value = NULL;
2322 if (!file_browser_handler->HasKey(keys::kFileFilters) || 2322 if (file_browser_handler->HasKey(keys::kFileAccessList)) {
2323 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || 2323 if (!file_browser_handler->GetList(keys::kFileAccessList,
2324 list_value->empty()) { 2324 &access_list_value) ||
2325 *error = ASCIIToUTF16(errors::kInvalidFileFiltersList); 2325 access_list_value->empty()) {
2326 *error = ASCIIToUTF16(errors::kInvalidFileAccessList);
2327 return NULL;
2328 }
2329 for (size_t i = 0; i < access_list_value->GetSize(); ++i) {
2330 std::string access;
2331 if (!access_list_value->GetString(i, &access) ||
2332 result->AddFileAccessPermission(access)) {
2333 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
2334 errors::kInvalidFileAccessValue, base::IntToString(i));
2335 return NULL;
2336 }
2337 }
2338 }
2339 if (!result->ValidateFileAccessPermissions()) {
2340 *error = ASCIIToUTF16(errors::kInvalidFileAccessList);
2326 return NULL; 2341 return NULL;
2327 } 2342 }
2328 for (size_t i = 0; i < list_value->GetSize(); ++i) { 2343
2329 std::string filter; 2344 // Initialize file filters (mandatory, unless "create" access is specified,
2330 if (!list_value->GetString(i, &filter)) { 2345 // in which case is ignored).
2331 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 2346 if (!result->HasCreateAccessPermission()) {
2332 errors::kInvalidFileFilterValue, base::IntToString(i)); 2347 ListValue* list_value = NULL;
2348 if (!file_browser_handler->HasKey(keys::kFileFilters) ||
2349 !file_browser_handler->GetList(keys::kFileFilters, &list_value) ||
2350 list_value->empty()) {
2351 *error = ASCIIToUTF16(errors::kInvalidFileFiltersList);
2333 return NULL; 2352 return NULL;
2334 } 2353 }
2335 StringToLowerASCII(&filter); 2354 for (size_t i = 0; i < list_value->GetSize(); ++i) {
2336 URLPattern pattern(URLPattern::SCHEME_FILESYSTEM); 2355 std::string filter;
2337 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { 2356 if (!list_value->GetString(i, &filter)) {
2338 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 2357 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
2339 errors::kInvalidURLPatternError, filter); 2358 errors::kInvalidFileFilterValue, base::IntToString(i));
2340 return NULL; 2359 return NULL;
2360 }
2361 StringToLowerASCII(&filter);
2362 URLPattern pattern(URLPattern::SCHEME_FILESYSTEM);
2363 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) {
2364 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
2365 errors::kInvalidURLPatternError, filter);
2366 return NULL;
2367 }
2368 std::string path = pattern.path();
2369 bool allowed = path == "*" || path == "*.*" ||
2370 (path.compare(0, 2, "*.") == 0 &&
2371 path.find_first_of('*', 2) == std::string::npos);
2372 if (!allowed) {
2373 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
2374 errors::kInvalidURLPatternError, filter);
2375 return NULL;
2376 }
2377 result->AddPattern(pattern);
2341 } 2378 }
2342 std::string path = pattern.path();
2343 bool allowed = path == "*" || path == "*.*" ||
2344 (path.compare(0, 2, "*.") == 0 &&
2345 path.find_first_of('*', 2) == std::string::npos);
2346 if (!allowed) {
2347 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
2348 errors::kInvalidURLPatternError, filter);
2349 return NULL;
2350 }
2351 result->AddPattern(pattern);
2352 } 2379 }
2353 2380
2354 std::string default_icon; 2381 std::string default_icon;
2355 // Read the file browser action |default_icon| (optional). 2382 // Read the file browser action |default_icon| (optional).
2356 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { 2383 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) {
2357 if (!file_browser_handler->GetString( 2384 if (!file_browser_handler->GetString(
2358 keys::kPageActionDefaultIcon, &default_icon) || 2385 keys::kPageActionDefaultIcon, &default_icon) ||
2359 default_icon.empty()) { 2386 default_icon.empty()) {
2360 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 2387 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
2361 return NULL; 2388 return NULL;
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3540 already_disabled(false), 3567 already_disabled(false),
3541 extension(extension) {} 3568 extension(extension) {}
3542 3569
3543 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3570 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3544 const Extension* extension, 3571 const Extension* extension,
3545 const ExtensionPermissionSet* permissions, 3572 const ExtensionPermissionSet* permissions,
3546 Reason reason) 3573 Reason reason)
3547 : reason(reason), 3574 : reason(reason),
3548 extension(extension), 3575 extension(extension),
3549 permissions(permissions) {} 3576 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_handler_util.cc ('k') | chrome/common/extensions/extension_manifest_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698