Bug 1390725 - Change the loading path of CDM host verification file on Mac. r=cpearce

The plugin-container sig file is located in another place.
Need to handle it as a special case.

MozReview-Commit-ID: 2e2gbM4CVDG

--HG--
extra : rebase_source : 26add2e4e68a919927b9500e7e391d7bb327ee81
This commit is contained in:
James Cheng 2017-08-17 00:13:05 +08:00
Родитель d2dd8c5d8f
Коммит 4c094ae65d
4 изменённых файлов: 74 добавлений и 21 удалений

Просмотреть файл

@ -27,9 +27,9 @@ extern const GMPPlatformAPI* sPlatform;
namespace mozilla {
ChromiumCDMAdapter::ChromiumCDMAdapter(nsTArray<nsCString>&& aHostFilePaths)
ChromiumCDMAdapter::ChromiumCDMAdapter(nsTArray<Pair<nsCString, nsCString>>&& aHostPathPairs)
{
PopulateHostFiles(Move(aHostFilePaths));
PopulateHostFiles(Move(aHostPathPairs));
}
void
@ -220,12 +220,12 @@ HostFile::TakePlatformFile()
}
void
ChromiumCDMAdapter::PopulateHostFiles(nsTArray<nsCString>&& aHostFilePaths)
ChromiumCDMAdapter::PopulateHostFiles(nsTArray<Pair<nsCString, nsCString>>&& aHostPathPairs)
{
for (const nsCString& path : aHostFilePaths) {
for (const auto& pair : aHostPathPairs) {
mHostFiles.AppendElement(
HostFileData(mozilla::HostFile(path),
mozilla::HostFile(path + NS_LITERAL_CSTRING(".sig"))));
HostFileData(mozilla::HostFile(pair.first()),
mozilla::HostFile(pair.second())));
}
}

Просмотреть файл

@ -12,6 +12,7 @@
#include "nsTArray.h"
#include "content_decryption_module_ext.h"
#include "nsString.h"
#include "mozilla/Pair.h"
struct GMPPlatformAPI;
@ -61,7 +62,7 @@ struct HostFileData
class ChromiumCDMAdapter : public gmp::GMPAdapter
{
public:
explicit ChromiumCDMAdapter(nsTArray<nsCString>&& aHostFilePaths);
explicit ChromiumCDMAdapter(nsTArray<Pair<nsCString, nsCString>>&& aHostPathPairs);
void SetAdaptee(PRLibrary* aLib) override;
@ -78,7 +79,7 @@ public:
int32_t aHostVersion);
private:
void PopulateHostFiles(nsTArray<nsCString>&& aHostFilePaths);
void PopulateHostFiles(nsTArray<Pair<nsCString, nsCString>>&& aHostFilePaths);
PRLibrary* mLib = nullptr;
nsTArray<HostFileData> mHostFiles;

Просмотреть файл

@ -376,19 +376,45 @@ GetFirefoxAppPath(nsCOMPtr<nsIFile> aPluginContainerPath,
aOutFirefoxAppPath = path;
return true;
}
static bool
GetPluginContainerSigPath(nsCOMPtr<nsIFile> aPluginContainerPath,
nsCOMPtr<nsIFile>& aOutPluginContainerSigPath)
{
// The sig file will be located in
// xxxx/NightlyDebug.app/Contents/MacOS/plugin-container.app/Contents/Resources/plugin-container.sig
// On MacOS the plugin-container.sig file is a few parent directories up from
// plugin-container.
// Start to search the path from the path of plugin-container.
MOZ_ASSERT(aPluginContainerPath);
nsCOMPtr<nsIFile> path = aPluginContainerPath;
for (int i = 0; i < 2; i++) {
nsCOMPtr<nsIFile> parent;
if (NS_FAILED(path->GetParent(getter_AddRefs(parent)))) {
return false;
}
path = parent;
}
MOZ_ASSERT(path);
aOutPluginContainerSigPath = path;
return NS_SUCCEEDED(path->Append(NS_LITERAL_STRING("Resources"))) &&
NS_SUCCEEDED(path->Append(NS_LITERAL_STRING("plugin-container.sig")));
}
#endif
nsTArray<nsCString>
nsTArray<Pair<nsCString, nsCString>>
GMPChild::MakeCDMHostVerificationPaths()
{
nsTArray<nsCString> paths;
// Record the file path and its sig file path.
nsTArray<Pair<nsCString, nsCString>> paths;
// Plugin binary path.
nsCOMPtr<nsIFile> path;
nsString str;
if (GetPluginFile(mPluginPath, path) && FileExists(path) &&
ResolveLinks(path) && NS_SUCCEEDED(path->GetPath(str))) {
paths.AppendElement(NS_ConvertUTF16toUTF8(str));
paths.AppendElement(
MakePair(nsCString(NS_ConvertUTF16toUTF8(str)),
nsCString(NS_ConvertUTF16toUTF8(str) + NS_LITERAL_CSTRING(".sig"))));
}
// Plugin-container binary path.
@ -403,7 +429,26 @@ GMPChild::MakeCDMHostVerificationPaths()
getter_AddRefs(path))) &&
FileExists(path) && ResolveLinks(path) &&
NS_SUCCEEDED(path->GetPath(str))) {
paths.AppendElement(nsCString(NS_ConvertUTF16toUTF8(str)));
nsCString filePath = NS_ConvertUTF16toUTF8(str);
nsCString sigFilePath;
#if defined(XP_MACOSX)
nsCOMPtr<nsIFile> sigFile;
if (GetPluginContainerSigPath(path, sigFile) &&
NS_SUCCEEDED(sigFile->GetPath(str))) {
sigFilePath = NS_ConvertUTF16toUTF8(str);
} else {
// Cannot successfully get the sig file path.
// Assume it is located at the same place as plugin-container alternatively.
sigFilePath = nsCString(NS_ConvertUTF16toUTF8(str) +
NS_LITERAL_CSTRING(".sig"));
}
#else
sigFilePath = nsCString(NS_ConvertUTF16toUTF8(str) +
NS_LITERAL_CSTRING(".sig"));
#endif
paths.AppendElement(
MakePair(Move(filePath),
Move(sigFilePath)));
} else {
// Without successfully determining plugin-container's path, we can't
// determine libxul's or Firefox's. So give up.
@ -419,7 +464,9 @@ GMPChild::MakeCDMHostVerificationPaths()
NS_SUCCEEDED(appDir->Clone(getter_AddRefs(path))) &&
NS_SUCCEEDED(path->Append(FIREFOX_FILE)) && FileExists(path) &&
ResolveLinks(path) && NS_SUCCEEDED(path->GetPath(str))) {
paths.AppendElement(NS_ConvertUTF16toUTF8(str));
paths.AppendElement(
MakePair(nsCString(NS_ConvertUTF16toUTF8(str)),
nsCString(NS_ConvertUTF16toUTF8(str) + NS_LITERAL_CSTRING(".sig"))));
}
#else
// Note: re-using 'path' var here, as on Windows/Linux we assume Firefox
@ -428,7 +475,9 @@ GMPChild::MakeCDMHostVerificationPaths()
NS_SUCCEEDED(appDir->Clone(getter_AddRefs(path))) &&
NS_SUCCEEDED(path->Append(FIREFOX_FILE)) && FileExists(path) &&
ResolveLinks(path) && NS_SUCCEEDED(path->GetPath(str))) {
paths.AppendElement(NS_ConvertUTF16toUTF8(str));
paths.AppendElement(
MakePair(nsCString(NS_ConvertUTF16toUTF8(str)),
nsCString(NS_ConvertUTF16toUTF8(str) + NS_LITERAL_CSTRING(".sig"))));
}
#endif
// Libxul path. Note: re-using 'path' var here, as we assume libxul is in
@ -437,21 +486,23 @@ GMPChild::MakeCDMHostVerificationPaths()
if (NS_SUCCEEDED(appDir->Clone(getter_AddRefs(path))) &&
NS_SUCCEEDED(path->Append(XUL_LIB_FILE)) && FileExists(path) &&
ResolveLinks(path) && NS_SUCCEEDED(path->GetPath(str))) {
paths.AppendElement(NS_ConvertUTF16toUTF8(str));
paths.AppendElement(
MakePair(nsCString(NS_ConvertUTF16toUTF8(str)),
nsCString(NS_ConvertUTF16toUTF8(str) + NS_LITERAL_CSTRING(".sig"))));
}
return paths;
}
static nsCString
ToCString(const nsTArray<nsCString>& aStrings)
ToCString(const nsTArray<Pair<nsCString, nsCString>>& aPairs)
{
nsCString result;
for (const nsCString& s : aStrings) {
for (const auto& p : aPairs) {
if (!result.IsEmpty()) {
result.AppendLiteral(",");
}
result.Append(s);
result.Append(nsPrintfCString("(%s,%s)", p.first().get(), p.second().get()));
}
return result;
}
@ -496,7 +547,7 @@ GMPChild::AnswerStartPlugin(const nsString& aAdapter)
if (isWidevine) {
adapter = new WidevineAdapter();
} else if (isChromium) {
nsTArray<nsCString> paths(MakeCDMHostVerificationPaths());
auto&& paths = MakeCDMHostVerificationPaths();
GMP_LOG("%s CDM host paths=%s", __func__, ToCString(paths).get());
adapter = new ChromiumCDMAdapter(Move(paths));
}

Просмотреть файл

@ -7,6 +7,7 @@
#define GMPChild_h_
#include "mozilla/gmp/PGMPChild.h"
#include "mozilla/Pair.h"
#include "GMPTimerChild.h"
#include "GMPStorageChild.h"
#include "GMPLoader.h"
@ -66,7 +67,7 @@ private:
GMPErr GetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI, uint32_t aDecryptorId = 0);
nsTArray<nsCString> MakeCDMHostVerificationPaths();
nsTArray<Pair<nsCString, nsCString>> MakeCDMHostVerificationPaths();
nsTArray<UniquePtr<GMPContentChild>> mGMPContentChildren;