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

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

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 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) 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 int loc2_rank = GetLocationRank(loc2); 279 int loc2_rank = GetLocationRank(loc2);
280 280
281 // If two different locations have the same rank, then we can not 281 // If two different locations have the same rank, then we can not
282 // deterministicly choose a location. 282 // deterministicly choose a location.
283 CHECK(loc1_rank != loc2_rank); 283 CHECK(loc1_rank != loc2_rank);
284 284
285 // Lowest rank has highest priority. 285 // Lowest rank has highest priority.
286 return (loc1_rank > loc2_rank ? loc1 : loc2 ); 286 return (loc1_rank > loc2_rank ? loc1 : loc2 );
287 } 287 }
288 288
289 ExtensionPermissionMessages Extension::GetPermissionMessages() const {
290 if (IsTrustedId(id_))
291 return ExtensionPermissionMessages();
292 else
293 return permission_set_->GetPermissionMessages();
294 }
295
296 std::vector<string16> Extension::GetPermissionMessageStrings() const {
297 if (IsTrustedId(id_))
298 return std::vector<string16>();
299 else
300 return permission_set_->GetWarningMessages();
301 }
302
303 void Extension::OverrideLaunchUrl(const GURL& override_url) { 289 void Extension::OverrideLaunchUrl(const GURL& override_url) {
304 GURL new_url(override_url); 290 GURL new_url(override_url);
305 if (!new_url.is_valid()) { 291 if (!new_url.is_valid()) {
306 LOG(WARNING) << "Invalid override url given for " << name(); 292 LOG(WARNING) << "Invalid override url given for " << name();
307 } else { 293 } else {
308 if (new_url.has_port()) { 294 if (new_url.has_port()) {
309 LOG(WARNING) << "Override URL passed for " << name() 295 LOG(WARNING) << "Override URL passed for " << name()
310 << " should not contain a port. Removing it."; 296 << " should not contain a port. Removing it.";
311 297
312 GURL::Replacements remove_port; 298 GURL::Replacements remove_port;
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, 1176 bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest,
1191 std::string* error) { 1177 std::string* error) {
1192 if (web_extent().is_empty()) 1178 if (web_extent().is_empty())
1193 return true; 1179 return true;
1194 1180
1195 for (DictionaryValue::key_iterator key = manifest->begin_keys(); 1181 for (DictionaryValue::key_iterator key = manifest->begin_keys();
1196 key != manifest->end_keys(); ++key) { 1182 key != manifest->end_keys(); ++key) {
1197 if (!IsBaseCrxKey(*key) && 1183 if (!IsBaseCrxKey(*key) &&
1198 *key != keys::kApp && 1184 *key != keys::kApp &&
1199 *key != keys::kPermissions && 1185 *key != keys::kPermissions &&
1186 *key != keys::kOptionalPermissions &&
1200 *key != keys::kOptionsPage && 1187 *key != keys::kOptionsPage &&
1201 *key != keys::kBackground) { 1188 *key != keys::kBackground) {
1202 *error = ExtensionErrorUtils::FormatErrorMessage( 1189 *error = ExtensionErrorUtils::FormatErrorMessage(
1203 errors::kHostedAppsCannotIncludeExtensionFeatures, *key); 1190 errors::kHostedAppsCannotIncludeExtensionFeatures, *key);
1204 return false; 1191 return false;
1205 } 1192 }
1206 } 1193 }
1207 1194
1208 return true; 1195 return true;
1209 } 1196 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 } 1360 }
1374 } 1361 }
1375 1362
1376 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { 1363 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) {
1377 return GURL(std::string(chrome::kExtensionScheme) + 1364 return GURL(std::string(chrome::kExtensionScheme) +
1378 chrome::kStandardSchemeSeparator + extension_id + "/"); 1365 chrome::kStandardSchemeSeparator + extension_id + "/");
1379 } 1366 }
1380 1367
1381 bool Extension::InitFromValue(const DictionaryValue& source, int flags, 1368 bool Extension::InitFromValue(const DictionaryValue& source, int flags,
1382 std::string* error) { 1369 std::string* error) {
1370 base::AutoLock auto_lock(runtime_data_lock_);
1383 // When strict error checks are enabled, make URL pattern parsing strict. 1371 // When strict error checks are enabled, make URL pattern parsing strict.
1384 URLPattern::ParseOption parse_strictness = 1372 URLPattern::ParseOption parse_strictness =
1385 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS 1373 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS
1386 : URLPattern::IGNORE_PORTS); 1374 : URLPattern::IGNORE_PORTS);
1387 1375
1388 // Initialize permissions with an empty, default permission set. 1376 // Initialize permissions with an empty, default permission set.
1389 permission_set_.reset(new ExtensionPermissionSet()); 1377 runtime_data_.SetActivePermissions(new ExtensionPermissionSet());
1378 optional_permission_set_.reset(new ExtensionPermissionSet());
1379 required_permission_set_.reset(new ExtensionPermissionSet());
1390 1380
1391 if (source.HasKey(keys::kPublicKey)) { 1381 if (source.HasKey(keys::kPublicKey)) {
1392 std::string public_key_bytes; 1382 std::string public_key_bytes;
1393 if (!source.GetString(keys::kPublicKey, 1383 if (!source.GetString(keys::kPublicKey,
1394 &public_key_) || 1384 &public_key_) ||
1395 !ParsePEMKeyBytes(public_key_, 1385 !ParsePEMKeyBytes(public_key_,
1396 &public_key_bytes) || 1386 &public_key_bytes) ||
1397 !GenerateId(public_key_bytes, &id_)) { 1387 !GenerateId(public_key_bytes, &id_)) {
1398 *error = errors::kInvalidKey; 1388 *error = errors::kInvalidKey;
1399 return false; 1389 return false;
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 return false; 1891 return false;
1902 } 1892 }
1903 options_url_ = GetResourceURL(options_str); 1893 options_url_ = GetResourceURL(options_str);
1904 if (!options_url_.is_valid()) { 1894 if (!options_url_.is_valid()) {
1905 *error = errors::kInvalidOptionsPage; 1895 *error = errors::kInvalidOptionsPage;
1906 return false; 1896 return false;
1907 } 1897 }
1908 } 1898 }
1909 } 1899 }
1910 1900
1901 // Initialize the permissions (optional).
1911 ExtensionAPIPermissionSet api_permissions; 1902 ExtensionAPIPermissionSet api_permissions;
1912 URLPatternSet host_permissions; 1903 URLPatternSet host_permissions;
1904 if (!ParsePermissions(&source,
1905 keys::kPermissions,
1906 flags,
1907 error,
1908 &api_permissions,
1909 &host_permissions)) {
1910 return false;
1911 }
1913 1912
1914 // Initialize the permissions (optional). 1913 // Initialize the optional permissions (optional).
1915 if (source.HasKey(keys::kPermissions)) { 1914 ExtensionAPIPermissionSet optional_api_permissions;
1916 ListValue* permissions = NULL; 1915 URLPatternSet optional_host_permissions;
1917 if (!source.GetList(keys::kPermissions, &permissions)) { 1916 if (!ParsePermissions(&source,
1918 *error = ExtensionErrorUtils::FormatErrorMessage( 1917 keys::kOptionalPermissions,
1919 errors::kInvalidPermissions, ""); 1918 flags,
1920 return false; 1919 error,
1921 } 1920 &optional_api_permissions,
1922 1921 &optional_host_permissions)) {
1923 for (size_t i = 0; i < permissions->GetSize(); ++i) { 1922 return false;
1924 std::string permission_str;
1925 if (!permissions->GetString(i, &permission_str)) {
1926 *error = ExtensionErrorUtils::FormatErrorMessage(
1927 errors::kInvalidPermission, base::IntToString(i));
1928 return false;
1929 }
1930
1931 ExtensionAPIPermission* permission =
1932 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str);
1933
1934 // Only COMPONENT extensions can use private APIs.
1935 // TODO(asargent) - We want a more general purpose mechanism for this,
1936 // and better error messages. (http://crbug.com/54013)
1937 if (!IsComponentOnlyPermission(permission)
1938 #ifndef NDEBUG
1939 && !CommandLine::ForCurrentProcess()->HasSwitch(
1940 switches::kExposePrivateExtensionApi)
1941 #endif
1942 ) {
1943 continue;
1944 }
1945
1946 if (web_extent().is_empty() || location() == Extension::COMPONENT) {
1947 // Check if it's a module permission. If so, enable that permission.
1948 if (permission != NULL) {
1949 // Only allow the experimental API permission if the command line
1950 // flag is present, or if the extension is a component of Chrome.
1951 if (IsDisallowedExperimentalPermission(permission->id()) &&
1952 location() != Extension::COMPONENT) {
1953 *error = errors::kExperimentalFlagRequired;
1954 return false;
1955 }
1956 api_permissions.insert(permission->id());
1957 continue;
1958 }
1959 } else {
1960 // Hosted apps only get access to a subset of the valid permissions.
1961 if (permission != NULL && permission->is_hosted_app()) {
1962 if (IsDisallowedExperimentalPermission(permission->id())) {
1963 *error = errors::kExperimentalFlagRequired;
1964 return false;
1965 }
1966 api_permissions.insert(permission->id());
1967 continue;
1968 }
1969 }
1970
1971 // Check if it's a host pattern permission.
1972 URLPattern pattern = URLPattern(CanExecuteScriptEverywhere() ?
1973 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes);
1974
1975 URLPattern::ParseResult parse_result = pattern.Parse(permission_str,
1976 parse_strictness);
1977 if (parse_result == URLPattern::PARSE_SUCCESS) {
1978 if (!CanSpecifyHostPermission(pattern)) {
1979 *error = ExtensionErrorUtils::FormatErrorMessage(
1980 errors::kInvalidPermissionScheme, base::IntToString(i));
1981 return false;
1982 }
1983
1984 // The path component is not used for host permissions, so we force it
1985 // to match all paths.
1986 pattern.SetPath("/*");
1987
1988 if (pattern.MatchesScheme(chrome::kFileScheme) &&
1989 !CanExecuteScriptEverywhere()) {
1990 wants_file_access_ = true;
1991 if (!(flags & ALLOW_FILE_ACCESS))
1992 pattern.SetValidSchemes(
1993 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
1994 }
1995
1996 host_permissions.AddPattern(pattern);
1997 }
1998
1999 // If it's not a host permission, then it's probably an unknown API
2000 // permission. Do not throw an error so extensions can retain
2001 // backwards compatability (http://crbug.com/42742).
2002 // TODO(jstritar): We can improve error messages by adding better
2003 // validation of API permissions here.
2004 // TODO(skerner): Consider showing the reason |permission_str| is not
2005 // a valid URL pattern if it is almost valid. For example, if it has
2006 // a valid scheme, and failed to parse because it has a port, show an
2007 // error.
2008 }
2009 } 1923 }
2010 1924
2011 // Initialize background url (optional). 1925 // Initialize background url (optional).
2012 if (source.HasKey(keys::kBackground)) { 1926 if (source.HasKey(keys::kBackground)) {
2013 std::string background_str; 1927 std::string background_str;
2014 if (!source.GetString(keys::kBackground, &background_str)) { 1928 if (!source.GetString(keys::kBackground, &background_str)) {
2015 *error = errors::kInvalidBackground; 1929 *error = errors::kInvalidBackground;
2016 return false; 1930 return false;
2017 } 1931 }
2018 1932
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 *error = errors::kInvalidIncognitoBehavior; 2298 *error = errors::kInvalidIncognitoBehavior;
2385 return false; 2299 return false;
2386 } 2300 }
2387 } 2301 }
2388 2302
2389 if (HasMultipleUISurfaces()) { 2303 if (HasMultipleUISurfaces()) {
2390 *error = errors::kOneUISurfaceOnly; 2304 *error = errors::kOneUISurfaceOnly;
2391 return false; 2305 return false;
2392 } 2306 }
2393 2307
2394 permission_set_.reset( 2308 runtime_data_.SetActivePermissions(new ExtensionPermissionSet(
2309 this, api_permissions, host_permissions));
2310 required_permission_set_.reset(
2395 new ExtensionPermissionSet(this, api_permissions, host_permissions)); 2311 new ExtensionPermissionSet(this, api_permissions, host_permissions));
2312 optional_permission_set_.reset(
2313 new ExtensionPermissionSet(optional_api_permissions,
2314 optional_host_permissions,
2315 URLPatternSet()));
2396 2316
2397 // Although |source| is passed in as a const, it's still possible to modify 2317 // Although |source| is passed in as a const, it's still possible to modify
2398 // it. This is dangerous since the utility process re-uses |source| after 2318 // it. This is dangerous since the utility process re-uses |source| after
2399 // it calls InitFromValue, passing it up to the browser process which calls 2319 // it calls InitFromValue, passing it up to the browser process which calls
2400 // InitFromValue again. As a result, we need to make sure that nobody 2320 // InitFromValue again. As a result, we need to make sure that nobody
2401 // accidentally modifies it. 2321 // accidentally modifies it.
2402 DCHECK(source.Equals(manifest_value_.get())); 2322 DCHECK(source.Equals(manifest_value_.get()));
2403 2323
2404 return true; 2324 return true;
2405 } 2325 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 2483
2564 GURL Extension::GetIconURL(int size, 2484 GURL Extension::GetIconURL(int size,
2565 ExtensionIconSet::MatchType match_type) const { 2485 ExtensionIconSet::MatchType match_type) const {
2566 std::string path = icons().Get(size, match_type); 2486 std::string path = icons().Get(size, match_type);
2567 if (path.empty()) 2487 if (path.empty())
2568 return GURL(); 2488 return GURL();
2569 else 2489 else
2570 return GetResourceURL(path); 2490 return GetResourceURL(path);
2571 } 2491 }
2572 2492
2493 bool Extension::ParsePermissions(const DictionaryValue* source,
2494 const char* key,
2495 int flags,
2496 std::string* error,
2497 ExtensionAPIPermissionSet* api_permissions,
2498 URLPatternSet* host_permissions) {
2499 if (source->HasKey(key)) {
2500 // When strict error checks are enabled, make URL pattern parsing strict.
2501 URLPattern::ParseOption parse_strictness =
2502 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS
2503 : URLPattern::IGNORE_PORTS);
2504 ListValue* permissions = NULL;
2505 if (!source->GetList(key, &permissions)) {
2506 LOG(INFO) << "BLAH1: " << key;
Mihai Parparita -not on Chrome 2011/07/21 21:18:13 Did you want to keep this logging statement?
jstritar 2011/07/22 19:21:55 Done.
2507 *error = ExtensionErrorUtils::FormatErrorMessage(
2508 errors::kInvalidPermissions, "");
2509 return false;
2510 }
2511
2512 for (size_t i = 0; i < permissions->GetSize(); ++i) {
2513 std::string permission_str;
2514 if (!permissions->GetString(i, &permission_str)) {
2515 LOG(INFO) << "BLAH2: " << key;
Mihai Parparita -not on Chrome 2011/07/21 21:18:13 Ditto.
jstritar 2011/07/22 19:21:55 Done.
2516 *error = ExtensionErrorUtils::FormatErrorMessage(
2517 errors::kInvalidPermission, base::IntToString(i));
2518 return false;
2519 }
2520
2521 ExtensionAPIPermission* permission =
2522 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str);
2523
2524 // Only COMPONENT extensions can use private APIs.
2525 // TODO(asargent) - We want a more general purpose mechanism for this,
2526 // and better error messages. (http://crbug.com/54013)
2527 if (!IsComponentOnlyPermission(permission)
2528 #ifndef NDEBUG
2529 && !CommandLine::ForCurrentProcess()->HasSwitch(
2530 switches::kExposePrivateExtensionApi)
2531 #endif
2532 ) {
2533 continue;
2534 }
2535
2536 if (web_extent().is_empty() || location() == Extension::COMPONENT) {
2537 // Check if it's a module permission. If so, enable that permission.
2538 if (permission != NULL) {
2539 // Only allow the experimental API permission if the command line
2540 // flag is present, or if the extension is a component of Chrome.
2541 if (IsDisallowedExperimentalPermission(permission->id()) &&
2542 location() != Extension::COMPONENT) {
2543 *error = errors::kExperimentalFlagRequired;
2544 return false;
2545 }
2546 api_permissions->insert(permission->id());
2547 continue;
2548 }
2549 } else {
2550 // Hosted apps only get access to a subset of the valid permissions.
2551 if (permission != NULL && permission->is_hosted_app()) {
2552 if (IsDisallowedExperimentalPermission(permission->id())) {
2553 *error = errors::kExperimentalFlagRequired;
2554 return false;
2555 }
2556 api_permissions->insert(permission->id());
2557 continue;
2558 }
2559 }
2560
2561 // Check if it's a host pattern permission.
2562 URLPattern pattern = URLPattern(CanExecuteScriptEverywhere() ?
2563 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes);
2564
2565 URLPattern::ParseResult parse_result = pattern.Parse(permission_str,
2566 parse_strictness);
2567 if (parse_result == URLPattern::PARSE_SUCCESS) {
2568 if (!CanSpecifyHostPermission(pattern)) {
2569 *error = ExtensionErrorUtils::FormatErrorMessage(
2570 errors::kInvalidPermissionScheme, base::IntToString(i));
2571 return false;
2572 }
2573
2574 // The path component is not used for host permissions, so we force it
2575 // to match all paths.
2576 pattern.SetPath("/*");
2577
2578 if (pattern.MatchesScheme(chrome::kFileScheme) &&
2579 !CanExecuteScriptEverywhere()) {
2580 wants_file_access_ = true;
2581 if (!(flags & ALLOW_FILE_ACCESS))
2582 pattern.SetValidSchemes(
2583 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
2584 }
2585
2586 host_permissions->AddPattern(pattern);
2587 }
2588
2589 // If it's not a host permission, then it's probably an unknown API
2590 // permission. Do not throw an error so extensions can retain
2591 // backwards compatability (http://crbug.com/42742).
2592 // TODO(jstritar): We can improve error messages by adding better
2593 // validation of API permissions here.
2594 // TODO(skerner): Consider showing the reason |permission_str| is not
2595 // a valid URL pattern if it is almost valid. For example, if it has
2596 // a valid scheme, and failed to parse because it has a port, show an
2597 // error.
2598 }
2599 }
2600 return true;
2601 }
2602
2573 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern) const { 2603 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern) const {
2574 if (!pattern.match_all_urls() && 2604 if (!pattern.match_all_urls() &&
2575 pattern.MatchesScheme(chrome::kChromeUIScheme)) { 2605 pattern.MatchesScheme(chrome::kChromeUIScheme)) {
2576 // Only allow access to chrome://favicon to regular extensions. Component 2606 // Only allow access to chrome://favicon to regular extensions. Component
2577 // extensions can have access to all of chrome://*. 2607 // extensions can have access to all of chrome://*.
2578 return (pattern.host() == chrome::kChromeUIFaviconHost || 2608 return (pattern.host() == chrome::kChromeUIFaviconHost ||
2579 CanExecuteScriptEverywhere()); 2609 CanExecuteScriptEverywhere());
2580 } 2610 }
2581 2611
2582 // Otherwise, the valid schemes were handled by URLPattern. 2612 // Otherwise, the valid schemes were handled by URLPattern.
2583 return true; 2613 return true;
2584 } 2614 }
2585 2615
2586 bool Extension::HasAPIPermission( 2616 bool Extension::HasAPIPermission(
2587 ExtensionAPIPermission::ID permission) const { 2617 ExtensionAPIPermission::ID permission) const {
2588 return permission_set()->HasAPIPermission(permission); 2618 base::AutoLock auto_lock(runtime_data_lock_);
2619 return runtime_data_.GetActivePermissions()->HasAPIPermission(permission);
2589 } 2620 }
2590 2621
2591 bool Extension::HasAPIPermission( 2622 bool Extension::HasAPIPermission(
2592 const std::string& function_name) const { 2623 const std::string& function_name) const {
2593 return permission_set()->HasAccessToFunction(function_name); 2624 base::AutoLock auto_lock(runtime_data_lock_);
2625 return runtime_data_.GetActivePermissions()->
2626 HasAccessToFunction(function_name);
2594 } 2627 }
2595 2628
2596 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { 2629 const URLPatternSet& Extension::GetEffectiveHostPermissions() const {
2597 return permission_set()->effective_hosts(); 2630 base::AutoLock auto_lock(runtime_data_lock_);
2631 return runtime_data_.GetActivePermissions()->effective_hosts();
2598 } 2632 }
2599 2633
2600 bool Extension::HasHostPermission(const GURL& url) const { 2634 bool Extension::HasHostPermission(const GURL& url) const {
2635 base::AutoLock auto_lock(runtime_data_lock_);
2601 if (url.SchemeIs(chrome::kChromeUIScheme) && 2636 if (url.SchemeIs(chrome::kChromeUIScheme) &&
2602 url.host() != chrome::kChromeUIFaviconHost && 2637 url.host() != chrome::kChromeUIFaviconHost &&
2603 location() != Extension::COMPONENT) 2638 location() != Extension::COMPONENT)
2604 return false; 2639 return false;
2605 return permission_set()->HasExplicitAccessToOrigin(url); 2640 return runtime_data_.GetActivePermissions()->
2641 HasExplicitAccessToOrigin(url);
2642 }
2643
2644 bool Extension::HasEffectiveAccessToAllHosts() const {
2645 base::AutoLock auto_lock(runtime_data_lock_);
2646 return runtime_data_.GetActivePermissions()->HasEffectiveAccessToAllHosts();
2647 }
2648
2649 bool Extension::HasFullPermissions() const {
2650 base::AutoLock auto_lock(runtime_data_lock_);
2651 return runtime_data_.GetActivePermissions()->HasEffectiveFullAccess();
2652 }
2653
2654 ExtensionPermissionMessages Extension::GetPermissionMessages() const {
2655 base::AutoLock auto_lock(runtime_data_lock_);
2656 if (IsTrustedId(id_))
2657 return ExtensionPermissionMessages();
2658 else
2659 return runtime_data_.GetActivePermissions()->GetPermissionMessages();
2660 }
2661
2662 std::vector<string16> Extension::GetPermissionMessageStrings() const {
2663 base::AutoLock auto_lock(runtime_data_lock_);
2664 if (IsTrustedId(id_))
2665 return std::vector<string16>();
2666 else
2667 return runtime_data_.GetActivePermissions()->GetWarningMessages();
2668 }
2669
2670 void Extension::SetActivePermissions(
2671 const ExtensionPermissionSet* permissions) const {
2672 base::AutoLock auto_lock(runtime_data_lock_);
2673 runtime_data_.SetActivePermissions(permissions);
2674 }
2675
2676 scoped_refptr<const ExtensionPermissionSet>
2677 Extension::GetActivePermissions() const {
2678 base::AutoLock auto_lock(runtime_data_lock_);
2679 return runtime_data_.GetActivePermissions();
2606 } 2680 }
2607 2681
2608 bool Extension::IsComponentOnlyPermission( 2682 bool Extension::IsComponentOnlyPermission(
2609 const ExtensionAPIPermission* api) const { 2683 const ExtensionAPIPermission* api) const {
2610 if (location() == Extension::COMPONENT) 2684 if (location() == Extension::COMPONENT)
2611 return true; 2685 return true;
2612 2686
2613 if (api == NULL) 2687 if (api == NULL)
2614 return true; 2688 return true;
2615 2689
(...skipping 11 matching lines...) Expand all
2627 2701
2628 if (is_app()) 2702 if (is_app())
2629 ++num_surfaces; 2703 ++num_surfaces;
2630 2704
2631 return num_surfaces > 1; 2705 return num_surfaces > 1;
2632 } 2706 }
2633 2707
2634 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, 2708 bool Extension::CanExecuteScriptOnPage(const GURL& page_url,
2635 const UserScript* script, 2709 const UserScript* script,
2636 std::string* error) const { 2710 std::string* error) const {
2711 base::AutoLock auto_lock(runtime_data_lock_);
2637 // The gallery is special-cased as a restricted URL for scripting to prevent 2712 // The gallery is special-cased as a restricted URL for scripting to prevent
2638 // access to special JS bindings we expose to the gallery (and avoid things 2713 // access to special JS bindings we expose to the gallery (and avoid things
2639 // like extensions removing the "report abuse" link). 2714 // like extensions removing the "report abuse" link).
2640 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing 2715 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing
2641 // against the store app extent? 2716 // against the store app extent?
2642 if ((page_url.host() == GURL(Extension::ChromeStoreLaunchURL()).host()) && 2717 if ((page_url.host() == GURL(Extension::ChromeStoreLaunchURL()).host()) &&
2643 !CanExecuteScriptEverywhere() && 2718 !CanExecuteScriptEverywhere() &&
2644 !CommandLine::ForCurrentProcess()->HasSwitch( 2719 !CommandLine::ForCurrentProcess()->HasSwitch(
2645 switches::kAllowScriptingGallery)) { 2720 switches::kAllowScriptingGallery)) {
2646 if (error) 2721 if (error)
2647 *error = errors::kCannotScriptGallery; 2722 *error = errors::kCannotScriptGallery;
2648 return false; 2723 return false;
2649 } 2724 }
2650 2725
2651 if (page_url.SchemeIs(chrome::kChromeUIScheme) && 2726 if (page_url.SchemeIs(chrome::kChromeUIScheme) &&
2652 !CanExecuteScriptEverywhere()) 2727 !CanExecuteScriptEverywhere())
2653 return false; 2728 return false;
2654 2729
2655 // If a script is specified, use its matches. 2730 // If a script is specified, use its matches.
2656 if (script) 2731 if (script)
2657 return script->MatchesURL(page_url); 2732 return script->MatchesURL(page_url);
2658 2733
2659 // Otherwise, see if this extension has permission to execute script 2734 // Otherwise, see if this extension has permission to execute script
2660 // programmatically on pages. 2735 // programmatically on pages.
2661 if (permission_set()->HasExplicitAccessToOrigin(page_url)) 2736 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin(
2737 page_url))
2662 return true; 2738 return true;
2663 2739
2664 if (error) { 2740 if (error) {
2665 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, 2741 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage,
2666 page_url.spec()); 2742 page_url.spec());
2667 } 2743 }
2668 2744
2669 return false; 2745 return false;
2670 } 2746 }
2671 2747
2672 bool Extension::HasEffectiveAccessToAllHosts() const {
2673 return permission_set_->HasEffectiveAccessToAllHosts();
2674 }
2675
2676 bool Extension::HasFullPermissions() const {
2677 return permission_set_->HasEffectiveFullAccess();
2678 }
2679
2680 bool Extension::ShowConfigureContextMenus() const { 2748 bool Extension::ShowConfigureContextMenus() const {
2681 // Don't show context menu for component extensions. We might want to show 2749 // Don't show context menu for component extensions. We might want to show
2682 // options for component extension button but now there is no component 2750 // options for component extension button but now there is no component
2683 // extension with options. All other menu items like uninstall have 2751 // extension with options. All other menu items like uninstall have
2684 // no sense for component extensions. 2752 // no sense for component extensions.
2685 return location() != Extension::COMPONENT; 2753 return location() != Extension::COMPONENT;
2686 } 2754 }
2687 2755
2688 bool Extension::IsDisallowedExperimentalPermission( 2756 bool Extension::IsDisallowedExperimentalPermission(
2689 ExtensionAPIPermission::ID permission) const { 2757 ExtensionAPIPermission::ID permission) const {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2757 Extension::Location location) 2825 Extension::Location location)
2758 : extension_id(id), 2826 : extension_id(id),
2759 extension_path(path), 2827 extension_path(path),
2760 extension_location(location) { 2828 extension_location(location) {
2761 if (manifest) 2829 if (manifest)
2762 extension_manifest.reset(manifest->DeepCopy()); 2830 extension_manifest.reset(manifest->DeepCopy());
2763 } 2831 }
2764 2832
2765 ExtensionInfo::~ExtensionInfo() {} 2833 ExtensionInfo::~ExtensionInfo() {}
2766 2834
2835 Extension::RuntimeData::RuntimeData() {}
2836 Extension::RuntimeData::RuntimeData(const ExtensionPermissionSet* active)
2837 : active_permissions_(active) {}
2838 Extension::RuntimeData::~RuntimeData() {}
2839
2840 scoped_refptr<const ExtensionPermissionSet>
2841 Extension::RuntimeData::GetActivePermissions() const {
2842 return active_permissions_;
2843 }
2844
2845 void Extension::RuntimeData::SetActivePermissions(
2846 const ExtensionPermissionSet* active) {
2847 active_permissions_ = active;
2848 }
2849
2767 UninstalledExtensionInfo::UninstalledExtensionInfo( 2850 UninstalledExtensionInfo::UninstalledExtensionInfo(
2768 const Extension& extension) 2851 const Extension& extension)
2769 : extension_id(extension.id()), 2852 : extension_id(extension.id()),
2770 extension_api_permissions( 2853 extension_api_permissions(
2771 extension.permission_set()->GetAPIsAsStrings()), 2854 extension.GetActivePermissions()->GetAPIsAsStrings()),
2772 extension_type(extension.GetType()), 2855 extension_type(extension.GetType()),
2773 update_url(extension.update_url()) {} 2856 update_url(extension.update_url()) {}
2774 2857
2775 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2858 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
2776 2859
2777 2860
2778 UnloadedExtensionInfo::UnloadedExtensionInfo( 2861 UnloadedExtensionInfo::UnloadedExtensionInfo(
2779 const Extension* extension, 2862 const Extension* extension,
2780 Reason reason) 2863 Reason reason)
2781 : reason(reason), 2864 : reason(reason),
2782 already_disabled(false), 2865 already_disabled(false),
2783 extension(extension) {} 2866 extension(extension) {}
2867
2868 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
2869 const Extension* extension,
2870 const ExtensionPermissionSet* permissions,
2871 Reason reason)
2872 : reason(reason),
2873 extension(extension),
2874 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698