Skip to content

Commit

Permalink
Backed out changeset c1ba8d240af2 (bug 1392485) for asserting and fai…
Browse files Browse the repository at this point in the history
…ling browser_eme.js on Windows 8 x64 debug. r=backout
  • Loading branch information
Archaeopteryx committed Aug 25, 2017
1 parent 5e563a8 commit 4f808a0
Showing 1 changed file with 1 addition and 109 deletions.
110 changes: 1 addition & 109 deletions dom/media/gmp/ChromiumCDMAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
#include "GMPLog.h"
#include "mozilla/Move.h"

#ifdef XP_WIN
#include "WinUtils.h"
#include "nsWindowsDllInterceptor.h"
#include <windows.h>
#include <strsafe.h>
#include <unordered_map>
#include <vector>
#else
#ifndef XP_WIN
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand All @@ -34,16 +27,8 @@ extern const GMPPlatformAPI* sPlatform;

namespace mozilla {

#ifdef XP_WIN
static void
InitializeHooks();
#endif

ChromiumCDMAdapter::ChromiumCDMAdapter(nsTArray<Pair<nsCString, nsCString>>&& aHostPathPairs)
{
#ifdef XP_WIN
InitializeHooks();
#endif
PopulateHostFiles(Move(aHostPathPairs));
}

Expand Down Expand Up @@ -184,99 +169,6 @@ ChromiumCDMAdapter::Supports(int32_t aModuleVersion,
aHostVersion == cdm::Host_8::kVersion;
}

#ifdef XP_WIN

static WindowsDllInterceptor sKernel32Intercept;

typedef DWORD(WINAPI* QueryDosDeviceWFnPtr)(_In_opt_ LPCWSTR lpDeviceName,
_Out_ LPWSTR lpTargetPath,
_In_ DWORD ucchMax);

static QueryDosDeviceWFnPtr sKernel32DllQueryDosDeviceWFnPtr = nullptr;

static std::unordered_map<std::wstring, std::wstring>* sDeviceNames = nullptr;

DWORD WINAPI
QueryDosDeviceWHook(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
{
if (!sDeviceNames) {
return 0;
}
std::wstring name = std::wstring(lpDeviceName);
auto iter = sDeviceNames->find(name);
if (iter == sDeviceNames->end()) {
return 0;
}
const std::wstring& device = iter->second;
if (device.size() + 1 > ucchMax) {
return 0;
}
PodCopy(lpTargetPath, device.c_str(), device.size());
lpTargetPath[device.size()] = 0;
return name.size();
}

static std::vector<std::wstring>
GetDosDeviceNames()
{
std::vector<std::wstring> v;
std::vector<wchar_t> buf;
buf.resize(1024);
DWORD rv = GetLogicalDriveStringsW(buf.size(), buf.data());
if (rv == 0) {
return v;
}

// buf will be a list of null terminated strings, with the last string
// being 0 length.
const wchar_t* p = buf.data();
const wchar_t* end = &buf.back();
size_t l;
while (p < end && (l = wcsnlen_s(p, end - p)) > 0) {
// The string is of the form "C:\". We need to strip off the trailing
// backslash.
std::wstring drive = std::wstring(p, p + l);
if (drive.back() == '\\') {
drive.erase(drive.end() - 1);
}
v.push_back(move(drive));
p += l + 1;
}
return v;
}

static std::wstring
GetDeviceMapping(const std::wstring& aDosDeviceName)
{
const size_t len = 256;
wchar_t buf[len] = { 0 };
DWORD rv = QueryDosDeviceW(aDosDeviceName.c_str(), buf, len);
if (rv == 0) {
return std::wstring(L"");
}
return std::wstring(buf, buf + rv);
}

static void
InitializeHooks()
{
static bool initialized = false;
if (initialized) {
return;
}
initialized = true;
sDeviceNames = new std::unordered_map<std::wstring, std::wstring>();
for (const std::wstring& name : GetDosDeviceNames()) {
sDeviceNames->emplace(name, GetDeviceMapping(name));
}

sKernel32Intercept.Init("kernel32.dll");
sKernel32Intercept.AddHook("QueryDosDeviceW",
reinterpret_cast<intptr_t>(QueryDosDeviceWHook),
(void**)(&sKernel32DllQueryDosDeviceWFnPtr));
}
#endif

HostFile::HostFile(HostFile&& aOther)
: mPath(aOther.mPath)
, mFile(aOther.TakePlatformFile())
Expand Down

0 comments on commit 4f808a0

Please sign in to comment.