From cc31ed7d583ace503239a37a009895662bb0f709 Mon Sep 17 00:00:00 2001 From: Kathy Brade Date: Fri, 30 Oct 2015 14:28:13 -0400 Subject: [PATCH] Bug 16620: Clear window.name when no referrer sent Convert JS implementation (within Torbutton) to a C++ browser patch. --- docshell/base/nsDocShell.cpp | 57 +++++++ docshell/test/mochitest.ini | 3 + docshell/test/test_tor_bug16620.html | 212 +++++++++++++++++++++++++++ docshell/test/tor_bug16620.html | 51 +++++++ docshell/test/tor_bug16620_form.html | 51 +++++++ 5 files changed, 374 insertions(+) create mode 100644 docshell/test/test_tor_bug16620.html create mode 100644 docshell/test/tor_bug16620.html create mode 100644 docshell/test/tor_bug16620_form.html diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index ab119a016aeac..fb6974fb1a0d2 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9110,6 +9110,63 @@ nsDocShell::CreateContentViewer(const nsACString& aContentType, aOpenedChannel->GetURI(getter_AddRefs(mLoadingURI)); } FirePageHideNotification(!mSavingOldViewer); + + // Tor bug 16620: Clear window.name of top-level documents if + // there is no referrer. We make an exception for new windows, + // e.g., window.open(url, "MyName"). + bool isNewWindowTarget = false; + nsCOMPtr props(do_QueryInterface(aRequest, &rv)); + if (props) { + props->GetPropertyAsBool(NS_LITERAL_STRING("docshell.newWindowTarget"), + &isNewWindowTarget); + } + + if (!isNewWindowTarget) { + nsCOMPtr httpChannel(do_QueryInterface(aOpenedChannel)); + nsCOMPtr httpReferrer; + if (httpChannel) + httpChannel->GetReferrer(getter_AddRefs(httpReferrer)); + + bool isTopFrame = true; + nsCOMPtr targetParentTreeItem; + rv = GetSameTypeParent(getter_AddRefs(targetParentTreeItem)); + if (NS_SUCCEEDED(rv) && targetParentTreeItem) { + isTopFrame = false; + } + +#ifdef DEBUG_WINDOW_NAME + printf("DOCSHELL %p CreateContentViewer - possibly clearing window.name:\n", this); + printf(" current window.name: \"%s\"\n", + NS_ConvertUTF16toUTF8(mName).get()); + + nsAutoCString curSpec, loadingSpec; + if (this->mCurrentURI) + mCurrentURI->GetSpec(curSpec); + if (mLoadingURI) + mLoadingURI->GetSpec(loadingSpec); + printf(" current URI: %s\n", curSpec.get()); + printf(" loading URI: %s\n", loadingSpec.get()); + printf(" is top document: %s\n", isTopFrame ? "Yes" : "No"); + + if (!httpReferrer) { + printf(" referrer: None\n"); + } else { + nsAutoCString refSpec; + httpReferrer->GetSpec(refSpec); + printf(" referrer: %s\n", refSpec.get()); + } +#endif + + bool clearName = isTopFrame && !httpReferrer; + if (clearName) + SetName(NS_LITERAL_STRING("")); + +#ifdef DEBUG_WINDOW_NAME + printf(" action taken: %s window.name\n", + clearName ? "Cleared" : "Preserved"); +#endif + } + mLoadingURI = nullptr; // Set mFiredUnloadEvent = false so that the unload handler for the diff --git a/docshell/test/mochitest.ini b/docshell/test/mochitest.ini index 725486b7711b6..af176dbe4c5b7 100644 --- a/docshell/test/mochitest.ini +++ b/docshell/test/mochitest.ini @@ -34,6 +34,8 @@ support-files = file_bug728939.html file_pushState_after_document_open.html historyframes.html + tor_bug16620.html + tor_bug16620_form.html [test_anchor_scroll_after_document_open.html] [test_bfcache_plus_hash.html] @@ -91,4 +93,5 @@ support-files = file_bug668513.html skip-if = toolkit == 'android' # bug 784321 support-files = file_framedhistoryframes.html [test_pushState_after_document_open.html] +[test_tor_bug16620.html] [test_windowedhistoryframes.html] diff --git a/docshell/test/test_tor_bug16620.html b/docshell/test/test_tor_bug16620.html new file mode 100644 index 0000000000000..d528e1738f67d --- /dev/null +++ b/docshell/test/test_tor_bug16620.html @@ -0,0 +1,212 @@ + + + + + + Test for Tor Bug 16620 - Clear window.name when no referrer sent + + + + +Tor Bug 16620 + + + diff --git a/docshell/test/tor_bug16620.html b/docshell/test/tor_bug16620.html new file mode 100644 index 0000000000000..a8e90502f1d14 --- /dev/null +++ b/docshell/test/tor_bug16620.html @@ -0,0 +1,51 @@ + + + + + + Supporting Doc for Tor Bug 16620 Tests + + +secondDoc + + + + diff --git a/docshell/test/tor_bug16620_form.html b/docshell/test/tor_bug16620_form.html new file mode 100644 index 0000000000000..3b6e6c72cfc94 --- /dev/null +++ b/docshell/test/tor_bug16620_form.html @@ -0,0 +1,51 @@ + + + + + + Supporting Form-based Doc for Tor Bug 16620 Tests + + + + +
+
+ + + -- GitLab