Skip to content

Commit

Permalink
Bug 1181329 - Make DataStore available to privileged homescreen app, …
Browse files Browse the repository at this point in the history
…r=fabrice
  • Loading branch information
bakulf committed Jul 7, 2015
1 parent 9c31c02 commit 06d9ba0
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions dom/datastore/DataStoreService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,41 @@ DataStoreService::CheckPermission(nsIPrincipal* aPrincipal)
return false;
}

// Only support DataStore API for certified apps for now.
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
// Certified apps are always allowed.
if (status == nsIPrincipal::APP_STATUS_CERTIFIED) {
return true;
}

if (status != nsIPrincipal::APP_STATUS_PRIVILEGED) {
return false;
}

// Privileged apps are allowed if they are the homescreen.
nsAdoptingString homescreen =
Preferences::GetString("dom.mozApps.homescreenURL");
if (!homescreen) {
return false;
}

uint32_t appId;
nsresult rv = aPrincipal->GetAppId(&appId);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}

nsCOMPtr<nsIAppsService> appsService =
do_GetService("@mozilla.org/AppsService;1");
if (NS_WARN_IF(!appsService)) {
return false;
}

nsAutoString manifestURL;
rv = appsService->GetManifestURLByLocalId(appId, manifestURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}

return manifestURL.Equals(homescreen);
}

NS_IMETHODIMP
Expand Down

0 comments on commit 06d9ba0

Please sign in to comment.