Skip to content

Commit

Permalink
Bug 1645234 - Add more warnings to document.requestStorageAccess(). r…
Browse files Browse the repository at this point in the history
…=annevk,englehardt,baku

The only common failure case that's not being warned about now is when the user
rejected the prompt, which I think is expected behavior.

Differential Revision: https://phabricator.services.mozilla.com/D79597
  • Loading branch information
Johann Hofmann committed Jul 4, 2020
1 parent a569b24 commit a88f889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15858,6 +15858,10 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(

// Step 2. If the document has a null origin, reject.
if (NodePrincipal()->GetIsNullPrincipal()) {
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("requestStorageAccess"),
this, nsContentUtils::eDOM_PROPERTIES,
"RequestStorageAccessNullPrincipal");
promise->MaybeRejectWithUndefined();
return promise.forget();
}
Expand Down Expand Up @@ -15907,19 +15911,29 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
// Step 6. If the sub frame doesn't have the token
// "allow-storage-access-by-user-activation", reject.
if (StorageAccessSandboxed()) {
nsContentUtils::ReportToConsole(
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("requestStorageAccess"),
this, nsContentUtils::eDOM_PROPERTIES, "RequestStorageAccessSandboxed");
promise->MaybeRejectWithUndefined();
return promise.forget();
}

// Step 7. If the sub frame's parent frame is not the top frame, reject.
RefPtr<BrowsingContext> parentBC = bc->GetParent();
if (parentBC && !parentBC->IsTopContent()) {
nsContentUtils::ReportToConsole(
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("requestStorageAccess"),
this, nsContentUtils::eDOM_PROPERTIES, "RequestStorageAccessNested");
promise->MaybeRejectWithUndefined();
return promise.forget();
}

// Step 8. If the browser is not processing a user gesture, reject.
if (!UserActivation::IsHandlingUserInput()) {
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("requestStorageAccess"),
this, nsContentUtils::eDOM_PROPERTIES,
"RequestStorageAccessUserGesture");
promise->MaybeRejectWithUndefined();
return promise.forget();
}
Expand Down
9 changes: 9 additions & 0 deletions dom/locales/en-US/chrome/dom/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,12 @@ UnknownProtocolNavigationPrevented=Prevented navigation to “%1$S” due to an
PostMessageSharedMemoryObjectToCrossOriginWarning=Cannot post message containing a shared memory object to a cross-origin window.
# LOCALIZATION NOTE: %S is the URL of the resource in question
UnusedLinkPreloadPending=The resource at “%S” preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.

# LOCALIZATION NOTE: Do not translate document.requestStorageAccess(), iframe, allow-same-origin and sandbox (though you may translate "sandboxed").
RequestStorageAccessNullPrincipal=document.requestStorageAccess() may not be called on a document with an opaque origin, such as a sandboxed iframe without allow-same-origin in its sandbox attribute.
# LOCALIZATION NOTE: Do not translate document.requestStorageAccess(), iframe, allow-storage-access-by-user-activation and sandbox (though you may translate "sandboxed").
RequestStorageAccessSandboxed=document.requestStorageAccess() may not be called in a sandboxed iframe without allow-storage-access-by-user-activation in its sandbox attribute.
# LOCALIZATION NOTE: Do not translate document.requestStorageAccess() and iframe.
RequestStorageAccessNested=document.requestStorageAccess() may not be called in a nested iframe.
# LOCALIZATION NOTE: Do not translate document.requestStorageAccess(). In some locales it may be preferable to not translate "event handler", either.
RequestStorageAccessUserGesture=document.requestStorageAccess() may only be requested from inside a short running user-generated event handler.

0 comments on commit a88f889

Please sign in to comment.