| 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 <utility> |
| 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
| 13 #include "extensions/common/extension_set.h" | 15 #include "extensions/common/extension_set.h" |
| 14 #include "extensions/common/feature_switch.h" | 16 #include "extensions/common/feature_switch.h" |
| 15 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
| 16 #include "extensions/common/manifest_handlers/permissions_parser.h" | 18 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 namespace extensions { | 29 namespace extensions { |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 const char kWwwPrefix[] = "www."; | 32 const char kWwwPrefix[] = "www."; |
| 31 | 33 |
| 32 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { | 34 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { |
| 33 scoped_ptr<GURL> manifest_url(new GURL(url)); | 35 scoped_ptr<GURL> manifest_url(new GURL(url)); |
| 34 if (!manifest_url->is_valid() || | 36 if (!manifest_url->is_valid() || |
| 35 !manifest_url->SchemeIsHTTPOrHTTPS()) | 37 !manifest_url->SchemeIsHTTPOrHTTPS()) |
| 36 return scoped_ptr<GURL>(); | 38 return scoped_ptr<GURL>(); |
| 37 return manifest_url.Pass(); | 39 return manifest_url; |
| 38 } | 40 } |
| 39 | 41 |
| 40 scoped_ptr<GURL> ParseHomepage(const ChromeSettingsOverrides& overrides, | 42 scoped_ptr<GURL> ParseHomepage(const ChromeSettingsOverrides& overrides, |
| 41 base::string16* error) { | 43 base::string16* error) { |
| 42 if (!overrides.homepage) | 44 if (!overrides.homepage) |
| 43 return scoped_ptr<GURL>(); | 45 return scoped_ptr<GURL>(); |
| 44 scoped_ptr<GURL> manifest_url = CreateManifestURL(*overrides.homepage); | 46 scoped_ptr<GURL> manifest_url = CreateManifestURL(*overrides.homepage); |
| 45 if (!manifest_url) { | 47 if (!manifest_url) { |
| 46 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( | 48 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( |
| 47 manifest_errors::kInvalidHomepageOverrideURL, *overrides.homepage); | 49 manifest_errors::kInvalidHomepageOverrideURL, *overrides.homepage); |
| 48 } | 50 } |
| 49 return manifest_url.Pass(); | 51 return manifest_url; |
| 50 } | 52 } |
| 51 | 53 |
| 52 std::vector<GURL> ParseStartupPage(const ChromeSettingsOverrides& overrides, | 54 std::vector<GURL> ParseStartupPage(const ChromeSettingsOverrides& overrides, |
| 53 base::string16* error) { | 55 base::string16* error) { |
| 54 std::vector<GURL> urls; | 56 std::vector<GURL> urls; |
| 55 if (!overrides.startup_pages) | 57 if (!overrides.startup_pages) |
| 56 return urls; | 58 return urls; |
| 57 | 59 |
| 58 for (std::vector<std::string>::const_iterator i = | 60 for (std::vector<std::string>::const_iterator i = |
| 59 overrides.startup_pages->begin(); i != overrides.startup_pages->end(); | 61 overrides.startup_pages->begin(); i != overrides.startup_pages->end(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 base::string16* error) { | 77 base::string16* error) { |
| 76 if (!overrides->search_provider) | 78 if (!overrides->search_provider) |
| 77 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); | 79 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); |
| 78 if (!CreateManifestURL(overrides->search_provider->search_url)) { | 80 if (!CreateManifestURL(overrides->search_provider->search_url)) { |
| 79 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( | 81 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( |
| 80 manifest_errors::kInvalidSearchEngineURL, | 82 manifest_errors::kInvalidSearchEngineURL, |
| 81 overrides->search_provider->search_url); | 83 overrides->search_provider->search_url); |
| 82 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); | 84 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); |
| 83 } | 85 } |
| 84 if (overrides->search_provider->prepopulated_id) | 86 if (overrides->search_provider->prepopulated_id) |
| 85 return overrides->search_provider.Pass(); | 87 return std::move(overrides->search_provider); |
| 86 if (!overrides->search_provider->name || | 88 if (!overrides->search_provider->name || |
| 87 !overrides->search_provider->keyword || | 89 !overrides->search_provider->keyword || |
| 88 !overrides->search_provider->encoding || | 90 !overrides->search_provider->encoding || |
| 89 !overrides->search_provider->favicon_url) { | 91 !overrides->search_provider->favicon_url) { |
| 90 *error = | 92 *error = |
| 91 base::ASCIIToUTF16(manifest_errors::kInvalidSearchEngineMissingKeys); | 93 base::ASCIIToUTF16(manifest_errors::kInvalidSearchEngineMissingKeys); |
| 92 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); | 94 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); |
| 93 } | 95 } |
| 94 if (!CreateManifestURL(*overrides->search_provider->favicon_url)) { | 96 if (!CreateManifestURL(*overrides->search_provider->favicon_url)) { |
| 95 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( | 97 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( |
| 96 manifest_errors::kInvalidSearchEngineURL, | 98 manifest_errors::kInvalidSearchEngineURL, |
| 97 *overrides->search_provider->favicon_url); | 99 *overrides->search_provider->favicon_url); |
| 98 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); | 100 return scoped_ptr<ChromeSettingsOverrides::Search_provider>(); |
| 99 } | 101 } |
| 100 return overrides->search_provider.Pass(); | 102 return std::move(overrides->search_provider); |
| 101 } | 103 } |
| 102 | 104 |
| 103 // A www. prefix is not informative and thus not worth the limited real estate | 105 // A www. prefix is not informative and thus not worth the limited real estate |
| 104 // in the permissions UI. | 106 // in the permissions UI. |
| 105 std::string RemoveWwwPrefix(const std::string& url) { | 107 std::string RemoveWwwPrefix(const std::string& url) { |
| 106 if (base::StartsWith(url, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII)) | 108 if (base::StartsWith(url, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII)) |
| 107 return url.substr(strlen(kWwwPrefix)); | 109 return url.substr(strlen(kWwwPrefix)); |
| 108 return url; | 110 return url; |
| 109 } | 111 } |
| 110 | 112 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 extension->SetManifestData(manifest_keys::kSettingsOverride, | 178 extension->SetManifestData(manifest_keys::kSettingsOverride, |
| 177 info.release()); | 179 info.release()); |
| 178 return true; | 180 return true; |
| 179 } | 181 } |
| 180 | 182 |
| 181 const std::vector<std::string> SettingsOverridesHandler::Keys() const { | 183 const std::vector<std::string> SettingsOverridesHandler::Keys() const { |
| 182 return SingleKey(manifest_keys::kSettingsOverride); | 184 return SingleKey(manifest_keys::kSettingsOverride); |
| 183 } | 185 } |
| 184 | 186 |
| 185 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |