| OLD | NEW |
| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/plugin_service.h" | 7 #include "chrome/browser/plugin_service.h" |
| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 44 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
| 45 !iter.Done(); ++iter) { | 45 !iter.Done(); ++iter) { |
| 46 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 46 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 47 plugin->OnAppActivation(); | 47 plugin->OnAppActivation(); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 bool PluginService::enable_chrome_plugins_ = true; | 53 bool PluginService::enable_chrome_plugins_ = true; |
| 54 bool PluginService::enable_internal_pdf_ = false; |
| 54 | 55 |
| 55 // static | 56 // static |
| 56 void PluginService::InitGlobalInstance(Profile* profile) { | 57 void PluginService::InitGlobalInstance(Profile* profile) { |
| 57 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 58 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 58 | 59 |
| 59 bool update_internal_dir = false; | 60 bool update_internal_dir = false; |
| 60 FilePath last_internal_dir = | 61 FilePath last_internal_dir = |
| 61 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); | 62 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); |
| 62 FilePath cur_internal_dir; | 63 FilePath cur_internal_dir; |
| 63 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir)) | 64 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
| 64 update_internal_dir = (cur_internal_dir != last_internal_dir); | 65 cur_internal_dir != last_internal_dir) { |
| 66 update_internal_dir = true; |
| 67 profile->GetPrefs()->SetFilePath( |
| 68 prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
| 69 } |
| 70 |
| 71 bool found_internal_pdf = false; |
| 72 bool force_enable_internal_pdf = false; |
| 73 FilePath pdf_path; |
| 74 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 75 FilePath::StringType pdf_path_str = pdf_path.value(); |
| 76 if (enable_internal_pdf_ && |
| 77 !profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { |
| 78 // We switched to the internal pdf plugin being on by default, and so we |
| 79 // need to force it to be enabled. We only want to do it this once though, |
| 80 // i.e. we don't want to enable it again if the user disables it afterwards. |
| 81 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); |
| 82 force_enable_internal_pdf = true; |
| 83 } |
| 65 | 84 |
| 66 // Disable plugins listed as disabled in prefs. | 85 // Disable plugins listed as disabled in prefs. |
| 67 if (const ListValue* saved_plugins_list = | 86 if (ListValue* saved_plugins_list = |
| 68 profile->GetPrefs()->GetList(prefs::kPluginsPluginsList)) { | 87 profile->GetPrefs()->GetMutableList(prefs::kPluginsPluginsList)) { |
| 69 for (ListValue::const_iterator it = saved_plugins_list->begin(); | 88 for (ListValue::const_iterator it = saved_plugins_list->begin(); |
| 70 it != saved_plugins_list->end(); | 89 it != saved_plugins_list->end(); |
| 71 ++it) { | 90 ++it) { |
| 72 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { | 91 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
| 73 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; | 92 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 74 continue; // Oops, don't know what to do with this item. | 93 continue; // Oops, don't know what to do with this item. |
| 75 } | 94 } |
| 76 | 95 |
| 77 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); | 96 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); |
| 78 FilePath::StringType path; | 97 FilePath::StringType path; |
| 98 if (!plugin->GetString(L"path", &path)) |
| 99 continue; |
| 100 |
| 79 bool enabled = true; | 101 bool enabled = true; |
| 80 plugin->GetBoolean(L"enabled", &enabled); | 102 plugin->GetBoolean(L"enabled", &enabled); |
| 81 if (!enabled && plugin->GetString(L"path", &path)) { | |
| 82 FilePath plugin_path(path); | |
| 83 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); | |
| 84 | 103 |
| 85 // If the internal plugin directory has changed and if the plugin looks | 104 if (path == pdf_path_str) { |
| 86 // internal, also disable it in the current internal plugins directory. | 105 found_internal_pdf = true; |
| 87 if (update_internal_dir && | 106 if (!enabled && force_enable_internal_pdf) { |
| 88 plugin_path.DirName() == last_internal_dir) { | 107 enabled = true; |
| 89 NPAPI::PluginList::Singleton()->DisablePlugin( | 108 plugin->SetBoolean(L"enabled", true); |
| 90 cur_internal_dir.Append(plugin_path.BaseName())); | |
| 91 } | 109 } |
| 92 } | 110 } |
| 111 |
| 112 FilePath plugin_path(path); |
| 113 if (update_internal_dir && plugin_path.DirName() == last_internal_dir) { |
| 114 // If the internal plugin directory has changed and if the plugin looks |
| 115 // internal, update its path in the prefs. |
| 116 plugin_path = cur_internal_dir.Append(plugin_path.BaseName()); |
| 117 plugin->SetString(L"path", plugin_path.value()); |
| 118 } |
| 119 |
| 120 if (!enabled) |
| 121 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); |
| 93 } | 122 } |
| 94 } | 123 } |
| 95 | 124 |
| 125 if (!enable_internal_pdf_ && !found_internal_pdf) { |
| 126 // The internal PDF plugin is disabled by default, and the user hasn't |
| 127 // overridden the default. |
| 128 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path); |
| 129 } |
| 130 |
| 96 // Have Chrome plugins write their data to the profile directory. | 131 // Have Chrome plugins write their data to the profile directory. |
| 97 GetInstance()->SetChromePluginDataDir(profile->GetPath()); | 132 GetInstance()->SetChromePluginDataDir(profile->GetPath()); |
| 98 } | 133 } |
| 99 | 134 |
| 100 // static | 135 // static |
| 101 PluginService* PluginService::GetInstance() { | 136 PluginService* PluginService::GetInstance() { |
| 102 return Singleton<PluginService>::get(); | 137 return Singleton<PluginService>::get(); |
| 103 } | 138 } |
| 104 | 139 |
| 105 // static | 140 // static |
| 106 void PluginService::EnableChromePlugins(bool enable) { | 141 void PluginService::EnableChromePlugins(bool enable) { |
| 107 enable_chrome_plugins_ = enable; | 142 enable_chrome_plugins_ = enable; |
| 108 } | 143 } |
| 109 | 144 |
| 110 PluginService::PluginService() | 145 PluginService::PluginService() |
| 111 : main_message_loop_(MessageLoop::current()), | 146 : main_message_loop_(MessageLoop::current()), |
| 112 resource_dispatcher_host_(NULL), | 147 resource_dispatcher_host_(NULL), |
| 113 ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) { | 148 ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) { |
| 114 // Have the NPAPI plugin list search for Chrome plugins as well. | 149 // Have the NPAPI plugin list search for Chrome plugins as well. |
| 115 ChromePluginLib::RegisterPluginsWithNPAPI(); | 150 ChromePluginLib::RegisterPluginsWithNPAPI(); |
| 116 // Load the one specified on the command line as well. | 151 // Load the one specified on the command line as well. |
| 117 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 152 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 118 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | 153 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
| 119 if (!path.empty()) { | 154 if (!path.empty()) |
| 155 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
| 156 |
| 157 // Register the internal Flash and PDF, if available. |
| 158 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 159 switches::kDisableInternalFlash) && |
| 160 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { |
| 120 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); | 161 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
| 121 } | 162 } |
| 122 | 163 |
| 123 FilePath pdf; | 164 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) |
| 124 if (command_line->HasSwitch(switches::kInternalPDF) && | 165 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
| 125 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf)) { | |
| 126 NPAPI::PluginList::Singleton()->AddExtraPluginPath(pdf); | |
| 127 } | |
| 128 | 166 |
| 129 #ifndef DISABLE_NACL | 167 #ifndef DISABLE_NACL |
| 130 if (command_line->HasSwitch(switches::kInternalNaCl)) | 168 if (command_line->HasSwitch(switches::kInternalNaCl)) |
| 131 RegisterInternalNaClPlugin(); | 169 RegisterInternalNaClPlugin(); |
| 132 #endif | 170 #endif |
| 133 | 171 |
| 134 chrome::RegisterInternalGPUPlugin(); | 172 chrome::RegisterInternalGPUPlugin(); |
| 135 | 173 |
| 136 #if defined(OS_WIN) | 174 #if defined(OS_WIN) |
| 137 hkcu_key_.Create( | 175 hkcu_key_.Create( |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); | 406 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); |
| 369 if (it == private_plugins_.end()) | 407 if (it == private_plugins_.end()) |
| 370 return true; // This plugin is not private, so it's allowed everywhere. | 408 return true; // This plugin is not private, so it's allowed everywhere. |
| 371 | 409 |
| 372 // We do a dumb compare of scheme and host, rather than using the domain | 410 // We do a dumb compare of scheme and host, rather than using the domain |
| 373 // service, since we only care about this for extensions. | 411 // service, since we only care about this for extensions. |
| 374 const GURL& required_url = it->second; | 412 const GURL& required_url = it->second; |
| 375 return (url.scheme() == required_url.scheme() && | 413 return (url.scheme() == required_url.scheme() && |
| 376 url.host() == required_url.host()); | 414 url.host() == required_url.host()); |
| 377 } | 415 } |
| OLD | NEW |