dom/workers/ServiceWorkerRegisterJob.cpp
author Masayuki Nakano <masayuki@d-toybox.com>
Fri, 19 May 2017 17:49:41 +0900
changeset 407399 b75c111837a802ceb953dba50a3c5a193d53ca22
parent 389445 f2d6e4198d851a595746ca1deb222b8f441edcf6
child 424885 9865180c7e5972d6bf0f490121a2426046624575
permissions -rw-r--r--
Bug 1339543 part 4 Change nsIWidget::ExecuteNativeKeyBinding() to nsIWidget::GetEditCommands() which just retrieves edit commands for the type r=smaug Now, nsIWidget::ExecuteNativeKeyBinding() isn't used by anybody for executing edit commands. Instead, they need array of edit commands for the key combination. So, the method should be renamed to GetEditCommands() and just return edit commands as an array. MozReview-Commit-ID: 4G0B1lJ8Lbe

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=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/. */

#include "ServiceWorkerRegisterJob.h"

#include "Workers.h"

namespace mozilla {
namespace dom {
namespace workers {

ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(nsIPrincipal* aPrincipal,
                                                   const nsACString& aScope,
                                                   const nsACString& aScriptSpec,
                                                   nsILoadGroup* aLoadGroup,
                                                   nsLoadFlags aLoadFlags)
  : ServiceWorkerUpdateJob(Type::Register, aPrincipal, aScope, aScriptSpec,
                           aLoadGroup, aLoadFlags)
{
}

void
ServiceWorkerRegisterJob::AsyncExecute()
{
  AssertIsOnMainThread();

  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
  if (Canceled() || !swm) {
    FailUpdateJob(NS_ERROR_DOM_ABORT_ERR);
    return;
  }

  RefPtr<ServiceWorkerRegistrationInfo> registration =
    swm->GetRegistration(mPrincipal, mScope);

  if (registration) {
    bool isSameLoadFlags = registration->GetLoadFlags() == GetLoadFlags();
    registration->SetLoadFlags(GetLoadFlags());

    // 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
    // results in the registration being gone on restart.
    if (registration->mPendingUninstall) {
      swm->StoreRegistration(mPrincipal, registration);
    }
    registration->mPendingUninstall = false;
    RefPtr<ServiceWorkerInfo> newest = registration->Newest();
    if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && isSameLoadFlags) {
      SetRegistration(registration);
      Finish(NS_OK);
      return;
    }
  } else {
    registration = swm->CreateNewRegistration(mScope, mPrincipal,
                                              GetLoadFlags());
    if (!registration) {
      FailUpdateJob(NS_ERROR_DOM_ABORT_ERR);
      return;
    }
  }

  SetRegistration(registration);
  Update();
}

ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob()
{
}

} // namespace workers
} // namespace dom
} // namespace mozilla