Bug 1353636 - Part 2: Expose ServieworkerRegistration.updateViaCache. r=bkelly
--- a/dom/interfaces/base/nsIServiceWorkerManager.idl
+++ b/dom/interfaces/base/nsIServiceWorkerManager.idl
@@ -69,16 +69,17 @@ interface nsIServiceWorkerRegistrationIn
const unsigned short UPDATE_VIA_CACHE_IMPORTS = 0;
const unsigned short UPDATE_VIA_CACHE_ALL = 1;
const unsigned short UPDATE_VIA_CACHE_NONE = 2;
readonly attribute nsIPrincipal principal;
readonly attribute DOMString scope;
readonly attribute DOMString scriptSpec;
+ readonly attribute unsigned short updateViaCache;
readonly attribute PRTime lastUpdateTime;
readonly attribute nsIServiceWorkerInfo installingWorker;
readonly attribute nsIServiceWorkerInfo waitingWorker;
readonly attribute nsIServiceWorkerInfo activeWorker;
// Allows to get the related nsIServiceWorkerInfo for a given
--- a/dom/webidl/ServiceWorkerRegistration.webidl
+++ b/dom/webidl/ServiceWorkerRegistration.webidl
@@ -12,16 +12,17 @@
[Func="mozilla::dom::ServiceWorkerRegistration::Visible",
Exposed=(Window,Worker)]
interface ServiceWorkerRegistration : EventTarget {
[Unforgeable] readonly attribute ServiceWorker? installing;
[Unforgeable] readonly attribute ServiceWorker? waiting;
[Unforgeable] readonly attribute ServiceWorker? active;
readonly attribute USVString scope;
+ readonly attribute ServiceWorkerUpdateViaCache updateViaCache;
[Throws, NewObject]
Promise<void> update();
[Throws, NewObject]
Promise<boolean> unregister();
// event
--- a/dom/workers/ServiceWorkerRegistration.cpp
+++ b/dom/workers/ServiceWorkerRegistration.cpp
@@ -134,16 +134,43 @@ public:
RegistrationRemoved() override;
void
GetScope(nsAString& aScope) const override
{
aScope = mScope;
}
+ ServiceWorkerUpdateViaCache
+ UpdateViaCache() const override
+ {
+ RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+ MOZ_ASSERT(swm);
+
+ nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
+ MOZ_ASSERT(window);
+
+ nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
+ MOZ_ASSERT(doc);
+
+ nsCOMPtr<nsIServiceWorkerRegistrationInfo> registration;
+ nsresult rv = swm->GetRegistrationByPrincipal(doc->NodePrincipal(), mScope,
+ getter_AddRefs(registration));
+ MOZ_ASSERT(NS_SUCCEEDED(rv) && registration);
+
+ uint16_t updateViaCache;
+ rv = registration->GetUpdateViaCache(&updateViaCache);
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
+
+ // Silence possible compiler warnings.
+ Unused << rv;
+
+ return static_cast<ServiceWorkerUpdateViaCache>(updateViaCache);
+ }
+
private:
~ServiceWorkerRegistrationMainThread();
already_AddRefed<ServiceWorker>
GetWorkerReference(WhichServiceWorker aWhichOne);
void
StartListeningForEvents();
@@ -911,16 +938,23 @@ public:
GetActive() override;
void
GetScope(nsAString& aScope) const override
{
aScope = mScope;
}
+ ServiceWorkerUpdateViaCache
+ UpdateViaCache() const override
+ {
+ // FIXME(hopang): Will be implemented after Bug 1113522.
+ return ServiceWorkerUpdateViaCache::Imports;
+ }
+
bool
Notify(Status aStatus) override;
already_AddRefed<PushManager>
GetPushManager(JSContext* aCx, ErrorResult& aRv) override;
private:
~ServiceWorkerRegistrationWorkerThread();
--- a/dom/workers/ServiceWorkerRegistration.h
+++ b/dom/workers/ServiceWorkerRegistration.h
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_ServiceWorkerRegistration_h
#define mozilla_dom_ServiceWorkerRegistration_h
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/ServiceWorkerBinding.h"
#include "mozilla/dom/ServiceWorkerCommon.h"
+#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
// Support for Notification API extension.
#include "mozilla/dom/NotificationBinding.h"
class nsPIDOMWindowInner;
@@ -85,16 +86,19 @@ public:
GetWaiting() = 0;
virtual already_AddRefed<workers::ServiceWorker>
GetActive() = 0;
virtual void
GetScope(nsAString& aScope) const = 0;
+ virtual ServiceWorkerUpdateViaCache
+ UpdateViaCache() const = 0;
+
virtual already_AddRefed<Promise>
Update(ErrorResult& aRv) = 0;
virtual already_AddRefed<Promise>
Unregister(ErrorResult& aRv) = 0;
virtual already_AddRefed<PushManager>
GetPushManager(JSContext* aCx, ErrorResult& aRv) = 0;
--- a/dom/workers/ServiceWorkerRegistrationInfo.cpp
+++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp
@@ -124,16 +124,23 @@ ServiceWorkerRegistrationInfo::GetScript
RefPtr<ServiceWorkerInfo> newest = Newest();
if (newest) {
CopyUTF8toUTF16(newest->ScriptSpec(), aScriptSpec);
}
return NS_OK;
}
NS_IMETHODIMP
+ServiceWorkerRegistrationInfo::GetUpdateViaCache(uint16_t* aUpdateViaCache)
+{
+ *aUpdateViaCache = static_cast<uint16_t>(GetUpdateViaCache());
+ return NS_OK;
+}
+
+NS_IMETHODIMP
ServiceWorkerRegistrationInfo::GetLastUpdateTime(PRTime* _retval)
{
AssertIsOnMainThread();
MOZ_ASSERT(_retval);
*_retval = mLastUpdateTime;
return NS_OK;
}