Commit ab796689 authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1354635 - Send permissions to the content process when debugging service workers, r=catalinb

MozReview-Commit-ID: 8cUh5znQcFN
parent aee9d1bf
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -355,6 +355,18 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
        "resource://devtools/server/service-worker-child.js", true);
      _serviceWorkerProcessScriptLoaded = true;
    }

    // XXX: Send the permissions down to the content process before starting
    // the service worker within the content process. As we don't know what
    // content process we're starting the service worker in (as we're using a
    // broadcast channel to talk to it), we just broadcast the permissions to
    // everyone as well.
    //
    // This call should be replaced with a proper implementation when
    // ServiceWorker debugging is improved to support multiple content processes
    // correctly.
    Services.perms.broadcastPermissionsForPrincipalToAllContentProcesses(this._registration.principal);

    Services.ppmm.broadcastAsyncMessage("serviceWorkerRegistration:start", {
      scope: this._registration.scope
    });
+13 −0
Original line number Diff line number Diff line
@@ -3089,3 +3089,16 @@ nsPermissionManager::GetAllKeysForPrincipal(nsIPrincipal* aPrincipal)
             "Every principal should have at least one key.");
  return keys;
}

NS_IMETHODIMP
nsPermissionManager::BroadcastPermissionsForPrincipalToAllContentProcesses(nsIPrincipal* aPrincipal)
{
  nsTArray<ContentParent*> cps;
  ContentParent::GetAll(cps);
  for (ContentParent* cp : cps) {
    nsresult rv = cp->TransmitPermissionsForPrincipal(aPrincipal);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}
+11 −0
Original line number Diff line number Diff line
@@ -315,6 +315,17 @@ interface nsIPermissionManager : nsISupports
   * @param perms  An array with the permissions which match the given key.
   */
  void setPermissionsWithKey(in ACString permissionKey, in IPCPermissionArrayRef perms);

  /**
   * Broadcasts permissions for the given principal to all content processes.
   *
   * DO NOT USE THIS METHOD if you can avoid it. It was added in bug XXX to
   * handle the current temporary implementation of ServiceWorker debugging. It
   * will be removed when service worker debugging is fixed.
   *
   * @param aPrincipal The principal to broadcast permissions for.
   */
  void broadcastPermissionsForPrincipalToAllContentProcesses(in nsIPrincipal aPrincipal);
};

%{ C++