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

Side by Side Diff: webkit/plugins/npapi/plugin_list.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/npapi/plugin_list.h ('k') | webkit/plugins/npapi/plugin_list_mac.mm » ('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 "webkit/plugins/npapi/plugin_list.h" 5 #include "webkit/plugins/npapi/plugin_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool PluginList::DebugPluginLoading() { 79 bool PluginList::DebugPluginLoading() {
80 return CommandLine::ForCurrentProcess()->HasSwitch( 80 return CommandLine::ForCurrentProcess()->HasSwitch(
81 switches::kDebugPluginLoading); 81 switches::kDebugPluginLoading);
82 } 82 }
83 83
84 void PluginList::RefreshPlugins() { 84 void PluginList::RefreshPlugins() {
85 base::AutoLock lock(lock_); 85 base::AutoLock lock(lock_);
86 loading_state_ = LOADING_STATE_NEEDS_REFRESH; 86 loading_state_ = LOADING_STATE_NEEDS_REFRESH;
87 } 87 }
88 88
89 void PluginList::AddExtraPluginPath(const FilePath& plugin_path) { 89 void PluginList::AddExtraPluginPath(const base::FilePath& plugin_path) {
90 if (!NPAPIPluginsSupported()) { 90 if (!NPAPIPluginsSupported()) {
91 // TODO(jam): remove and just have CHECK once we're sure this doesn't get 91 // TODO(jam): remove and just have CHECK once we're sure this doesn't get
92 // triggered. 92 // triggered.
93 DLOG(INFO) << "NPAPI plugins not supported"; 93 DLOG(INFO) << "NPAPI plugins not supported";
94 return; 94 return;
95 } 95 }
96 96
97 // Chrome OS only loads plugins from /opt/google/chrome/plugins. 97 // Chrome OS only loads plugins from /opt/google/chrome/plugins.
98 #if !defined(OS_CHROMEOS) 98 #if !defined(OS_CHROMEOS)
99 base::AutoLock lock(lock_); 99 base::AutoLock lock(lock_);
100 extra_plugin_paths_.push_back(plugin_path); 100 extra_plugin_paths_.push_back(plugin_path);
101 #endif 101 #endif
102 } 102 }
103 103
104 void PluginList::RemoveExtraPluginPath(const FilePath& plugin_path) { 104 void PluginList::RemoveExtraPluginPath(const base::FilePath& plugin_path) {
105 base::AutoLock lock(lock_); 105 base::AutoLock lock(lock_);
106 std::vector<FilePath>::iterator it = 106 std::vector<base::FilePath>::iterator it =
107 std::find(extra_plugin_paths_.begin(), extra_plugin_paths_.end(), 107 std::find(extra_plugin_paths_.begin(), extra_plugin_paths_.end(),
108 plugin_path); 108 plugin_path);
109 if (it != extra_plugin_paths_.end()) 109 if (it != extra_plugin_paths_.end())
110 extra_plugin_paths_.erase(it); 110 extra_plugin_paths_.erase(it);
111 } 111 }
112 112
113 void PluginList::AddExtraPluginDir(const FilePath& plugin_dir) { 113 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) {
114 // Chrome OS only loads plugins from /opt/google/chrome/plugins. 114 // Chrome OS only loads plugins from /opt/google/chrome/plugins.
115 #if !defined(OS_CHROMEOS) 115 #if !defined(OS_CHROMEOS)
116 base::AutoLock lock(lock_); 116 base::AutoLock lock(lock_);
117 extra_plugin_dirs_.push_back(plugin_dir); 117 extra_plugin_dirs_.push_back(plugin_dir);
118 #endif 118 #endif
119 } 119 }
120 120
121 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, 121 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info,
122 bool add_at_beginning) { 122 bool add_at_beginning) {
123 PluginEntryPoints entry_points = {0}; 123 PluginEntryPoints entry_points = {0};
(...skipping 17 matching lines...) Expand all
141 internal_plugins_.push_back(plugin); 141 internal_plugins_.push_back(plugin);
142 if (add_at_beginning) { 142 if (add_at_beginning) {
143 // Newer registrations go earlier in the list so they can override the MIME 143 // Newer registrations go earlier in the list so they can override the MIME
144 // types of older registrations. 144 // types of older registrations.
145 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path); 145 extra_plugin_paths_.insert(extra_plugin_paths_.begin(), info.path);
146 } else { 146 } else {
147 extra_plugin_paths_.push_back(info.path); 147 extra_plugin_paths_.push_back(info.path);
148 } 148 }
149 } 149 }
150 150
151 void PluginList::UnregisterInternalPlugin(const FilePath& path) { 151 void PluginList::UnregisterInternalPlugin(const base::FilePath& path) {
152 base::AutoLock lock(lock_); 152 base::AutoLock lock(lock_);
153 for (size_t i = 0; i < internal_plugins_.size(); i++) { 153 for (size_t i = 0; i < internal_plugins_.size(); i++) {
154 if (internal_plugins_[i].info.path == path) { 154 if (internal_plugins_[i].info.path == path) {
155 internal_plugins_.erase(internal_plugins_.begin() + i); 155 internal_plugins_.erase(internal_plugins_.begin() + i);
156 return; 156 return;
157 } 157 }
158 } 158 }
159 NOTREACHED(); 159 NOTREACHED();
160 } 160 }
161 161
162 void PluginList::GetInternalPlugins( 162 void PluginList::GetInternalPlugins(
163 std::vector<webkit::WebPluginInfo>* internal_plugins) { 163 std::vector<webkit::WebPluginInfo>* internal_plugins) {
164 base::AutoLock lock(lock_); 164 base::AutoLock lock(lock_);
165 165
166 for (std::vector<InternalPlugin>::iterator it = internal_plugins_.begin(); 166 for (std::vector<InternalPlugin>::iterator it = internal_plugins_.begin();
167 it != internal_plugins_.end(); 167 it != internal_plugins_.end();
168 ++it) { 168 ++it) {
169 internal_plugins->push_back(it->info); 169 internal_plugins->push_back(it->info);
170 } 170 }
171 } 171 }
172 172
173 bool PluginList::ReadPluginInfo(const FilePath& filename, 173 bool PluginList::ReadPluginInfo(const base::FilePath& filename,
174 webkit::WebPluginInfo* info, 174 webkit::WebPluginInfo* info,
175 const PluginEntryPoints** entry_points) { 175 const PluginEntryPoints** entry_points) {
176 { 176 {
177 base::AutoLock lock(lock_); 177 base::AutoLock lock(lock_);
178 for (size_t i = 0; i < internal_plugins_.size(); ++i) { 178 for (size_t i = 0; i < internal_plugins_.size(); ++i) {
179 if (filename == internal_plugins_[i].info.path) { 179 if (filename == internal_plugins_[i].info.path) {
180 *entry_points = &internal_plugins_[i].entry_points; 180 *entry_points = &internal_plugins_[i].entry_points;
181 *info = internal_plugins_[i].info; 181 *info = internal_plugins_[i].info;
182 return true; 182 return true;
183 } 183 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void PluginList::LoadPluginsIntoPluginListInternal( 245 void PluginList::LoadPluginsIntoPluginListInternal(
246 std::vector<webkit::WebPluginInfo>* plugins) { 246 std::vector<webkit::WebPluginInfo>* plugins) {
247 base::Closure will_load_callback; 247 base::Closure will_load_callback;
248 { 248 {
249 base::AutoLock lock(lock_); 249 base::AutoLock lock(lock_);
250 will_load_callback = will_load_plugins_callback_; 250 will_load_callback = will_load_plugins_callback_;
251 } 251 }
252 if (!will_load_callback.is_null()) 252 if (!will_load_callback.is_null())
253 will_load_callback.Run(); 253 will_load_callback.Run();
254 254
255 std::vector<FilePath> plugin_paths; 255 std::vector<base::FilePath> plugin_paths;
256 GetPluginPathsToLoad(&plugin_paths); 256 GetPluginPathsToLoad(&plugin_paths);
257 257
258 for (std::vector<FilePath>::const_iterator it = plugin_paths.begin(); 258 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin();
259 it != plugin_paths.end(); 259 it != plugin_paths.end();
260 ++it) { 260 ++it) {
261 WebPluginInfo plugin_info; 261 WebPluginInfo plugin_info;
262 LoadPluginIntoPluginList(*it, plugins, &plugin_info); 262 LoadPluginIntoPluginList(*it, plugins, &plugin_info);
263 } 263 }
264 } 264 }
265 265
266 void PluginList::LoadPlugins() { 266 void PluginList::LoadPlugins() {
267 { 267 {
268 base::AutoLock lock(lock_); 268 base::AutoLock lock(lock_);
(...skipping 10 matching lines...) Expand all
279 base::AutoLock lock(lock_); 279 base::AutoLock lock(lock_);
280 plugins_list_.swap(new_plugins); 280 plugins_list_.swap(new_plugins);
281 281
282 // If we haven't been invalidated in the mean time, mark the plug-in list as 282 // If we haven't been invalidated in the mean time, mark the plug-in list as
283 // up-to-date. 283 // up-to-date.
284 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) 284 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH)
285 loading_state_ = LOADING_STATE_UP_TO_DATE; 285 loading_state_ = LOADING_STATE_UP_TO_DATE;
286 } 286 }
287 287
288 bool PluginList::LoadPluginIntoPluginList( 288 bool PluginList::LoadPluginIntoPluginList(
289 const FilePath& path, 289 const base::FilePath& path,
290 std::vector<webkit::WebPluginInfo>* plugins, 290 std::vector<webkit::WebPluginInfo>* plugins,
291 WebPluginInfo* plugin_info) { 291 WebPluginInfo* plugin_info) {
292 LOG_IF(ERROR, PluginList::DebugPluginLoading()) 292 LOG_IF(ERROR, PluginList::DebugPluginLoading())
293 << "Loading plugin " << path.value(); 293 << "Loading plugin " << path.value();
294 const PluginEntryPoints* entry_points; 294 const PluginEntryPoints* entry_points;
295 295
296 if (!ReadPluginInfo(path, plugin_info, &entry_points)) 296 if (!ReadPluginInfo(path, plugin_info, &entry_points))
297 return false; 297 return false;
298 298
299 if (!ShouldLoadPluginUsingPluginList(*plugin_info, plugins)) 299 if (!ShouldLoadPluginUsingPluginList(*plugin_info, plugins))
300 return false; 300 return false;
301 301
302 #if defined(OS_WIN) && !defined(NDEBUG) 302 #if defined(OS_WIN) && !defined(NDEBUG)
303 if (path.BaseName().value() != L"npspy.dll") // Make an exception for NPSPY 303 if (path.BaseName().value() != L"npspy.dll") // Make an exception for NPSPY
304 #endif 304 #endif
305 { 305 {
306 for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) { 306 for (size_t i = 0; i < plugin_info->mime_types.size(); ++i) {
307 // TODO: don't load global handlers for now. 307 // TODO: don't load global handlers for now.
308 // WebKit hands to the Plugin before it tries 308 // WebKit hands to the Plugin before it tries
309 // to handle mimeTypes on its own. 309 // to handle mimeTypes on its own.
310 const std::string &mime_type = plugin_info->mime_types[i].mime_type; 310 const std::string &mime_type = plugin_info->mime_types[i].mime_type;
311 if (mime_type == "*") 311 if (mime_type == "*")
312 return false; 312 return false;
313 } 313 }
314 } 314 }
315 plugins->push_back(*plugin_info); 315 plugins->push_back(*plugin_info);
316 return true; 316 return true;
317 } 317 }
318 318
319 void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) { 319 void PluginList::GetPluginPathsToLoad(std::vector<base::FilePath>* plugin_paths) {
320 // Don't want to hold the lock while loading new plugins, so we don't block 320 // Don't want to hold the lock while loading new plugins, so we don't block
321 // other methods if they're called on other threads. 321 // other methods if they're called on other threads.
322 std::vector<FilePath> extra_plugin_paths; 322 std::vector<base::FilePath> extra_plugin_paths;
323 std::vector<FilePath> extra_plugin_dirs; 323 std::vector<base::FilePath> extra_plugin_dirs;
324 { 324 {
325 base::AutoLock lock(lock_); 325 base::AutoLock lock(lock_);
326 extra_plugin_paths = extra_plugin_paths_; 326 extra_plugin_paths = extra_plugin_paths_;
327 extra_plugin_dirs = extra_plugin_dirs_; 327 extra_plugin_dirs = extra_plugin_dirs_;
328 } 328 }
329 329
330 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { 330 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) {
331 const FilePath& path = extra_plugin_paths[i]; 331 const base::FilePath& path = extra_plugin_paths[i];
332 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != 332 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) !=
333 plugin_paths->end()) { 333 plugin_paths->end()) {
334 continue; 334 continue;
335 } 335 }
336 plugin_paths->push_back(path); 336 plugin_paths->push_back(path);
337 } 337 }
338 338
339 if (NPAPIPluginsSupported()) { 339 if (NPAPIPluginsSupported()) {
340 // A bit confusingly, this function is used to load Pepper plugins as well. 340 // A bit confusingly, this function is used to load Pepper plugins as well.
341 // Those are all internal plugins so we have to use extra_plugin_paths. 341 // Those are all internal plugins so we have to use extra_plugin_paths.
342 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) 342 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i)
343 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); 343 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths);
344 344
345 std::vector<FilePath> directories_to_scan; 345 std::vector<base::FilePath> directories_to_scan;
346 GetPluginDirectories(&directories_to_scan); 346 GetPluginDirectories(&directories_to_scan);
347 for (size_t i = 0; i < directories_to_scan.size(); ++i) 347 for (size_t i = 0; i < directories_to_scan.size(); ++i)
348 GetPluginsInDir(directories_to_scan[i], plugin_paths); 348 GetPluginsInDir(directories_to_scan[i], plugin_paths);
349 349
350 #if defined(OS_WIN) 350 #if defined(OS_WIN)
351 GetPluginPathsFromRegistry(plugin_paths); 351 GetPluginPathsFromRegistry(plugin_paths);
352 #endif 352 #endif
353 } 353 }
354 } 354 }
355 355
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 if (!use_stale) 395 if (!use_stale)
396 LoadPlugins(); 396 LoadPlugins();
397 base::AutoLock lock(lock_); 397 base::AutoLock lock(lock_);
398 if (use_stale) 398 if (use_stale)
399 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE); 399 *use_stale = (loading_state_ != LOADING_STATE_UP_TO_DATE);
400 info->clear(); 400 info->clear();
401 if (actual_mime_types) 401 if (actual_mime_types)
402 actual_mime_types->clear(); 402 actual_mime_types->clear();
403 403
404 std::set<FilePath> visited_plugins; 404 std::set<base::FilePath> visited_plugins;
405 405
406 // Add in plugins by mime type. 406 // Add in plugins by mime type.
407 for (size_t i = 0; i < plugins_list_.size(); ++i) { 407 for (size_t i = 0; i < plugins_list_.size(); ++i) {
408 if (SupportsType(plugins_list_[i], mime_type, allow_wildcard)) { 408 if (SupportsType(plugins_list_[i], mime_type, allow_wildcard)) {
409 FilePath path = plugins_list_[i].path; 409 base::FilePath path = plugins_list_[i].path;
410 if (visited_plugins.insert(path).second) { 410 if (visited_plugins.insert(path).second) {
411 info->push_back(plugins_list_[i]); 411 info->push_back(plugins_list_[i]);
412 if (actual_mime_types) 412 if (actual_mime_types)
413 actual_mime_types->push_back(mime_type); 413 actual_mime_types->push_back(mime_type);
414 } 414 }
415 } 415 }
416 } 416 }
417 417
418 // Add in plugins by url. 418 // Add in plugins by url.
419 std::string path = url.path(); 419 std::string path = url.path();
420 std::string::size_type last_dot = path.rfind('.'); 420 std::string::size_type last_dot = path.rfind('.');
421 if (last_dot != std::string::npos) { 421 if (last_dot != std::string::npos) {
422 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); 422 std::string extension = StringToLowerASCII(std::string(path, last_dot+1));
423 std::string actual_mime_type; 423 std::string actual_mime_type;
424 for (size_t i = 0; i < plugins_list_.size(); ++i) { 424 for (size_t i = 0; i < plugins_list_.size(); ++i) {
425 if (SupportsExtension(plugins_list_[i], extension, &actual_mime_type)) { 425 if (SupportsExtension(plugins_list_[i], extension, &actual_mime_type)) {
426 FilePath path = plugins_list_[i].path; 426 base::FilePath path = plugins_list_[i].path;
427 if (visited_plugins.insert(path).second && 427 if (visited_plugins.insert(path).second &&
428 AllowMimeTypeMismatch(mime_type, actual_mime_type)) { 428 AllowMimeTypeMismatch(mime_type, actual_mime_type)) {
429 info->push_back(plugins_list_[i]); 429 info->push_back(plugins_list_[i]);
430 if (actual_mime_types) 430 if (actual_mime_types)
431 actual_mime_types->push_back(actual_mime_type); 431 actual_mime_types->push_back(actual_mime_type);
432 } 432 }
433 } 433 }
434 } 434 }
435 } 435 }
436 } 436 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 468 }
469 return false; 469 return false;
470 } 470 }
471 471
472 PluginList::~PluginList() { 472 PluginList::~PluginList() {
473 } 473 }
474 474
475 475
476 } // namespace npapi 476 } // namespace npapi
477 } // namespace webkit 477 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_list.h ('k') | webkit/plugins/npapi/plugin_list_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698