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