Bug 625497 - Clear Adobe Flash Cookies (LSOs) when "Forget This Site" is selected. r=ehsan, a=final+
authorDan Witte <dwitte@mozilla.com>
Tue, 08 Feb 2011 14:16:09 -0800
changeset 62175 2ff5b862446372b8eb2511427c148414ceef1d12
parent 62174 d0ea866fef6e2b9b61e7dede3d5dd7d0e4a797e3
child 62176 37094ed97c9e82d2161c21f9edc6c2a0b97438ab
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersehsan, final
bugs625497
milestone2.0b12pre
Bug 625497 - Clear Adobe Flash Cookies (LSOs) when "Forget This Site" is selected. r=ehsan, a=final+
browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
browser/components/privatebrowsing/test/browser/Makefile.in
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_clearplugindata.html
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_clearplugindata.js
--- a/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
+++ b/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
@@ -611,16 +611,32 @@ PrivateBrowsingService.prototype = {
               getService(Ci.nsICookieManager2)) {
       let enumerator = cm.getCookiesFromHost(aDomain);
       while (enumerator.hasMoreElements()) {
         let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
         cm.remove(cookie.host, cookie.name, cookie.path, false);
       }
     }
 
+    // Plugin data
+    let (ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost)) {
+      const phInterface = Ci.nsIPluginHost_MOZILLA_2_0_BRANCH;
+      const FLAG_CLEAR_ALL = phInterface.FLAG_CLEAR_ALL;
+      ph.QueryInterface(phInterface);
+
+      let tags = ph.getPluginTags();
+      for (let i = 0; i < tags.length; i++) {
+        try {
+          ph.clearSiteData(tags[i], aDomain, FLAG_CLEAR_ALL, -1);
+        } catch (e) {
+          // Ignore errors from the plugin
+        }
+      }
+    }
+
     // Downloads
     let (dm = Cc["@mozilla.org/download-manager;1"].
               getService(Ci.nsIDownloadManager)) {
       // Active downloads
       let enumerator = dm.activeDownloads;
       while (enumerator.hasMoreElements()) {
         let dl = enumerator.getNext().QueryInterface(Ci.nsIDownload);
         if (dl.source.host.hasRootDomain(aDomain)) {
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -72,16 +72,18 @@ include $(topsrcdir)/config/rules.mk
 		browser_privatebrowsing_ui.js \
 		browser_privatebrowsing_urlbarfocus.js \
 		browser_privatebrowsing_urlbarundo.js \
 		browser_privatebrowsing_viewsource.js \
 		browser_privatebrowsing_windowtitle.js \
 		browser_privatebrowsing_windowtitle_page.html \
 		browser_privatebrowsing_zoom.js \
 		browser_privatebrowsing_zoomrestore.js \
+		browser_privatebrowsing_clearplugindata.js \
+		browser_privatebrowsing_clearplugindata.html \
 		ctxmenu.html \
 		ctxmenu-image.png \
 		popup.html \
 		staller.sjs \
 		title.sjs \
 		$(NULL)
 
 # Disabled until bug 564934 is fixed:
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_clearplugindata.html
@@ -0,0 +1,32 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+  <head>
+    <title>Plugin Clear Site Data clear by domain test</title>
+
+    <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
+
+    <script type="application/javascript">
+      function testSteps()
+      {
+        var p = document.getElementById("plugin1");
+
+        p.setSitesWithData(
+          "foo.com:0:0," +
+          "bar.foo.com:0:0," +
+          "baz.foo.com:0:0," +
+          "bar.com:1:0," +
+          "[192.168.1.1]:0:0," +
+          "localhost:0:0"
+        );
+
+        setTimeout(testFinishedCallback, 0);
+      }
+    </script>
+  </head>
+
+  <body onload="testSteps();"></body>
+
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_clearplugindata.js
@@ -0,0 +1,97 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Test clearing plugin data by domain using nsPrivateBrowsingService.
+const testURL = "http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_clearplugindata.html";
+
+const pluginHostIface = Ci.nsIPluginHost_MOZILLA_2_0_BRANCH;
+var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
+pluginHost.QueryInterface(pluginHostIface);
+
+var pluginTag;
+
+function stored(needles) {
+  var something = pluginHost.siteHasData(this.pluginTag, null);
+  if (!needles)
+    return something;
+
+  if (!something)
+    return false;
+
+  for (var i = 0; i < needles.length; ++i) {
+    if (!pluginHost.siteHasData(this.pluginTag, needles[i]))
+      return false;
+  }
+  return true;
+}
+
+function test() {
+  waitForExplicitFinish();
+
+  var tags = pluginHost.getPluginTags();
+
+  // Find the test plugin
+  for (var i = 0; i < tags.length; i++)
+  {
+    if (tags[i].name == "Test Plug-in")
+    {
+      pluginTag = tags[i];
+    }
+  }
+
+  executeSoon(do_test);
+}
+
+function setFinishedCallback(callback)
+{
+  let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
+  testPage.testFinishedCallback = function() {
+    setTimeout(function() {
+      info("got finished callback");
+      callback();
+    }, 0);
+  }
+}
+
+function do_test()
+{
+  // Load page to set data for the plugin.
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function () {
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+
+    setFinishedCallback(function() {
+      ok(stored(["192.168.1.1","foo.com","nonexistent.foo.com","bar.com","localhost"]),
+        "Data stored for sites");
+
+      let pb = Cc["@mozilla.org/privatebrowsing;1"].
+               getService(Ci.nsIPrivateBrowsingService);
+
+      // Clear data for "foo.com" and its subdomains.
+      pb.removeDataFromDomain("foo.com");
+      ok(stored(["bar.com","192.168.1.1","localhost"]), "Data stored for sites");
+      ok(!stored(["foo.com"]), "Data cleared for foo.com");
+      ok(!stored(["bar.foo.com"]), "Data cleared for subdomains of foo.com");
+
+      // Clear data for "bar.com" using a subdomain.
+      pb.removeDataFromDomain("foo.bar.com");
+      ok(!stored(["bar.com"]), "Data cleared for bar.com");
+
+      // Clear data for "192.168.1.1".
+      pb.removeDataFromDomain("192.168.1.1");
+      ok(!stored(["192.168.1.1"]), "Data cleared for 192.168.1.1");
+
+      // Clear data for "localhost".
+      pb.removeDataFromDomain("localhost");
+      ok(!stored(null), "All data cleared");
+
+      gBrowser.removeCurrentTab();
+
+      executeSoon(finish);
+    });
+  }, true);
+  content.location = testURL;
+}
+