Bug 1344751 - use nsStandardURL for http and https in workers. r=baku

This commit is contained in:
Catalin Badea 2017-06-09 14:20:16 +01:00
Родитель 49e524747b
Коммит 6f29260d28
3 изменённых файлов: 297 добавлений и 52 удалений

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

@ -11,8 +11,13 @@
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
#include "WorkerRunnable.h" #include "WorkerRunnable.h"
#include "WorkerScope.h" #include "WorkerScope.h"
#include "nsStandardURL.h"
#include "nsURLHelper.h"
namespace mozilla { namespace mozilla {
using net::nsStandardURL;
namespace dom { namespace dom {
using namespace workers; using namespace workers;
@ -505,24 +510,6 @@ private:
bool mFailed; bool mFailed;
}; };
already_AddRefed<URLWorker>
FinishConstructor(JSContext* aCx, WorkerPrivate* aPrivate,
ConstructorRunnable* aRunnable, ErrorResult& aRv)
{
aRunnable->Dispatch(Terminating, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<URLWorker::URLProxy> proxy = aRunnable->GetURLProxy(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<URLWorker> url = new URLWorker(aPrivate, proxy);
return url.forget();
}
/* static */ already_AddRefed<URLWorker> /* static */ already_AddRefed<URLWorker>
URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL,
const Optional<nsAString>& aBase, ErrorResult& aRv) const Optional<nsAString>& aBase, ErrorResult& aRv)
@ -530,26 +517,20 @@ URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL,
JSContext* cx = aGlobal.Context(); JSContext* cx = aGlobal.Context();
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx); WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
RefPtr<ConstructorRunnable> runnable = RefPtr<URLWorker> url = new URLWorker(workerPrivate);
new ConstructorRunnable(workerPrivate, aURL, aBase); url->Init(aURL, aBase, aRv);
return FinishConstructor(cx, workerPrivate, runnable, aRv); return aRv.Failed() ? nullptr : url.forget();
} }
/* static */ already_AddRefed<URLWorker> /* static */ already_AddRefed<URLWorker>
URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL,
const nsAString& aBase, ErrorResult& aRv) const nsAString& aBase, ErrorResult& aRv)
{ {
JSContext* cx = aGlobal.Context();
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
Optional<nsAString> base; Optional<nsAString> base;
base = &aBase; base = &aBase;
RefPtr<ConstructorRunnable> runnable = return Constructor(aGlobal, aURL, base, aRv);
new ConstructorRunnable(workerPrivate, aURL, base);
return FinishConstructor(cx, workerPrivate, runnable, aRv);
} }
/* static */ void /* static */ void
@ -624,12 +605,57 @@ URLWorker::IsValidURL(const GlobalObject& aGlobal, const nsAString& aUrl,
return runnable->IsValidURL(); return runnable->IsValidURL();
} }
URLWorker::URLWorker(WorkerPrivate* aWorkerPrivate, URLProxy* aURLProxy) URLWorker::URLWorker(WorkerPrivate* aWorkerPrivate)
: URL(nullptr) : URL(nullptr)
, mWorkerPrivate(aWorkerPrivate) , mWorkerPrivate(aWorkerPrivate)
, mURLProxy(aURLProxy)
{} {}
void
URLWorker::Init(const nsAString& aURL, const Optional<nsAString>& aBase,
ErrorResult& aRv)
{
nsAutoCString scheme;
nsresult rv = net_ExtractURLScheme(NS_ConvertUTF16toUTF8(aURL), scheme);
if (NS_FAILED(rv)) {
// this may be a relative URL, check baseURL
if (!aBase.WasPassed()) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aURL);
return;
}
rv = net_ExtractURLScheme(NS_ConvertUTF16toUTF8(aBase.Value()), scheme);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aURL);
return;
}
}
if (scheme.Equals(NS_LITERAL_CSTRING("http")) ||
scheme.Equals(NS_LITERAL_CSTRING("https"))) {
RefPtr<nsStandardURL> baseURL;
if (aBase.WasPassed()) {
baseURL = new nsStandardURL();
rv = baseURL->SetSpec(NS_ConvertUTF16toUTF8(aBase.Value()));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aBase.Value());
return;
}
}
mStdURL = new nsStandardURL();
aRv = mStdURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1,
NS_ConvertUTF16toUTF8(aURL), nullptr, baseURL);
return;
}
// create url proxy
RefPtr<ConstructorRunnable> runnable =
new ConstructorRunnable(mWorkerPrivate, aURL, aBase);
runnable->Dispatch(Terminating, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mURLProxy = runnable->GetURLProxy(aRv);
}
URLWorker::~URLWorker() URLWorker::~URLWorker()
{ {
if (mURLProxy) { if (mURLProxy) {
@ -648,16 +674,56 @@ URLWorker::~URLWorker()
void void
URLWorker::GetHref(nsAString& aHref, ErrorResult& aRv) const URLWorker::GetHref(nsAString& aHref, ErrorResult& aRv) const
{ {
aHref.Truncate();
if (mStdURL) {
nsAutoCString href;
aRv = mStdURL->GetSpec(href);
if (!aRv.Failed()) {
CopyUTF8toUTF16(href, aHref);
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHref, aHref, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHref, aHref,
mURLProxy); mURLProxy);
runnable->Dispatch(aRv); runnable->Dispatch(aRv);
} }
void void
URLWorker::SetHref(const nsAString& aHref, ErrorResult& aRv) URLWorker::SetHref(const nsAString& aHref, ErrorResult& aRv)
{ {
nsAutoCString scheme;
nsresult rv = net_ExtractURLScheme(NS_ConvertUTF16toUTF8(aHref), scheme);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aHref);
return;
}
if (scheme.Equals(NS_LITERAL_CSTRING("http")) ||
scheme.Equals(NS_LITERAL_CSTRING("https"))) {
mStdURL = new nsStandardURL();
aRv = mStdURL->SetSpec(NS_ConvertUTF16toUTF8(aHref));
if (mURLProxy) {
mWorkerPrivate->AssertIsOnWorkerThread();
RefPtr<TeardownURLRunnable> runnable =
new TeardownURLRunnable(mURLProxy);
mURLProxy = nullptr;
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(runnable)))) {
return;
}
}
UpdateURLSearchParams();
return;
}
mStdURL = nullptr;
// fallback to using a main thread url proxy
if (mURLProxy) {
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHref, aHref, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHref, aHref,
mURLProxy); mURLProxy);
@ -667,17 +733,31 @@ URLWorker::SetHref(const nsAString& aHref, ErrorResult& aRv)
return; return;
} }
if (runnable->Failed()) { UpdateURLSearchParams();
aRv.ThrowTypeError<MSG_INVALID_URL>(aHref);
return; return;
} }
// create the proxy now
RefPtr<ConstructorRunnable> runnable =
new ConstructorRunnable(mWorkerPrivate, aHref, Optional<nsAString>());
runnable->Dispatch(Terminating, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mURLProxy = runnable->GetURLProxy(aRv);
UpdateURLSearchParams(); UpdateURLSearchParams();
} }
void void
URLWorker::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const URLWorker::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const
{ {
if (mStdURL) {
nsContentUtils::GetUTFOrigin(mStdURL, aOrigin);
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterOrigin, aOrigin, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterOrigin, aOrigin,
mURLProxy); mURLProxy);
@ -688,6 +768,18 @@ URLWorker::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const
void void
URLWorker::GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const URLWorker::GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const
{ {
aProtocol.Truncate();
nsAutoCString protocol;
if (mStdURL) {
if (NS_SUCCEEDED(mStdURL->GetScheme(protocol))) {
CopyASCIItoUTF16(protocol, aProtocol);
aProtocol.Append(char16_t(':'));
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterProtocol, aProtocol, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterProtocol, aProtocol,
mURLProxy); mURLProxy);
@ -698,6 +790,30 @@ URLWorker::GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const
void void
URLWorker::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv) URLWorker::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv)
{ {
if (mStdURL) {
nsAString::const_iterator start, end;
aProtocol.BeginReading(start);
aProtocol.EndReading(end);
nsAString::const_iterator iter(start);
FindCharInReadable(':', iter, end);
nsresult rv = mStdURL->SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsAutoCString href;
rv = mStdURL->GetSpec(href);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
SetHref(NS_ConvertUTF8toUTF16(href), aRv);
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterProtocol, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterProtocol,
aProtocol, mURLProxy); aProtocol, mURLProxy);
@ -707,9 +823,29 @@ URLWorker::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv)
MOZ_ASSERT(!runnable->Failed()); MOZ_ASSERT(!runnable->Failed());
} }
#define STDURL_GETTER(value, method) \
if (mStdURL) { \
value.Truncate(); \
nsAutoCString tmp; \
nsresult rv = mStdURL->method(tmp); \
if (NS_SUCCEEDED(rv)) { \
CopyUTF8toUTF16(tmp, value); \
} \
return; \
}
#define STDURL_SETTER(value, method) \
if (mStdURL) { \
aRv = mStdURL->method(NS_ConvertUTF16toUTF8(value)); \
return; \
}
void void
URLWorker::GetUsername(nsAString& aUsername, ErrorResult& aRv) const URLWorker::GetUsername(nsAString& aUsername, ErrorResult& aRv) const
{ {
STDURL_GETTER(aUsername, GetUsername);
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterUsername, aUsername, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterUsername, aUsername,
mURLProxy); mURLProxy);
@ -720,6 +856,9 @@ URLWorker::GetUsername(nsAString& aUsername, ErrorResult& aRv) const
void void
URLWorker::SetUsername(const nsAString& aUsername, ErrorResult& aRv) URLWorker::SetUsername(const nsAString& aUsername, ErrorResult& aRv)
{ {
STDURL_SETTER(aUsername, SetUsername);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterUsername, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterUsername,
aUsername, mURLProxy); aUsername, mURLProxy);
@ -735,6 +874,9 @@ URLWorker::SetUsername(const nsAString& aUsername, ErrorResult& aRv)
void void
URLWorker::GetPassword(nsAString& aPassword, ErrorResult& aRv) const URLWorker::GetPassword(nsAString& aPassword, ErrorResult& aRv) const
{ {
STDURL_GETTER(aPassword, GetPassword);
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPassword, aPassword, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPassword, aPassword,
mURLProxy); mURLProxy);
@ -745,6 +887,9 @@ URLWorker::GetPassword(nsAString& aPassword, ErrorResult& aRv) const
void void
URLWorker::SetPassword(const nsAString& aPassword, ErrorResult& aRv) URLWorker::SetPassword(const nsAString& aPassword, ErrorResult& aRv)
{ {
STDURL_SETTER(aPassword, SetPassword);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPassword, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPassword,
aPassword, mURLProxy); aPassword, mURLProxy);
@ -760,6 +905,9 @@ URLWorker::SetPassword(const nsAString& aPassword, ErrorResult& aRv)
void void
URLWorker::GetHost(nsAString& aHost, ErrorResult& aRv) const URLWorker::GetHost(nsAString& aHost, ErrorResult& aRv) const
{ {
STDURL_GETTER(aHost, GetHostPort);
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHost, aHost, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHost, aHost,
mURLProxy); mURLProxy);
@ -770,6 +918,9 @@ URLWorker::GetHost(nsAString& aHost, ErrorResult& aRv) const
void void
URLWorker::SetHost(const nsAString& aHost, ErrorResult& aRv) URLWorker::SetHost(const nsAString& aHost, ErrorResult& aRv)
{ {
STDURL_SETTER(aHost, SetHostPort);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHost, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHost,
aHost, mURLProxy); aHost, mURLProxy);
@ -785,6 +936,13 @@ URLWorker::SetHost(const nsAString& aHost, ErrorResult& aRv)
void void
URLWorker::GetHostname(nsAString& aHostname, ErrorResult& aRv) const URLWorker::GetHostname(nsAString& aHostname, ErrorResult& aRv) const
{ {
aHostname.Truncate();
if (mStdURL) {
aRv = nsContentUtils::GetHostOrIPv6WithBrackets(mStdURL, aHostname);
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHostname, aHostname, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHostname, aHostname,
mURLProxy); mURLProxy);
@ -795,6 +953,9 @@ URLWorker::GetHostname(nsAString& aHostname, ErrorResult& aRv) const
void void
URLWorker::SetHostname(const nsAString& aHostname, ErrorResult& aRv) URLWorker::SetHostname(const nsAString& aHostname, ErrorResult& aRv)
{ {
STDURL_SETTER(aHostname, SetHost);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHostname, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHostname,
aHostname, mURLProxy); aHostname, mURLProxy);
@ -810,6 +971,20 @@ URLWorker::SetHostname(const nsAString& aHostname, ErrorResult& aRv)
void void
URLWorker::GetPort(nsAString& aPort, ErrorResult& aRv) const URLWorker::GetPort(nsAString& aPort, ErrorResult& aRv) const
{ {
aPort.Truncate();
if (mStdURL) {
int32_t port;
nsresult rv = mStdURL->GetPort(&port);
if (NS_SUCCEEDED(rv) && port != -1) {
nsAutoString portStr;
portStr.AppendInt(port, 10);
aPort.Assign(portStr);
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPort, aPort, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPort, aPort,
mURLProxy); mURLProxy);
@ -820,6 +995,24 @@ URLWorker::GetPort(nsAString& aPort, ErrorResult& aRv) const
void void
URLWorker::SetPort(const nsAString& aPort, ErrorResult& aRv) URLWorker::SetPort(const nsAString& aPort, ErrorResult& aRv)
{ {
if (mStdURL) {
nsresult rv;
nsAutoString portStr(aPort);
int32_t port = -1;
// nsIURI uses -1 as default value.
if (!portStr.IsEmpty()) {
port = portStr.ToInteger(&rv);
if (NS_FAILED(rv)) {
return;
}
}
mStdURL->SetPort(port);
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPort, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPort,
aPort, mURLProxy); aPort, mURLProxy);
@ -835,6 +1028,18 @@ URLWorker::SetPort(const nsAString& aPort, ErrorResult& aRv)
void void
URLWorker::GetPathname(nsAString& aPathname, ErrorResult& aRv) const URLWorker::GetPathname(nsAString& aPathname, ErrorResult& aRv) const
{ {
aPathname.Truncate();
if (mStdURL) {
nsAutoCString file;
nsresult rv = mStdURL->GetFilePath(file);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(file, aPathname);
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPathname, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPathname,
aPathname, mURLProxy); aPathname, mURLProxy);
@ -845,6 +1050,9 @@ URLWorker::GetPathname(nsAString& aPathname, ErrorResult& aRv) const
void void
URLWorker::SetPathname(const nsAString& aPathname, ErrorResult& aRv) URLWorker::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
{ {
STDURL_SETTER(aPathname, SetFilePath);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPathname, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPathname,
aPathname, mURLProxy); aPathname, mURLProxy);
@ -860,6 +1068,20 @@ URLWorker::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
void void
URLWorker::GetSearch(nsAString& aSearch, ErrorResult& aRv) const URLWorker::GetSearch(nsAString& aSearch, ErrorResult& aRv) const
{ {
aSearch.Truncate();
if (mStdURL) {
nsAutoCString search;
nsresult rv;
rv = mStdURL->GetQuery(search);
if (NS_SUCCEEDED(rv) && !search.IsEmpty()) {
CopyUTF8toUTF16(NS_LITERAL_CSTRING("?") + search, aSearch);
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterSearch, aSearch, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterSearch, aSearch,
mURLProxy); mURLProxy);
@ -870,6 +1092,18 @@ URLWorker::GetSearch(nsAString& aSearch, ErrorResult& aRv) const
void void
URLWorker::GetHash(nsAString& aHash, ErrorResult& aRv) const URLWorker::GetHash(nsAString& aHash, ErrorResult& aRv) const
{ {
aHash.Truncate();
if (mStdURL) {
nsAutoCString ref;
nsresult rv = mStdURL->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
}
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<GetterRunnable> runnable = RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHash, aHash, new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHash, aHash,
mURLProxy); mURLProxy);
@ -880,6 +1114,9 @@ URLWorker::GetHash(nsAString& aHash, ErrorResult& aRv) const
void void
URLWorker::SetHash(const nsAString& aHash, ErrorResult& aRv) URLWorker::SetHash(const nsAString& aHash, ErrorResult& aRv)
{ {
STDURL_SETTER(aHash, SetRef);
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHash, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHash,
aHash, mURLProxy); aHash, mURLProxy);
@ -895,6 +1132,13 @@ URLWorker::SetHash(const nsAString& aHash, ErrorResult& aRv)
void void
URLWorker::SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv) URLWorker::SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv)
{ {
if (mStdURL) {
// URLMainThread ignores failures here.
mStdURL->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
return;
}
MOZ_ASSERT(mURLProxy);
RefPtr<SetterRunnable> runnable = RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterSearch, new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterSearch,
aSearch, mURLProxy); aSearch, mURLProxy);
@ -923,12 +1167,5 @@ URLWorker::UpdateURLSearchParams()
} }
} }
URLWorker::URLProxy*
URLWorker::GetURLProxy() const
{
mWorkerPrivate->AssertIsOnWorkerThread();
return mURLProxy;
}
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla

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

@ -11,6 +11,11 @@
#include "URLMainThread.h" #include "URLMainThread.h"
namespace mozilla { namespace mozilla {
namespace net {
class nsStandardURL;
}
namespace dom { namespace dom {
namespace workers { namespace workers {
@ -43,7 +48,11 @@ public:
IsValidURL(const GlobalObject& aGlobal, const nsAString& aUrl, IsValidURL(const GlobalObject& aGlobal, const nsAString& aUrl,
ErrorResult& aRv); ErrorResult& aRv);
URLWorker(workers::WorkerPrivate* aWorkerPrivate, URLProxy* aURLProxy); explicit URLWorker(workers::WorkerPrivate* aWorkerPrivate);
void
Init(const nsAString& aURL, const Optional<nsAString>& aBase,
ErrorResult& aRv);
virtual void virtual void
GetHref(nsAString& aHref, ErrorResult& aRv) const override; GetHref(nsAString& aHref, ErrorResult& aRv) const override;
@ -110,14 +119,12 @@ public:
virtual void virtual void
SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv) override; SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv) override;
URLProxy*
GetURLProxy() const;
private: private:
~URLWorker(); ~URLWorker();
workers::WorkerPrivate* mWorkerPrivate; workers::WorkerPrivate* mWorkerPrivate;
RefPtr<URLProxy> mURLProxy; RefPtr<URLProxy> mURLProxy;
RefPtr<net::nsStandardURL> mStdURL;
}; };
} // namespace dom } // namespace dom

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

@ -21,6 +21,7 @@ UNIFIED_SOURCES += [
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'../workers', '../workers',
'/netwerk/base',
] ]
MOCHITEST_MANIFESTS += ['tests/mochitest.ini'] MOCHITEST_MANIFESTS += ['tests/mochitest.ini']