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 3 // found in the LICENSE file. 4 5 #include "content/common/pepper_plugin_list.h" 6 7 #include "base/command_line.h" 8 #include "base/strings/string_split.h" 9 #include "base/strings/string_util.h" 10 #include "base/strings/utf_string_conversions.h" 11 #include "content/public/common/content_client.h" 12 #include "content/public/common/content_switches.h" 13 #include "content/public/common/pepper_plugin_info.h" 14 #include "ppapi/shared_impl/ppapi_permissions.h" 15 16 namespace content { 17 namespace { 18 19 // Appends any plugins from the command line to the given vector. 20 void ComputePluginsFromCommandLine(std::vector<PepperPluginInfo>* plugins) { 21 bool out_of_process = true; 22 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiInProcess)) 23 out_of_process = false; 24 25 const std::string value = 26 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 27 switches::kRegisterPepperPlugins); 28 if (value.empty()) 29 return; 30 31 // FORMAT: 32 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) 33 // plugin-entry = 34 // <file-path> + 35 // ["#" + <name> + ["#" + <description> + ["#" + <version>]]] + 36 // *1( LWS + ";" + LWS + <mime-type> ) 37 std::vector<std::string> modules; 38 base::SplitString(value, ',', &modules); 39 for (size_t i = 0; i < modules.size(); ++i) { 40 std::vector<std::string> parts; 41 base::SplitString(modules[i], ';', &parts); 42 if (parts.size() < 2) { 43 DLOG(ERROR) << "Required mime-type not found"; 44 continue; 45 } 46 47 std::vector<std::string> name_parts; 48 base::SplitString(parts[0], '#', &name_parts); 49 50 PepperPluginInfo plugin; 51 plugin.is_out_of_process = out_of_process; 52 #if defined(OS_WIN) 53 // This means we can't provide plugins from non-ASCII paths, but 54 // since this switch is only for development I don't think that's 55 // too awful. 56 plugin.path = base::FilePath(ASCIIToUTF16(name_parts[0])); 57 #else 58 plugin.path = base::FilePath(name_parts[0]); 59 #endif 60 if (name_parts.size() > 1) 61 plugin.name = name_parts[1]; 62 if (name_parts.size() > 2) 63 plugin.description = name_parts[2]; 64 if (name_parts.size() > 3) 65 plugin.version = name_parts[3]; 66 for (size_t j = 1; j < parts.size(); ++j) { 67 WebPluginMimeType mime_type(parts[j], 68 std::string(), 69 plugin.description); 70 plugin.mime_types.push_back(mime_type); 71 } 72 73 // If the plugin name is empty, use the filename. 74 if (plugin.name.empty()) 75 plugin.name = UTF16ToUTF8(plugin.path.BaseName().LossyDisplayName()); 76 77 // Command-line plugins get full permissions. 78 plugin.permissions = ppapi::PERMISSION_ALL_BITS; 79 80 plugins->push_back(plugin); 81 } 82 } 83 84 } // namespace 85 86 bool MakePepperPluginInfo(const WebPluginInfo& webplugin_info, 87 PepperPluginInfo* pepper_info) { 88 if (!webplugin_info.is_pepper_plugin()) 89 return false; 90 91 pepper_info->is_out_of_process = 92 webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS || 93 webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; 94 pepper_info->is_sandboxed = webplugin_info.type != 95 WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; 96 97 pepper_info->path = base::FilePath(webplugin_info.path); 98 pepper_info->name = UTF16ToASCII(webplugin_info.name); 99 pepper_info->description = UTF16ToASCII(webplugin_info.desc); 100 pepper_info->version = UTF16ToASCII(webplugin_info.version); 101 pepper_info->mime_types = webplugin_info.mime_types; 102 pepper_info->permissions = webplugin_info.pepper_permissions; 103 104 return true; 105 } 106 107 void ComputePepperPluginList(std::vector<PepperPluginInfo>* plugins) { 108 GetContentClient()->AddPepperPlugins(plugins); 109 ComputePluginsFromCommandLine(plugins); 110 } 111 112 } // namespace content 113