2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-20 03:14:07 +04: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/. */
|
|
|
|
|
2018-01-27 00:08:59 +03:00
|
|
|
#ifndef mozilla_dom_serviceworker_h__
|
|
|
|
#define mozilla_dom_serviceworker_h__
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2018-01-31 20:10:26 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerDescriptor.h"
|
2018-07-02 17:44:18 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerUtils.h"
|
2013-11-20 03:14:07 +04:00
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#undef PostMessage
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 20:10:25 +03:00
|
|
|
class nsIGlobalObject;
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-25 17:03:18 +03:00
|
|
|
class ServiceWorkerCloneData;
|
2018-05-14 16:02:15 +03:00
|
|
|
|
2018-02-21 21:53:52 +03:00
|
|
|
#define NS_DOM_SERVICEWORKER_IID \
|
|
|
|
{0xd42e0611, 0x3647, 0x4319, {0xae, 0x05, 0x19, 0x89, 0x59, 0xba, 0x99, 0x5e}}
|
|
|
|
|
2014-11-06 18:57:57 +03:00
|
|
|
bool
|
|
|
|
ServiceWorkerVisible(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ServiceWorker final : public DOMEventTargetHelper
|
2013-11-20 03:14:07 +04:00
|
|
|
{
|
|
|
|
public:
|
2018-01-31 20:10:26 +03:00
|
|
|
// Abstract interface for the internal representation of the
|
|
|
|
// ServiceWorker object.
|
|
|
|
class Inner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// This will be called when a DOM ServiceWorker object is
|
|
|
|
// created and takes a strong ref to the Inner object.
|
|
|
|
// RemoveServiceWorker() is guaranteed to be called on the
|
|
|
|
// current thread before the ServiceWorker is destroyed.
|
|
|
|
//
|
|
|
|
// In addition, the Inner object should check to see if
|
|
|
|
// the ServiceWorker's state is correct. If not, it should
|
|
|
|
// be updated automatically by calling SetState(). This is
|
|
|
|
// necessary to handle race conditions where the DOM
|
|
|
|
// ServiceWorker object is created while the state is being
|
|
|
|
// updated in another process.
|
|
|
|
virtual void
|
|
|
|
AddServiceWorker(ServiceWorker* aWorker) = 0;
|
|
|
|
|
|
|
|
// This is called when the DOM ServiceWorker object is
|
|
|
|
// destroyed and drops its ref to the Inner object.
|
|
|
|
virtual void
|
|
|
|
RemoveServiceWorker(ServiceWorker* aWorker) = 0;
|
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
// Get the associated registration for this ServiceWorker. The success
|
|
|
|
// callback should always be called asynchronously.
|
|
|
|
virtual void
|
|
|
|
GetRegistration(ServiceWorkerRegistrationCallback&& aSuccessCB,
|
|
|
|
ServiceWorkerFailureCallback&& aFailureCB) = 0;
|
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
virtual void
|
2018-06-25 17:03:18 +03:00
|
|
|
PostMessage(RefPtr<ServiceWorkerCloneData>&& aData,
|
2018-05-14 16:02:15 +03:00
|
|
|
const ClientInfo& aClientInfo,
|
|
|
|
const ClientState& aClientState) = 0;
|
2018-01-31 20:10:26 +03:00
|
|
|
|
|
|
|
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
|
|
|
};
|
|
|
|
|
2018-02-21 21:53:52 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKER_IID)
|
2013-11-20 03:14:07 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2018-07-02 17:44:18 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorker, DOMEventTargetHelper)
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(statechange)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2018-01-31 20:10:25 +03:00
|
|
|
static already_AddRefed<ServiceWorker>
|
|
|
|
Create(nsIGlobalObject* aOwner, const ServiceWorkerDescriptor& aDescriptor);
|
|
|
|
|
2013-11-20 03:14:07 +04:00
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
ServiceWorkerState
|
2018-01-31 20:10:26 +03:00
|
|
|
State() const;
|
2013-11-20 03:14:07 +04:00
|
|
|
|
2014-12-19 14:25:56 +03:00
|
|
|
void
|
2018-01-31 20:10:26 +03:00
|
|
|
SetState(ServiceWorkerState aState);
|
2014-12-19 14:25:56 +03:00
|
|
|
|
2013-11-20 03:14:07 +04:00
|
|
|
void
|
2015-02-19 19:40:21 +03:00
|
|
|
GetScriptURL(nsString& aURL) const;
|
2013-11-20 03:14:07 +04:00
|
|
|
|
2015-02-09 20:42:00 +03:00
|
|
|
void
|
|
|
|
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
|
2015-02-09 20:42:00 +03:00
|
|
|
|
2018-02-19 23:06:19 +03:00
|
|
|
const ServiceWorkerDescriptor&
|
|
|
|
Descriptor() const;
|
2018-01-31 20:10:26 +03:00
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
void
|
|
|
|
DisconnectFromOwner() override;
|
|
|
|
|
2013-11-20 03:14:07 +04:00
|
|
|
private:
|
2018-01-31 20:10:26 +03:00
|
|
|
ServiceWorker(nsIGlobalObject* aWindow,
|
|
|
|
const ServiceWorkerDescriptor& aDescriptor,
|
2018-01-31 20:10:26 +03:00
|
|
|
Inner* aInner);
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
// This class is reference-counted and will be destroyed from Release().
|
|
|
|
~ServiceWorker();
|
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
void
|
|
|
|
MaybeAttachToRegistration(ServiceWorkerRegistration* aRegistration);
|
|
|
|
|
2018-01-31 20:10:26 +03:00
|
|
|
ServiceWorkerDescriptor mDescriptor;
|
2018-03-03 00:02:50 +03:00
|
|
|
|
|
|
|
RefPtr<Inner> mInner;
|
2018-07-02 17:44:18 +03:00
|
|
|
RefPtr<ServiceWorkerRegistration> mRegistration;
|
2013-11-20 03:14:07 +04:00
|
|
|
};
|
|
|
|
|
2018-02-21 21:53:52 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorker, NS_DOM_SERVICEWORKER_IID)
|
|
|
|
|
2013-11-20 03:14:07 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-27 00:08:59 +03:00
|
|
|
#endif // mozilla_dom_serviceworker_h__
|