mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1112469 - Part 2: Update the service workers in the parent and all child processes every day; r=nsm
This commit is contained in:
parent
f8f4fef68c
commit
0dc6170284
@ -33,7 +33,7 @@ interface nsIServiceWorkerInfo : nsISupports
|
||||
readonly attribute DOMString waitingCacheName;
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(3cd3acce-8c80-4fcc-9265-067ebe8cab92)]
|
||||
[scriptable, builtinclass, uuid(c05b3b45-7f39-458c-8097-afafc7d69b01)]
|
||||
interface nsIServiceWorkerManager : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -124,6 +124,8 @@ interface nsIServiceWorkerManager : nsISupports
|
||||
|
||||
void sendPushEvent(in ACString scope, in DOMString data);
|
||||
void sendPushSubscriptionChangedEvent(in ACString scope);
|
||||
|
||||
void updateAllRegistrations();
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
@ -78,6 +78,7 @@
|
||||
#include "nsIMutable.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIServiceWorkerManager.h"
|
||||
#include "nsScreenManagerProxy.h"
|
||||
#include "nsMemoryInfoDumper.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
@ -1239,6 +1240,16 @@ ContentChild::RecvBidiKeyboardNotify(const bool& aIsLangRTL)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvUpdateServiceWorkerRegistrations()
|
||||
{
|
||||
nsCOMPtr<nsIServiceWorkerManager> swm = mozilla::services::GetServiceWorkerManager();
|
||||
if (swm) {
|
||||
swm->UpdateAllRegistrations();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static CancelableTask* sFirstIdleTask;
|
||||
|
||||
static void FirstIdle(void)
|
||||
|
@ -301,6 +301,8 @@ public:
|
||||
|
||||
virtual bool RecvBidiKeyboardNotify(const bool& isLangRTL) override;
|
||||
|
||||
virtual bool RecvUpdateServiceWorkerRegistrations() override;
|
||||
|
||||
virtual bool RecvNotifyVisited(const URIParams& aURI) override;
|
||||
// auto remove when alertfinished is received.
|
||||
nsresult AddRemoteAlertObserver(const nsString& aData, nsIObserver* aObserver);
|
||||
|
@ -465,6 +465,8 @@ child:
|
||||
*/
|
||||
async BidiKeyboardNotify(bool isLangRTL);
|
||||
|
||||
async UpdateServiceWorkerRegistrations();
|
||||
|
||||
async DataStoreNotify(uint32_t aAppId, nsString aName,
|
||||
nsString aManifestURL);
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
@ -3110,6 +3111,28 @@ ServiceWorkerManager::GetAllRegistrations(nsIArray** aResult)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
UpdateEachRegistration(const nsACString& aKey,
|
||||
ServiceWorkerRegistrationInfo* aInfo,
|
||||
void* aUserArg) {
|
||||
auto This = static_cast<ServiceWorkerManager*>(aUserArg);
|
||||
MOZ_ASSERT(!aInfo->mScope.IsEmpty());
|
||||
nsresult res = This->Update(NS_ConvertUTF8toUTF16(aInfo->mScope));
|
||||
unused << NS_WARN_IF(NS_FAILED(res));
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServiceWorkerManager::UpdateAllRegistrations()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
mServiceWorkerRegistrationInfos.EnumerateRead(UpdateEachRegistration, this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerInfo::AppendWorker(ServiceWorker* aWorker)
|
||||
{
|
||||
|
@ -6,6 +6,10 @@
|
||||
|
||||
#include "ServiceWorkerPeriodicUpdater.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "nsIServiceWorkerManager.h"
|
||||
|
||||
#define OBSERVER_TOPIC_IDLE_DAILY "idle-daily"
|
||||
|
||||
@ -45,7 +49,19 @@ ServiceWorkerPeriodicUpdater::Observe(nsISupports* aSubject,
|
||||
const char16_t* aData)
|
||||
{
|
||||
if (strcmp(aTopic, OBSERVER_TOPIC_IDLE_DAILY) == 0) {
|
||||
// TODO: Update the service workers NOW!!!!!
|
||||
// First, update all registrations in the parent process.
|
||||
nsCOMPtr<nsIServiceWorkerManager> swm =
|
||||
mozilla::services::GetServiceWorkerManager();
|
||||
if (swm) {
|
||||
swm->UpdateAllRegistrations();
|
||||
}
|
||||
|
||||
// Now, tell all child processes to update their registrations as well.
|
||||
nsTArray<ContentParent*> children;
|
||||
ContentParent::GetAll(children);
|
||||
for (uint32_t i = 0; i < children.Length(); i++) {
|
||||
unused << children[i]->SendUpdateServiceWorkerRegistrations();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -15,6 +15,14 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
namespace workers {
|
||||
|
||||
/**
|
||||
* This XPCOM component is main-process only, which means that it will never
|
||||
* get instantiated in child processes. When we receive the idle-daily
|
||||
* notification in this component, we iterate over all PContent children, and
|
||||
* send each one a message that will trigger a call to
|
||||
* nsIServiceWorkerManager::UpdateAllRegistrations() in all child processes.
|
||||
*/
|
||||
|
||||
class ServiceWorkerPeriodicUpdater final : public nsIObserver
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user