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: */
|
2013-11-19 23:14:07 +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/. */
|
|
|
|
|
2014-08-19 13:56:00 +00:00
|
|
|
#ifndef mozilla_dom_serviceworkercontainer_h__
|
|
|
|
#define mozilla_dom_serviceworkercontainer_h__
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
class nsPIDOMWindowInner;
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2015-03-10 01:57:06 +00:00
|
|
|
struct RegistrationOptions;
|
2013-11-19 23:14:07 +00:00
|
|
|
class ServiceWorker;
|
|
|
|
|
|
|
|
// Lightweight serviceWorker APIs collection.
|
2015-03-21 16:28:04 +00:00
|
|
|
class ServiceWorkerContainer final : public DOMEventTargetHelper
|
2013-11-19 23:14:07 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper)
|
|
|
|
|
2014-06-17 18:01:28 +00:00
|
|
|
IMPL_EVENT_HANDLER(controllerchange)
|
2013-11-19 23:14:07 +00:00
|
|
|
IMPL_EVENT_HANDLER(error)
|
2015-02-25 19:38:37 +00:00
|
|
|
IMPL_EVENT_HANDLER(message)
|
2013-11-19 23:14:07 +00:00
|
|
|
|
2015-06-26 18:18:18 +00:00
|
|
|
static bool IsEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
explicit ServiceWorkerContainer(nsPIDOMWindowInner* aWindow);
|
2013-11-19 23:14:07 +00:00
|
|
|
|
2015-01-06 20:15:42 +00:00
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Register(const nsAString& aScriptURL,
|
2015-03-10 01:57:06 +00:00
|
|
|
const RegistrationOptions& aOptions,
|
2013-11-19 23:14:07 +00:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2018-01-26 21:08:59 +00:00
|
|
|
already_AddRefed<ServiceWorker>
|
2014-06-17 18:01:28 +00:00
|
|
|
GetController();
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-08-19 13:56:00 +00:00
|
|
|
GetRegistration(const nsAString& aDocumentURL,
|
|
|
|
ErrorResult& aRv);
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-08-19 13:56:00 +00:00
|
|
|
GetRegistrations(ErrorResult& aRv);
|
2013-11-19 23:14:07 +00:00
|
|
|
|
2014-08-26 08:16:03 +00:00
|
|
|
Promise*
|
2014-08-19 13:56:00 +00:00
|
|
|
GetReady(ErrorResult& aRv);
|
2014-07-23 21:05:08 +00:00
|
|
|
|
2014-07-11 18:52:19 +00:00
|
|
|
// Testing only.
|
|
|
|
void
|
|
|
|
GetScopeForUrl(const nsAString& aUrl, nsString& aScope, ErrorResult& aRv);
|
|
|
|
|
2014-08-26 08:16:03 +00:00
|
|
|
// DOMEventTargetHelper
|
2015-03-21 16:28:04 +00:00
|
|
|
void DisconnectFromOwner() override;
|
2014-08-26 08:16:03 +00:00
|
|
|
|
2015-05-14 19:41:42 +00:00
|
|
|
// Invalidates |mControllerWorker| and dispatches a "controllerchange"
|
|
|
|
// event.
|
|
|
|
void
|
|
|
|
ControllerChanged(ErrorResult& aRv);
|
|
|
|
|
2013-11-19 23:14:07 +00:00
|
|
|
private:
|
2014-07-23 21:05:08 +00:00
|
|
|
~ServiceWorkerContainer();
|
2013-11-19 23:14:07 +00:00
|
|
|
|
2014-08-28 16:04:51 +00:00
|
|
|
void RemoveReadyPromise();
|
|
|
|
|
2014-07-23 21:05:08 +00:00
|
|
|
// This only changes when a worker hijacks everything in its scope by calling
|
2015-05-14 19:41:42 +00:00
|
|
|
// claim.
|
2018-01-26 21:08:59 +00:00
|
|
|
RefPtr<ServiceWorker> mControllerWorker;
|
2014-08-26 08:16:03 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Promise> mReadyPromise;
|
2013-11-19 23:14:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-26 21:08:59 +00:00
|
|
|
#endif /* mozilla_dom_serviceworkercontainer_h__ */
|