1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/common/extensions/extension.h" 6 #include "chrome/common/extensions/permissions/api_permission_set.h" 7 #include "chrome/common/extensions/permissions/chrome_scheme_hosts.h" 8 #include "chrome/common/url_constants.h" 9 #include "extensions/common/url_pattern.h" 10 #include "extensions/common/url_pattern_set.h" 11 #include "grit/generated_resources.h" 12 #include "ui/base/l10n/l10n_util.h" 13 14 namespace { 15 const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh"; 16 } // namespace 17 18 namespace extensions { 19 20 PermissionMessages GetChromeSchemePermissionWarnings( 21 const URLPatternSet& hosts) { 22 PermissionMessages messages; 23 for (URLPatternSet::const_iterator i = hosts.begin(); 24 i != hosts.end(); ++i) { 25 if (i->scheme() != chrome::kChromeUIScheme) 26 continue; 27 // chrome://favicon is the only URL for chrome:// scheme that we 28 // want to support. We want to deprecate the "chrome" scheme. 29 // We should not add any additional "host" here. 30 if (GURL(chrome::kChromeUIFaviconURL).host() != i->host()) 31 continue; 32 messages.push_back(PermissionMessage( 33 PermissionMessage::kFavicon, 34 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FAVICON))); 35 break; 36 } 37 return messages; 38 } 39 40 URLPatternSet GetPermittedChromeSchemeHosts( 41 const Extension* extension, 42 const APIPermissionSet& api_permissions) { 43 URLPatternSet hosts; 44 // Regular extensions are only allowed access to chrome://favicon. 45 hosts.AddPattern(URLPattern(URLPattern::SCHEME_CHROMEUI, 46 chrome::kChromeUIFaviconURL)); 47 48 // Experimental extensions are also allowed chrome://thumb. 49 // 50 // TODO: A public API should be created for retrieving thumbnails. 51 // See http://crbug.com/222856. A temporary hack is implemented here to 52 // make chrome://thumbs available to NTP Russia extension as 53 // non-experimental. 54 if ((api_permissions.find(APIPermission::kExperimental) != 55 api_permissions.end()) || 56 (extension->id() == kThumbsWhiteListedExtension && 57 extension->from_webstore())) { 58 hosts.AddPattern(URLPattern(URLPattern::SCHEME_CHROMEUI, 59 chrome::kChromeUIThumbnailURL)); 60 } 61 return hosts; 62 } 63 64 } // namespace extensions 65