Backed out 4 changesets (bug 982726) for the same serviceworker perma-fails it hit last time it landed.

Backed out changeset 9674f68df2e5 (bug 982726)
Backed out changeset 9d397edb8e9a (bug 982726)
Backed out changeset ebe7add5dd11 (bug 982726)
Backed out changeset 2771520aa1b9 (bug 982726)
This commit is contained in:
Ryan VanderMeulen 2014-09-03 21:45:30 -04:00
Родитель ab2d367e37
Коммит 8be77b965e
29 изменённых файлов: 6 добавлений и 1155 удалений

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

@ -1058,16 +1058,6 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/workers/bindings/ServiceWorker.h',
},
'ServiceWorkerClient': {
'nativeType': 'mozilla::dom::workers::ServiceWorkerClient',
'headerFile': 'mozilla/dom/workers/bindings/ServiceWorkerClient.h',
},
'ServiceWorkerClients': {
'nativeType': 'mozilla::dom::workers::ServiceWorkerClients',
'headerFile': 'mozilla/dom/workers/bindings/ServiceWorkerClients.h',
},
'ServiceWorkerGlobalScope': {
'headerFile': 'mozilla/dom/WorkerScope.h',
'workers': True,

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

@ -8,6 +8,8 @@
*
*/
// Still unclear what should be subclassed.
// https://github.com/slightlyoff/ServiceWorker/issues/189
[Pref="dom.serviceWorkers.enabled",
// XXXbz I have no idea where this should be exposed. The spec makes
// no sense. But since it's got a pref, let's say window.
@ -18,10 +20,6 @@ interface ServiceWorker : EventTarget {
readonly attribute ServiceWorkerState state;
attribute EventHandler onstatechange;
// FIXME(catalinb): Bug 1053483 - This should be inherited from MessageUtils
[Throws]
void postMessage(any message, optional sequence<Transferable> transferable);
};
ServiceWorker implements AbstractWorker;

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

@ -1,16 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
*
*/
[Exposed=ServiceWorker]
interface ServiceWorkerClient {
readonly attribute unsigned long id;
[Throws]
void postMessage(any message, optional sequence<Transferable> transfer);
};

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

@ -1,19 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
*
*/
[Exposed=ServiceWorker]
interface ServiceWorkerClients {
// A list of client objects, identifiable by ID, that correspond to windows
// (or workers) that are "controlled" by this SW
[Throws]
Promise<sequence<ServiceWorkerClient>?> getServiced();
[Throws]
Promise<any> reloadAll();
};

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

@ -16,7 +16,10 @@ interface ServiceWorkerGlobalScope : WorkerGlobalScope {
// FIXME(nsm): Bug 982725
// readonly attribute CacheList caches;
readonly attribute ServiceWorkerClients clients;
// FIXME(nsm): Bug 982726
// A container for a list of window objects, identifiable by ID, that
// correspond to windows (or workers) that are "controlled" by this SW
// readonly attribute ServiceWorkerClients clients;
[Unforgeable] readonly attribute DOMString scope;

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

@ -331,8 +331,6 @@ WEBIDL_FILES = [
'ScrollAreaEvent.webidl',
'Selection.webidl',
'ServiceWorker.webidl',
'ServiceWorkerClient.webidl',
'ServiceWorkerClients.webidl',
'ServiceWorkerContainer.webidl',
'ServiceWorkerGlobalScope.webidl',
'ServiceWorkerRegistration.webidl',

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

@ -11,7 +11,6 @@
#include "mozilla/dom/Promise.h"
using mozilla::ErrorResult;
using namespace mozilla::dom;
USING_WORKERS_NAMESPACE
@ -47,17 +46,6 @@ ServiceWorker::WrapObject(JSContext* aCx)
return ServiceWorkerBinding::Wrap(aCx, this);
}
void
ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv)
{
WorkerPrivate* workerPrivate = GetWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->PostMessage(aCx, aMessage, aTransferable, aRv);
}
WorkerPrivate*
ServiceWorker::GetWorkerPrivate() const
{

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

@ -52,11 +52,6 @@ public:
aURL = mURL;
}
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv);
WorkerPrivate*
GetWorkerPrivate() const;

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

@ -1,159 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "ServiceWorkerClient.h"
#include "mozilla/dom/MessageEvent.h"
#include "nsGlobalWindow.h"
#include "WorkerPrivate.h"
#include "mozilla/dom/ServiceWorkerClientBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::workers;
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ServiceWorkerClient, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(ServiceWorkerClient)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ServiceWorkerClient)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerClient)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
JSObject*
ServiceWorkerClient::WrapObject(JSContext* aCx)
{
return ServiceWorkerClientBinding::Wrap(aCx, this);
}
namespace {
class ServiceWorkerClientPostMessageRunnable MOZ_FINAL : public nsRunnable
{
uint64_t mId;
JSAutoStructuredCloneBuffer mBuffer;
nsTArray<nsCOMPtr<nsISupports>> mClonedObjects;
public:
ServiceWorkerClientPostMessageRunnable(uint64_t aId,
JSAutoStructuredCloneBuffer&& aData,
nsTArray<nsCOMPtr<nsISupports>>& aClonedObjects)
: mId(aId),
mBuffer(Move(aData))
{
mClonedObjects.SwapElements(aClonedObjects);
}
NS_IMETHOD
Run()
{
AssertIsOnMainThread();
nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mId);
if (!window) {
return NS_ERROR_FAILURE;
}
AutoJSAPI jsapi;
jsapi.Init(window);
JSContext* cx = jsapi.cx();
return DispatchDOMEvent(cx, window);
}
private:
NS_IMETHOD
DispatchDOMEvent(JSContext* aCx, nsGlobalWindow* aTargetWindow)
{
AssertIsOnMainThread();
// Release reference to objects that were AddRef'd for
// cloning into worker when array goes out of scope.
nsTArray<nsCOMPtr<nsISupports>> clonedObjects;
clonedObjects.SwapElements(mClonedObjects);
JS::Rooted<JS::Value> messageData(aCx);
if (!mBuffer.read(aCx, &messageData,
WorkerStructuredCloneCallbacks(true))) {
xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMMessageEvent> event = new MessageEvent(aTargetWindow,
nullptr, nullptr);
nsresult rv =
event->InitMessageEvent(NS_LITERAL_STRING("message"),
false /* non-bubbling */,
false /* not cancelable */,
messageData,
EmptyString(),
EmptyString(),
nullptr);
if (NS_FAILED(rv)) {
xpc::Throw(aCx, rv);
return NS_ERROR_FAILURE;
}
event->SetTrusted(true);
bool status = false;
aTargetWindow->DispatchEvent(event, &status);
if (!status) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
};
} // anonymous namespace
void
ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv)
{
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->AssertIsOnWorkerThread();
JS::Rooted<JS::Value> transferable(aCx, JS::UndefinedValue());
if (aTransferable.WasPassed()) {
const Sequence<JS::Value>& realTransferable = aTransferable.Value();
JS::HandleValueArray elements =
JS::HandleValueArray::fromMarkedLocation(realTransferable.Length(),
realTransferable.Elements());
JSObject* array = JS_NewArrayObject(aCx, elements);
if (!array) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
transferable.setObject(*array);
}
JSStructuredCloneCallbacks* callbacks = WorkerStructuredCloneCallbacks(false);
nsTArray<nsCOMPtr<nsISupports>> clonedObjects;
JSAutoStructuredCloneBuffer buffer;
if (!buffer.write(aCx, aMessage, transferable, callbacks, &clonedObjects)) {
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
return;
}
nsRefPtr<ServiceWorkerClientPostMessageRunnable> runnable =
new ServiceWorkerClientPostMessageRunnable(mId, Move(buffer), clonedObjects);
nsresult rv = NS_DispatchToMainThread(runnable);
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);
}
}

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

@ -1,68 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
#ifndef mozilla_dom_workers_serviceworkerclient_h
#define mozilla_dom_workers_serviceworkerclient_h
#include "nsCOMPtr.h"
#include "nsWrapperCache.h"
namespace mozilla {
class ErrorResult;
namespace dom {
class Promise;
template<typename T> class Optional;
template<typename T> class Sequence;
namespace workers {
class ServiceWorkerClient MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ServiceWorkerClient)
ServiceWorkerClient(nsISupports* aOwner, uint64_t aId)
: mOwner(aOwner),
mId(aId)
{
SetIsDOMBinding();
}
uint32_t Id() const
{
return mId;
}
void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv);
nsISupports* GetParentObject() const
{
return mOwner;
}
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
private:
~ServiceWorkerClient()
{
}
nsCOMPtr<nsISupports> mOwner;
uint64_t mId;
};
} // namespace workers
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_workers_serviceworkerclient_h

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

@ -1,229 +0,0 @@
/* -*- 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 "ServiceWorkerClient.h"
#include "ServiceWorkerClients.h"
#include "ServiceWorkerManager.h"
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"
#include "WorkerScope.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ServiceWorkerClientsBinding.h"
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);
SetIsDOMBinding();
}
JSObject*
ServiceWorkerClients::WrapObject(JSContext* aCx)
{
return ServiceWorkerClientsBinding::Wrap(aCx, this);
}
namespace {
// Helper class used for passing the promise between threads while
// keeping the worker alive.
class PromiseHolder MOZ_FINAL : public WorkerFeature
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PromiseHolder)
public:
PromiseHolder(WorkerPrivate* aWorkerPrivate,
Promise* aPromise)
: mWorkerPrivate(aWorkerPrivate),
mPromise(aPromise),
mClean(false)
{
MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mPromise);
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(mWorkerPrivate->GetJSContext(), this))) {
// Worker has been canceled and will go away.
// The ResolvePromiseWorkerRunnable won't run, so we can set mPromise to
// nullptr.
mPromise = nullptr;
mClean = true;
}
}
Promise*
Get() const
{
return mPromise;
}
void
Clean()
{
mWorkerPrivate->AssertIsOnWorkerThread();
if (mClean) {
return;
}
mPromise = nullptr;
mWorkerPrivate->RemoveFeature(mWorkerPrivate->GetJSContext(), this);
mClean = true;
}
bool
Notify(JSContext* aCx, Status aStatus)
{
mWorkerPrivate->AssertIsOnWorkerThread();
if (aStatus > Running) {
Clean();
}
return true;
}
private:
~PromiseHolder()
{
MOZ_ASSERT(mClean);
}
WorkerPrivate* mWorkerPrivate;
nsRefPtr<Promise> mPromise;
bool mClean;
};
class ResolvePromiseWorkerRunnable MOZ_FINAL : public WorkerRunnable
{
nsRefPtr<PromiseHolder> mPromiseHolder;
nsAutoPtr<nsTArray<uint64_t>> mValue;
public:
ResolvePromiseWorkerRunnable(WorkerPrivate* aWorkerPrivate,
PromiseHolder* aPromiseHolder,
nsAutoPtr<nsTArray<uint64_t>>& aValue)
: WorkerRunnable(aWorkerPrivate, WorkerThreadModifyBusyCount),
mPromiseHolder(aPromiseHolder),
mValue(aValue)
{
AssertIsOnMainThread();
}
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
Promise* promise = mPromiseHolder->Get();
MOZ_ASSERT(promise);
nsTArray<nsRefPtr<ServiceWorkerClient>> ret;
for (size_t i = 0; i < mValue->Length(); i++) {
ret.AppendElement(nsRefPtr<ServiceWorkerClient>(
new ServiceWorkerClient(promise->GetParentObject(),
mValue->ElementAt(i))));
}
promise->MaybeResolve(ret);
// release the reference on the worker thread.
mPromiseHolder->Clean();
return true;
}
};
class GetServicedRunnable MOZ_FINAL : public nsRunnable
{
WorkerPrivate* mWorkerPrivate;
nsCString mScope;
nsRefPtr<PromiseHolder> mPromiseHolder;
public:
GetServicedRunnable(WorkerPrivate* aWorkerPrivate,
Promise* aPromise,
const nsCString& aScope)
: mWorkerPrivate(aWorkerPrivate),
mScope(aScope)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
mPromiseHolder = new PromiseHolder(aWorkerPrivate, aPromise);
}
NS_IMETHOD
Run() MOZ_OVERRIDE
{
AssertIsOnMainThread();
nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
nsAutoPtr<nsTArray<uint64_t>> result(new nsTArray<uint64_t>());
swm->GetServicedClients(mScope, result);
nsRefPtr<ResolvePromiseWorkerRunnable> r =
new ResolvePromiseWorkerRunnable(mWorkerPrivate, mPromiseHolder, result);
AutoSafeJSContext cx;
r->Dispatch(cx);
return NS_OK;
}
};
} // anonymous namespace
already_AddRefed<Promise>
ServiceWorkerClients::GetServiced(ErrorResult& aRv)
{
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->AssertIsOnWorkerThread();
DOMString scope;
mWorkerScope->GetScope(scope);
nsRefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
nsRefPtr<GetServicedRunnable> r =
new GetServicedRunnable(workerPrivate, promise, NS_ConvertUTF16toUTF8(scope));
nsresult rv = NS_DispatchToMainThread(r);
if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
}
return promise.forget();
}
// FIXME(catalinb): Bug 1045257 - Implement ReloadAll
already_AddRefed<Promise>
ServiceWorkerClients::ReloadAll(ErrorResult& aRv)
{
nsRefPtr<Promise> promise = Promise::Create(mWorkerScope, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
return promise.forget();
}

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

@ -1,56 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
#ifndef mozilla_dom_workers_serviceworkerclients_h
#define mozilla_dom_workers_serviceworkerclients_h
#include "nsAutoPtr.h"
#include "nsWrapperCache.h"
namespace mozilla {
class ErrorResult;
namespace dom {
class Promise;
namespace workers {
class ServiceWorkerGlobalScope;
class ServiceWorkerClients MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ServiceWorkerClients)
ServiceWorkerClients(ServiceWorkerGlobalScope* aWorkerScope);
already_AddRefed<Promise> GetServiced(ErrorResult& aRv);
already_AddRefed<Promise> ReloadAll(ErrorResult& aRv);
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
ServiceWorkerGlobalScope* GetParentObject() const
{
return mWorkerScope;
}
private:
~ServiceWorkerClients()
{
}
nsRefPtr<ServiceWorkerGlobalScope> mWorkerScope;
};
} // namespace workers
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_workers_serviceworkerclients_h

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

@ -24,7 +24,6 @@
#include "RuntimeService.h"
#include "ServiceWorker.h"
#include "ServiceWorkerClient.h"
#include "ServiceWorkerRegistration.h"
#include "ServiceWorkerEvents.h"
#include "WorkerInlines.h"
@ -2174,54 +2173,4 @@ ServiceWorkerManager::InvalidateServiceWorkerRegistrationWorker(ServiceWorkerReg
}
}
namespace {
class MOZ_STACK_CLASS FilterRegistrationData
{
public:
FilterRegistrationData(nsTArray<uint64_t>* aDocuments,
ServiceWorkerRegistrationInfo* aRegistration)
: mDocuments(aDocuments),
mRegistration(aRegistration)
{
}
nsTArray<uint64_t>* mDocuments;
nsRefPtr<ServiceWorkerRegistrationInfo> mRegistration;
};
static PLDHashOperator
EnumControlledDocuments(nsISupports* aKey,
ServiceWorkerRegistrationInfo* aRegistration,
void* aData)
{
FilterRegistrationData* data = static_cast<FilterRegistrationData*>(aData);
if (data->mRegistration != aRegistration) {
return PL_DHASH_NEXT;
}
nsCOMPtr<nsIDocument> document = do_QueryInterface(aKey);
if (!document || !document->GetInnerWindow()) {
return PL_DHASH_NEXT;
}
data->mDocuments->AppendElement(document->GetInnerWindow()->WindowID());
return PL_DHASH_NEXT;
}
} // anonymous namespace
void
ServiceWorkerManager::GetServicedClients(const nsCString& aScope,
nsTArray<uint64_t>* aControlledDocuments)
{
nsRefPtr<ServiceWorkerDomainInfo> domainInfo = GetDomainInfo(aScope);
nsRefPtr<ServiceWorkerRegistrationInfo> registration =
domainInfo->GetRegistration(aScope);
MOZ_ASSERT(registration);
FilterRegistrationData data(aControlledDocuments, registration);
domainInfo->mControlledDocuments.EnumerateRead(EnumControlledDocuments,
&data);
}
END_WORKERS_NAMESPACE

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

@ -318,10 +318,6 @@ public:
uint32_t aColumnNumber,
uint32_t aFlags);
void
GetServicedClients(const nsCString& aScope,
nsTArray<uint64_t>* aControlledDocuments);
static already_AddRefed<ServiceWorkerManager>
GetInstance();

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

@ -346,14 +346,6 @@ SharedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx)
true);
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope,
mClients)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServiceWorkerGlobalScope)
NS_INTERFACE_MAP_END_INHERITING(WorkerGlobalScope)
NS_IMPL_ADDREF_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope)
NS_IMPL_RELEASE_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope)
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
const nsACString& aScope)
: WorkerGlobalScope(aWorkerPrivate),

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

@ -8,7 +8,6 @@
#include "Workers.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "ServiceWorkerClients.h"
namespace mozilla {
namespace dom {
@ -164,15 +163,9 @@ public:
class ServiceWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
{
const nsString mScope;
nsRefPtr<ServiceWorkerClients> mClients;
~ServiceWorkerGlobalScope() { }
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
WorkerGlobalScope)
ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
virtual JSObject*
@ -202,15 +195,6 @@ public:
// FIXME(nsm): Bug 982728
}
ServiceWorkerClients*
Clients() {
if (!mClients) {
mClients = new ServiceWorkerClients(this);
}
return mClients;
}
IMPL_EVENT_HANDLER(activate)
IMPL_EVENT_HANDLER(beforeevicted)
IMPL_EVENT_HANDLER(evicted)

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

@ -29,8 +29,6 @@ EXPORTS.mozilla.dom.workers.bindings += [
'Navigator.h',
'Performance.h',
'ServiceWorker.h',
'ServiceWorkerClient.h',
'ServiceWorkerClients.h',
'SharedWorker.h',
'URL.h',
'WorkerFeature.h',
@ -53,8 +51,6 @@ SOURCES += [
'RuntimeService.cpp',
'ScriptLoader.cpp',
'ServiceWorker.cpp',
'ServiceWorkerClient.cpp',
'ServiceWorkerClients.cpp',
'ServiceWorkerContainer.cpp',
'ServiceWorkerEvents.cpp',
'ServiceWorkerManager.cpp',

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

@ -1,16 +0,0 @@
function loop() {
self.clients.getServiced().then(function(result) {
setTimeout(loop, 0);
});
}
onactivate = function(e) {
// spam getServiced until the worker is closed.
loop();
}
onclose = function(e) {
for (var i = 0; i < 100; ++i) {
self.clients.getServiced();
}
}

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

@ -1,12 +0,0 @@
onmessage = function(e) {
if (!e.data) {
dump("ERROR: message has no data.\n");
}
self.clients.getServiced().then(function(res) {
if (res.length === 0) {
dump("ERROR: no client is currently being controlled.\n");
}
res[res.length - 1].postMessage(res.length);
});
};

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

@ -1,7 +0,0 @@
onmessage = function() {
self.clients.getServiced().then(function(result) {
for (i = 0; i < result.length; i++) {
result[i].postMessage(i);
}
});
};

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

@ -1,9 +0,0 @@
onmessage = function(e) {
self.clients.getServiced().then(function(res) {
if (!res.length) {
dump("ERROR: no clients are currently controlled.\n");
}
res[0].postMessage(e.data);
});
};

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

@ -10,21 +10,10 @@ support-files =
simpleregister/ready.html
controller/index.html
unregister/index.html
sw_clients/simple.html
get_serviced_worker.js
get_serviced_worker_advanced.js
message_posting_worker.js
sw_clients/service_worker_controlled.html
get_serviced_worker_enumerate.js
[test_get_serviced.html]
[test_get_serviced_advanced.html]
[test_get_serviced_enumerate.html]
[test_installation_simple.html]
[test_install_event.html]
[test_navigator.html]
[test_post_message.html]
[test_post_message_advanced.html]
[test_scopes.html]
[test_controller.html]
[test_unregister.html]

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

@ -1,39 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>controlled page</title>
<!--
Paged controlled by a service worker for testing getServiced().
See bug 982726.
-->
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script class="testbody" type="text/javascript">
function fail(msg) {
info("service_worker_controlled.html: " + msg);
opener.postMessage("FAIL", "*");
}
if (!opener) {
info("service_worker_controlled.html should not be launched directly!");
}
window.onload = function() {
navigator.serviceWorker.ready.then(function(swr) {
opener.postMessage("READY", "*");
});
}
window.onmessage = function(msg) {
// forward message to the test page.
opener.postMessage(msg.data, "*");
};
</script>
</head>
<body>
</body>
</html>

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

@ -1,25 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - test get_serviced not crashing</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
window.onload = function() {
opener.postMessage("READY", "*");
}
</script>
</pre>
</body>
</html>

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

@ -1,57 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - test get_serviced not crashing</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
// get_serviced_worker will call getServiced until the worker shuts down.
// Test passes if the browser doesn't crash on leaked promise objects.
var controlled_window;
function simpleRegister() {
return navigator.serviceWorker.register("get_serviced_worker.js", { scope: "./sw_clients/" });
}
function openWindow() {
var p = new Promise(function(resolve, reject) {
window.onmessage = function(e) {
if (e.data === "READY") {
resolve();
}
}
});
controlled_window = window.open("sw_clients/simple.html");
return p;
}
function runTest() {
simpleRegister()
.then(openWindow).catch(function(e) {
ok(false, "Some test failed with error " + e);
}).then(function() {
ok(true, "Didn't crash on resolving getServiced promises while worker shuts down.");
SimpleTest.finish();
controlled_window.close();
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
</script>
</pre>
</body>
</html>

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

@ -1,80 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - test get_serviced </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var opened = [];
var registration;
function start() {
return navigator.serviceWorker.register("get_serviced_worker_advanced.js",
{ scope: "./sw_clients/" }).then((swr) => registration = swr);
}
function testGetServiced() {
var p = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
opened.push(w);
registration.active.postMessage("getServiced");
} else if (e.data === opened.length) {
ok(true, "getServiced returned the correct value.");
res();
} else {
ok(false, "Wrong value. Expected: " + opened.length +
", got: " + e.data);
res();
}
}
});
var w;
setTimeout(function() {
w = window.open("sw_clients/service_worker_controlled.html");
}, 100);
return p;
}
function removeAndTest() {
opened.pop().close();
opened.pop().close();
return testGetServiced();
}
function runTest() {
start()
.then(testGetServiced)
.then(testGetServiced)
.then(testGetServiced)
.then(removeAndTest)
.then(function(e) {
while (opened.length) {
opened.pop().close();
}
SimpleTest.finish();
}).catch(function(e) {
ok(false, "Some test failed with error " + e);
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
</script>
</pre>
</body>
</html>

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

@ -1,82 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - test get_serviced </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var registration;
var opened = [];
var results = [];
function start() {
return navigator.serviceWorker.register("get_serviced_worker_enumerate.js",
{ scope: "./sw_clients/" }).then((swr) => registration = swr);
}
function openWindow() {
var p = new Promise(function(res, rej) {
var w = window.open("sw_clients/service_worker_controlled.html");
window.onmessage = function(e) {
if (e.data === "READY") {
opened.push(w);
res();
}
}
});
return p;
}
function testGetServiced() {
var count = 0;
return new Promise(function (res, rej) {
registration.active.postMessage("getServiced");
// wait for response
window.onmessage = function(msg) {
results[msg.data] = "ok";
count = count + 1;
if (count == opened.length) {
for (i = 0; i < count; i++) {
ok(results[i] == "ok", "Client received the message.");
}
res();
}
}
});
}
function runTest() {
start()
.then(openWindow).then(openWindow)
.then(openWindow).then(openWindow)
.then(testGetServiced)
.then(function(e) {
while (opened.length) {
opened.pop().close();
}
SimpleTest.finish();
}).catch(function(e) {
ok(false, "Some test failed with error " + e);
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
</script>
</pre>
</body>
</html>

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

@ -1,62 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - Test service worker post message </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var magic_value = "MAGIC_VALUE_123";
function start() {
return navigator.serviceWorker.register("message_posting_worker.js",
{ scope: "./sw_clients/" });
}
function testPostMessage(swr) {
var p = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
swr.active.postMessage(magic_value);
} else if (e.data === magic_value) {
ok(true, "Worker posted the correct value.");
res();
} else {
ok(false, "Wrong value. Expected: " + magic_value +
", got: " + e.data);
res();
}
}
});
var w;
setTimeout(function() {
w = window.open("sw_clients/service_worker_controlled.html");
}, 100);
return p.then(() => w.close());
}
function runTest() {
start()
.then(testPostMessage).catch(function(e) {
ok(false, "Some test failed with error " + e);
}).then(SimpleTest.finish);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
</script>
</pre>
</body>
</html>

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

@ -1,91 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 982726 - Test service worker post message advanced </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var registration;
var base = ["string", true, 42];
var blob = new Blob(["blob_content"]);
var file = new File(["file_content"], "file");
var obj = { body : "object_content" };
function readBlob(blob) {
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsText(blob);
});
}
function equals(v1, v2) {
return Promise.all([v1, v2]).then(function(val) {
ok(val[0] === val[1], "Values should match.");
});
}
function blob_equals(b1, b2) {
return equals(readBlob(b1), readBlob(b2));
}
function file_equals(f1, f2) {
return equals(f1.name, f2.name).then(blob_equals(f1, f2));
}
function obj_equals(o1, o2) {
return equals(o1.body, o2.body);
}
function start() {
return navigator.serviceWorker.register("message_posting_worker.js",
{ scope: "./sw_clients/" }).then((swr) => registration = swr);
}
function testPostMessageObject(obj, test) {
var p = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
registration.active.postMessage(obj)
} else {
test(obj, e.data).then(res);
}
}
});
var w = window.open("sw_clients/service_worker_controlled.html");
return p.then(() => w.close());
}
function runTest() {
start()
.then(testPostMessageObject.bind(this, base[0], equals))
.then(testPostMessageObject.bind(this, base[1], equals))
.then(testPostMessageObject.bind(this, base[2], equals))
.then(testPostMessageObject.bind(this, blob, blob_equals))
.then(testPostMessageObject.bind(this, file, file_equals))
.then(testPostMessageObject.bind(this, obj, obj_equals))
.catch(function(e) {
ok(false, "Some test failed with error " + e);
}).then(SimpleTest.finish);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
</script>
</pre>
</body>
</html>