Bug 1290944 - Part 2.3: Set the load flags when registering a service worker. r=bkelly

--HG--
extra : rebase_source : e9aa5dcd79d696dd097fbe88775ba4a5be74d462
extra : histedit_source : 289384bf6f96ddd998828e1c365b3f7256e4f7f8
This commit is contained in:
Ho-Pang Hsu 2017-01-04 17:08:51 +08:00
Родитель 7b90ecb108
Коммит 011108b52a
7 изменённых файлов: 35 добавлений и 9 удалений

Просмотреть файл

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
#include "nsIRequest.idl"
interface mozIDOMWindow;
interface nsPIDOMWindowInner;
@ -98,7 +99,10 @@ interface nsIServiceWorkerManager : nsISupports
*
* Returns a Promise.
*/
nsISupports register(in mozIDOMWindow aWindow, in nsIURI aScope, in nsIURI aScriptURI);
nsISupports register(in mozIDOMWindow aWindow,
in nsIURI aScope,
in nsIURI aScriptURI,
in nsLoadFlags aLoadFlags);
/**
* Unregister an existing ServiceWorker registration for `aScope`.

Просмотреть файл

@ -207,9 +207,14 @@ ServiceWorkerContainer::Register(const nsAString& aScriptURL,
}
}
bool useCache = aOptions.mUseCache.WasPassed() && aOptions.mUseCache.Value();
nsLoadFlags loadFlags = useCache ? nsIRequest::LOAD_NORMAL
: nsIRequest::VALIDATE_ALWAYS;
// The spec says that the "client" passed to Register() must be the global
// where the ServiceWorkerContainer was retrieved from.
aRv = swm->Register(GetOwner(), scopeURI, scriptURI, getter_AddRefs(promise));
aRv = swm->Register(GetOwner(), scopeURI, scriptURI, loadFlags,
getter_AddRefs(promise));
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

Просмотреть файл

@ -494,6 +494,7 @@ NS_IMETHODIMP
ServiceWorkerManager::Register(mozIDOMWindow* aWindow,
nsIURI* aScopeURI,
nsIURI* aScriptURI,
nsLoadFlags aLoadFlags,
nsISupports** aPromise)
{
AssertIsOnMainThread();
@ -620,7 +621,7 @@ ServiceWorkerManager::Register(mozIDOMWindow* aWindow,
RefPtr<ServiceWorkerRegisterJob> job =
new ServiceWorkerRegisterJob(documentPrincipal, cleanedScope, spec,
loadGroup);
loadGroup, aLoadFlags);
job->AppendResultCallback(cb);
queue->ScheduleJob(job);

Просмотреть файл

@ -15,9 +15,11 @@ namespace workers {
ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(nsIPrincipal* aPrincipal,
const nsACString& aScope,
const nsACString& aScriptSpec,
nsILoadGroup* aLoadGroup)
nsILoadGroup* aLoadGroup,
nsLoadFlags aLoadFlags)
: ServiceWorkerUpdateJob(Type::Register, aPrincipal, aScope, aScriptSpec,
aLoadGroup)
, mLoadFlags(aLoadFlags)
{
}
@ -36,6 +38,9 @@ ServiceWorkerRegisterJob::AsyncExecute()
swm->GetRegistration(mPrincipal, mScope);
if (registration) {
bool isSameLoadFlags = registration->GetLoadFlags() == mLoadFlags;
registration->SetLoadFlags(mLoadFlags);
// If we are resurrecting an uninstalling registration, then persist
// it to disk again. We preemptively removed it earlier during
// unregister so that closing the window by shutting down the browser
@ -45,14 +50,13 @@ ServiceWorkerRegisterJob::AsyncExecute()
}
registration->mPendingUninstall = false;
RefPtr<ServiceWorkerInfo> newest = registration->Newest();
if (newest && mScriptSpec.Equals(newest->ScriptSpec())) {
if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && isSameLoadFlags) {
SetRegistration(registration);
Finish(NS_OK);
return;
}
} else {
registration = swm->CreateNewRegistration(mScope, mPrincipal,
nsIRequest::LOAD_NORMAL);
registration = swm->CreateNewRegistration(mScope, mPrincipal, mLoadFlags);
}
SetRegistration(registration);

Просмотреть файл

@ -18,11 +18,14 @@ namespace workers {
// spec algorithms.
class ServiceWorkerRegisterJob final : public ServiceWorkerUpdateJob
{
const nsLoadFlags mLoadFlags;
public:
ServiceWorkerRegisterJob(nsIPrincipal* aPrincipal,
const nsACString& aScope,
const nsACString& aScriptSpec,
nsILoadGroup* aLoadGroup);
nsILoadGroup* aLoadGroup,
nsLoadFlags aLoadFlags);
private:
// Implement the Register algorithm steps and then call the parent class

Просмотреть файл

@ -556,4 +556,10 @@ ServiceWorkerRegistrationInfo::GetLoadFlags() const
return mLoadFlags;
}
void
ServiceWorkerRegistrationInfo::SetLoadFlags(nsLoadFlags aLoadFlags)
{
mLoadFlags = aLoadFlags;
}
END_WORKERS_NAMESPACE

Просмотреть файл

@ -27,7 +27,7 @@ class ServiceWorkerRegistrationInfo final
uint64_t mLastUpdateCheckTime;
const nsLoadFlags mLoadFlags;
nsLoadFlags mLoadFlags;
RefPtr<ServiceWorkerInfo> mEvaluatingWorker;
RefPtr<ServiceWorkerInfo> mActiveWorker;
@ -179,6 +179,9 @@ public:
nsLoadFlags
GetLoadFlags() const;
void
SetLoadFlags(nsLoadFlags aLoadFlags);
private:
enum TransitionType {
TransitionToNextState = 0,