Bug 553124 - After bug 147777 lands, private browsing doesn't need to disable coloring of visited links any more; r=sdwilsh,bzbarsky
☠☠ backed out by 81086dc562b0 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 06 Apr 2010 13:47:42 -0400
changeset 40500 9786ae3984b3d467bbe0c372c38fb69ff9775526
parent 40499 aa2b262d938a21f0787962899ed826c1c5229d3d
child 40501 7788846fd5d562375e259f0d6e59c5b5aa81ee1e
child 40547 81086dc562b0610c0a7bbcf2470df9e1bbb4ac8a
push id12635
push usereakhgari@mozilla.com
push dateTue, 06 Apr 2010 19:54:18 +0000
treeherdermozilla-central@7788846fd5d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, bzbarsky
bugs553124, 147777
milestone1.9.3a4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 553124 - After bug 147777 lands, private browsing doesn't need to disable coloring of visited links any more; r=sdwilsh,bzbarsky
layout/build/nsLayoutStatics.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRuleProcessor.h
toolkit/components/places/tests/Makefile.in
toolkit/components/places/tests/mochitest/bug_461710/Makefile.in
toolkit/components/places/tests/mochitest/bug_461710/link_page-2.html
toolkit/components/places/tests/mochitest/bug_461710/link_page-3.html
toolkit/components/places/tests/mochitest/bug_461710/link_page.html
toolkit/components/places/tests/mochitest/bug_461710/visited_page.html
toolkit/components/places/tests/mochitest/test_bug_461710.html
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -250,21 +250,17 @@ nsLayoutStatics::Initialize()
   }
 
   rv = nsCCUncollectableMarker::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsCCUncollectableMarker");
     return rv;
   }
 
-  rv = nsCSSRuleProcessor::Startup();
-  if (NS_FAILED(rv)) {
-    NS_ERROR("Could not initialize nsCSSRuleProcessor");
-    return rv;
-  }
+  nsCSSRuleProcessor::Startup();
 
 #ifdef MOZ_XUL
   rv = nsXULPopupManager::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsXULPopupManager");
     return rv;
   }
 #endif
@@ -307,17 +303,17 @@ nsLayoutStatics::Shutdown()
 #endif
   nsDOMStorageManager::Shutdown();
   txMozillaXSLTProcessor::Shutdown();
   nsDOMAttribute::Shutdown();
   nsDOMEventRTTearoff::Shutdown();
   nsEventListenerManager::Shutdown();
   nsComputedDOMStyle::Shutdown();
   nsCSSParser::Shutdown();
-  nsCSSRuleProcessor::Shutdown();
+  nsCSSRuleProcessor::FreeSystemMetrics();
   nsTextFrameTextRunCache::Shutdown();
   nsHTMLDNSPrefetch::Shutdown();
   nsCSSRendering::Shutdown();
 #ifdef DEBUG
   nsFrame::DisplayReflowShutdown();
 #endif
   nsCellMap::Shutdown();
 
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -82,19 +82,16 @@
 #include "nsServiceManagerUtils.h"
 #include "nsTArray.h"
 #include "nsContentUtils.h"
 #include "nsIMediaList.h"
 #include "nsCSSRules.h"
 #include "nsIPrincipal.h"
 #include "nsStyleSet.h"
 #include "prlog.h"
-#include "nsIObserverService.h"
-#include "nsIPrivateBrowsingService.h"
-#include "nsNetCID.h"
 
 #define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled"
 
 static PRBool gSupportVisitedPseudo = PR_TRUE;
 
 static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
 static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
 
@@ -770,72 +767,16 @@ RuleCascadeData::AttributeListFor(nsIAto
       PL_DHashTableRawRemove(&mAttributeSelectors, entry);
       return nsnull;
     }
     entry->mAttribute = aAttribute;
   }
   return entry->mSelectors;
 }
 
-class nsPrivateBrowsingObserver : nsIObserver,
-                                  nsSupportsWeakReference
-{
-public:
-  nsPrivateBrowsingObserver();
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  void Init();
-  PRBool InPrivateBrowsing() const { return mInPrivateBrowsing; }
-
-private:
-  PRBool mInPrivateBrowsing;
-};
-
-NS_IMPL_ISUPPORTS2(nsPrivateBrowsingObserver, nsIObserver, nsISupportsWeakReference)
-
-nsPrivateBrowsingObserver::nsPrivateBrowsingObserver()
-  : mInPrivateBrowsing(PR_FALSE)
-{
-}
-
-void
-nsPrivateBrowsingObserver::Init()
-{
-  nsCOMPtr<nsIPrivateBrowsingService> pbService =
-    do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
-  if (pbService) {
-    pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
-
-    nsCOMPtr<nsIObserverService> observerService =
-      do_GetService("@mozilla.org/observer-service;1");
-    if (observerService) {
-      observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
-    }
-  }
-}
-
-nsresult
-nsPrivateBrowsingObserver::Observe(nsISupports *aSubject,
-                                   const char *aTopic,
-                                   const PRUnichar *aData)
-{
-  if (!strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC)) {
-    if (!nsCRT::strcmp(aData, NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).get())) {
-      mInPrivateBrowsing = PR_TRUE;
-    } else {
-      mInPrivateBrowsing = PR_FALSE;
-    }
-  }
-  return NS_OK;
-}
-
-static nsPrivateBrowsingObserver *gPrivateBrowsingObserver = nsnull;
-
 // -------------------------------
 // CSS Style rule processor implementation
 //
 
 nsCSSRuleProcessor::nsCSSRuleProcessor(const nsCOMArray<nsICSSStyleSheet>& aSheets,
                                        PRUint8 aSheetType)
   : mSheets(aSheets)
   , mRuleCascades(nsnull)
@@ -851,31 +792,24 @@ nsCSSRuleProcessor::~nsCSSRuleProcessor(
   for (PRInt32 i = mSheets.Count() - 1; i >= 0; --i)
     mSheets[i]->DropRuleProcessor(this);
   mSheets.Clear();
   ClearRuleCascades();
 }
 
 NS_IMPL_ISUPPORTS1(nsCSSRuleProcessor, nsIStyleRuleProcessor)
 
-/* static */ nsresult
+/* static */ void
 nsCSSRuleProcessor::Startup()
 {
   nsContentUtils::AddBoolPrefVarCache(VISITED_PSEUDO_PREF,
                                       &gSupportVisitedPseudo);
   // We want to default to true, not false as AddBoolPrefVarCache does.
   gSupportVisitedPseudo =
     nsContentUtils::GetBoolPref(VISITED_PSEUDO_PREF, PR_TRUE);
-
-  gPrivateBrowsingObserver = new nsPrivateBrowsingObserver();
-  NS_ENSURE_TRUE(gPrivateBrowsingObserver, NS_ERROR_OUT_OF_MEMORY);
-  NS_ADDREF(gPrivateBrowsingObserver);
-  gPrivateBrowsingObserver->Init();
-
-  return NS_OK;
 }
 
 static PRBool
 InitSystemMetrics()
 {
   NS_ASSERTION(!sSystemMetrics, "already initialized");
 
   sSystemMetrics = new nsTArray< nsCOMPtr<nsIAtom> >;
@@ -955,24 +889,16 @@ InitSystemMetrics()
 
 /* static */ void
 nsCSSRuleProcessor::FreeSystemMetrics()
 {
   delete sSystemMetrics;
   sSystemMetrics = nsnull;
 }
 
-/* static */ void
-nsCSSRuleProcessor::Shutdown()
-{
-  FreeSystemMetrics();
-  // Make sure we don't crash if Shutdown is called before Init
-  NS_IF_RELEASE(gPrivateBrowsingObserver);
-}
-
 /* static */ PRBool
 nsCSSRuleProcessor::HasSystemMetric(nsIAtom* aMetric)
 {
   if (!sSystemMetrics && !InitSystemMetrics()) {
     return PR_FALSE;
   }
   return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
 }
@@ -1112,19 +1038,17 @@ RuleProcessorData::ContentState()
     } else {
       mContentState = mContent->IntrinsicState();
     }
 
     // If we are not supposed to mark visited links as such, be sure to
     // flip the bits appropriately.  We want to do this here, rather
     // than in GetContentStateForVisitedHandling, so that we don't
     // expose that :visited support is disabled to the Web page.
-    if ((!gSupportVisitedPseudo ||
-        gPrivateBrowsingObserver->InPrivateBrowsing()) &&
-        (mContentState & NS_EVENT_STATE_VISITED)) {
+    if (!gSupportVisitedPseudo && (mContentState & NS_EVENT_STATE_VISITED)) {
       mContentState = (mContentState & ~PRUint32(NS_EVENT_STATE_VISITED)) |
                       NS_EVENT_STATE_UNVISITED;
     }
   }
   return mContentState;
 }
 
 PRUint32
--- a/layout/style/nsCSSRuleProcessor.h
+++ b/layout/style/nsCSSRuleProcessor.h
@@ -71,18 +71,17 @@ public:
                      PRUint8 aSheetType);
   virtual ~nsCSSRuleProcessor();
 
   NS_DECL_ISUPPORTS
 
 public:
   nsresult ClearRuleCascades();
 
-  static nsresult Startup();
-  static void Shutdown();
+  static void Startup();
   static void FreeSystemMetrics();
   static PRBool HasSystemMetric(nsIAtom* aMetric);
 
   /*
    * Returns true if the given RuleProcessorData matches one of the
    * selectors in aSelectorList.  Note that this method will assume
    * the matching is not for styling purposes.  aSelectorList must not
    * include any pseudo-element selectors.  aSelectorList is allowed
--- a/toolkit/components/places/tests/Makefile.in
+++ b/toolkit/components/places/tests/Makefile.in
@@ -59,23 +59,21 @@ XPCSHELL_TESTS = \
 # Files in the main "tests" folder.
 XPCSHELL_TESTS_COMMON = \
   head_common.js \
 	$(NULL)
 
 # Simple MochiTests
 MOCHI_TESTS = \
 	mochitest/test_bug_411966.html \
-	mochitest/test_bug_461710.html \
 	$(NULL)
 
 DIRS = \
 	chrome \
 	mochitest/bug_411966 \
-	mochitest/bug_461710 \
 	browser \
 	$(NULL)
 
 TOOL_DIRS = \
   cpp \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/Makefile.in
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is Bug 461710 test code.
-#
-# The Initial Developer of the Original Code is
-# Ehsan Akhgari.
-# Portions created by the Initial Developer are Copyright (C) 2005
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#   Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../../../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-relativesrcdir = toolkit/components/places/tests/bug_461710
-
-include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-
-_HTTP_FILES	= \
-		visited_page.html \
-		link_page.html \
-		link_page-2.html \
-		link_page-3.html \
-		$(NULL)
-
-libs:: $(_HTTP_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page-2.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Link page 2</title>
-    <style type="text/css">
-      a:link { color: #0000ff; }
-      a:visited { color: #ff0000; }
-    </style>
-  </head>
-  <body>
-    <p><a href="visited_page.html" id="link">Link to the second visited page</a></p>
-  </body>
-</html>
\ No newline at end of file
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page-3.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Link page 3</title>
-    <style type="text/css">
-      a:link { color: #0000ff; }
-      a:visited { color: #ff0000; }
-    </style>
-  </head>
-  <body>
-    <p><a href="visited_page.html" id="link">Link to the third visited page</a></p>
-  </body>
-</html>
\ No newline at end of file
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Link page</title>
-    <style type="text/css">
-      a:link { color: #0000ff; }
-      a:visited { color: #ff0000; }
-    </style>
-  </head>
-  <body>
-    <p><a href="visited_page.html" id="link">Link to the visited page</a></p>
-  </body>
-</html>
\ No newline at end of file
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/visited_page.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Visited page</title>
-  </head>
-  <body>
-    <p>This page is marked as visited</p>
-  </body>
-</html>
\ No newline at end of file
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/test_bug_461710.html
+++ /dev/null
@@ -1,234 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=461710
--->
-<head>
-  <title>Test for Bug 461710</title>
-  <script type="text/javascript" src="/MochiKit/packed.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=461710">Mozilla Bug 461710</a>
-<p id="display"></p>
-<iframe id="iframe"></iframe>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-/** Test for Bug 461710 **/
-
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-const Cr = Components.results;
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
-
-const LAZY_ADD_TIMER = 3000;
-
-/**
- * Helper function which waits until another function returns true, and
- * then notifies a callback.
- *
- * Original function stolen from docshell/test/chrome/docshell_helpers.js.
- *
- * Parameters:
- *
- *    fn: a function which is evaluated repeatedly, and when it turns true,
- *        the onWaitComplete callback is notified.
- *
- *    onWaitComplete:  a callback which will be notified when fn() returns
- *        true.
- */
-function waitForTrue(fn, onWaitComplete) {
-  var start = new Date().valueOf();
-
-  // Loop until the test function returns true, or until a timeout occurs,
-  // if a timeout is defined.
-  var intervalid =
-    setInterval(
-      function() {
-        if (fn.call()) {
-          // Stop calling the test function and notify the callback.
-          clearInterval(intervalid);
-          onWaitComplete.call();
-        }
-      }, 20);
-}
-
-const kRed = "rgb(255, 0, 0)";
-const kBlue = "rgb(0, 0, 255)";
-
-var testpath = document.location.pathname + "/../bug_461710/";
-var prefix = "http://mochi.test:8888" + testpath;
-var subtests = [
-                   "visited_page.html",   // 1
-                   "link_page.html",      // 2
-                   "link_page-2.html",    // 3
-                   "link_page-3.html"     // 4
-               ];
-
-
-var testNum = 0;
-function loadNextTest() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-  // run the initialization code for each test
-  switch (++ testNum) {
-    case 1:
-      // nothing to do here
-      break;
-
-    case 2:
-      ok(!pb.privateBrowsingEnabled, "Test #" + testNum + " should be run outside of private mode");
-      break;
-
-    case 3:
-      pb.privateBrowsingEnabled = true;
-      ok(pb.privateBrowsingEnabled, "Test #" + testNum + " should be run inside of private mode");
-      break;
-
-    case 4:
-      pb.privateBrowsingEnabled = false;
-      ok(!pb.privateBrowsingEnabled, "Test #" + testNum + " should be run outside of private mode");
-      break;
-
-    default:
-      ok(false, "Unexpected call to loadNextTest for test #" + testNum);
-  }
-
-  if (testNum == 1) {
-    // Because of LAZY_ADD, the page won't be marked as visited until three seconds,
-    // so wait for four seconds to be safe
-    setTimeout(handleLoad, LAZY_ADD_TIMER * 2);
-  } else {
-    observer.expectURL(prefix + subtests[0]);
-    waitForTrue(function() observer.resolved, function() {
-      // And the nodes get notified after the "link-visited" topic, so
-      // we need to execute soon...
-      SimpleTest.executeSoon(handleLoad);
-    });
-  }
-  iframe.src = prefix + subtests[testNum-1];
-}
-
-function getColor(doc, win, id) {
-  var elem = doc.getElementById(id);
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                getInterface(Components.interfaces.nsIDOMWindowUtils);
-  return utils.getVisitedDependentComputedStyle(elem, "", "color");
-}
-
-function checkTest() {
-  switch (testNum) {
-    case 1:
-      // nothing to do here, we just want to mark the page as visited
-      break;
-
-    case 2:
-      // run outside of private mode, link should appear as visited
-      var doc = iframe.contentDocument;
-      var win = doc.defaultView;
-      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
-      break;
-
-    case 3:
-      // run inside of private mode, link should appear as not visited
-      var doc = iframe.contentDocument;
-      var win = doc.defaultView;
-      is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
-      break;
-
-    case 4:
-      // run outside of private mode, link should appear as visited
-      var doc = iframe.contentDocument;
-      var win = doc.defaultView;
-      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
-      break;
-
-    default:
-      ok(false, "Unexpected call to checkTest for test #" + testNum);
-  }
-}
-
-
-var _PBSvc = null;
-function get_PBSvc() {
-  if (_PBSvc)
-    return _PBSvc;
-
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  try {
-    _PBSvc = Cc["@mozilla.org/privatebrowsing;1"].
-             getService(Ci.nsIPrivateBrowsingService);
-    return _PBSvc;
-  } catch (e) {}
-  return null;
-}
-
-
-function handleLoad() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-  checkTest();
-
-  if (testNum < subtests.length) {
-    loadNextTest();
-  } else {
-    prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session");
-    SimpleTest.finish();
-  }
-}
-
-const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
-var os, observer = {
-  uri: null,
-  resolved: true,
-  observe: function (aSubject, aTopic, aData) {
-    SimpleTest.is(aTopic, URI_VISITED_RESOLUTION_TOPIC, "Unexpected topic");
-
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-    if (this.uri.equals(aSubject.QueryInterface(Ci.nsIURI))) {
-      this.resolved = true;
-
-      os.removeObserver(this, URI_VISITED_RESOLUTION_TOPIC);
-    }
-  },
-  expectURL: function (url) {
-    ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
-    this.resolved = false;
-
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-    this.uri = NetUtil.newURI(url);
-    os.addObserver(this, URI_VISITED_RESOLUTION_TOPIC, false);
-  }
-};
-
-var pb = get_PBSvc();
-if (!pb) { // Private Browsing might not be available
-  ok(true, "Private Browsing is not available");
-  SimpleTest.finish();
-} else {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-  var prefBranch = Cc["@mozilla.org/preferences-service;1"].
-                   getService(Ci.nsIPrefBranch);
-  prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-
-  os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
-
-  var iframe = document.getElementById("iframe");
-
-  SimpleTest.waitForExplicitFinish();
-
-  loadNextTest();
-}
-
-</script>
-</pre>
-</body>
-</html>