| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/media/pepper_cdm_test_helper.h" | 5 #include "chrome/browser/media/pepper_cdm_test_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/public/browser/plugin_service.h" |
| 11 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 13 #include "content/public/common/webplugininfo.h" |
| 12 #include "media/cdm/cdm_paths.h" | 14 #include "media/cdm/cdm_paths.h" |
| 13 | 15 |
| 14 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 16 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 15 | 17 |
| 16 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm"; | 18 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm"; |
| 17 | 19 |
| 18 const char kClearKeyCdmAdapterFileName[] = | 20 const char kClearKeyCdmAdapterFileName[] = |
| 19 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 20 "clearkeycdmadapter.plugin"; | 22 "clearkeycdmadapter.plugin"; |
| 21 #elif defined(OS_WIN) | 23 #elif defined(OS_WIN) |
| 22 "clearkeycdmadapter.dll"; | 24 "clearkeycdmadapter.dll"; |
| 23 #elif defined(OS_POSIX) | 25 #elif defined(OS_POSIX) |
| 24 "libclearkeycdmadapter.so"; | 26 "libclearkeycdmadapter.so"; |
| 25 #endif | 27 #endif |
| 26 | 28 |
| 27 const char kClearKeyCdmDisplayName[] = "Clear Key CDM"; | 29 const char kClearKeyCdmDisplayName[] = "Clear Key CDM"; |
| 28 | 30 |
| 29 const char kClearKeyCdmPepperMimeType[] = "application/x-ppapi-clearkey-cdm"; | 31 const char kClearKeyCdmPepperMimeType[] = "application/x-ppapi-clearkey-cdm"; |
| 30 | 32 |
| 33 base::FilePath GetPepperCdmPath(const std::string& adapter_base_dir, |
| 34 const std::string& adapter_file_name) { |
| 35 base::FilePath adapter_path; |
| 36 PathService::Get(base::DIR_MODULE, &adapter_path); |
| 37 adapter_path = adapter_path.Append( |
| 38 media::GetPlatformSpecificDirectory(adapter_base_dir)); |
| 39 adapter_path = adapter_path.AppendASCII(adapter_file_name); |
| 40 return adapter_path; |
| 41 } |
| 42 |
| 31 base::FilePath::StringType BuildPepperCdmRegistration( | 43 base::FilePath::StringType BuildPepperCdmRegistration( |
| 32 const std::string& adapter_base_dir, | 44 const std::string& adapter_base_dir, |
| 33 const std::string& adapter_file_name, | 45 const std::string& adapter_file_name, |
| 34 const std::string& display_name, | 46 const std::string& display_name, |
| 35 const std::string& mime_type, | 47 const std::string& mime_type, |
| 36 bool expect_adapter_exists) { | 48 bool expect_adapter_exists) { |
| 37 base::FilePath adapter_path; | 49 base::FilePath adapter_path = |
| 38 PathService::Get(base::DIR_MODULE, &adapter_path); | 50 GetPepperCdmPath(adapter_base_dir, adapter_file_name); |
| 39 adapter_path = adapter_path.Append( | |
| 40 media::GetPlatformSpecificDirectory(adapter_base_dir)); | |
| 41 adapter_path = adapter_path.AppendASCII(adapter_file_name); | |
| 42 DCHECK_EQ(expect_adapter_exists, base::PathExists(adapter_path)) | 51 DCHECK_EQ(expect_adapter_exists, base::PathExists(adapter_path)) |
| 43 << adapter_path.MaybeAsASCII(); | 52 << adapter_path.MaybeAsASCII(); |
| 44 | 53 |
| 45 base::FilePath::StringType pepper_cdm_registration = adapter_path.value(); | 54 base::FilePath::StringType pepper_cdm_registration = adapter_path.value(); |
| 46 | 55 |
| 47 std::string string_to_append = "#"; | 56 std::string string_to_append = "#"; |
| 48 string_to_append.append(display_name); | 57 string_to_append.append(display_name); |
| 49 string_to_append.append("#CDM#0.1.0.0;"); | 58 string_to_append.append("#CDM#0.1.0.0;"); |
| 50 string_to_append.append(mime_type); | 59 string_to_append.append(mime_type); |
| 51 | 60 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 bool expect_adapter_exists) { | 75 bool expect_adapter_exists) { |
| 67 base::FilePath::StringType pepper_cdm_registration = | 76 base::FilePath::StringType pepper_cdm_registration = |
| 68 BuildPepperCdmRegistration(adapter_base_dir, adapter_file_name, | 77 BuildPepperCdmRegistration(adapter_base_dir, adapter_file_name, |
| 69 display_name, mime_type, | 78 display_name, mime_type, |
| 70 expect_adapter_exists); | 79 expect_adapter_exists); |
| 71 | 80 |
| 72 // Append the switch to register the CDM Adapter. | 81 // Append the switch to register the CDM Adapter. |
| 73 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | 82 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| 74 pepper_cdm_registration); | 83 pepper_cdm_registration); |
| 75 } | 84 } |
| 85 |
| 86 bool IsPepperCdmRegistered(const std::string& mime_type) { |
| 87 std::vector<content::WebPluginInfo> plugins; |
| 88 content::PluginService::GetInstance()->GetInternalPlugins(&plugins); |
| 89 for (const auto& plugin : plugins) { |
| 90 for (const auto& plugin_mime_type : plugin.mime_types) { |
| 91 if (plugin_mime_type.mime_type == mime_type) |
| 92 return true; |
| 93 } |
| 94 } |
| 95 return false; |
| 96 } |
| OLD | NEW |