OLD | NEW |
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 "content/browser/plugin_service_impl.h" | 5 #include "content/browser/plugin_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); | 131 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 // static | 135 // static |
136 PluginServiceImpl* PluginServiceImpl::GetInstance() { | 136 PluginServiceImpl* PluginServiceImpl::GetInstance() { |
137 return Singleton<PluginServiceImpl>::get(); | 137 return Singleton<PluginServiceImpl>::get(); |
138 } | 138 } |
139 | 139 |
140 PluginServiceImpl::PluginServiceImpl() | 140 PluginServiceImpl::PluginServiceImpl() |
141 : plugin_list_(NULL), filter_(NULL) { | 141 : filter_(NULL) { |
142 // Collect the total number of browser processes (which create | 142 // Collect the total number of browser processes (which create |
143 // PluginServiceImpl objects, to be precise). The number is used to normalize | 143 // PluginServiceImpl objects, to be precise). The number is used to normalize |
144 // the number of processes which start at least one NPAPI/PPAPI Flash process. | 144 // the number of processes which start at least one NPAPI/PPAPI Flash process. |
145 static bool counted = false; | 145 static bool counted = false; |
146 if (!counted) { | 146 if (!counted) { |
147 counted = true; | 147 counted = true; |
148 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, | 148 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
149 FLASH_USAGE_ENUM_COUNT); | 149 FLASH_USAGE_ENUM_COUNT); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 PluginServiceImpl::~PluginServiceImpl() { | 153 PluginServiceImpl::~PluginServiceImpl() { |
154 #if defined(OS_WIN) | 154 #if defined(OS_WIN) |
155 // Release the events since they're owned by RegKey, not WaitableEvent. | 155 // Release the events since they're owned by RegKey, not WaitableEvent. |
156 hkcu_watcher_.StopWatching(); | 156 hkcu_watcher_.StopWatching(); |
157 hklm_watcher_.StopWatching(); | 157 hklm_watcher_.StopWatching(); |
158 if (hkcu_event_) | 158 if (hkcu_event_) |
159 hkcu_event_->Release(); | 159 hkcu_event_->Release(); |
160 if (hklm_event_) | 160 if (hklm_event_) |
161 hklm_event_->Release(); | 161 hklm_event_->Release(); |
162 #endif | 162 #endif |
163 // Make sure no plugin channel requests have been leaked. | 163 // Make sure no plugin channel requests have been leaked. |
164 DCHECK(pending_plugin_clients_.empty()); | 164 DCHECK(pending_plugin_clients_.empty()); |
165 } | 165 } |
166 | 166 |
167 void PluginServiceImpl::Init() { | 167 void PluginServiceImpl::Init() { |
168 if (!plugin_list_) | |
169 plugin_list_ = webkit::npapi::PluginList::Singleton(); | |
170 | |
171 plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); | 168 plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
172 plugin_list_->set_will_load_plugins_callback( | 169 webkit::npapi::PluginList::Singleton()->set_will_load_plugins_callback( |
173 base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); | 170 base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
174 | 171 |
175 RegisterPepperPlugins(); | 172 RegisterPepperPlugins(); |
176 | 173 |
177 // The --site-per-process flag enables an out-of-process iframes | 174 // The --site-per-process flag enables an out-of-process iframes |
178 // prototype, which uses WebView for rendering. We need to register the MIME | 175 // prototype, which uses WebView for rendering. We need to register the MIME |
179 // type we use with the plugin, so the renderer can instantiate it. | 176 // type we use with the plugin, so the renderer can instantiate it. |
180 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 177 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
181 if (command_line->HasSwitch(switches::kSitePerProcess)) { | 178 if (command_line->HasSwitch(switches::kSitePerProcess)) { |
182 webkit::WebPluginInfo webview_plugin( | 179 webkit::WebPluginInfo webview_plugin( |
183 ASCIIToUTF16("WebView Tag"), | 180 ASCIIToUTF16("WebView Tag"), |
184 base::FilePath(), | 181 base::FilePath(), |
185 ASCIIToUTF16("1.2.3.4"), | 182 ASCIIToUTF16("1.2.3.4"), |
186 ASCIIToUTF16("Browser Plugin.")); | 183 ASCIIToUTF16("Browser Plugin.")); |
187 webview_plugin.type = webkit::WebPluginInfo::PLUGIN_TYPE_NPAPI; | 184 webview_plugin.type = webkit::WebPluginInfo::PLUGIN_TYPE_NPAPI; |
188 webkit::WebPluginMimeType webview_plugin_mime_type; | 185 webkit::WebPluginMimeType webview_plugin_mime_type; |
189 webview_plugin_mime_type.mime_type = "application/browser-plugin"; | 186 webview_plugin_mime_type.mime_type = "application/browser-plugin"; |
190 webview_plugin_mime_type.file_extensions.push_back("*"); | 187 webview_plugin_mime_type.file_extensions.push_back("*"); |
191 webview_plugin.mime_types.push_back(webview_plugin_mime_type); | 188 webview_plugin.mime_types.push_back(webview_plugin_mime_type); |
192 RegisterInternalPlugin(webview_plugin, true); | 189 RegisterInternalPlugin(webview_plugin, true); |
193 } | 190 } |
194 | 191 |
195 // Load any specified on the command line as well. | 192 // Load any specified on the command line as well. |
196 base::FilePath path = | 193 base::FilePath path = |
197 command_line->GetSwitchValuePath(switches::kLoadPlugin); | 194 command_line->GetSwitchValuePath(switches::kLoadPlugin); |
198 if (!path.empty()) | 195 if (!path.empty()) |
199 AddExtraPluginPath(path); | 196 AddExtraPluginPath(path); |
200 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 197 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
201 if (!path.empty()) | 198 if (!path.empty()) |
202 plugin_list_->AddExtraPluginDir(path); | 199 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
203 | 200 |
204 if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) | 201 if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) |
205 plugin_list_->DisablePluginsDiscovery(); | 202 webkit::npapi::PluginList::Singleton()->DisablePluginsDiscovery(); |
206 } | 203 } |
207 | 204 |
208 void PluginServiceImpl::StartWatchingPlugins() { | 205 void PluginServiceImpl::StartWatchingPlugins() { |
209 // Start watching for changes in the plugin list. This means watching | 206 // Start watching for changes in the plugin list. This means watching |
210 // for changes in the Windows registry keys and on both Windows and POSIX | 207 // for changes in the Windows registry keys and on both Windows and POSIX |
211 // watch for changes in the paths that are expected to contain plugins. | 208 // watch for changes in the paths that are expected to contain plugins. |
212 #if defined(OS_WIN) | 209 #if defined(OS_WIN) |
213 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 210 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
214 webkit::npapi::kRegistryMozillaPlugins, | 211 webkit::npapi::kRegistryMozillaPlugins, |
215 KEY_NOTIFY) == ERROR_SUCCESS) { | 212 KEY_NOTIFY) == ERROR_SUCCESS) { |
(...skipping 17 matching lines...) Expand all Loading... |
233 } | 230 } |
234 } | 231 } |
235 #endif | 232 #endif |
236 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | 233 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
237 // On ChromeOS the user can't install plugins anyway and on Windows all | 234 // On ChromeOS the user can't install plugins anyway and on Windows all |
238 // important plugins register themselves in the registry so no need to do that. | 235 // important plugins register themselves in the registry so no need to do that. |
239 | 236 |
240 // Get the list of all paths for registering the FilePathWatchers | 237 // Get the list of all paths for registering the FilePathWatchers |
241 // that will track and if needed reload the list of plugins on runtime. | 238 // that will track and if needed reload the list of plugins on runtime. |
242 std::vector<base::FilePath> plugin_dirs; | 239 std::vector<base::FilePath> plugin_dirs; |
243 plugin_list_->GetPluginDirectories(&plugin_dirs); | 240 webkit::npapi::PluginList::Singleton()->GetPluginDirectories(&plugin_dirs); |
244 | 241 |
245 for (size_t i = 0; i < plugin_dirs.size(); ++i) { | 242 for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
246 // FilePathWatcher can not handle non-absolute paths under windows. | 243 // FilePathWatcher can not handle non-absolute paths under windows. |
247 // We don't watch for file changes in windows now but if this should ever | 244 // We don't watch for file changes in windows now but if this should ever |
248 // be extended to Windows these lines might save some time of debugging. | 245 // be extended to Windows these lines might save some time of debugging. |
249 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
250 if (!plugin_dirs[i].IsAbsolute()) | 247 if (!plugin_dirs[i].IsAbsolute()) |
251 continue; | 248 continue; |
252 #endif | 249 #endif |
253 FilePathWatcher* watcher = new FilePathWatcher(); | 250 FilePathWatcher* watcher = new FilePathWatcher(); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 503 } |
507 } | 504 } |
508 | 505 |
509 bool PluginServiceImpl::GetPluginInfoArray( | 506 bool PluginServiceImpl::GetPluginInfoArray( |
510 const GURL& url, | 507 const GURL& url, |
511 const std::string& mime_type, | 508 const std::string& mime_type, |
512 bool allow_wildcard, | 509 bool allow_wildcard, |
513 std::vector<webkit::WebPluginInfo>* plugins, | 510 std::vector<webkit::WebPluginInfo>* plugins, |
514 std::vector<std::string>* actual_mime_types) { | 511 std::vector<std::string>* actual_mime_types) { |
515 bool use_stale = false; | 512 bool use_stale = false; |
516 plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard, | 513 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( |
517 &use_stale, plugins, actual_mime_types); | 514 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types); |
518 return use_stale; | 515 return use_stale; |
519 } | 516 } |
520 | 517 |
521 bool PluginServiceImpl::GetPluginInfo(int render_process_id, | 518 bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
522 int render_view_id, | 519 int render_view_id, |
523 ResourceContext* context, | 520 ResourceContext* context, |
524 const GURL& url, | 521 const GURL& url, |
525 const GURL& page_url, | 522 const GURL& page_url, |
526 const std::string& mime_type, | 523 const std::string& mime_type, |
527 bool allow_wildcard, | 524 bool allow_wildcard, |
(...skipping 19 matching lines...) Expand all Loading... |
547 *actual_mime_type = mime_types[i]; | 544 *actual_mime_type = mime_types[i]; |
548 return true; | 545 return true; |
549 } | 546 } |
550 } | 547 } |
551 return false; | 548 return false; |
552 } | 549 } |
553 | 550 |
554 bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path, | 551 bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path, |
555 webkit::WebPluginInfo* info) { | 552 webkit::WebPluginInfo* info) { |
556 std::vector<webkit::WebPluginInfo> plugins; | 553 std::vector<webkit::WebPluginInfo> plugins; |
557 plugin_list_->GetPluginsNoRefresh(&plugins); | 554 webkit::npapi::PluginList::Singleton()->GetPluginsNoRefresh(&plugins); |
558 | 555 |
559 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); | 556 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); |
560 it != plugins.end(); | 557 it != plugins.end(); |
561 ++it) { | 558 ++it) { |
562 if (it->path == plugin_path) { | 559 if (it->path == plugin_path) { |
563 *info = *it; | 560 *info = *it; |
564 return true; | 561 return true; |
565 } | 562 } |
566 } | 563 } |
567 | 564 |
(...skipping 28 matching lines...) Expand all Loading... |
596 plugin_list_token_, | 593 plugin_list_token_, |
597 FROM_HERE, | 594 FROM_HERE, |
598 base::Bind(&PluginServiceImpl::GetPluginsInternal, | 595 base::Bind(&PluginServiceImpl::GetPluginsInternal, |
599 base::Unretained(this), | 596 base::Unretained(this), |
600 target_loop, callback), | 597 target_loop, callback), |
601 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 598 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
602 return; | 599 return; |
603 } | 600 } |
604 #if defined(OS_POSIX) | 601 #if defined(OS_POSIX) |
605 std::vector<webkit::WebPluginInfo> cached_plugins; | 602 std::vector<webkit::WebPluginInfo> cached_plugins; |
606 if (plugin_list_->GetPluginsNoRefresh(&cached_plugins)) { | 603 if (webkit::npapi::PluginList::Singleton()->GetPluginsNoRefresh( |
| 604 &cached_plugins)) { |
607 // Can't assume the caller is reentrant. | 605 // Can't assume the caller is reentrant. |
608 target_loop->PostTask(FROM_HERE, | 606 target_loop->PostTask(FROM_HERE, |
609 base::Bind(callback, cached_plugins)); | 607 base::Bind(callback, cached_plugins)); |
610 } else { | 608 } else { |
611 // If we switch back to loading plugins in process, then we need to make | 609 // If we switch back to loading plugins in process, then we need to make |
612 // sure g_thread_init() gets called since plugins may call glib at load. | 610 // sure g_thread_init() gets called since plugins may call glib at load. |
613 if (!plugin_loader_.get()) | 611 if (!plugin_loader_.get()) |
614 plugin_loader_ = new PluginLoaderPosix; | 612 plugin_loader_ = new PluginLoaderPosix; |
615 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 613 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
616 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, | 614 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, |
617 target_loop, callback)); | 615 target_loop, callback)); |
618 } | 616 } |
619 #else | 617 #else |
620 NOTREACHED(); | 618 NOTREACHED(); |
621 #endif | 619 #endif |
622 } | 620 } |
623 | 621 |
624 void PluginServiceImpl::GetPluginsInternal( | 622 void PluginServiceImpl::GetPluginsInternal( |
625 base::MessageLoopProxy* target_loop, | 623 base::MessageLoopProxy* target_loop, |
626 const PluginService::GetPluginsCallback& callback) { | 624 const PluginService::GetPluginsCallback& callback) { |
627 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 625 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
628 plugin_list_token_)); | 626 plugin_list_token_)); |
629 | 627 |
630 std::vector<webkit::WebPluginInfo> plugins; | 628 std::vector<webkit::WebPluginInfo> plugins; |
631 plugin_list_->GetPlugins(&plugins); | 629 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
632 | 630 |
633 target_loop->PostTask(FROM_HERE, | 631 target_loop->PostTask(FROM_HERE, |
634 base::Bind(callback, plugins)); | 632 base::Bind(callback, plugins)); |
635 } | 633 } |
636 | 634 |
637 void PluginServiceImpl::OnWaitableEventSignaled( | 635 void PluginServiceImpl::OnWaitableEventSignaled( |
638 base::WaitableEvent* waitable_event) { | 636 base::WaitableEvent* waitable_event) { |
639 #if defined(OS_WIN) | 637 #if defined(OS_WIN) |
640 if (waitable_event == hkcu_event_) { | 638 if (waitable_event == hkcu_event_) { |
641 hkcu_key_.StartWatching(); | 639 hkcu_key_.StartWatching(); |
642 } else { | 640 } else { |
643 hklm_key_.StartWatching(); | 641 hklm_key_.StartWatching(); |
644 } | 642 } |
645 | 643 |
646 plugin_list_->RefreshPlugins(); | 644 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
647 PurgePluginListCache(NULL, false); | 645 PurgePluginListCache(NULL, false); |
648 #else | 646 #else |
649 // This event should only get signaled on a Windows machine. | 647 // This event should only get signaled on a Windows machine. |
650 NOTREACHED(); | 648 NOTREACHED(); |
651 #endif // defined(OS_WIN) | 649 #endif // defined(OS_WIN) |
652 } | 650 } |
653 | 651 |
654 void PluginServiceImpl::RegisterPepperPlugins() { | 652 void PluginServiceImpl::RegisterPepperPlugins() { |
655 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. | 653 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
656 PepperPluginRegistry::ComputeList(&ppapi_plugins_); | 654 PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 return false; | 742 return false; |
745 } | 743 } |
746 if (i->second.size() != kMaxCrashesPerInterval) { | 744 if (i->second.size() != kMaxCrashesPerInterval) { |
747 return false; | 745 return false; |
748 } | 746 } |
749 base::TimeDelta delta = base::Time::Now() - i->second[0]; | 747 base::TimeDelta delta = base::Time::Now() - i->second[0]; |
750 return delta.InSeconds() <= kCrashesInterval; | 748 return delta.InSeconds() <= kCrashesInterval; |
751 } | 749 } |
752 | 750 |
753 void PluginServiceImpl::RefreshPlugins() { | 751 void PluginServiceImpl::RefreshPlugins() { |
754 plugin_list_->RefreshPlugins(); | 752 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
755 } | 753 } |
756 | 754 |
757 void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { | 755 void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { |
758 plugin_list_->AddExtraPluginPath(path); | 756 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
| 757 } |
| 758 |
| 759 void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { |
| 760 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath(path); |
759 } | 761 } |
760 | 762 |
761 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { | 763 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { |
762 plugin_list_->AddExtraPluginDir(path); | 764 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
763 } | 765 } |
764 | 766 |
765 void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { | 767 void PluginServiceImpl::RegisterInternalPlugin( |
766 plugin_list_->RemoveExtraPluginPath(path); | 768 const webkit::WebPluginInfo& info, |
| 769 bool add_at_beginning) { |
| 770 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( |
| 771 info, add_at_beginning); |
767 } | 772 } |
768 | 773 |
769 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { | 774 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
770 plugin_list_->UnregisterInternalPlugin(path); | 775 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path); |
771 } | 776 } |
772 | 777 |
773 void PluginServiceImpl::SetPluginListForTesting( | 778 void PluginServiceImpl::GetInternalPlugins( |
774 webkit::npapi::PluginList* plugin_list) { | 779 std::vector<webkit::WebPluginInfo>* plugins) { |
775 plugin_list_ = plugin_list; | 780 webkit::npapi::PluginList::Singleton()->GetInternalPlugins(plugins); |
| 781 } |
| 782 |
| 783 void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { |
| 784 webkit::npapi::PluginList::Singleton()->DisablePluginsDiscovery(); |
776 } | 785 } |
777 | 786 |
778 #if defined(OS_MACOSX) | 787 #if defined(OS_MACOSX) |
779 void PluginServiceImpl::AppActivated() { | 788 void PluginServiceImpl::AppActivated() { |
780 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 789 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
781 base::Bind(&NotifyPluginsOfActivation)); | 790 base::Bind(&NotifyPluginsOfActivation)); |
782 } | 791 } |
783 #endif | 792 #endif |
784 | 793 |
785 void PluginServiceImpl::RegisterInternalPlugin( | |
786 const webkit::WebPluginInfo& info, | |
787 bool add_at_beginning) { | |
788 plugin_list_->RegisterInternalPlugin(info, add_at_beginning); | |
789 } | |
790 | |
791 void PluginServiceImpl::GetInternalPlugins( | |
792 std::vector<webkit::WebPluginInfo>* plugins) { | |
793 plugin_list_->GetInternalPlugins(plugins); | |
794 } | |
795 | |
796 } // namespace content | 794 } // namespace content |
OLD | NEW |