OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/manifest_handlers/settings_overrides_handler. h" | 5 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler. h" |
6 | 6 |
7 #include "base/strings/string_util.h" | |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/common/extensions/permissions/permissions_data.h" | |
10 #include "chrome/common/extensions/permissions/settings_override_permission.h" | |
8 #include "extensions/common/error_utils.h" | 11 #include "extensions/common/error_utils.h" |
9 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
13 #include "extensions/common/permissions/api_permission_set.h" | |
14 #include "extensions/common/permissions/permissions_info.h" | |
15 #include "url/gurl.h" | |
10 | 16 |
11 using extensions::api::manifest_types::ChromeSettingsOverrides; | 17 using extensions::api::manifest_types::ChromeSettingsOverrides; |
12 | 18 |
13 namespace extensions { | 19 namespace extensions { |
14 namespace { | 20 namespace { |
15 | 21 |
22 const char* kWwwPrefix = "www."; | |
23 | |
16 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { | 24 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { |
17 scoped_ptr<GURL> manifest_url(new GURL(url)); | 25 scoped_ptr<GURL> manifest_url(new GURL(url)); |
18 if (!manifest_url->is_valid() || | 26 if (!manifest_url->is_valid() || |
19 !manifest_url->SchemeIsHTTPOrHTTPS()) | 27 !manifest_url->SchemeIsHTTPOrHTTPS()) |
20 return scoped_ptr<GURL>(); | 28 return scoped_ptr<GURL>(); |
21 return manifest_url.Pass(); | 29 return manifest_url.Pass(); |
22 } | 30 } |
23 | 31 |
24 scoped_ptr<GURL> ParseHomepage(const ChromeSettingsOverrides& overrides, | 32 scoped_ptr<GURL> ParseHomepage(const ChromeSettingsOverrides& overrides, |
25 string16* error) { | 33 string16* error) { |
(...skipping 21 matching lines...) Expand all Loading... | |
47 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( | 55 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( |
48 manifest_errors::kInvalidStartupOverrideURL, *i); | 56 manifest_errors::kInvalidStartupOverrideURL, *i); |
49 } else { | 57 } else { |
50 urls.push_back(GURL()); | 58 urls.push_back(GURL()); |
51 urls.back().Swap(manifest_url.get()); | 59 urls.back().Swap(manifest_url.get()); |
52 } | 60 } |
53 } | 61 } |
54 return urls; | 62 return urls; |
55 } | 63 } |
56 | 64 |
65 // A www. prefix is not informative and thus not worth the limited real estate | |
66 // in the permissions UI. | |
67 std::string RemoveWwwPrefix(const std::string& url) { | |
68 if (StartsWithASCII(url, kWwwPrefix, false)) | |
69 return url.substr(strlen(kWwwPrefix)); | |
70 return url; | |
71 } | |
72 | |
57 } // namespace | 73 } // namespace |
58 | 74 |
59 SettingsOverrides::SettingsOverrides() {} | 75 SettingsOverrides::SettingsOverrides() {} |
60 | 76 |
61 SettingsOverrides::~SettingsOverrides() {} | 77 SettingsOverrides::~SettingsOverrides() {} |
62 | 78 |
63 const SettingsOverrides* SettingsOverrides::Get( | 79 const SettingsOverrides* SettingsOverrides::Get( |
64 const Extension* extension) { | 80 const Extension* extension) { |
65 return static_cast<SettingsOverrides*>( | 81 return static_cast<SettingsOverrides*>( |
66 extension->GetManifestData(manifest_keys::kSettingsOverride)); | 82 extension->GetManifestData(manifest_keys::kSettingsOverride)); |
(...skipping 12 matching lines...) Expand all Loading... | |
79 return false; | 95 return false; |
80 | 96 |
81 scoped_ptr<SettingsOverrides> info(new SettingsOverrides); | 97 scoped_ptr<SettingsOverrides> info(new SettingsOverrides); |
82 info->homepage = ParseHomepage(*settings, error); | 98 info->homepage = ParseHomepage(*settings, error); |
83 info->search_engine = settings->search_provider.Pass(); | 99 info->search_engine = settings->search_provider.Pass(); |
84 info->startup_pages = ParseStartupPage(*settings, error); | 100 info->startup_pages = ParseStartupPage(*settings, error); |
85 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { | 101 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { |
86 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); | 102 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); |
87 return false; | 103 return false; |
88 } | 104 } |
105 APIPermissionSet* permission_set = | |
106 PermissionsData::GetInitialAPIPermissions(extension); | |
107 DCHECK(permission_set); | |
108 if (info->search_engine) { | |
109 permission_set->insert(new SettingsOverrideAPIPermission( | |
110 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSearchSettings), | |
111 RemoveWwwPrefix(CreateManifestURL(info->search_engine->search_url)-> | |
112 GetOrigin().host()))); | |
113 } | |
114 if (!info->startup_pages.empty()) { | |
115 permission_set->insert(new SettingsOverrideAPIPermission( | |
116 PermissionsInfo::GetInstance()->GetByID(APIPermission::kStartupPages), | |
117 // We only support one startup page. | |
Yoyo Zhou
2013/11/04 22:15:50
Is this "we only support warning for one startup p
MAD
2013/11/05 01:02:06
No, we only support one startup page in the manife
| |
118 RemoveWwwPrefix(info->startup_pages[0].GetContent()))); | |
119 } | |
120 if (info->homepage) { | |
121 permission_set->insert(new SettingsOverrideAPIPermission( | |
122 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomePage), | |
123 RemoveWwwPrefix(info->homepage.get()->GetContent()))); | |
124 } | |
89 extension->SetManifestData(manifest_keys::kSettingsOverride, | 125 extension->SetManifestData(manifest_keys::kSettingsOverride, |
90 info.release()); | 126 info.release()); |
91 return true; | 127 return true; |
92 } | 128 } |
93 | 129 |
94 const std::vector<std::string> SettingsOverridesHandler::Keys() const { | 130 const std::vector<std::string> SettingsOverridesHandler::Keys() const { |
95 return SingleKey(manifest_keys::kSettingsOverride); | 131 return SingleKey(manifest_keys::kSettingsOverride); |
96 } | 132 } |
97 | 133 |
98 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |