Skip to content

Commit

Permalink
Bug 967264 - Patch 1: ServiceWorkerGlobalScope stub. r=khuey sr=jst
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilm committed May 13, 2014
1 parent ce0373d commit d16ae2c
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 3 deletions.
5 changes: 5 additions & 0 deletions content/base/src/nsGkAtomList.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ GK_ATOM(ol, "ol")
GK_ATOM(omitXmlDeclaration, "omit-xml-declaration")
GK_ATOM(ona2dpstatuschanged, "ona2dpstatuschanged")
GK_ATOM(onabort, "onabort")
GK_ATOM(onactivate, "onactivate")
GK_ATOM(onadapteradded, "onadapteradded")
GK_ATOM(onafterprint, "onafterprint")
GK_ATOM(onafterscriptexecute, "onafterscriptexecute")
Expand All @@ -661,6 +662,7 @@ GK_ATOM(onaudioprocess, "onaudioprocess")
GK_ATOM(onbeforecopy, "onbeforecopy")
GK_ATOM(onbeforecut, "onbeforecut")
GK_ATOM(onbeforepaste, "onbeforepaste")
GK_ATOM(onbeforeevicted, "onbeforeevicted")
GK_ATOM(onbeforeprint, "onbeforeprint")
GK_ATOM(onbeforescriptexecute, "onbeforescriptexecute")
GK_ATOM(onbeforeunload, "onbeforeunload")
Expand Down Expand Up @@ -727,7 +729,9 @@ GK_ATOM(ondrop, "ondrop")
GK_ATOM(onenabled, "onenabled")
GK_ATOM(onemergencycbmodechange, "onemergencycbmodechange")
GK_ATOM(onerror, "onerror")
GK_ATOM(onevicted, "onevicted")
GK_ATOM(onfailed, "onfailed")
GK_ATOM(onfetch, "onfetch")
GK_ATOM(onfocus, "onfocus")
GK_ATOM(onfrequencychange, "onfrequencychange")
GK_ATOM(onspeakerforcedchange, "onspeakerforcedchange")
Expand All @@ -744,6 +748,7 @@ GK_ATOM(oniccinfochange, "oniccinfochange")
GK_ATOM(oniccundetected, "oniccundetected")
GK_ATOM(onincoming, "onincoming")
GK_ATOM(oninput, "oninput")
GK_ATOM(oninstall, "oninstall")
GK_ATOM(oninvalid, "oninvalid")
GK_ATOM(onkeydown, "onkeydown")
GK_ATOM(onkeypress, "onkeypress")
Expand Down
5 changes: 5 additions & 0 deletions dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/ServiceWorkerContainer.h',
},

'ServiceWorkerGlobalScope': {
'headerFile': 'mozilla/dom/WorkerScope.h',
'workers': True,
},

'SharedWorker': {
'nativeType': 'mozilla::dom::workers::SharedWorker',
'headerFile': 'mozilla/dom/workers/bindings/SharedWorker.h',
Expand Down
48 changes: 48 additions & 0 deletions dom/webidl/ServiceWorkerGlobalScope.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* -*- 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
*
* You are granted a license to use, reproduce and create derivative works of
* this document.
*/

// The Pref controls exposure in general, the Func restricts it to inside the
// ServiceWorkerGlobalScope (itself).
[Global, Func="mozilla::dom::workers::ServiceWorkerGlobalScope::Visible",
Pref="dom.serviceWorkers.enabled"]
interface ServiceWorkerGlobalScope : WorkerGlobalScope {
// FIXME(nsm): Bug 982725
// readonly attribute CacheList caches;

// 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;

// FIXME(nsm): Bug 995484
// ResponsePromise<any> fetch((Request or [EnsureUTF16] DOMString) request);

void update();
void unregister();

attribute EventHandler oninstall;
attribute EventHandler onactivate;
attribute EventHandler onfetch;
attribute EventHandler onbeforeevicted;
attribute EventHandler onevicted;

// The event.source of these MessageEvents are instances of Client
attribute EventHandler onmessage;

// close() method inherited from WorkerGlobalScope is not exposed.
// FIXME(nsm): For now, overridden so it can be a no-op.
void close();
};


1 change: 1 addition & 0 deletions dom/webidl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ WEBIDL_FILES = [
'Selection.webidl',
'ServiceWorker.webidl',
'ServiceWorkerContainer.webidl',
'ServiceWorkerGlobalScope.webidl',
'SettingsManager.webidl',
'ShadowRoot.webidl',
'SharedWorker.webidl',
Expand Down
5 changes: 3 additions & 2 deletions dom/workers/WorkerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5821,8 +5821,9 @@ WorkerPrivate::CreateGlobalScope(JSContext* aCx)
nsRefPtr<WorkerGlobalScope> globalScope;
if (IsSharedWorker()) {
globalScope = new SharedWorkerGlobalScope(this, SharedWorkerName());
}
else {
} else if (IsServiceWorker()) {
globalScope = new ServiceWorkerGlobalScope(this, SharedWorkerName());
} else {
globalScope = new DedicatedWorkerGlobalScope(this);
}

Expand Down
30 changes: 30 additions & 0 deletions dom/workers/WorkerScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mozilla/EventListenerManager.h"
#include "mozilla/dom/FunctionBinding.h"
#include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
#include "mozilla/dom/SharedWorkerGlobalScopeBinding.h"
#include "mozilla/dom/Console.h"

Expand Down Expand Up @@ -341,6 +342,35 @@ SharedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx)
true);
}

ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
const nsACString& aScope)
: WorkerGlobalScope(aWorkerPrivate),
mScope(NS_ConvertUTF8toUTF16(aScope))
{
}

/* static */ bool
ServiceWorkerGlobalScope::Visible(JSContext* aCx, JSObject* aObj)
{
ServiceWorkerGlobalScope* self = nullptr;
nsresult rv = UNWRAP_WORKER_OBJECT(ServiceWorkerGlobalScope, aObj, self);
return NS_SUCCEEDED(rv) && self;
}

JSObject*
ServiceWorkerGlobalScope::WrapGlobalObject(JSContext* aCx)
{
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());

JS::CompartmentOptions options;
mWorkerPrivate->CopyJSCompartmentOptions(options);

return ServiceWorkerGlobalScopeBinding_workers::Wrap(aCx, this, this, options,
GetWorkerPrincipal(),
true);
}

bool
GetterOnlyJSNative(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
{
Expand Down
49 changes: 48 additions & 1 deletion dom/workers/WorkerScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,60 @@ class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
virtual JSObject*
WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;

void GetName(DOMString& aName) const {
void GetName(DOMString& aName) const
{
aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
}

IMPL_EVENT_HANDLER(connect)
};

class ServiceWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
{
const nsString mScope;
~ServiceWorkerGlobalScope() { }

public:
ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);

static bool
Visible(JSContext* aCx, JSObject* aObj);

virtual JSObject*
WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;

void
GetScope(DOMString& aScope) const
{
aScope.AsAString() = mScope;
}

void
Close() const
{
// no-op close.
}

void
Update()
{
// FIXME(nsm): Bug 982728
}

void
Unregister()
{
// FIXME(nsm): Bug 982728
}

IMPL_EVENT_HANDLER(activate)
IMPL_EVENT_HANDLER(beforeevicted)
IMPL_EVENT_HANDLER(evicted)
IMPL_EVENT_HANDLER(fetch)
IMPL_EVENT_HANDLER(install)
IMPL_EVENT_HANDLER(message)
};

JSObject*
CreateGlobalScope(JSContext* aCx);

Expand Down

0 comments on commit d16ae2c

Please sign in to comment.