mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Backed out 3 changesets (bug 1432846) for build bustage on Windows at dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp:301. CLOSED TREE
Backed out changeset 5e3b28d03b34 (bug 1432846) Backed out changeset a2ae02b5fe72 (bug 1432846) Backed out changeset a92cc56bbaa4 (bug 1432846)
This commit is contained in:
parent
4afd7c8460
commit
226c2ef8a3
@ -1947,7 +1947,7 @@ void
|
||||
ServiceWorkerPrivate::StoreISupports(nsISupports* aSupports)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate);
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
MOZ_ASSERT(!mSupportsArray.Contains(aSupports));
|
||||
|
||||
mSupportsArray.AppendElement(aSupports);
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "ServiceWorker.h"
|
||||
#include "ServiceWorkerManager.h"
|
||||
#include "ServiceWorkerPrivate.h"
|
||||
#include "ServiceWorkerRegistration.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
@ -134,7 +133,7 @@ namespace {
|
||||
|
||||
void
|
||||
UpdateInternal(nsIPrincipal* aPrincipal,
|
||||
const nsACString& aScope,
|
||||
const nsAString& aScope,
|
||||
ServiceWorkerUpdateFinishCallback* aCallback)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -147,7 +146,7 @@ UpdateInternal(nsIPrincipal* aPrincipal,
|
||||
return;
|
||||
}
|
||||
|
||||
swm->Update(aPrincipal, aScope, aCallback);
|
||||
swm->Update(aPrincipal, NS_ConvertUTF16toUTF8(aScope), aCallback);
|
||||
}
|
||||
|
||||
class MainThreadUpdateCallback final : public ServiceWorkerUpdateFinishCallback
|
||||
@ -282,52 +281,12 @@ public:
|
||||
|
||||
class SWRUpdateRunnable final : public Runnable
|
||||
{
|
||||
class TimerCallback final : public nsITimerCallback
|
||||
{
|
||||
RefPtr<ServiceWorkerPrivate> mPrivate;
|
||||
RefPtr<Runnable> mRunnable;
|
||||
|
||||
public:
|
||||
TimerCallback(ServiceWorkerPrivate* aPrivate,
|
||||
Runnable* aRunnable)
|
||||
: mPrivate(aPrivate)
|
||||
, mRunnable(aRunnable)
|
||||
{
|
||||
MOZ_ASSERT(mPrivate);
|
||||
MOZ_ASSERT(aRunnable);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Notify(nsITimer* aTimer) override
|
||||
{
|
||||
mRunnable->Run();
|
||||
mPrivate->RemoveISupports(aTimer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
private:
|
||||
~TimerCallback()
|
||||
{ }
|
||||
};
|
||||
|
||||
public:
|
||||
explicit SWRUpdateRunnable(PromiseWorkerProxy* aPromiseProxy)
|
||||
SWRUpdateRunnable(PromiseWorkerProxy* aPromiseProxy, const nsAString& aScope)
|
||||
: Runnable("dom::SWRUpdateRunnable")
|
||||
, mPromiseProxy(aPromiseProxy)
|
||||
, mDescriptor(aPromiseProxy->GetWorkerPrivate()->GetServiceWorkerDescriptor())
|
||||
, mDelayed(false)
|
||||
{
|
||||
MOZ_ASSERT(mPromiseProxy);
|
||||
|
||||
// This runnable is used for update calls originating from a worker thread,
|
||||
// which may be delayed in some cases.
|
||||
MOZ_ASSERT(mPromiseProxy->GetWorkerPrivate()->IsServiceWorker());
|
||||
MOZ_ASSERT(mPromiseProxy->GetWorkerPrivate());
|
||||
mPromiseProxy->GetWorkerPrivate()->AssertIsOnWorkerThread();
|
||||
}
|
||||
, mScope(aScope)
|
||||
{}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
@ -348,65 +307,20 @@ public:
|
||||
}
|
||||
MOZ_ASSERT(principal);
|
||||
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
if (NS_WARN_IF(!swm)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This will delay update jobs originating from a service worker thread.
|
||||
// We don't currently handle ServiceWorkerRegistration.update() from other
|
||||
// worker types. Also, we assume this registration matches self.registration
|
||||
// on the service worker global. This is ok for now because service worker globals
|
||||
// are the only worker contexts where we expose ServiceWorkerRegistration.
|
||||
RefPtr<ServiceWorkerRegistrationInfo> registration =
|
||||
swm->GetRegistration(principal, mDescriptor.Scope());
|
||||
if (NS_WARN_IF(!registration)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<ServiceWorkerInfo> worker = registration->GetByDescriptor(mDescriptor);
|
||||
uint32_t delay = registration->GetUpdateDelay();
|
||||
|
||||
// if we have a timer object, it means we've already been delayed once.
|
||||
if (delay && !mDelayed) {
|
||||
nsCOMPtr<nsITimerCallback> cb = new TimerCallback(worker->WorkerPrivate(), this);
|
||||
Result<nsCOMPtr<nsITimer>, nsresult> result =
|
||||
NS_NewTimerWithCallback(cb, delay, nsITimer::TYPE_ONE_SHOT,
|
||||
SystemGroup::EventTargetFor(TaskCategory::Other));
|
||||
|
||||
nsCOMPtr<nsITimer> timer = result.unwrapOr(nullptr);
|
||||
if (NS_WARN_IF(!timer)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDelayed = true;
|
||||
// We're storing the timer object on the calling service worker's private.
|
||||
// ServiceWorkerPrivate will drop the reference if the worker terminates,
|
||||
// which will cancel the timer.
|
||||
worker->WorkerPrivate()->StoreISupports(timer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<WorkerThreadUpdateCallback> cb =
|
||||
new WorkerThreadUpdateCallback(mPromiseProxy);
|
||||
UpdateInternal(principal, mDescriptor.Scope(), cb);
|
||||
UpdateInternal(principal, mScope, cb);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
~SWRUpdateRunnable()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
{}
|
||||
|
||||
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
||||
const ServiceWorkerDescriptor mDescriptor;
|
||||
bool mDelayed;
|
||||
const nsString mScope;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(SWRUpdateRunnable::TimerCallback, nsITimerCallback)
|
||||
|
||||
class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback
|
||||
{
|
||||
PromiseWindowProxy mPromise;
|
||||
@ -619,7 +533,7 @@ ServiceWorkerRegistrationMainThread::Update(ErrorResult& aRv)
|
||||
|
||||
RefPtr<MainThreadUpdateCallback> cb =
|
||||
new MainThreadUpdateCallback(mOuter->GetOwner(), promise);
|
||||
UpdateInternal(doc->NodePrincipal(), NS_ConvertUTF16toUTF8(mScope), cb);
|
||||
UpdateInternal(doc->NodePrincipal(), mScope, cb);
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
@ -934,7 +848,7 @@ ServiceWorkerRegistrationWorkerThread::Update(ErrorResult& aRv)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<SWRUpdateRunnable> r = new SWRUpdateRunnable(proxy);
|
||||
RefPtr<SWRUpdateRunnable> r = new SWRUpdateRunnable(proxy, mScope);
|
||||
MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget()));
|
||||
|
||||
return promise.forget();
|
||||
|
@ -87,7 +87,6 @@ ServiceWorkerRegistrationInfo::ServiceWorkerRegistrationInfo(
|
||||
: mPrincipal(aPrincipal)
|
||||
, mDescriptor(aPrincipal, aScope, aUpdateViaCache)
|
||||
, mControlledClientsCounter(0)
|
||||
, mDelayMultiplier(0)
|
||||
, mUpdateState(NoUpdate)
|
||||
, mCreationTime(PR_Now())
|
||||
, mCreationTimeStamp(TimeStamp::Now())
|
||||
@ -710,25 +709,5 @@ ServiceWorkerRegistrationInfo::Descriptor() const
|
||||
return mDescriptor;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ServiceWorkerRegistrationInfo::GetUpdateDelay()
|
||||
{
|
||||
uint32_t delay = Preferences::GetInt("dom.serviceWorkers.update_delay",
|
||||
1000);
|
||||
// This can potentially happen if you spam registration->Update(). We don't
|
||||
// want to wrap to a lower value.
|
||||
if (mDelayMultiplier >= INT_MAX / (delay ? delay : 1)) {
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
delay *= mDelayMultiplier;
|
||||
|
||||
if (!mControlledClientsCounter && mDelayMultiplier < (INT_MAX / 30)) {
|
||||
mDelayMultiplier = (mDelayMultiplier ? mDelayMultiplier : 1) * 30;
|
||||
}
|
||||
|
||||
return delay;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -23,7 +23,6 @@ class ServiceWorkerRegistrationInfo final
|
||||
nsTArray<nsCOMPtr<nsIServiceWorkerRegistrationInfoListener>> mListeners;
|
||||
|
||||
uint32_t mControlledClientsCounter;
|
||||
uint32_t mDelayMultiplier;
|
||||
|
||||
enum
|
||||
{
|
||||
@ -95,7 +94,6 @@ public:
|
||||
StartControllingClient()
|
||||
{
|
||||
++mControlledClientsCounter;
|
||||
mDelayMultiplier = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -213,9 +211,6 @@ public:
|
||||
const ServiceWorkerRegistrationDescriptor&
|
||||
Descriptor() const;
|
||||
|
||||
uint32_t
|
||||
GetUpdateDelay();
|
||||
|
||||
private:
|
||||
// Roughly equivalent to [[Update Registration State algorithm]]. Make sure
|
||||
// this is called *before* updating SW instances' state, otherwise they
|
||||
|
@ -232,7 +232,6 @@ support-files =
|
||||
bug1290951_worker_imported.sjs
|
||||
sw_storage_not_allow.js
|
||||
update_worker.sjs
|
||||
self_update_worker.sjs
|
||||
|
||||
[test_bug1151916.html]
|
||||
[test_bug1240436.html]
|
||||
@ -349,4 +348,3 @@ tags = openwindow
|
||||
[test_bad_script_cache.html]
|
||||
[test_file_upload.html]
|
||||
support-files = script_file_upload.js sw_file_upload.js server_file_upload.sjs
|
||||
[test_self_update_worker.html]
|
||||
|
@ -1,43 +0,0 @@
|
||||
/* 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/. */
|
||||
"use strict";
|
||||
|
||||
const WORKER_BODY = `
|
||||
onactivate = function(event) {
|
||||
let promise = clients.matchAll({includeUncontrolled: true}).then(function(clients) {
|
||||
for (i = 0; i < clients.length; i++) {
|
||||
clients[i].postMessage({version: version});
|
||||
}
|
||||
}).then(function() {
|
||||
return self.registration.update();
|
||||
});
|
||||
event.waitUntil(promise);
|
||||
};
|
||||
`;
|
||||
|
||||
function handleRequest(request, response) {
|
||||
if (request.queryString == 'clearcounter') {
|
||||
setState('count', "1");
|
||||
response.write("ok");
|
||||
return;
|
||||
}
|
||||
|
||||
let count = getState("count");
|
||||
if (count === "") {
|
||||
count = 1;
|
||||
} else {
|
||||
count = parseInt(count);
|
||||
}
|
||||
|
||||
let worker = "var version = " + count + ";\n";
|
||||
worker = worker + WORKER_BODY;
|
||||
|
||||
// This header is necessary for making this script able to be loaded.
|
||||
response.setHeader("Content-Type", "application/javascript");
|
||||
|
||||
// If this is the first request, return the first source.
|
||||
response.write(worker);
|
||||
setState("count", "" + (count + 1));
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Test that a self updating service worker can't keep running forever when the
|
||||
script changes.
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1432846</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script src="/tests/SimpleTest/SpawnTask.js"></script>
|
||||
<script src="error_reporting_helpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
</head>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1432846">Mozilla Bug 1432846</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<script src="utils.js"></script>
|
||||
<script class="testbody" type="text/javascript">
|
||||
add_task(function setupPrefs() {
|
||||
return SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true],
|
||||
]});
|
||||
});
|
||||
|
||||
function activateDummyWorker() {
|
||||
return navigator.serviceWorker.register("empty.js",
|
||||
{ scope: "./empty?random=" + Date.now() })
|
||||
.then(function(registration) {
|
||||
var worker = registration.installing;
|
||||
return waitForState(worker, 'activated', registration).then(function() {
|
||||
ok(true, "got dummy!");
|
||||
return registration.unregister();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_update() {
|
||||
navigator.serviceWorker.onmessage = function(event) {
|
||||
ok (event.data.version < 3, "Service worker updated too many times." + event.data.version);
|
||||
}
|
||||
|
||||
await SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.idle_timeout", 0],
|
||||
["dom.serviceWorkers.update_delay", 30000],
|
||||
["dom.serviceWorkers.idle_extended_timeout", 299999]]});
|
||||
|
||||
// clear version counter
|
||||
await fetch("self_update_worker.sjs?clearcounter");
|
||||
|
||||
var worker;
|
||||
let registration = await navigator.serviceWorker.register(
|
||||
"self_update_worker.sjs",
|
||||
{ scope: "./test_self_update_worker.html?random=" + Date.now()})
|
||||
.then(function(registration) {
|
||||
worker = registration.installing;
|
||||
return waitForState(worker, 'activated', registration);
|
||||
});
|
||||
|
||||
// We need to wait a reasonable time to give the self updating worker a chance
|
||||
// to change to a newer version. Register and activate an empty worker 5 times.
|
||||
for (i = 0; i < 5; i++) {
|
||||
await activateDummyWorker();
|
||||
}
|
||||
|
||||
|
||||
await registration.unregister();
|
||||
await SpecialPowers.popPrefEnv();
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -174,10 +174,6 @@ pref("dom.serviceWorkers.idle_timeout", 30000);
|
||||
// The amount of time (milliseconds) service workers can be kept running using waitUntil promises.
|
||||
pref("dom.serviceWorkers.idle_extended_timeout", 300000);
|
||||
|
||||
// The amount of time (milliseconds) an update request is delayed when triggered
|
||||
// by a service worker that doesn't control any clients.
|
||||
pref("dom.serviceWorkers.update_delay", 1000);
|
||||
|
||||
// Enable test for 24 hours update, service workers will always treat last update check time is over 24 hours
|
||||
pref("dom.serviceWorkers.testUpdateOverOneDay", false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user