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

Side by Side Diff: chrome/browser/plugin_service.cc

Issue 6259008: When we detect a PDF with an unsupported feature, ask the user if they want t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | « chrome/browser/plugin_service.h ('k') | chrome/browser/plugin_service_browsertest.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/plugin_service.h" 5 #include "chrome/browser/plugin_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/browser_thread.h" 17 #include "chrome/browser/browser_thread.h"
18 #include "chrome/browser/chrome_plugin_host.h" 18 #include "chrome/browser/chrome_plugin_host.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/plugin_updater.h" 20 #include "chrome/browser/plugin_updater.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/renderer_host/render_process_host.h" 22 #include "chrome/browser/renderer_host/render_process_host.h"
23 #include "chrome/browser/renderer_host/render_view_host.h"
23 #include "chrome/common/chrome_plugin_lib.h" 24 #include "chrome/common/chrome_plugin_lib.h"
24 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/default_plugin.h" 27 #include "chrome/common/default_plugin.h"
27 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
28 #include "chrome/common/gpu_plugin.h" 29 #include "chrome/common/gpu_plugin.h"
29 #include "chrome/common/logging_chrome.h" 30 #include "chrome/common/logging_chrome.h"
30 #include "chrome/common/notification_type.h" 31 #include "chrome/common/notification_type.h"
31 #include "chrome/common/notification_service.h" 32 #include "chrome/common/notification_service.h"
32 #include "chrome/common/pepper_plugin_registry.h" 33 #include "chrome/common/pepper_plugin_registry.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 205 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
205 NotificationService::AllSources()); 206 NotificationService::AllSources());
206 #if defined(OS_MACOSX) 207 #if defined(OS_MACOSX)
207 // We need to know when the browser comes forward so we can bring modal plugin 208 // We need to know when the browser comes forward so we can bring modal plugin
208 // windows forward too. 209 // windows forward too.
209 registrar_.Add(this, NotificationType::APP_ACTIVATED, 210 registrar_.Add(this, NotificationType::APP_ACTIVATED,
210 NotificationService::AllSources()); 211 NotificationService::AllSources());
211 #endif 212 #endif
212 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, 213 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED,
213 NotificationService::AllSources()); 214 NotificationService::AllSources());
215 registrar_.Add(this,
216 NotificationType::RENDERER_PROCESS_CLOSED,
217 NotificationService::AllSources());
214 } 218 }
215 219
216 PluginService::~PluginService() { 220 PluginService::~PluginService() {
217 #if defined(OS_WIN) 221 #if defined(OS_WIN)
218 // Release the events since they're owned by RegKey, not WaitableEvent. 222 // Release the events since they're owned by RegKey, not WaitableEvent.
219 hkcu_watcher_.StopWatching(); 223 hkcu_watcher_.StopWatching();
220 hklm_watcher_.StopWatching(); 224 hklm_watcher_.StopWatching();
221 hkcu_event_->Release(); 225 hkcu_event_->Release();
222 hklm_event_->Release(); 226 hklm_event_->Release();
223 #endif 227 #endif
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); 280 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost());
277 if (!new_host->Init(info, ui_locale_)) { 281 if (!new_host->Init(info, ui_locale_)) {
278 NOTREACHED(); // Init is not expected to fail 282 NOTREACHED(); // Init is not expected to fail
279 return NULL; 283 return NULL;
280 } 284 }
281 285
282 return new_host.release(); 286 return new_host.release();
283 } 287 }
284 288
285 void PluginService::OpenChannelToPlugin( 289 void PluginService::OpenChannelToPlugin(
290 int render_process_id,
291 int render_view_id,
286 const GURL& url, 292 const GURL& url,
287 const std::string& mime_type, 293 const std::string& mime_type,
288 PluginProcessHost::Client* client) { 294 PluginProcessHost::Client* client) {
289 // The PluginList::GetFirstAllowedPluginInfo may need to load the 295 // The PluginList::GetFirstAllowedPluginInfo may need to load the
290 // plugins. Don't do it on the IO thread. 296 // plugins. Don't do it on the IO thread.
291 BrowserThread::PostTask( 297 BrowserThread::PostTask(
292 BrowserThread::FILE, FROM_HERE, 298 BrowserThread::FILE, FROM_HERE,
293 NewRunnableMethod( 299 NewRunnableMethod(
294 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, 300 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin,
295 url, mime_type, client)); 301 render_process_id, render_view_id, url, mime_type, client));
296 } 302 }
297 303
298 void PluginService::GetAllowedPluginForOpenChannelToPlugin( 304 void PluginService::GetAllowedPluginForOpenChannelToPlugin(
305 int render_process_id,
306 int render_view_id,
299 const GURL& url, 307 const GURL& url,
300 const std::string& mime_type, 308 const std::string& mime_type,
301 PluginProcessHost::Client* client) { 309 PluginProcessHost::Client* client) {
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
303 webkit::npapi::WebPluginInfo info; 311 webkit::npapi::WebPluginInfo info;
304 bool found = GetFirstAllowedPluginInfo(url, mime_type, &info, NULL); 312 bool found = GetFirstAllowedPluginInfo(
313 render_process_id, render_view_id, url, mime_type, &info, NULL);
305 FilePath plugin_path; 314 FilePath plugin_path;
306 if (found && info.enabled) 315 if (found && info.enabled)
307 plugin_path = FilePath(info.path); 316 plugin_path = FilePath(info.path);
308 317
309 // Now we jump back to the IO thread to finish opening the channel. 318 // Now we jump back to the IO thread to finish opening the channel.
310 BrowserThread::PostTask( 319 BrowserThread::PostTask(
311 BrowserThread::IO, FROM_HERE, 320 BrowserThread::IO, FROM_HERE,
312 NewRunnableMethod( 321 NewRunnableMethod(
313 this, &PluginService::FinishOpenChannelToPlugin, 322 this, &PluginService::FinishOpenChannelToPlugin,
314 plugin_path, client)); 323 plugin_path, client));
315 } 324 }
316 325
317 void PluginService::FinishOpenChannelToPlugin( 326 void PluginService::FinishOpenChannelToPlugin(
318 const FilePath& plugin_path, 327 const FilePath& plugin_path,
319 PluginProcessHost::Client* client) { 328 PluginProcessHost::Client* client) {
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
321 330
322 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); 331 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path);
323 if (plugin_host) 332 if (plugin_host)
324 plugin_host->OpenChannelToPlugin(client); 333 plugin_host->OpenChannelToPlugin(client);
325 else 334 else
326 client->OnError(); 335 client->OnError();
327 } 336 }
328 337
329 bool PluginService::GetFirstAllowedPluginInfo( 338 bool PluginService::GetFirstAllowedPluginInfo(
339 int render_process_id,
340 int render_view_id,
330 const GURL& url, 341 const GURL& url,
331 const std::string& mime_type, 342 const std::string& mime_type,
332 webkit::npapi::WebPluginInfo* info, 343 webkit::npapi::WebPluginInfo* info,
333 std::string* actual_mime_type) { 344 std::string* actual_mime_type) {
334 // GetPluginInfoArray may need to load the plugins, so we need to be 345 // GetPluginInfoArray may need to load the plugins, so we need to be
335 // on the FILE thread. 346 // on the FILE thread.
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
337 bool allow_wildcard = true; 348 bool allow_wildcard = true;
338 #if defined(OS_CHROMEOS) 349 #if defined(OS_CHROMEOS)
339 std::vector<webkit::npapi::WebPluginInfo> info_array; 350 std::vector<webkit::npapi::WebPluginInfo> info_array;
340 std::vector<std::string> actual_mime_types; 351 std::vector<std::string> actual_mime_types;
341 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( 352 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
342 url, mime_type, allow_wildcard, &info_array, &actual_mime_types); 353 url, mime_type, allow_wildcard, &info_array, &actual_mime_types);
343 354
344 // Now we filter by the plugin selection policy. 355 // Now we filter by the plugin selection policy.
345 int allowed_index = plugin_selection_policy_->FindFirstAllowed(url, 356 int allowed_index = plugin_selection_policy_->FindFirstAllowed(url,
346 info_array); 357 info_array);
347 if (!info_array.empty() && allowed_index >= 0) { 358 if (!info_array.empty() && allowed_index >= 0) {
348 *info = info_array[allowed_index]; 359 *info = info_array[allowed_index];
349 if (actual_mime_type) 360 if (actual_mime_type)
350 *actual_mime_type = actual_mime_types[allowed_index]; 361 *actual_mime_type = actual_mime_types[allowed_index];
351 return true; 362 return true;
352 } 363 }
353 return false; 364 return false;
354 #else 365 #else
366 {
367 AutoLock auto_lock(overridden_plugins_lock_);
368 for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
369 if (overridden_plugins_[i].render_process_id == render_process_id &&
370 overridden_plugins_[i].render_view_id == render_view_id &&
371 overridden_plugins_[i].url == url) {
372 *actual_mime_type = mime_type;
373 *info = overridden_plugins_[i].plugin;
374 return true;
375 }
376 }
377 }
355 return webkit::npapi::PluginList::Singleton()->GetPluginInfo( 378 return webkit::npapi::PluginList::Singleton()->GetPluginInfo(
356 url, mime_type, allow_wildcard, info, actual_mime_type); 379 url, mime_type, allow_wildcard, info, actual_mime_type);
357 #endif 380 #endif
358 } 381 }
359 382
360 void PluginService::OnWaitableEventSignaled( 383 void PluginService::OnWaitableEventSignaled(
361 base::WaitableEvent* waitable_event) { 384 base::WaitableEvent* waitable_event) {
362 #if defined(OS_WIN) 385 #if defined(OS_WIN)
363 if (waitable_event == hkcu_event_.get()) { 386 if (waitable_event == hkcu_event_.get()) {
364 hkcu_key_.StartWatching(); 387 hkcu_key_.StartWatching();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 450 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
428 NewRunnableFunction(&NotifyPluginsOfActivation)); 451 NewRunnableFunction(&NotifyPluginsOfActivation));
429 break; 452 break;
430 } 453 }
431 #endif 454 #endif
432 455
433 case NotificationType::PLUGIN_ENABLE_STATUS_CHANGED: { 456 case NotificationType::PLUGIN_ENABLE_STATUS_CHANGED: {
434 PurgePluginListCache(false); 457 PurgePluginListCache(false);
435 break; 458 break;
436 } 459 }
460 case NotificationType::RENDERER_PROCESS_CLOSED: {
461 int render_process_id = Source<RenderProcessHost>(source).ptr()->id();
462
463 AutoLock auto_lock(overridden_plugins_lock_);
464 for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
465 if (overridden_plugins_[i].render_process_id == render_process_id) {
466 overridden_plugins_.erase(overridden_plugins_.begin() + i);
467 break;
468 }
469 }
470 break;
471 }
437 default: 472 default:
438 NOTREACHED(); 473 NOTREACHED();
439 } 474 }
440 } 475 }
441 476
442 bool PluginService::PrivatePluginAllowedForURL(const FilePath& plugin_path, 477 bool PluginService::PrivatePluginAllowedForURL(const FilePath& plugin_path,
443 const GURL& url) { 478 const GURL& url) {
444 if (url.is_empty()) 479 if (url.is_empty())
445 return true; // Caller wants all plugins. 480 return true; // Caller wants all plugins.
446 481
447 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); 482 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path);
448 if (it == private_plugins_.end()) 483 if (it == private_plugins_.end())
449 return true; // This plugin is not private, so it's allowed everywhere. 484 return true; // This plugin is not private, so it's allowed everywhere.
450 485
451 // We do a dumb compare of scheme and host, rather than using the domain 486 // We do a dumb compare of scheme and host, rather than using the domain
452 // service, since we only care about this for extensions. 487 // service, since we only care about this for extensions.
453 const GURL& required_url = it->second; 488 const GURL& required_url = it->second;
454 return (url.scheme() == required_url.scheme() && 489 return (url.scheme() == required_url.scheme() &&
455 url.host() == required_url.host()); 490 url.host() == required_url.host());
456 } 491 }
457 492
493 void PluginService::OverridePluginForTab(OverriddenPlugin plugin) {
494 AutoLock auto_lock(overridden_plugins_lock_);
495 overridden_plugins_.push_back(plugin);
496 }
497
458 void PluginService::RegisterPepperPlugins() { 498 void PluginService::RegisterPepperPlugins() {
459 std::vector<PepperPluginInfo> plugins; 499 std::vector<PepperPluginInfo> plugins;
460 PepperPluginRegistry::GetList(&plugins); 500 PepperPluginRegistry::GetList(&plugins);
461 for (size_t i = 0; i < plugins.size(); ++i) { 501 for (size_t i = 0; i < plugins.size(); ++i) {
462 webkit::npapi::WebPluginInfo info; 502 webkit::npapi::WebPluginInfo info;
463 info.path = plugins[i].path; 503 info.path = plugins[i].path;
464 info.name = plugins[i].name.empty() ? 504 info.name = plugins[i].name.empty() ?
465 WideToUTF16(plugins[i].path.BaseName().ToWStringHack()) : 505 WideToUTF16(plugins[i].path.BaseName().ToWStringHack()) :
466 ASCIIToUTF16(plugins[i].name); 506 ASCIIToUTF16(plugins[i].name);
467 info.desc = ASCIIToUTF16(plugins[i].description); 507 info.desc = ASCIIToUTF16(plugins[i].description);
(...skipping 18 matching lines...) Expand all
486 #if defined(OS_LINUX) 526 #if defined(OS_LINUX)
487 // static 527 // static
488 void PluginService::RegisterFilePathWatcher( 528 void PluginService::RegisterFilePathWatcher(
489 FilePathWatcher *watcher, 529 FilePathWatcher *watcher,
490 const FilePath& path, 530 const FilePath& path,
491 FilePathWatcher::Delegate* delegate) { 531 FilePathWatcher::Delegate* delegate) {
492 bool result = watcher->Watch(path, delegate); 532 bool result = watcher->Watch(path, delegate);
493 DCHECK(result); 533 DCHECK(result);
494 } 534 }
495 #endif 535 #endif
OLDNEW
« no previous file with comments | « chrome/browser/plugin_service.h ('k') | chrome/browser/plugin_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698