2015-05-03 19:32:37 +00: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: */
|
2014-10-27 11:03:00 +00: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/. */
|
|
|
|
|
2016-03-16 18:51:11 +00:00
|
|
|
#include "ServiceWorkerClients.h"
|
|
|
|
|
2015-02-20 15:16:17 +00:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2015-04-07 13:25:08 +00:00
|
|
|
#include "mozilla/dom/PromiseWorkerProxy.h"
|
2015-02-20 15:16:17 +00:00
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
#include "ServiceWorkerClient.h"
|
|
|
|
#include "ServiceWorkerManager.h"
|
2016-03-16 18:51:11 +00:00
|
|
|
#include "ServiceWorkerPrivate.h"
|
2015-03-06 13:04:49 +00:00
|
|
|
#include "ServiceWorkerWindowClient.h"
|
2014-10-27 11:03:00 +00:00
|
|
|
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
|
|
|
#include "WorkerScope.h"
|
|
|
|
|
2016-03-16 18:51:11 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIBrowserDOMWindow.h"
|
2015-10-24 12:16:23 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDOMChromeWindow.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
2015-10-29 23:30:57 +00:00
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
2016-03-16 18:51:11 +00:00
|
|
|
#include "nsNetUtil.h"
|
2015-10-29 23:30:57 +00:00
|
|
|
#include "nsPIWindowWatcher.h"
|
|
|
|
#include "nsWindowWatcher.h"
|
2015-10-24 12:16:23 +00:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::workers;
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ServiceWorkerClients)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(ServiceWorkerClients)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ServiceWorkerClients, mWorkerScope)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerClients)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
ServiceWorkerClients::ServiceWorkerClients(ServiceWorkerGlobalScope* aWorkerScope)
|
|
|
|
: mWorkerScope(aWorkerScope)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
ServiceWorkerClients::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return ClientsBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-27 11:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class GetRunnable final : public Runnable
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
2015-11-27 22:27:53 +00:00
|
|
|
class ResolvePromiseWorkerRunnable final : public WorkerRunnable
|
|
|
|
{
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
UniquePtr<ServiceWorkerClientInfo> mValue;
|
|
|
|
nsresult mRv;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResolvePromiseWorkerRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
UniquePtr<ServiceWorkerClientInfo>&& aValue,
|
|
|
|
nsresult aRv)
|
2016-06-28 17:28:13 +00:00
|
|
|
: WorkerRunnable(aWorkerPrivate),
|
2015-11-27 22:27:53 +00:00
|
|
|
mPromiseProxy(aPromiseProxy),
|
|
|
|
mValue(Move(aValue)),
|
|
|
|
mRv(Move(aRv))
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2015-11-27 22:27:53 +00:00
|
|
|
bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
Promise* promise = mPromiseProxy->WorkerPromise();
|
|
|
|
MOZ_ASSERT(promise);
|
|
|
|
|
|
|
|
if (NS_FAILED(mRv)) {
|
|
|
|
promise->MaybeReject(mRv);
|
|
|
|
} else if (mValue) {
|
|
|
|
RefPtr<ServiceWorkerWindowClient> windowClient =
|
|
|
|
new ServiceWorkerWindowClient(promise->GetParentObject(), *mValue);
|
|
|
|
promise->MaybeResolve(windowClient.get());
|
|
|
|
} else {
|
2016-08-09 09:15:13 +00:00
|
|
|
promise->MaybeResolveWithUndefined();
|
2015-11-27 22:27:53 +00:00
|
|
|
}
|
2016-02-29 19:52:42 +00:00
|
|
|
mPromiseProxy->CleanUp();
|
2015-11-27 22:27:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
nsString mClientId;
|
2014-10-27 11:03:00 +00:00
|
|
|
public:
|
2015-11-27 22:27:53 +00:00
|
|
|
GetRunnable(PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
const nsAString& aClientId)
|
|
|
|
: mPromiseProxy(aPromiseProxy),
|
|
|
|
mClientId(aClientId)
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-27 22:27:53 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
2015-11-27 22:27:53 +00:00
|
|
|
AssertIsOnMainThread();
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2015-11-27 22:27:53 +00:00
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
|
|
|
return NS_OK;
|
2014-10-27 11:03:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 22:27:53 +00:00
|
|
|
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
ErrorResult rv;
|
|
|
|
UniquePtr<ServiceWorkerClientInfo> result = swm->GetClient(workerPrivate->GetPrincipal(),
|
|
|
|
mClientId, rv);
|
|
|
|
RefPtr<ResolvePromiseWorkerRunnable> r =
|
|
|
|
new ResolvePromiseWorkerRunnable(mPromiseProxy->GetWorkerPrivate(),
|
|
|
|
mPromiseProxy, Move(result),
|
|
|
|
rv.StealNSResult());
|
|
|
|
rv.SuppressException();
|
|
|
|
|
2016-02-26 20:23:12 +00:00
|
|
|
r->Dispatch();
|
2015-11-27 22:27:53 +00:00
|
|
|
return NS_OK;
|
2014-10-27 11:03:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class MatchAllRunnable final : public Runnable
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
2015-11-27 22:27:53 +00:00
|
|
|
class ResolvePromiseWorkerRunnable final : public WorkerRunnable
|
|
|
|
{
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
nsTArray<ServiceWorkerClientInfo> mValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResolvePromiseWorkerRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
nsTArray<ServiceWorkerClientInfo>& aValue)
|
2016-06-28 17:28:13 +00:00
|
|
|
: WorkerRunnable(aWorkerPrivate),
|
2015-11-27 22:27:53 +00:00
|
|
|
mPromiseProxy(aPromiseProxy)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mValue.SwapElements(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
Promise* promise = mPromiseProxy->WorkerPromise();
|
|
|
|
MOZ_ASSERT(promise);
|
|
|
|
|
|
|
|
nsTArray<RefPtr<ServiceWorkerClient>> ret;
|
|
|
|
for (size_t i = 0; i < mValue.Length(); i++) {
|
|
|
|
ret.AppendElement(RefPtr<ServiceWorkerClient>(
|
|
|
|
new ServiceWorkerWindowClient(promise->GetParentObject(),
|
|
|
|
mValue.ElementAt(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
promise->MaybeResolve(ret);
|
2016-02-29 19:52:42 +00:00
|
|
|
mPromiseProxy->CleanUp();
|
2015-11-27 22:27:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
2014-10-28 09:29:00 +00:00
|
|
|
nsCString mScope;
|
2015-11-30 19:29:51 +00:00
|
|
|
bool mIncludeUncontrolled;
|
2014-10-27 11:03:00 +00:00
|
|
|
public:
|
2015-09-02 17:07:26 +00:00
|
|
|
MatchAllRunnable(PromiseWorkerProxy* aPromiseProxy,
|
2015-11-30 19:29:51 +00:00
|
|
|
const nsCString& aScope,
|
|
|
|
bool aIncludeUncontrolled)
|
2015-09-02 17:07:26 +00:00
|
|
|
: mPromiseProxy(aPromiseProxy),
|
2015-11-30 19:29:51 +00:00
|
|
|
mScope(aScope),
|
|
|
|
mIncludeUncontrolled(aIncludeUncontrolled)
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
2015-09-02 17:07:26 +00:00
|
|
|
MOZ_ASSERT(mPromiseProxy);
|
2014-10-27 11:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
Run() override
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2015-09-02 17:07:26 +00:00
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
2014-10-28 09:29:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
2015-03-06 13:04:49 +00:00
|
|
|
nsTArray<ServiceWorkerClientInfo> result;
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2015-11-30 19:29:51 +00:00
|
|
|
swm->GetAllClients(mPromiseProxy->GetWorkerPrivate()->GetPrincipal(), mScope,
|
|
|
|
mIncludeUncontrolled, result);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ResolvePromiseWorkerRunnable> r =
|
2015-09-02 17:07:26 +00:00
|
|
|
new ResolvePromiseWorkerRunnable(mPromiseProxy->GetWorkerPrivate(),
|
|
|
|
mPromiseProxy, result);
|
2014-10-30 15:13:00 +00:00
|
|
|
|
2016-02-26 20:23:12 +00:00
|
|
|
r->Dispatch();
|
2014-10-27 11:03:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-14 19:41:42 +00:00
|
|
|
class ResolveClaimRunnable final : public WorkerRunnable
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
2015-05-14 19:41:42 +00:00
|
|
|
nsresult mResult;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResolveClaimRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
nsresult aResult)
|
2016-06-28 17:28:13 +00:00
|
|
|
: WorkerRunnable(aWorkerPrivate)
|
2015-05-14 19:41:42 +00:00
|
|
|
, mPromiseProxy(aPromiseProxy)
|
|
|
|
, mResult(aResult)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = mPromiseProxy->WorkerPromise();
|
2015-05-14 19:41:42 +00:00
|
|
|
MOZ_ASSERT(promise);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mResult)) {
|
2016-08-09 09:15:13 +00:00
|
|
|
promise->MaybeResolveWithUndefined();
|
2015-05-14 19:41:42 +00:00
|
|
|
} else {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
|
2016-02-29 19:52:42 +00:00
|
|
|
mPromiseProxy->CleanUp();
|
2015-05-14 19:41:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class ClaimRunnable final : public Runnable
|
2015-05-14 19:41:42 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
2015-05-14 19:41:42 +00:00
|
|
|
nsCString mScope;
|
|
|
|
uint64_t mServiceWorkerID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ClaimRunnable(PromiseWorkerProxy* aPromiseProxy, const nsCString& aScope)
|
|
|
|
: mPromiseProxy(aPromiseProxy)
|
|
|
|
, mScope(aScope)
|
2015-09-02 17:07:26 +00:00
|
|
|
// Safe to call GetWorkerPrivate() since we are being called on the worker
|
|
|
|
// thread via script (so no clean up has occured yet).
|
2015-05-14 19:41:42 +00:00
|
|
|
, mServiceWorkerID(aPromiseProxy->GetWorkerPrivate()->ServiceWorkerID())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPromiseProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
|
|
|
{
|
2015-09-02 17:07:26 +00:00
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
2015-05-14 19:41:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
2015-06-03 08:43:43 +00:00
|
|
|
MOZ_ASSERT(swm);
|
|
|
|
|
|
|
|
nsresult rv = swm->ClaimClients(workerPrivate->GetPrincipal(),
|
|
|
|
mScope, mServiceWorkerID);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ResolveClaimRunnable> r =
|
2015-05-14 19:41:42 +00:00
|
|
|
new ResolveClaimRunnable(workerPrivate, mPromiseProxy, rv);
|
|
|
|
|
2016-02-26 20:23:12 +00:00
|
|
|
r->Dispatch();
|
2015-05-14 19:41:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-24 12:16:23 +00:00
|
|
|
class ResolveOpenWindowRunnable final : public WorkerRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ResolveOpenWindowRunnable(PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
UniquePtr<ServiceWorkerClientInfo>&& aClientInfo,
|
|
|
|
const nsresult aStatus)
|
2016-06-28 17:28:13 +00:00
|
|
|
: WorkerRunnable(aPromiseProxy->GetWorkerPrivate())
|
2015-10-24 12:16:23 +00:00
|
|
|
, mPromiseProxy(aPromiseProxy)
|
|
|
|
, mClientInfo(Move(aClientInfo))
|
|
|
|
, mStatus(aStatus)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
MOZ_ASSERT(aPromiseProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
Promise* promise = mPromiseProxy->WorkerPromise();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(mStatus))) {
|
|
|
|
promise->MaybeReject(mStatus);
|
|
|
|
} else if (mClientInfo) {
|
|
|
|
RefPtr<ServiceWorkerWindowClient> client =
|
|
|
|
new ServiceWorkerWindowClient(promise->GetParentObject(),
|
|
|
|
*mClientInfo);
|
|
|
|
promise->MaybeResolve(client);
|
|
|
|
} else {
|
|
|
|
promise->MaybeResolve(JS::NullHandleValue);
|
|
|
|
}
|
|
|
|
|
2016-02-29 19:52:42 +00:00
|
|
|
mPromiseProxy->CleanUp();
|
2015-10-24 12:16:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
UniquePtr<ServiceWorkerClientInfo> mClientInfo;
|
|
|
|
const nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WebProgressListener final : public nsIWebProgressListener,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(WebProgressListener, nsIWebProgressListener)
|
|
|
|
|
|
|
|
WebProgressListener(PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
ServiceWorkerPrivate* aServiceWorkerPrivate,
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* aWindow,
|
2015-10-24 12:16:23 +00:00
|
|
|
nsIURI* aBaseURI)
|
|
|
|
: mPromiseProxy(aPromiseProxy)
|
|
|
|
, mServiceWorkerPrivate(aServiceWorkerPrivate)
|
|
|
|
, mWindow(aWindow)
|
|
|
|
, mBaseURI(aBaseURI)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPromiseProxy);
|
|
|
|
MOZ_ASSERT(aServiceWorkerPrivate);
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
MOZ_ASSERT(aWindow->IsOuterWindow());
|
|
|
|
MOZ_ASSERT(aBaseURI);
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
mServiceWorkerPrivate->StoreISupports(static_cast<nsIWebProgressListener*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
uint32_t aStateFlags, nsresult aStatus) override
|
|
|
|
{
|
|
|
|
if (!(aStateFlags & STATE_IS_DOCUMENT) ||
|
|
|
|
!(aStateFlags & (STATE_STOP | STATE_TRANSFERRING))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Our caller keeps a strong reference, so it is safe to remove the listener
|
|
|
|
// from ServiceWorkerPrivate.
|
|
|
|
mServiceWorkerPrivate->RemoveISupports(static_cast<nsIWebProgressListener*>(this));
|
|
|
|
aWebProgress->RemoveProgressListener(this);
|
|
|
|
|
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
UniquePtr<ServiceWorkerClientInfo> clientInfo;
|
|
|
|
if (doc) {
|
|
|
|
// Check same origin.
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
nsresult rv = securityManager->CheckSameOriginURI(doc->GetOriginalURI(),
|
|
|
|
mBaseURI, false);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
clientInfo.reset(new ServiceWorkerClientInfo(doc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ResolveOpenWindowRunnable> r =
|
|
|
|
new ResolveOpenWindowRunnable(mPromiseProxy,
|
|
|
|
Move(clientInfo),
|
|
|
|
NS_OK);
|
2016-02-26 20:23:12 +00:00
|
|
|
r->Dispatch();
|
2015-10-24 12:16:23 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnProgressChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "Unexpected notification.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsIURI* aLocation,
|
|
|
|
uint32_t aFlags) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "Unexpected notification.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus, const char16_t* aMessage) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "Unexpected notification.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
OnSecurityChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
uint32_t aState) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "Unexpected notification.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~WebProgressListener()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
RefPtr<ServiceWorkerPrivate> mServiceWorkerPrivate;
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
|
2015-10-24 12:16:23 +00:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebProgressListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebProgressListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(WebProgressListener, mPromiseProxy,
|
|
|
|
mServiceWorkerPrivate, mWindow)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebProgressListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class OpenWindowRunnable final : public Runnable
|
2015-10-24 12:16:23 +00:00
|
|
|
{
|
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
|
|
|
nsString mUrl;
|
|
|
|
nsString mScope;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenWindowRunnable(PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
const nsAString& aUrl,
|
|
|
|
const nsAString& aScope)
|
|
|
|
: mPromiseProxy(aPromiseProxy)
|
|
|
|
, mUrl(aUrl)
|
|
|
|
, mScope(aScope)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPromiseProxy);
|
|
|
|
MOZ_ASSERT(aPromiseProxy->GetWorkerPrivate());
|
|
|
|
aPromiseProxy->GetWorkerPrivate()->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window;
|
2015-10-24 12:16:23 +00:00
|
|
|
nsresult rv = OpenWindow(getter_AddRefs(window));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
2016-03-31 14:06:00 +00:00
|
|
|
rv = nsContentUtils::DispatchFocusChromeEvent(window);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:16:23 +00:00
|
|
|
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
WorkerPrivate::LocationInfo& info = workerPrivate->GetLocationInfo();
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2015-11-06 07:39:00 +00:00
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), info.mHref);
|
2015-10-24 12:16:23 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
|
|
|
|
|
|
|
|
if (!webProgress) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
MOZ_ASSERT(swm);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = workerPrivate->GetPrincipal();
|
|
|
|
MOZ_ASSERT(principal);
|
|
|
|
RefPtr<ServiceWorkerRegistrationInfo> registration =
|
|
|
|
swm->GetRegistration(principal, NS_ConvertUTF16toUTF8(mScope));
|
|
|
|
if (NS_WARN_IF(!registration)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
RefPtr<ServiceWorkerInfo> serviceWorkerInfo =
|
|
|
|
registration->GetServiceWorkerInfoById(workerPrivate->ServiceWorkerID());
|
|
|
|
if (NS_WARN_IF(!serviceWorkerInfo)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener =
|
|
|
|
new WebProgressListener(mPromiseProxy, serviceWorkerInfo->WorkerPrivate(),
|
|
|
|
window, baseURI);
|
|
|
|
|
|
|
|
rv = webProgress->AddProgressListener(listener,
|
|
|
|
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ResolveOpenWindowRunnable> resolveRunnable =
|
|
|
|
new ResolveOpenWindowRunnable(mPromiseProxy, nullptr, rv);
|
|
|
|
|
2016-02-26 20:23:12 +00:00
|
|
|
NS_WARN_IF(!resolveRunnable->Dispatch());
|
2015-10-24 12:16:23 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult
|
2016-01-30 17:05:36 +00:00
|
|
|
OpenWindow(nsPIDOMWindowOuter** aWindow)
|
2015-10-24 12:16:23 +00:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
|
|
|
|
|
|
|
|
// [[1. Let url be the result of parsing url with entry settings object's API
|
|
|
|
// base URL.]]
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
WorkerPrivate::LocationInfo& info = workerPrivate->GetLocationInfo();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2015-11-06 07:39:00 +00:00
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), info.mHref);
|
2015-10-24 12:16:23 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), mUrl, nullptr, baseURI);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_TYPE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [[6.1 Open Window]]
|
|
|
|
nsCOMPtr<nsIWindowMediator> wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID,
|
|
|
|
&rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:30:57 +00:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
// ContentProcess
|
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch =
|
|
|
|
do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsPIWindowWatcher> pwwatch(do_QueryInterface(wwatch));
|
|
|
|
NS_ENSURE_STATE(pwwatch);
|
|
|
|
|
|
|
|
nsCString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> newWindow;
|
2015-10-29 23:30:57 +00:00
|
|
|
pwwatch->OpenWindow2(nullptr,
|
|
|
|
spec.get(),
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2016-07-05 16:00:07 +00:00
|
|
|
false, false, true, nullptr, 1.0f, 0,
|
2015-10-29 23:30:57 +00:00
|
|
|
getter_AddRefs(newWindow));
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> pwindow = nsPIDOMWindowOuter::From(newWindow);
|
2015-10-29 23:30:57 +00:00
|
|
|
pwindow.forget(aWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:16:23 +00:00
|
|
|
// Find the most recent browser window and open a new tab in it.
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> browserWindow =
|
2015-12-11 18:32:15 +00:00
|
|
|
nsContentUtils::GetMostRecentNonPBWindow();
|
|
|
|
if (!browserWindow) {
|
2015-10-24 12:16:23 +00:00
|
|
|
// It is possible to be running without a browser window on Mac OS, so
|
|
|
|
// we need to open a new chrome window.
|
|
|
|
// TODO(catalinb): open new chrome window. Bug 1218080
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(browserWindow);
|
|
|
|
if (NS_WARN_IF(!chromeWin)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBrowserDOMWindow> bwin;
|
|
|
|
chromeWin->GetBrowserDOMWindow(getter_AddRefs(bwin));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!bwin)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> win;
|
2015-10-24 12:16:23 +00:00
|
|
|
rv = bwin->OpenURI(uri, nullptr,
|
|
|
|
nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
|
|
|
|
nsIBrowserDOMWindow::OPEN_NEW,
|
|
|
|
getter_AddRefs(win));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_ENSURE_STATE(win);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> pWin = nsPIDOMWindowOuter::From(win);
|
2015-10-24 12:16:23 +00:00
|
|
|
pWin.forget(aWindow);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2015-11-27 22:27:53 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
ServiceWorkerClients::Get(const nsAString& aClientId, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
RefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PromiseWorkerProxy> promiseProxy =
|
|
|
|
PromiseWorkerProxy::Create(workerPrivate, promise);
|
|
|
|
if (!promiseProxy) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<GetRunnable> r =
|
|
|
|
new GetRunnable(promiseProxy, aClientId);
|
2016-03-28 17:28:15 +00:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
|
2015-11-27 22:27:53 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
already_AddRefed<Promise>
|
2015-02-20 15:16:17 +00:00
|
|
|
ServiceWorkerClients::MatchAll(const ClientQueryOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2014-10-27 11:03:00 +00:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-02-12 23:39:26 +00:00
|
|
|
nsString scope;
|
2014-10-27 11:03:00 +00:00
|
|
|
mWorkerScope->GetScope(scope);
|
|
|
|
|
2015-11-30 19:29:51 +00:00
|
|
|
if (aOptions.mType != ClientType::Window) {
|
2015-02-20 15:16:17 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
|
2014-10-27 11:03:00 +00:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PromiseWorkerProxy> promiseProxy =
|
2015-04-07 13:25:08 +00:00
|
|
|
PromiseWorkerProxy::Create(workerPrivate, promise);
|
2015-09-02 17:07:26 +00:00
|
|
|
if (!promiseProxy) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
2014-10-28 09:29:00 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MatchAllRunnable> r =
|
2015-09-02 17:07:26 +00:00
|
|
|
new MatchAllRunnable(promiseProxy,
|
2015-11-30 19:29:51 +00:00
|
|
|
NS_ConvertUTF16toUTF8(scope),
|
|
|
|
aOptions.mIncludeUncontrolled);
|
2016-03-28 17:28:15 +00:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
|
2014-10-27 11:03:00 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
2015-03-06 13:04:49 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2015-10-24 12:16:23 +00:00
|
|
|
ServiceWorkerClients::OpenWindow(const nsAString& aUrl,
|
|
|
|
ErrorResult& aRv)
|
2015-03-06 13:04:49 +00:00
|
|
|
{
|
2015-10-24 12:16:23 +00:00
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
RefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aUrl.EqualsLiteral("about:blank")) {
|
|
|
|
promise->MaybeReject(NS_ERROR_TYPE_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// [[4. If this algorithm is not allowed to show a popup ..]]
|
|
|
|
// In Gecko the service worker is allowed to show a popup only if the user
|
|
|
|
// just clicked on a notification.
|
|
|
|
if (!workerPrivate->GlobalScope()->WindowInteractionAllowed()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PromiseWorkerProxy> promiseProxy =
|
|
|
|
PromiseWorkerProxy::Create(workerPrivate, promise);
|
|
|
|
|
|
|
|
if (!promiseProxy) {
|
2015-03-06 13:04:49 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:16:23 +00:00
|
|
|
nsString scope;
|
|
|
|
mWorkerScope->GetScope(scope);
|
|
|
|
|
|
|
|
RefPtr<OpenWindowRunnable> r = new OpenWindowRunnable(promiseProxy,
|
|
|
|
aUrl, scope);
|
2016-03-28 17:28:15 +00:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
|
2015-10-24 12:16:23 +00:00
|
|
|
|
2015-03-06 13:04:49 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2015-05-14 19:41:42 +00:00
|
|
|
ServiceWorkerClients::Claim(ErrorResult& aRv)
|
2015-03-06 13:04:49 +00:00
|
|
|
{
|
2015-05-14 19:41:42 +00:00
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
|
2015-05-14 19:41:42 +00:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2015-03-06 13:04:49 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PromiseWorkerProxy> promiseProxy =
|
2015-05-14 19:41:42 +00:00
|
|
|
PromiseWorkerProxy::Create(workerPrivate, promise);
|
2015-09-02 17:07:26 +00:00
|
|
|
if (!promiseProxy) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
2015-05-14 19:41:42 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString scope;
|
|
|
|
mWorkerScope->GetScope(scope);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ClaimRunnable> runnable =
|
2015-05-14 19:41:42 +00:00
|
|
|
new ClaimRunnable(promiseProxy, NS_ConvertUTF16toUTF8(scope));
|
|
|
|
|
2016-03-28 17:28:15 +00:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
|
2015-03-06 13:04:49 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|