Skip to content

Commit

Permalink
Backed out changeset 2e69a9d98234 (bug 1763672) for causing bustages …
Browse files Browse the repository at this point in the history
…on nsDocShell.cpp. CLOSED TREE
  • Loading branch information
crisscozmuta committed Apr 13, 2022
1 parent 9d3a871 commit a1b5f9b
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 355 deletions.
11 changes: 0 additions & 11 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3076,10 +3076,6 @@ mozilla::dom::TouchEventsOverride BrowsingContext::TouchEventsOverride() const {
return mozilla::dom::TouchEventsOverride::None;
}

bool BrowsingContext::TargetTopLevelLinkClicksToBlank() const {
return Top()->GetTargetTopLevelLinkClicksToBlankInternal();
}

// We map `watchedByDevTools` WebIDL attribute to `watchedByDevToolsInternal`
// BC field. And we map it to the top level BrowsingContext.
bool BrowsingContext::WatchedByDevTools() {
Expand Down Expand Up @@ -3479,13 +3475,6 @@ void BrowsingContext::DidSet(FieldIndex<IDX_HasSessionHistory>,
}
}

bool BrowsingContext::CanSet(
FieldIndex<IDX_TargetTopLevelLinkClicksToBlankInternal>,
const bool& aTargetTopLevelLinkClicksToBlankInternal,
ContentParent* aSource) {
return XRE_IsParentProcess() && !aSource && IsTop();
}

bool BrowsingContext::CanSet(FieldIndex<IDX_BrowserId>, const uint32_t& aValue,
ContentParent* aSource) {
// We should only be able to set this for toplevel contexts which don't have
Expand Down
6 changes: 0 additions & 6 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ enum class ExplicitActiveStatus : uint8_t {
FIELD(AllowContentRetargetingOnChildren, bool) \
FIELD(ForceEnableTrackingProtection, bool) \
FIELD(UseGlobalHistory, bool) \
FIELD(TargetTopLevelLinkClicksToBlankInternal, bool) \
FIELD(FullscreenAllowedByOwner, bool) \
/* \
* "is popup" in the spec. \
Expand Down Expand Up @@ -558,7 +557,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void SetWatchedByDevTools(bool aWatchedByDevTools, ErrorResult& aRv);

dom::TouchEventsOverride TouchEventsOverride() const;
bool TargetTopLevelLinkClicksToBlank() const;

bool FullscreenAllowed() const;

Expand Down Expand Up @@ -1141,10 +1139,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool CanSet(FieldIndex<IDX_UseGlobalHistory>, const bool& aUseGlobalHistory,
ContentParent* aSource);

bool CanSet(FieldIndex<IDX_TargetTopLevelLinkClicksToBlankInternal>,
const bool& aTargetTopLevelLinkClicksToBlankInternal,
ContentParent* aSource);

void DidSet(FieldIndex<IDX_HasSessionHistory>, bool aOldValue);

bool CanSet(FieldIndex<IDX_BrowserId>, const uint32_t& aValue,
Expand Down
8 changes: 0 additions & 8 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ void CanonicalBrowsingContext::ReplacedBy(
// about:blank documents created in it.
txn.SetSandboxFlags(GetSandboxFlags());
txn.SetInitialSandboxFlags(GetSandboxFlags());
txn.SetTargetTopLevelLinkClicksToBlankInternal(
TargetTopLevelLinkClicksToBlank());
if (aNewContext->EverAttached()) {
MOZ_ALWAYS_SUCCEEDS(txn.Commit(aNewContext));
} else {
Expand Down Expand Up @@ -2680,12 +2678,6 @@ void CanonicalBrowsingContext::SetTouchEventsOverride(
SetTouchEventsOverrideInternal(aOverride, aRv);
}

void CanonicalBrowsingContext::SetTargetTopLevelLinkClicksToBlank(
bool aTargetTopLevelLinkClicksToBlank, ErrorResult& aRv) {
SetTargetTopLevelLinkClicksToBlankInternal(aTargetTopLevelLinkClicksToBlank,
aRv);
}

void CanonicalBrowsingContext::AddPageAwakeRequest() {
MOZ_ASSERT(IsTop());
auto count = GetPageAwakeRequestCount();
Expand Down
2 changes: 0 additions & 2 deletions docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ class CanonicalBrowsingContext final : public BrowsingContext {
}

void SetTouchEventsOverride(dom::TouchEventsOverride, ErrorResult& aRv);
void SetTargetTopLevelLinkClicksToBlank(bool aTargetTopLevelLinkClicksToBlank,
ErrorResult& aRv);

bool IsReplaced() const { return mIsReplaced; }

Expand Down
40 changes: 12 additions & 28 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12860,8 +12860,7 @@ nsresult nsDocShell::OnLinkClick(

bool noOpenerImplied = false;
nsAutoString target(aTargetSpec);
if (aFileName.IsVoid() &&
ShouldOpenInBlankTarget(aTargetSpec, aURI, aContent, aIsUserTriggered)) {
if (ShouldOpenInBlankTarget(aTargetSpec, aURI, aContent)) {
target = u"_blank";
if (!aTargetSpec.Equals(target)) {
noOpenerImplied = true;
Expand All @@ -12887,32 +12886,8 @@ nsresult nsDocShell::OnLinkClick(
}

bool nsDocShell::ShouldOpenInBlankTarget(const nsAString& aOriginalTarget,
nsIURI* aLinkURI, nsIContent* aContent,
bool aIsUserTriggered) {
if (net::SchemeIsJavascript(aLinkURI)) {
return false;
}

// External links from within app tabs should always open in new tabs
// instead of replacing the app tab's page (Bug 575561)
// nsIURI.host can throw for non-nsStandardURL nsIURIs. If we fail to
// get either host, just return false to use the original target.
nsAutoCString linkHost;
if (NS_FAILED(aLinkURI->GetHost(linkHost))) {
return false;
}

// The targetTopLevelLinkClicksToBlank property on BrowsingContext allows
// privileged code to change the default targeting behaviour. In particular,
// if a user-initiated link click for the (or targetting the) top-level frame
// is detected, we default the target to "_blank" to give it a new
// top-level BrowsingContext.
if (mBrowsingContext->TargetTopLevelLinkClicksToBlank() && aIsUserTriggered &&
(aOriginalTarget.IsEmpty() && mBrowsingContext->IsTop() ||
aOriginalTarget == u"_top"_ns)) {
return true;
}

nsIURI* aLinkURI,
nsIContent* aContent) {
// Don't modify non-default targets.
if (!aOriginalTarget.IsEmpty()) {
return false;
Expand All @@ -12925,6 +12900,15 @@ bool nsDocShell::ShouldOpenInBlankTarget(const nsAString& aOriginalTarget,
return false;
}

// External links from within app tabs should always open in new tabs
// instead of replacing the app tab's page (Bug 575561)
// nsIURI.host can throw for non-nsStandardURL nsIURIs. If we fail to
// get either host, just return false to use the original target.
nsAutoCString linkHost;
if (NS_FAILED(aLinkURI->GetHost(linkHost))) {
return false;
}

nsCOMPtr<nsIURI> docURI = aContent->OwnerDoc()->GetDocumentURIObject();
if (!docURI) {
return false;
Expand Down
3 changes: 1 addition & 2 deletions docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,7 @@ class nsDocShell final : public nsDocLoader,
bool NoopenerForceEnabled();

bool ShouldOpenInBlankTarget(const nsAString& aOriginalTarget,
nsIURI* aLinkURI, nsIContent* aContent,
bool aIsUserTriggered);
nsIURI* aLinkURI, nsIContent* aContent);

void RecordSingleChannelId(bool aStartRequest, nsIRequest* aRequest);

Expand Down
1 change: 0 additions & 1 deletion docshell/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ https_first_disabled = true
support-files =
file_backforward_restore_scroll.html
file_backforward_restore_scroll.html^headers^
[browser_targetTopLevelLinkClicksToBlank.js]
[browser_title_in_session_history.js]
skip-if = !sessionHistoryInParent
[browser_uriFixupIntegration.js]
Expand Down
Loading

0 comments on commit a1b5f9b

Please sign in to comment.