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