Skip to content

Instantly share code, notes, and snippets.

@ehsan
Created November 19, 2018 17:20
Show Gist options
  • Save ehsan/915cd54556514b48b761a611b070969c to your computer and use it in GitHub Desktop.
Save ehsan/915cd54556514b48b761a611b070969c to your computer and use it in GitHub Desktop.
//RefPtr<StorageAccessGrantPromise::Private> p = new StorageAccessGrantPromise::Private(__func__);
auto holder = MakeRefPtr<MozPromiseHolder<StorageAccessGrantPromise>>();
RefPtr<StorageAccessGrantPromise> p = holder->Ensure(__func__);
auto storePermission = [pwin, parentWindow, origin, trackingOrigin, holder = std::move(holder),
trackingURI, topLevelStoragePrincipal, aReason] {
nsIChannel* channel =
pwin->GetCurrentInnerWindow()->GetExtantDoc()->GetChannel();
pwin->NotifyContentBlockingState(blockReason, channel, false, trackingURI);
NS_ConvertUTF16toUTF8 grantedOrigin(origin);
ReportUnblockingConsole(parentWindow, NS_ConvertUTF8toUTF16(trackingOrigin),
origin, aReason);
if (XRE_IsParentProcess()) {
LOG(("Saving the permission: trackingOrigin=%s, grantedOrigin=%s",
trackingOrigin.get(), grantedOrigin.get()));
SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(topLevelStoragePrincipal,
trackingOrigin,
grantedOrigin,
[holder = std::move(holder)] (bool success) {
holder->Resolve(success, __func__);
});
return;
}
ContentChild* cc = ContentChild::GetSingleton();
MOZ_ASSERT(cc);
LOG(("Asking the parent process to save the permission for us: trackingOrigin=%s, grantedOrigin=%s",
trackingOrigin.get(), grantedOrigin.get()));
// This is not really secure, because here we have the content process sending
// the request of storing a permission.
cc->SendFirstPartyStorageAccessGrantedForOrigin(IPC::Principal(topLevelStoragePrincipal),
trackingOrigin,
grantedOrigin)
->Then(GetCurrentThreadSerialEventTarget(), __func__,
[p] (bool success) {
p->Resolve(success, __func__);
}, [p] (ipc::ResponseRejectReason aReason) {
p->Reject(false, __func__);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment