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

Side by Side Diff: chrome/common/extensions/manifest_handlers/settings_overrides_handler.cc

Issue 71303009: Fix browser crash when parsing invalid Settings Override extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed SettingsOverridePermissionTest.* Created 7 years, 1 month 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
« no previous file with comments | « no previous file | chrome/common/extensions/manifest_handlers/settings_overrides_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/common/extensions/permissions/settings_override_permission.h" 9 #include "chrome/common/extensions/permissions/settings_override_permission.h"
10 #include "extensions/common/error_utils.h" 10 #include "extensions/common/error_utils.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( 55 *error = extensions::ErrorUtils::FormatErrorMessageUTF16(
56 manifest_errors::kInvalidStartupOverrideURL, *i); 56 manifest_errors::kInvalidStartupOverrideURL, *i);
57 } else { 57 } else {
58 urls.push_back(GURL()); 58 urls.push_back(GURL());
59 urls.back().Swap(manifest_url.get()); 59 urls.back().Swap(manifest_url.get());
60 } 60 }
61 } 61 }
62 return urls; 62 return urls;
63 } 63 }
64 64
65 scoped_ptr<ChromeSettingsOverrides::Search_provider> ParseSearchEngine(
66 ChromeSettingsOverrides* overrides,
67 string16* error) {
68 if (!overrides->search_provider)
69 return scoped_ptr<ChromeSettingsOverrides::Search_provider>();
70 if (!CreateManifestURL(overrides->search_provider->favicon_url)) {
71 *error = extensions::ErrorUtils::FormatErrorMessageUTF16(
72 manifest_errors::kInvalidSearchEngineURL,
73 overrides->search_provider->favicon_url);
74 return scoped_ptr<ChromeSettingsOverrides::Search_provider>();
75 }
76 if (!CreateManifestURL(overrides->search_provider->search_url)) {
77 *error = extensions::ErrorUtils::FormatErrorMessageUTF16(
78 manifest_errors::kInvalidSearchEngineURL,
79 overrides->search_provider->search_url);
80 return scoped_ptr<ChromeSettingsOverrides::Search_provider>();
81 }
82 return overrides->search_provider.Pass();
83 }
84
65 // A www. prefix is not informative and thus not worth the limited real estate 85 // A www. prefix is not informative and thus not worth the limited real estate
66 // in the permissions UI. 86 // in the permissions UI.
67 std::string RemoveWwwPrefix(const std::string& url) { 87 std::string RemoveWwwPrefix(const std::string& url) {
68 if (StartsWithASCII(url, kWwwPrefix, false)) 88 if (StartsWithASCII(url, kWwwPrefix, false))
69 return url.substr(strlen(kWwwPrefix)); 89 return url.substr(strlen(kWwwPrefix));
70 return url; 90 return url;
71 } 91 }
72 92
73 } // namespace 93 } // namespace
74 94
(...skipping 14 matching lines...) Expand all
89 bool SettingsOverridesHandler::Parse(Extension* extension, string16* error) { 109 bool SettingsOverridesHandler::Parse(Extension* extension, string16* error) {
90 const base::Value* dict = NULL; 110 const base::Value* dict = NULL;
91 CHECK(extension->manifest()->Get(manifest_keys::kSettingsOverride, &dict)); 111 CHECK(extension->manifest()->Get(manifest_keys::kSettingsOverride, &dict));
92 scoped_ptr<ChromeSettingsOverrides> settings( 112 scoped_ptr<ChromeSettingsOverrides> settings(
93 ChromeSettingsOverrides::FromValue(*dict, error)); 113 ChromeSettingsOverrides::FromValue(*dict, error));
94 if (!settings) 114 if (!settings)
95 return false; 115 return false;
96 116
97 scoped_ptr<SettingsOverrides> info(new SettingsOverrides); 117 scoped_ptr<SettingsOverrides> info(new SettingsOverrides);
98 info->homepage = ParseHomepage(*settings, error); 118 info->homepage = ParseHomepage(*settings, error);
99 info->search_engine = settings->search_provider.Pass(); 119 info->search_engine = ParseSearchEngine(settings.get(), error);
100 info->startup_pages = ParseStartupPage(*settings, error); 120 info->startup_pages = ParseStartupPage(*settings, error);
101 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { 121 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) {
102 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); 122 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides);
103 return false; 123 return false;
104 } 124 }
105 APIPermissionSet* permission_set = 125 APIPermissionSet* permission_set =
106 PermissionsData::GetInitialAPIPermissions(extension); 126 PermissionsData::GetInitialAPIPermissions(extension);
107 DCHECK(permission_set); 127 DCHECK(permission_set);
108 if (info->search_engine) { 128 if (info->search_engine) {
109 permission_set->insert(new SettingsOverrideAPIPermission( 129 permission_set->insert(new SettingsOverrideAPIPermission(
(...skipping 16 matching lines...) Expand all
126 extension->SetManifestData(manifest_keys::kSettingsOverride, 146 extension->SetManifestData(manifest_keys::kSettingsOverride,
127 info.release()); 147 info.release());
128 return true; 148 return true;
129 } 149 }
130 150
131 const std::vector<std::string> SettingsOverridesHandler::Keys() const { 151 const std::vector<std::string> SettingsOverridesHandler::Keys() const {
132 return SingleKey(manifest_keys::kSettingsOverride); 152 return SingleKey(manifest_keys::kSettingsOverride);
133 } 153 }
134 154
135 } // namespace extensions 155 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/manifest_handlers/settings_overrides_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698