Backed out changeset 21276955f659 (bug 1720926) for causing hybrid bustages on nsIPrincipal. CLOSED TREE

This commit is contained in:
criss 2021-10-18 16:30:48 +03:00
parent 9e2d25382b
commit 56b294e821
6 changed files with 17 additions and 38 deletions

View File

@ -29,7 +29,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1314912
"history.back": () => win.history.back(),
"history.forward": () => win.history.forward(),
"history.go": () => win.history.go(-1),
"location.href": () => win.location.href = win.location.href + "",
"location.hash": () => win.location.hash = inc++,
"location.host": () => win.location.host = win.location.host + "",
"location.hostname": () => win.location.hostname = win.location.hostname + "",
@ -37,9 +36,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1314912
"location.port": () => win.location.port = win.location.port + "",
"location.protocol": () => win.location.protocol = win.location.protocol + "",
"location.search": () => win.location.search = win.location.search + "",
"location.assign": () => win.location.assign(`${win.location.href}#${inc++}`),
"location.replace": () => win.location.replace(`${win.location.href}#${inc++}`),
"location.reload": () => win.location.reload(),
});
async function test() {

View File

@ -548,13 +548,7 @@ void Location::SetSearch(const nsAString& aSearch,
SetURI(uri, aSubjectPrincipal, aRv);
}
void Location::Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv) {
if (!CallerSubsumes(&aSubjectPrincipal)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
void Location::Reload(bool aForceget, ErrorResult& aRv) {
nsCOMPtr<nsIDocShell> docShell(GetDocShell());
if (!docShell) {
return aRv.Throw(NS_ERROR_FAILURE);
@ -580,21 +574,6 @@ void Location::Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
}
}
RefPtr<BrowsingContext> bc = GetBrowsingContext();
if (!bc || bc->IsDiscarded()) {
return;
}
CallerType callerType = aSubjectPrincipal.IsSystemPrincipal()
? CallerType::System
: CallerType::NonSystem;
nsresult rv = bc->CheckLocationChangeRateLimit(callerType);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
uint32_t reloadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
if (aForceget) {
@ -602,7 +581,7 @@ void Location::Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
}
rv = nsDocShell::Cast(docShell)->Reload(reloadFlags);
nsresult rv = nsDocShell::Cast(docShell)->Reload(reloadFlags);
if (NS_FAILED(rv) && rv != NS_BINDING_ABORTED) {
// NS_BINDING_ABORTED is returned when we attempt to reload a POST result
// and the user says no at the "do you want to reload?" prompt. Don't

View File

@ -43,7 +43,14 @@ class Location final : public nsISupports,
ErrorResult& aError);
void Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
ErrorResult& aError);
ErrorResult& aError) {
if (!CallerSubsumes(&aSubjectPrincipal)) {
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
Reload(aForceget, aError);
}
void GetHref(nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
ErrorResult& aError) {
@ -111,6 +118,8 @@ class Location final : public nsISupports,
nsresult ToString(nsAString& aString) { return GetHref(aString); }
void Reload(bool aForceget, ErrorResult& aRv);
protected:
virtual ~Location();

View File

@ -137,8 +137,7 @@ void nsHistory::GetState(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
aResult.setNull();
}
void nsHistory::Go(int32_t aDelta, nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv) {
void nsHistory::Go(int32_t aDelta, CallerType aCallerType, ErrorResult& aRv) {
LOG(("nsHistory::Go(%d)", aDelta));
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryReferent(mInnerWindow));
if (!win || !win->HasActiveDocument()) {
@ -150,7 +149,7 @@ void nsHistory::Go(int32_t aDelta, nsIPrincipal& aSubjectPrincipal,
// "When the go(delta) method is invoked, if delta is zero, the user agent
// must act as if the location.reload() method was called instead."
RefPtr<Location> location = win->Location();
return location->Reload(false, aSubjectPrincipal, aRv);
return location->Reload(false, aRv);
}
RefPtr<ChildSHistory> session_history = GetSessionHistory();
@ -164,16 +163,12 @@ void nsHistory::Go(int32_t aDelta, nsIPrincipal& aSubjectPrincipal,
? win->GetWindowContext()->HasValidTransientUserGestureActivation()
: false;
CallerType callerType = aSubjectPrincipal.IsSystemPrincipal()
? CallerType::System
: CallerType::NonSystem;
// Ignore the return value from Go(), since returning errors from Go() can
// lead to exceptions and a possible leak of history length
// AsyncGo throws if we hit the location change rate limit.
if (StaticPrefs::dom_window_history_async()) {
session_history->AsyncGo(aDelta, /* aRequireUserInteraction = */ false,
userActivation, callerType, aRv);
userActivation, aCallerType, aRv);
} else {
session_history->Go(aDelta, /* aRequireUserInteraction = */ false,
userActivation, IgnoreErrors());

View File

@ -45,7 +45,7 @@ class nsHistory final : public nsISupports, public nsWrapperCache {
mozilla::ErrorResult& aRv);
void GetState(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
mozilla::ErrorResult& aRv) const;
void Go(int32_t aDelta, nsIPrincipal& aSubjectPrincipal,
void Go(int32_t aDelta, mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aRv);
void Back(mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aRv);
void Forward(mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aRv);

View File

@ -21,7 +21,7 @@ interface History {
attribute ScrollRestoration scrollRestoration;
[Throws]
readonly attribute any state;
[Throws, NeedsSubjectPrincipal]
[Throws, NeedsCallerType]
void go(optional long delta = 0);
[Throws, NeedsCallerType]
void back();