2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-02-05 15:17:17 -08:00
|
|
|
/* 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 "URL.h"
|
|
|
|
|
2013-10-23 06:16:49 -07:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-02-05 15:17:17 -08:00
|
|
|
|
2014-10-08 09:15:23 -07:00
|
|
|
#include "mozilla/dom/File.h"
|
2013-09-04 10:07:34 -07:00
|
|
|
#include "mozilla/dom/URL.h"
|
2013-11-05 06:16:25 -08:00
|
|
|
#include "mozilla/dom/URLBinding.h"
|
2013-12-12 11:30:27 -08:00
|
|
|
#include "mozilla/dom/URLSearchParams.h"
|
2014-12-19 11:59:02 -08:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
|
|
|
#include "mozilla/dom/ipc/nsIRemoteBlob.h"
|
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
2013-10-23 06:16:49 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsHostObjectProtocolHandler.h"
|
2013-09-04 10:07:34 -07:00
|
|
|
#include "nsNetCID.h"
|
2013-10-23 06:16:49 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
2015-07-02 05:54:00 -07:00
|
|
|
#include "WorkerScope.h"
|
2013-09-04 10:07:34 -07:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
2013-08-22 22:17:08 -07:00
|
|
|
using mozilla::dom::GlobalObject;
|
2013-02-05 15:17:17 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class URLProxy final
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLProxy)
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
explicit URLProxy(already_AddRefed<mozilla::dom::URL> aURL)
|
2013-09-04 10:07:34 -07:00
|
|
|
: mURL(aURL)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::dom::URL* URL()
|
|
|
|
{
|
|
|
|
return mURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* URI()
|
|
|
|
{
|
|
|
|
return mURL->GetURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReleaseURI()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mURL = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-04-02 09:21:03 -07:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
|
|
|
~URLProxy()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mURL);
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<mozilla::dom::URL> mURL;
|
|
|
|
};
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
// This class creates an URL from a DOM Blob on the main thread.
|
2014-02-24 05:57:03 -08:00
|
|
|
class CreateURLRunnable : public WorkerMainThreadRunnable
|
2013-02-05 15:17:17 -08:00
|
|
|
{
|
|
|
|
private:
|
2015-05-12 05:11:03 -07:00
|
|
|
BlobImpl* mBlobImpl;
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAString& mURL;
|
2013-02-05 15:17:17 -08:00
|
|
|
|
|
|
|
public:
|
2015-05-12 05:11:03 -07:00
|
|
|
CreateURLRunnable(WorkerPrivate* aWorkerPrivate, BlobImpl* aBlobImpl,
|
2013-08-22 22:17:09 -07:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAString& aURL)
|
2015-05-07 00:06:24 -07:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, mBlobImpl(aBlobImpl)
|
|
|
|
, mURL(aURL)
|
2013-02-05 15:17:17 -08:00
|
|
|
{
|
2014-06-26 20:46:34 -07:00
|
|
|
MOZ_ASSERT(aBlobImpl);
|
2015-01-13 14:15:04 -08:00
|
|
|
|
|
|
|
DebugOnly<bool> isMutable;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(aBlobImpl->GetMutable(&isMutable)));
|
|
|
|
MOZ_ASSERT(!isMutable);
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-02-05 15:17:17 -08:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
2014-12-19 11:59:02 -08:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2015-05-12 05:11:03 -07:00
|
|
|
nsRefPtr<BlobImpl> newBlobImplHolder;
|
2014-12-19 11:59:02 -08:00
|
|
|
|
|
|
|
if (nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(mBlobImpl)) {
|
|
|
|
if (BlobChild* blobChild = remoteBlob->GetBlobChild()) {
|
|
|
|
if (PBackgroundChild* blobManager = blobChild->GetBackgroundManager()) {
|
|
|
|
PBackgroundChild* backgroundManager =
|
|
|
|
BackgroundChild::GetForCurrentThread();
|
|
|
|
MOZ_ASSERT(backgroundManager);
|
|
|
|
|
|
|
|
if (blobManager != backgroundManager) {
|
|
|
|
// Always make sure we have a blob from an actor we can use on this
|
|
|
|
// thread.
|
|
|
|
blobChild = BlobChild::GetOrCreate(backgroundManager, mBlobImpl);
|
|
|
|
MOZ_ASSERT(blobChild);
|
|
|
|
|
|
|
|
newBlobImplHolder = blobChild->GetBlobImpl();
|
|
|
|
MOZ_ASSERT(newBlobImplHolder);
|
|
|
|
|
|
|
|
mBlobImpl = newBlobImplHolder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 14:15:04 -08:00
|
|
|
DebugOnly<bool> isMutable;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mBlobImpl->GetMutable(&isMutable)));
|
|
|
|
MOZ_ASSERT(!isMutable);
|
|
|
|
|
2015-05-07 00:06:24 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = mWorkerPrivate->GetPrincipal();
|
2013-02-05 15:17:17 -08:00
|
|
|
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAutoCString url;
|
2013-02-05 15:17:17 -08:00
|
|
|
nsresult rv = nsHostObjectProtocolHandler::AddDataEntry(
|
|
|
|
NS_LITERAL_CSTRING(BLOBURI_SCHEME),
|
2014-06-26 20:46:34 -07:00
|
|
|
mBlobImpl, principal, url);
|
2013-02-05 15:17:17 -08:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to add data entry for the blob!");
|
|
|
|
SetDOMStringToNull(mURL);
|
2014-02-24 05:57:03 -08:00
|
|
|
return false;
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
|
2015-05-07 00:06:24 -07:00
|
|
|
if (!mWorkerPrivate->IsSharedWorker() &&
|
|
|
|
!mWorkerPrivate->IsServiceWorker()) {
|
|
|
|
// Walk up to top worker object.
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (WorkerPrivate* parent = wp->GetParent()) {
|
|
|
|
wp = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> sc = wp->GetScriptContext();
|
|
|
|
// We could not have a ScriptContext in JSM code. In this case, we leak.
|
|
|
|
if (sc) {
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = sc->GetGlobalObject();
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
|
|
|
global->RegisterHostObjectURI(url);
|
|
|
|
}
|
2013-06-22 14:48:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
mURL = NS_ConvertUTF8toUTF16(url);
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class revokes an URL on the main thread.
|
2014-02-24 05:57:03 -08:00
|
|
|
class RevokeURLRunnable : public WorkerMainThreadRunnable
|
2013-02-05 15:17:17 -08:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
const nsString mURL;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RevokeURLRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsAString& aURL)
|
2015-05-07 00:06:24 -07:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, mURL(aURL)
|
2013-02-05 15:17:17 -08:00
|
|
|
{}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-02-05 15:17:17 -08:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 url(mURL);
|
|
|
|
|
2013-06-22 14:48:00 -07:00
|
|
|
nsIPrincipal* urlPrincipal =
|
2013-02-05 15:17:17 -08:00
|
|
|
nsHostObjectProtocolHandler::GetDataEntryPrincipal(url);
|
|
|
|
|
2015-05-07 00:06:24 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = mWorkerPrivate->GetPrincipal();
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
bool subsumes;
|
2013-06-22 14:48:00 -07:00
|
|
|
if (urlPrincipal &&
|
|
|
|
NS_SUCCEEDED(principal->Subsumes(urlPrincipal, &subsumes)) &&
|
2013-02-05 15:17:17 -08:00
|
|
|
subsumes) {
|
|
|
|
nsHostObjectProtocolHandler::RemoveDataEntry(url);
|
|
|
|
}
|
2013-06-22 14:48:00 -07:00
|
|
|
|
2015-05-07 00:06:24 -07:00
|
|
|
if (!mWorkerPrivate->IsSharedWorker() &&
|
|
|
|
!mWorkerPrivate->IsServiceWorker()) {
|
|
|
|
// Walk up to top worker object.
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (WorkerPrivate* parent = wp->GetParent()) {
|
|
|
|
wp = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> sc = wp->GetScriptContext();
|
|
|
|
// We could not have a ScriptContext in JSM code. In this case, we leak.
|
|
|
|
if (sc) {
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = sc->GetGlobalObject();
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
|
|
|
global->UnregisterHostObjectURI(url);
|
|
|
|
}
|
2013-06-22 14:48:00 -07:00
|
|
|
}
|
2014-02-24 05:57:03 -08:00
|
|
|
|
|
|
|
return true;
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
// This class creates a URL object on the main thread.
|
2014-02-24 05:57:03 -08:00
|
|
|
class ConstructorRunnable : public WorkerMainThreadRunnable
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
const nsString mURL;
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
nsString mBase; // IsVoid() if we have no base URI string.
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<URLProxy> mBaseProxy;
|
|
|
|
mozilla::ErrorResult& mRv;
|
|
|
|
|
|
|
|
nsRefPtr<URLProxy> mRetval;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConstructorRunnable(WorkerPrivate* aWorkerPrivate,
|
2015-05-05 10:38:56 -07:00
|
|
|
const nsAString& aURL, const Optional<nsAString>& aBase,
|
2013-09-04 10:07:34 -07:00
|
|
|
mozilla::ErrorResult& aRv)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mURL(aURL)
|
|
|
|
, mRv(aRv)
|
|
|
|
{
|
2015-05-05 10:38:56 -07:00
|
|
|
if (aBase.WasPassed()) {
|
|
|
|
mBase = aBase.Value();
|
|
|
|
} else {
|
|
|
|
mBase.SetIsVoid(true);
|
|
|
|
}
|
2013-09-04 10:07:34 -07:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstructorRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsAString& aURL, URLProxy* aBaseProxy,
|
|
|
|
mozilla::ErrorResult& aRv)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mURL(aURL)
|
|
|
|
, mBaseProxy(aBaseProxy)
|
|
|
|
, mRv(aRv)
|
|
|
|
{
|
2015-05-05 10:38:56 -07:00
|
|
|
mBase.SetIsVoid(true);
|
2013-09-04 10:07:34 -07:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-09-04 10:07:34 -07:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
nsRefPtr<mozilla::dom::URL> url;
|
|
|
|
if (mBaseProxy) {
|
2015-06-29 09:03:47 -07:00
|
|
|
url = mozilla::dom::URL::Constructor(nullptr, mURL, mBaseProxy->URI(),
|
|
|
|
mRv);
|
2015-05-05 10:38:56 -07:00
|
|
|
} else if (!mBase.IsVoid()) {
|
2015-06-29 09:03:47 -07:00
|
|
|
url = mozilla::dom::URL::Constructor(nullptr, mURL, mBase, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
} else {
|
2015-06-29 09:03:47 -07:00
|
|
|
url = mozilla::dom::URL::Constructor(nullptr, mURL, nullptr, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
if (mRv.Failed()) {
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
mRetval = new URLProxy(url.forget());
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
URLProxy*
|
|
|
|
GetURLProxy()
|
|
|
|
{
|
|
|
|
return mRetval;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-18 12:02:24 -08:00
|
|
|
class TeardownURLRunnable : public nsRunnable
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit TeardownURLRunnable(URLProxy* aURLProxy)
|
2013-09-04 10:07:34 -07:00
|
|
|
: mURLProxy(aURLProxy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
mURLProxy->ReleaseURI();
|
|
|
|
mURLProxy = nullptr;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<URLProxy> mURLProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is the generic getter for any URL property.
|
2014-02-24 05:57:03 -08:00
|
|
|
class GetterRunnable : public WorkerMainThreadRunnable
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum GetterType {
|
|
|
|
GetterHref,
|
|
|
|
GetterOrigin,
|
|
|
|
GetterProtocol,
|
|
|
|
GetterUsername,
|
|
|
|
GetterPassword,
|
|
|
|
GetterHost,
|
|
|
|
GetterHostname,
|
|
|
|
GetterPort,
|
|
|
|
GetterPathname,
|
|
|
|
GetterSearch,
|
|
|
|
GetterHash,
|
|
|
|
};
|
|
|
|
|
|
|
|
GetterRunnable(WorkerPrivate* aWorkerPrivate,
|
2015-02-27 11:10:20 -08:00
|
|
|
GetterType aType, nsAString& aValue,
|
2013-09-04 10:07:34 -07:00
|
|
|
URLProxy* aURLProxy)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mValue(aValue)
|
|
|
|
, mType(aType)
|
|
|
|
, mURLProxy(aURLProxy)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-09-04 10:07:34 -07:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2014-07-11 16:30:27 -07:00
|
|
|
ErrorResult rv;
|
2013-09-04 10:07:34 -07:00
|
|
|
switch (mType) {
|
|
|
|
case GetterHref:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetHref(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterOrigin:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetOrigin(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterProtocol:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetProtocol(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterUsername:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetUsername(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterPassword:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetPassword(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterHost:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetHost(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterHostname:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetHostname(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterPort:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetPort(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterPathname:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetPathname(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterSearch:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetSearch(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GetterHash:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->GetHash(mValue, rv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-02-24 05:57:03 -08:00
|
|
|
|
2014-07-11 16:30:27 -07:00
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAString& mValue;
|
2013-09-04 10:07:34 -07:00
|
|
|
GetterType mType;
|
|
|
|
nsRefPtr<URLProxy> mURLProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is the generic setter for any URL property.
|
2014-02-24 05:57:03 -08:00
|
|
|
class SetterRunnable : public WorkerMainThreadRunnable
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum SetterType {
|
|
|
|
SetterHref,
|
|
|
|
SetterProtocol,
|
|
|
|
SetterUsername,
|
|
|
|
SetterPassword,
|
|
|
|
SetterHost,
|
|
|
|
SetterHostname,
|
|
|
|
SetterPort,
|
|
|
|
SetterPathname,
|
|
|
|
SetterSearch,
|
|
|
|
SetterHash,
|
|
|
|
};
|
|
|
|
|
|
|
|
SetterRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
SetterType aType, const nsAString& aValue,
|
|
|
|
URLProxy* aURLProxy, mozilla::ErrorResult& aRv)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mValue(aValue)
|
|
|
|
, mType(aType)
|
|
|
|
, mURLProxy(aURLProxy)
|
|
|
|
, mRv(aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-09-04 10:07:34 -07:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case SetterHref:
|
|
|
|
mURLProxy->URL()->SetHref(mValue, mRv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterProtocol:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetProtocol(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterUsername:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetUsername(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterPassword:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetPassword(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterHost:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetHost(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterHostname:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetHostname(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterPort:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetPort(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterPathname:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetPathname(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterSearch:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetSearch(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SetterHash:
|
2014-07-11 16:30:27 -07:00
|
|
|
mURLProxy->URL()->SetHash(mValue, mRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-02-24 05:57:03 -08:00
|
|
|
|
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsString mValue;
|
|
|
|
SetterType mType;
|
|
|
|
nsRefPtr<URLProxy> mURLProxy;
|
|
|
|
mozilla::ErrorResult& mRv;
|
|
|
|
};
|
|
|
|
|
2015-07-15 04:50:59 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(URL, mSearchParams)
|
2013-12-12 11:30:27 -08:00
|
|
|
|
|
|
|
// The reason for using worker::URL is to have different refcnt logging than
|
|
|
|
// for main thread URL.
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(workers::URL)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(workers::URL)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URL)
|
2015-07-15 04:50:59 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-12-12 11:30:27 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-04 10:07:21 -07:00
|
|
|
// static
|
2014-08-27 15:43:55 -07:00
|
|
|
already_AddRefed<URL>
|
2013-09-04 10:07:21 -07:00
|
|
|
URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
|
URL& aBase, ErrorResult& aRv)
|
|
|
|
{
|
2014-06-16 11:08:00 -07:00
|
|
|
JSContext* cx = aGlobal.Context();
|
2013-09-04 10:07:34 -07:00
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
|
|
|
|
nsRefPtr<ConstructorRunnable> runnable =
|
|
|
|
new ConstructorRunnable(workerPrivate, aUrl, aBase.GetURLProxy(), aRv);
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
return FinishConstructor(cx, workerPrivate, runnable, aRv);
|
|
|
|
}
|
2013-09-04 10:07:34 -07:00
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
// static
|
|
|
|
already_AddRefed<URL>
|
|
|
|
URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
|
const Optional<nsAString>& aBase, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
2013-09-04 10:07:34 -07:00
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
nsRefPtr<ConstructorRunnable> runnable =
|
|
|
|
new ConstructorRunnable(workerPrivate, aUrl, aBase, aRv);
|
|
|
|
|
|
|
|
return FinishConstructor(cx, workerPrivate, runnable, aRv);
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2014-08-27 15:43:55 -07:00
|
|
|
already_AddRefed<URL>
|
2013-09-04 10:07:21 -07:00
|
|
|
URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
|
const nsAString& aBase, ErrorResult& aRv)
|
|
|
|
{
|
2014-06-16 11:08:00 -07:00
|
|
|
JSContext* cx = aGlobal.Context();
|
2013-09-04 10:07:34 -07:00
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
Optional<nsAString> base;
|
|
|
|
base = &aBase;
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<ConstructorRunnable> runnable =
|
2015-05-05 10:38:56 -07:00
|
|
|
new ConstructorRunnable(workerPrivate, aUrl, base, aRv);
|
2013-09-04 10:07:34 -07:00
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
return FinishConstructor(cx, workerPrivate, runnable, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<URL>
|
|
|
|
URL::FinishConstructor(JSContext* aCx, WorkerPrivate* aPrivate,
|
|
|
|
ConstructorRunnable* aRunnable, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!aRunnable->Dispatch(aCx)) {
|
|
|
|
JS_ReportPendingException(aCx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
nsRefPtr<URLProxy> proxy = aRunnable->GetURLProxy();
|
2013-09-04 10:07:34 -07:00
|
|
|
if (!proxy) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-05 10:38:56 -07:00
|
|
|
nsRefPtr<URL> url = new URL(aPrivate, proxy);
|
2014-08-27 15:43:55 -07:00
|
|
|
return url.forget();
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
URL::URL(WorkerPrivate* aWorkerPrivate, URLProxy* aURLProxy)
|
2013-11-05 06:16:25 -08:00
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mURLProxy(aURLProxy)
|
|
|
|
{
|
2013-11-05 06:16:25 -08:00
|
|
|
MOZ_COUNT_CTOR(workers::URL);
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
URL::~URL()
|
|
|
|
{
|
2013-11-05 06:16:25 -08:00
|
|
|
MOZ_COUNT_DTOR(workers::URL);
|
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
if (mURLProxy) {
|
2014-02-18 12:02:24 -08:00
|
|
|
nsRefPtr<TeardownURLRunnable> runnable =
|
|
|
|
new TeardownURLRunnable(mURLProxy);
|
2013-09-04 10:07:34 -07:00
|
|
|
mURLProxy = nullptr;
|
|
|
|
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
|
|
|
|
NS_ERROR("Failed to dispatch teardown runnable!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 09:03:47 -07:00
|
|
|
JSObject*
|
|
|
|
URL::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
2015-06-29 09:03:47 -07:00
|
|
|
return URLBinding_workers::Wrap(aCx, this, aGivenProto);
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetHref(nsAString& aHref, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHref, aHref,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHref, aHref,
|
|
|
|
mURLProxy, aRv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-12-12 11:30:27 -08:00
|
|
|
|
2014-02-03 08:48:38 -08:00
|
|
|
UpdateURLSearchParams();
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterOrigin, aOrigin,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterProtocol, aProtocol,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterProtocol,
|
|
|
|
aProtocol, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetUsername(nsAString& aUsername, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterUsername, aUsername,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetUsername(const nsAString& aUsername, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterUsername,
|
|
|
|
aUsername, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetPassword(nsAString& aPassword, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPassword, aPassword,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetPassword(const nsAString& aPassword, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPassword,
|
|
|
|
aPassword, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetHost(nsAString& aHost, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHost, aHost,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetHost(const nsAString& aHost, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHost,
|
|
|
|
aHost, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetHostname(nsAString& aHostname, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHostname, aHostname,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetHostname(const nsAString& aHostname, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHostname,
|
|
|
|
aHostname, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetPort(nsAString& aPort, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPort, aPort,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetPort(const nsAString& aPort, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPort,
|
|
|
|
aPort, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetPathname(nsAString& aPathname, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPathname, aPathname,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPathname,
|
|
|
|
aPathname, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetSearch(nsAString& aSearch, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterSearch, aSearch,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetSearch(const nsAString& aSearch, ErrorResult& aRv)
|
2013-12-12 11:30:27 -08:00
|
|
|
{
|
|
|
|
SetSearchInternal(aSearch);
|
2014-02-03 08:48:38 -08:00
|
|
|
UpdateURLSearchParams();
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
URL::SetSearchInternal(const nsAString& aSearch)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterSearch,
|
|
|
|
aSearch, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
2013-12-12 11:30:27 -08:00
|
|
|
mozilla::dom::URLSearchParams*
|
2014-03-19 08:36:46 -07:00
|
|
|
URL::SearchParams()
|
2013-12-12 11:30:27 -08:00
|
|
|
{
|
|
|
|
CreateSearchParamsIfNeeded();
|
|
|
|
return mSearchParams;
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:21 -07:00
|
|
|
void
|
2015-02-27 11:10:20 -08:00
|
|
|
URL::GetHash(nsAString& aHash, ErrorResult& aRv) const
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
nsRefPtr<GetterRunnable> runnable =
|
|
|
|
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHash, aHash,
|
|
|
|
mURLProxy);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::SetHash(const nsAString& aHash, ErrorResult& aRv)
|
2013-09-04 10:07:21 -07:00
|
|
|
{
|
2013-09-04 10:07:34 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<SetterRunnable> runnable =
|
|
|
|
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHash,
|
|
|
|
aHash, mURLProxy, rv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
|
|
|
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
|
|
|
}
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 10:16:11 -07:00
|
|
|
// static
|
|
|
|
void
|
2015-05-12 05:09:51 -07:00
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
|
2014-10-07 10:16:11 -07:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAString& aResult, mozilla::ErrorResult& aRv)
|
2014-10-07 10:16:11 -07:00
|
|
|
{
|
2014-10-08 09:15:22 -07:00
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
|
2015-05-12 05:11:03 -07:00
|
|
|
nsRefPtr<BlobImpl> blobImpl = aBlob.Impl();
|
2015-01-13 14:15:04 -08:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
aRv = blobImpl->SetMutable(false);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-08 09:15:22 -07:00
|
|
|
nsRefPtr<CreateURLRunnable> runnable =
|
2015-01-13 14:15:04 -08:00
|
|
|
new CreateURLRunnable(workerPrivate, blobImpl, aOptions, aResult);
|
2014-10-08 09:15:22 -07:00
|
|
|
|
|
|
|
if (!runnable->Dispatch(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
2015-05-07 00:06:24 -07:00
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (workerPrivate->IsSharedWorker() || workerPrivate->IsServiceWorker()) {
|
|
|
|
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
|
|
|
MOZ_ASSERT(scope);
|
|
|
|
|
|
|
|
scope->RegisterHostObjectURI(NS_ConvertUTF16toUTF8(aResult));
|
|
|
|
}
|
2014-10-07 10:16:11 -07:00
|
|
|
}
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
// static
|
|
|
|
void
|
2015-05-07 00:05:43 -07:00
|
|
|
URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
|
ErrorResult& aRv)
|
2013-02-05 15:17:17 -08:00
|
|
|
{
|
2014-06-16 11:08:00 -07:00
|
|
|
JSContext* cx = aGlobal.Context();
|
2013-02-05 15:17:17 -08:00
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
|
|
|
|
nsRefPtr<RevokeURLRunnable> runnable =
|
|
|
|
new RevokeURLRunnable(workerPrivate, aUrl);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
2015-05-07 00:06:24 -07:00
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (workerPrivate->IsSharedWorker() || workerPrivate->IsServiceWorker()) {
|
|
|
|
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
|
|
|
MOZ_ASSERT(scope);
|
|
|
|
|
|
|
|
scope->UnregisterHostObjectURI(NS_ConvertUTF16toUTF8(aUrl));
|
|
|
|
}
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
|
2013-12-12 11:30:27 -08:00
|
|
|
void
|
2014-08-07 17:45:21 -07:00
|
|
|
URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
2013-12-12 11:30:27 -08:00
|
|
|
{
|
2014-02-03 08:48:38 -08:00
|
|
|
MOZ_ASSERT(mSearchParams);
|
2014-08-07 17:45:21 -07:00
|
|
|
MOZ_ASSERT(mSearchParams == aSearchParams);
|
2013-12-12 11:30:27 -08:00
|
|
|
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAutoString search;
|
2013-12-12 11:30:27 -08:00
|
|
|
mSearchParams->Serialize(search);
|
|
|
|
SetSearchInternal(search);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-02-03 08:48:38 -08:00
|
|
|
URL::UpdateURLSearchParams()
|
2013-12-12 11:30:27 -08:00
|
|
|
{
|
2014-02-03 08:48:38 -08:00
|
|
|
if (mSearchParams) {
|
2015-02-27 11:10:20 -08:00
|
|
|
nsAutoString search;
|
2014-07-11 16:30:27 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
GetSearch(search, rv);
|
2015-06-24 12:15:59 -07:00
|
|
|
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)));
|
2014-02-03 08:48:38 -08:00
|
|
|
}
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
URL::CreateSearchParamsIfNeeded()
|
|
|
|
{
|
|
|
|
if (!mSearchParams) {
|
2015-06-29 09:03:47 -07:00
|
|
|
mSearchParams = new URLSearchParams(nullptr, this);
|
2014-02-03 08:48:38 -08:00
|
|
|
UpdateURLSearchParams();
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
END_WORKERS_NAMESPACE
|