2013-11-19 23:14:07 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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"
|
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2015-03-10 01:57:06 +00:00
|
|
|
struct RegistrationOptions;
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class ServiceWorker;
|
2014-08-19 13:56:00 +00:00
|
|
|
}
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
// 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(reloadpage)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
2015-02-25 19:38:37 +00:00
|
|
|
IMPL_EVENT_HANDLER(message)
|
2013-11-19 23:14:07 +00:00
|
|
|
|
2014-07-23 21:05:08 +00:00
|
|
|
explicit ServiceWorkerContainer(nsPIDOMWindow* 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);
|
|
|
|
|
2014-08-19 13:56:00 +00:00
|
|
|
already_AddRefed<workers::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
|
|
|
|
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
|
|
|
|
// replace().
|
|
|
|
// FIXME(nsm): Bug 982711. Provide API to let SWM invalidate this.
|
2014-08-19 13:56:00 +00:00
|
|
|
nsRefPtr<workers::ServiceWorker> mControllerWorker;
|
2014-08-26 08:16:03 +00:00
|
|
|
|
|
|
|
nsRefPtr<Promise> mReadyPromise;
|
2013-11-19 23:14:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_workers_serviceworkercontainer_h__ */
|