Bug 1190252 - Remove use of mozilla\/Tokenizer from GMPChild so bug 1190252 can be uplift to 41. r=gerald

This commit is contained in:
Chris Pearce 2015-08-10 13:27:04 +12:00
Родитель bf4d4d1817
Коммит 751d662f3d
5 изменённых файлов: 78 добавлений и 22 удалений

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

@ -19,7 +19,7 @@
#include "gmp-video-encode.h"
#include "GMPPlatform.h"
#include "mozilla/dom/CrashReporterChild.h"
#include "mozilla/Tokenizer.h"
#include "GMPUtils.h"
#include "prio.h"
using mozilla::dom::CrashReporterChild;
@ -341,24 +341,6 @@ ReadIntoString(nsIFile* aFile,
return rv;
}
static nsTArray<nsCString>
SplitAt(Tokenizer::Token aDelim, const nsACString& aInput)
{
nsTArray<nsCString> tokens;
Tokenizer tokenizer(aInput);
while (!tokenizer.HasFailed()) {
tokenizer.Record();
Tokenizer::Token token;
while (tokenizer.Next(token) && !token.Equals(aDelim))
; // Skip up to next delimeter, or EOF.
nsAutoCString value;
tokenizer.Claim(value);
tokens.AppendElement(value);
}
return tokens;
}
// Pre-load DLLs that need to be used by the EME plugin but that can't be
// loaded after the sandbox has started
bool
@ -387,7 +369,9 @@ GMPChild::PreLoadLibraries(const nsAString& aPluginPath)
return false;
}
nsTArray<nsCString> lines = SplitAt(Tokenizer::Token::NewLine(), info);
// Note: we pass "\r\n" to SplitAt so that we'll split lines delimited
// by \n (Unix), \r\n (Windows) and \r (old MacOSX).
nsTArray<nsCString> lines = SplitAt("\r\n", info);
for (nsCString line : lines) {
// Make lowercase.
std::transform(line.BeginWriting(),
@ -401,8 +385,8 @@ GMPChild::PreLoadLibraries(const nsAString& aPluginPath)
continue;
}
// Line starts with "libraries:".
nsTArray<nsCString> libs = SplitAt(Tokenizer::Token::Char(','),
Substring(line, offset + strlen(libraries)));
nsTArray<nsCString> libs =
SplitAt(",", Substring(line, offset + strlen(libraries)));
for (nsCString lib : libs) {
lib.Trim(" ");
for (const char* whiteListedLib : whitelist) {

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

@ -9,6 +9,8 @@
#include "nsIFile.h"
#include "nsCOMPtr.h"
#include "nsLiteralString.h"
#include "nsCRTGlue.h"
#include "nsTArray.h"
namespace mozilla {
@ -36,4 +38,17 @@ EMEVoucherFileExists()
exists;
}
nsTArray<nsCString>
SplitAt(const char* aDelims, const nsACString& aInput)
{
nsTArray<nsCString> tokens;
nsAutoCString str(aInput);
char* end = str.BeginWriting();
const char* start = nullptr;
while (!!(start = NS_strtok(aDelims, &end))) {
tokens.AppendElement(nsCString(start));
}
return tokens;
}
} // namespace mozilla

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

@ -27,6 +27,9 @@ bool GetEMEVoucherPath(nsIFile** aPath);
bool EMEVoucherFileExists();
nsTArray<nsCString>
SplitAt(const char* aDelims, const nsACString& aInput);
} // namespace mozilla
#endif

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

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "GMPUtils.h"
#include <string>
#include <vector>
using namespace std;
using namespace mozilla;
struct SplitAtTest {
string mInput;
const char* mDelims;
vector<string> mTokens;
};
static const SplitAtTest sSplitAtTests[] {
{
"1,2,3,4",
",",
{ "1", "2", "3", "4" },
}, {
"a simple, comma, seperated, list",
",",
{"a simple", " comma", " seperated", " list"},
}, {
// Various platform line endings...
"line1\r\n" // Windows
"line2\r" // Old MacOSX
"line3\n" // Unix
"line4",
"\r\n",
{ "line1", "line2", "line3", "line4" },
},
};
TEST(GeckoMediaPlugins, GMPUtils) {
for (const SplitAtTest& test : sSplitAtTests) {
nsCString input(test.mInput.c_str(), test.mInput.size());
nsTArray<nsCString> tokens = SplitAt(test.mDelims, input);
EXPECT_EQ(tokens.Length(), test.mTokens.size()) << "Should get expected number of tokens";
for (size_t i = 0; i < tokens.Length(); i++) {
EXPECT_TRUE(tokens[i].EqualsASCII(test.mTokens[i].c_str()))
<< "Tokenize fail; expected=" << test.mTokens[i] << " got=" <<
tokens[i].BeginReading();
}
}
}

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

@ -9,6 +9,7 @@ UNIFIED_SOURCES += [
'TestAudioCompactor.cpp',
'TestGMPCrossOrigin.cpp',
'TestGMPRemoveAndDelete.cpp',
'TestGMPUtils.cpp',
'TestIntervalSet.cpp',
'TestMediaEventSource.cpp',
'TestMozPromise.cpp',