2013-02-05 15:17:17 -08:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* 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-03-21 17:05:20 -07:00
|
|
|
#include "nsIDocument.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"
|
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"
|
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
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
class URLProxy MOZ_FINAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLProxy)
|
|
|
|
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit URLProxy(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:
|
2014-10-08 09:15:23 -07:00
|
|
|
FileImpl* mBlobImpl;
|
2013-02-05 15:17:17 -08:00
|
|
|
nsString& mURL;
|
|
|
|
|
|
|
|
public:
|
2014-10-08 09:15:23 -07:00
|
|
|
CreateURLRunnable(WorkerPrivate* aWorkerPrivate, FileImpl* aBlobImpl,
|
2013-08-22 22:17:09 -07:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2013-02-05 15:17:17 -08:00
|
|
|
nsString& aURL)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate),
|
2014-06-26 20:46:34 -07:00
|
|
|
mBlobImpl(aBlobImpl),
|
2013-02-05 15:17:17 -08:00
|
|
|
mURL(aURL)
|
|
|
|
{
|
2014-06-26 20:46:34 -07:00
|
|
|
MOZ_ASSERT(aBlobImpl);
|
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();
|
|
|
|
|
2013-06-22 14:48:00 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsIDocument* doc = nullptr;
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = mWorkerPrivate->GetWindow();
|
2013-06-22 14:48:00 -07:00
|
|
|
if (window) {
|
|
|
|
doc = window->GetExtantDoc();
|
|
|
|
if (!doc) {
|
|
|
|
SetDOMStringToNull(mURL);
|
2014-02-24 05:57:03 -08:00
|
|
|
return false;
|
2013-06-22 14:48:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
principal = doc->NodePrincipal();
|
|
|
|
} else {
|
2013-07-18 07:30:41 -07:00
|
|
|
MOZ_ASSERT_IF(!mWorkerPrivate->GetParent(), mWorkerPrivate->IsChromeWorker());
|
2013-06-22 14:48:00 -07:00
|
|
|
principal = mWorkerPrivate->GetPrincipal();
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString url;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-22 14:48:00 -07:00
|
|
|
if (doc) {
|
|
|
|
doc->RegisterHostObjectUri(url);
|
|
|
|
} else {
|
|
|
|
mWorkerPrivate->RegisterHostObjectURI(url);
|
|
|
|
}
|
|
|
|
|
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)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate),
|
2013-02-05 15:17:17 -08:00
|
|
|
mURL(aURL)
|
|
|
|
{}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-02-05 15:17:17 -08:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2013-06-22 14:48:00 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsIDocument* doc = nullptr;
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = mWorkerPrivate->GetWindow();
|
2013-06-22 14:48:00 -07:00
|
|
|
if (window) {
|
|
|
|
doc = window->GetExtantDoc();
|
|
|
|
if (!doc) {
|
2014-02-24 05:57:03 -08:00
|
|
|
return false;
|
2013-06-22 14:48:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
principal = doc->NodePrincipal();
|
|
|
|
} else {
|
2013-07-18 07:30:41 -07:00
|
|
|
MOZ_ASSERT_IF(!mWorkerPrivate->GetParent(), mWorkerPrivate->IsChromeWorker());
|
2013-06-22 14:48:00 -07:00
|
|
|
principal = mWorkerPrivate->GetPrincipal();
|
2013-02-05 15:17:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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) {
|
2013-06-22 14:48:00 -07:00
|
|
|
if (doc) {
|
|
|
|
doc->UnregisterHostObjectUri(url);
|
|
|
|
}
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
nsHostObjectProtocolHandler::RemoveDataEntry(url);
|
|
|
|
}
|
2013-06-22 14:48:00 -07:00
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
mWorkerPrivate->UnregisterHostObjectURI(url);
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
const nsString mBase;
|
|
|
|
nsRefPtr<URLProxy> mBaseProxy;
|
|
|
|
mozilla::ErrorResult& mRv;
|
|
|
|
|
|
|
|
nsRefPtr<URLProxy> mRetval;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConstructorRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsAString& aURL, const nsAString& aBase,
|
|
|
|
mozilla::ErrorResult& aRv)
|
2014-02-24 05:57:03 -08:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
2013-09-04 10:07:34 -07:00
|
|
|
, mURL(aURL)
|
|
|
|
, mBase(aBase)
|
|
|
|
, mRv(aRv)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2014-02-24 05:57:03 -08:00
|
|
|
bool
|
2013-09-04 10:07:34 -07:00
|
|
|
MainThreadRun()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mRv.Throw(rv);
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURL;
|
|
|
|
|
|
|
|
if (!mBaseProxy) {
|
|
|
|
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(mBase), nullptr, nullptr,
|
|
|
|
getter_AddRefs(baseURL));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
baseURL = mBaseProxy->URI();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(mURL), nullptr, baseURL,
|
|
|
|
getter_AddRefs(url));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
2014-02-24 05:57:03 -08:00
|
|
|
return true;
|
2013-09-04 10:07:34 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 23:56:01 -07:00
|
|
|
mRetval = new URLProxy(new mozilla::dom::URL(url));
|
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,
|
|
|
|
GetterType aType, nsString& aValue,
|
|
|
|
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:
|
|
|
|
nsString& mValue;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(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)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<URLProxy> proxy = runnable->GetURLProxy();
|
|
|
|
if (!proxy) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-27 15:43:55 -07:00
|
|
|
nsRefPtr<URL> url = new URL(workerPrivate, proxy);
|
|
|
|
return url.forget();
|
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);
|
|
|
|
|
|
|
|
nsRefPtr<ConstructorRunnable> runnable =
|
|
|
|
new ConstructorRunnable(workerPrivate, aUrl, aBase, aRv);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<URLProxy> proxy = runnable->GetURLProxy();
|
|
|
|
if (!proxy) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-27 15:43:55 -07:00
|
|
|
nsRefPtr<URL> url = new URL(workerPrivate, proxy);
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 06:16:25 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
URL::WrapObject(JSContext* aCx)
|
2013-09-04 10:07:34 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return URLBinding_workers::Wrap(aCx, this);
|
2013-09-04 10:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetHref(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetOrigin(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetProtocol(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetUsername(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetPassword(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetHost(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetHostname(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetPort(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetPathname(nsString& 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
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetSearch(nsString& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-19 08:36:46 -07:00
|
|
|
URL::SetSearchParams(URLSearchParams& aSearchParams)
|
2013-12-12 11:30:27 -08:00
|
|
|
{
|
2014-02-03 08:48:38 -08:00
|
|
|
if (mSearchParams) {
|
|
|
|
mSearchParams->RemoveObserver(this);
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
|
2014-03-19 08:36:46 -07:00
|
|
|
mSearchParams = &aSearchParams;
|
2014-02-03 08:48:38 -08:00
|
|
|
mSearchParams->AddObserver(this);
|
2013-12-12 11:30:27 -08:00
|
|
|
|
|
|
|
nsString search;
|
|
|
|
mSearchParams->Serialize(search);
|
|
|
|
SetSearchInternal(search);
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:21 -07:00
|
|
|
void
|
2014-07-11 16:30:27 -07:00
|
|
|
URL::GetHash(nsString& 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
|
|
|
}
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
// static
|
|
|
|
void
|
2013-08-22 22:17:08 -07:00
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, JSObject* aBlob,
|
2013-08-22 22:17:09 -07:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2013-02-05 15:17:17 -08:00
|
|
|
nsString& aResult, mozilla::ErrorResult& aRv)
|
2013-02-15 00:04:11 -08:00
|
|
|
{
|
2014-10-08 09:15:22 -07:00
|
|
|
SetDOMStringToNull(aResult);
|
2014-10-07 10:16:11 -07:00
|
|
|
|
2014-10-08 09:15:22 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(argStr, "Argument 1 of URL.createObjectURL");
|
|
|
|
NS_NAMED_LITERAL_STRING(blobStr, "MediaStream");
|
|
|
|
aRv.ThrowTypeError(MSG_DOES_NOT_IMPLEMENT_INTERFACE, &argStr, &blobStr);
|
2013-02-15 00:04:11 -08:00
|
|
|
}
|
|
|
|
|
2014-10-07 10:16:11 -07:00
|
|
|
// static
|
|
|
|
void
|
2014-10-08 09:15:23 -07:00
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, File& aBlob,
|
2014-10-07 10:16:11 -07:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
|
|
|
nsString& aResult, mozilla::ErrorResult& aRv)
|
|
|
|
{
|
2014-10-08 09:15:22 -07:00
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
|
|
|
|
nsRefPtr<CreateURLRunnable> runnable =
|
|
|
|
new CreateURLRunnable(workerPrivate, aBlob.Impl(), aOptions, aResult);
|
|
|
|
|
|
|
|
if (!runnable->Dispatch(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
2014-10-07 10:16:11 -07:00
|
|
|
}
|
|
|
|
|
2013-02-05 15:17:17 -08:00
|
|
|
// static
|
|
|
|
void
|
2013-08-22 22:17:08 -07:00
|
|
|
URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
nsString search;
|
|
|
|
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) {
|
|
|
|
nsString search;
|
2014-07-11 16:30:27 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
GetSearch(search, rv);
|
2014-02-03 08:48:38 -08:00
|
|
|
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)), this);
|
|
|
|
}
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
URL::CreateSearchParamsIfNeeded()
|
|
|
|
{
|
|
|
|
if (!mSearchParams) {
|
|
|
|
mSearchParams = new URLSearchParams();
|
2014-02-03 08:48:38 -08:00
|
|
|
mSearchParams->AddObserver(this);
|
|
|
|
UpdateURLSearchParams();
|
2013-12-12 11:30:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:34 -07:00
|
|
|
END_WORKERS_NAMESPACE
|