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

Side by Side Diff: chrome/browser/plugins/plugin_finder.cc

Issue 1093153003: Handle malformed built-in PluginFinder data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix and rebase Created 5 years, 7 months 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/plugins/plugin_finder.h" 5 #include "chrome/browser/plugins/plugin_finder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/plugins/plugin_metadata.h" 18 #include "chrome/browser/plugins/plugin_metadata.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/plugin_service.h" 21 #include "content/public/browser/plugin_service.h"
21 #include "grit/browser_resources.h" 22 #include "grit/browser_resources.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 #if defined(ENABLE_PLUGIN_INSTALLATION) 26 #if defined(ENABLE_PLUGIN_INSTALLATION)
26 #include "chrome/browser/plugins/plugin_installer.h" 27 #include "chrome/browser/plugins/plugin_installer.h"
27 #endif 28 #endif
28 29
29 using base::DictionaryValue; 30 using base::DictionaryValue;
30 using content::PluginService; 31 using content::PluginService;
31 32
32 namespace { 33 namespace {
33 34
34 typedef std::map<std::string, PluginMetadata*> PluginMap; 35 typedef std::map<std::string, PluginMetadata*> PluginMap;
35 36
37 // Do not change these values, as they are used in UMA.
38 enum class PluginListError {
39 // NO_ERROR is defined by Windows headers.
40 PLUGIN_LIST_NO_ERROR = 0,
41 JSON_INVALID_ESCAPE = 1,
42 JSON_SYNTAX_ERROR = 2,
43 JSON_UNEXPECTED_TOKEN = 3,
44 JSON_TRAILING_COMMA = 4,
45 JSON_TOO_MUCH_NESTING = 5,
46 JSON_UNEXPECTED_DATA_AFTER_ROOT = 5,
47 JSON_UNSUPPORTED_ENCODING = 6,
48 JSON_UNQUOTED_DICTIONARY_KEY = 7,
49 SCHEMA_ERROR = 8,
50 NUM_VALUES
51 };
52
36 // Gets the full path of the plugin file as the identifier. 53 // Gets the full path of the plugin file as the identifier.
37 std::string GetLongIdentifier(const content::WebPluginInfo& plugin) { 54 std::string GetLongIdentifier(const content::WebPluginInfo& plugin) {
38 return plugin.path.AsUTF8Unsafe(); 55 return plugin.path.AsUTF8Unsafe();
39 } 56 }
40 57
41 // Gets the base name of the file path as the identifier. 58 // Gets the base name of the file path as the identifier.
42 std::string GetIdentifier(const content::WebPluginInfo& plugin) { 59 std::string GetIdentifier(const content::WebPluginInfo& plugin) {
43 return plugin.path.BaseName().AsUTF8Unsafe(); 60 return plugin.path.BaseName().AsUTF8Unsafe();
44 } 61 }
45 62
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(success); 138 DCHECK(success);
122 plugin->AddVersion(Version(version), status); 139 plugin->AddVersion(Version(version), status);
123 } 140 }
124 } 141 }
125 142
126 LoadMimeTypes(false, plugin_dict, plugin); 143 LoadMimeTypes(false, plugin_dict, plugin);
127 LoadMimeTypes(true, plugin_dict, plugin); 144 LoadMimeTypes(true, plugin_dict, plugin);
128 return plugin; 145 return plugin;
129 } 146 }
130 147
148 void RecordBuiltInPluginListError(PluginListError error_code) {
149 UMA_HISTOGRAM_ENUMERATION("PluginFinder.BuiltInPluginList.ErrorCode",
150 static_cast<int>(error_code),
151 static_cast<int>(PluginListError::NUM_VALUES));
152 }
153
131 } // namespace 154 } // namespace
132 155
133 // static 156 // static
134 void PluginFinder::RegisterPrefs(PrefRegistrySimple* registry) { 157 void PluginFinder::RegisterPrefs(PrefRegistrySimple* registry) {
135 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false); 158 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
136 } 159 }
137 160
138 // static 161 // static
139 PluginFinder* PluginFinder::GetInstance() { 162 PluginFinder* PluginFinder::GetInstance() {
140 // PluginFinder::GetInstance() is the only method that's allowed to call 163 // PluginFinder::GetInstance() is the only method that's allowed to call
141 // Singleton<PluginFinder>::get(). 164 // Singleton<PluginFinder>::get().
142 return Singleton<PluginFinder>::get(); 165 return Singleton<PluginFinder>::get();
143 } 166 }
144 167
145 PluginFinder::PluginFinder() : version_(-1) { 168 PluginFinder::PluginFinder() : version_(-1) {
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
147 } 170 }
148 171
149 void PluginFinder::Init() { 172 void PluginFinder::Init() {
150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 173 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
151 // Load the built-in plugin list first. If we have a newer version stored 174 // Load the built-in plugin list first. If we have a newer version stored
152 // locally or download one, we will replace this one with it. 175 // locally or download one, we will replace this one with it.
153 scoped_ptr<base::DictionaryValue> plugin_list(LoadBuiltInPluginList()); 176 scoped_ptr<base::DictionaryValue> plugin_list(LoadBuiltInPluginList());
154 DCHECK(plugin_list); 177
178 // Gracefully handle the case where we couldn't parse the built-in plugin list
179 // for some reason (https://crbug.com/388560). TODO(bauerb): Change back to a
180 // DCHECK once we have gathered more data about the underlying problem.
181 if (!plugin_list)
182 return;
183
155 ReinitializePlugins(plugin_list.get()); 184 ReinitializePlugins(plugin_list.get());
156 } 185 }
157 186
158 // static 187 // static
159 base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() { 188 base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() {
160 base::StringPiece json_resource( 189 base::StringPiece json_resource(
161 ResourceBundle::GetSharedInstance().GetRawDataResource( 190 ResourceBundle::GetSharedInstance().GetRawDataResource(
162 IDR_PLUGIN_DB_JSON)); 191 IDR_PLUGIN_DB_JSON));
163 std::string error_str; 192 std::string error_str;
193 int error_code = base::JSONReader::JSON_NO_ERROR;
164 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( 194 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError(
165 json_resource, 195 json_resource, base::JSON_PARSE_RFC, &error_code, &error_str));
166 base::JSON_PARSE_RFC, 196 if (!value) {
167 NULL,
168 &error_str));
169 if (!value.get()) {
170 DLOG(ERROR) << error_str; 197 DLOG(ERROR) << error_str;
171 return NULL; 198 switch (error_code) {
199 case base::JSONReader::JSON_INVALID_ESCAPE:
200 RecordBuiltInPluginListError(PluginListError::JSON_INVALID_ESCAPE);
201 break;
202 case base::JSONReader::JSON_SYNTAX_ERROR:
203 RecordBuiltInPluginListError(PluginListError::JSON_SYNTAX_ERROR);
204 break;
205 case base::JSONReader::JSON_UNEXPECTED_TOKEN:
206 RecordBuiltInPluginListError(PluginListError::JSON_UNEXPECTED_TOKEN);
207 break;
208 case base::JSONReader::JSON_TRAILING_COMMA:
209 RecordBuiltInPluginListError(PluginListError::JSON_TRAILING_COMMA);
210 break;
211 case base::JSONReader::JSON_TOO_MUCH_NESTING:
212 RecordBuiltInPluginListError(PluginListError::JSON_TOO_MUCH_NESTING);
213 break;
214 case base::JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT:
215 RecordBuiltInPluginListError(
216 PluginListError::JSON_UNEXPECTED_DATA_AFTER_ROOT);
217 break;
218 case base::JSONReader::JSON_UNSUPPORTED_ENCODING:
219 RecordBuiltInPluginListError(
220 PluginListError::JSON_UNSUPPORTED_ENCODING);
221 break;
222 case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY:
223 RecordBuiltInPluginListError(
224 PluginListError::JSON_UNQUOTED_DICTIONARY_KEY);
225 break;
226 case base::JSONReader::JSON_NO_ERROR:
227 case base::JSONReader::JSON_PARSE_ERROR_COUNT:
228 NOTREACHED();
229 break;
230 }
231 return nullptr;
172 } 232 }
173 if (value->GetType() != base::Value::TYPE_DICTIONARY) 233
174 return NULL; 234 if (value->GetType() != base::Value::TYPE_DICTIONARY) {
235 // JSONReader::JSON_PARSE_ERROR_COUNT is used for the case where the JSON
236 // value has the wrong type.
237 RecordBuiltInPluginListError(PluginListError::SCHEMA_ERROR);
238 return nullptr;
239 }
240
241 DCHECK_EQ(base::JSONReader::JSON_NO_ERROR, error_code);
242 RecordBuiltInPluginListError(PluginListError::PLUGIN_LIST_NO_ERROR);
175 return static_cast<base::DictionaryValue*>(value.release()); 243 return static_cast<base::DictionaryValue*>(value.release());
176 } 244 }
177 245
178 PluginFinder::~PluginFinder() { 246 PluginFinder::~PluginFinder() {
179 #if defined(ENABLE_PLUGIN_INSTALLATION) 247 #if defined(ENABLE_PLUGIN_INSTALLATION)
180 STLDeleteValues(&installers_); 248 STLDeleteValues(&installers_);
181 #endif 249 #endif
182 STLDeleteValues(&identifier_plugin_); 250 STLDeleteValues(&identifier_plugin_);
183 } 251 }
184 252
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); 362 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type);
295 363
296 DCHECK(metadata->MatchesPlugin(plugin)); 364 DCHECK(metadata->MatchesPlugin(plugin));
297 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) 365 if (identifier_plugin_.find(identifier) != identifier_plugin_.end())
298 identifier = GetLongIdentifier(plugin); 366 identifier = GetLongIdentifier(plugin);
299 367
300 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); 368 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end());
301 identifier_plugin_[identifier] = metadata; 369 identifier_plugin_[identifier] = metadata;
302 return metadata->Clone(); 370 return metadata->Clone();
303 } 371 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698