bug 818009 - canActivate: only click-to-play-type plugins are valid r=jaws
authorDavid Keeler <dkeeler@mozilla.com>
Wed, 05 Dec 2012 13:00:52 -0800
changeset 115119 e8e24d4bed52d70cb31dac9e74e56aad680ca1ed
parent 115118 6400692c072eba204e4cd9f7319f83cc789738e4
child 115120 b5c19fdea86e150a6625f04653e8ee404c779575
push id23973
push useremorley@mozilla.com
push dateThu, 06 Dec 2012 10:04:18 +0000
treeherdermozilla-central@ddda5400c826 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs818009
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 818009 - canActivate: only click-to-play-type plugins are valid r=jaws
browser/base/content/browser-plugins.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug818009.js
browser/base/content/test/plugin_bug818009.html
content/base/public/nsIObjectLoadingContent.idl
content/base/src/nsObjectLoadingContent.h
--- a/browser/base/content/browser-plugins.js
+++ b/browser/base/content/browser-plugins.js
@@ -243,17 +243,18 @@ var gPluginHandler = {
     if (objLoadingContent.actualType) {
       let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
       let browser = gBrowser.getBrowserForDocument(objLoadingContent.ownerDocument.defaultView.top.document);
       pluginPermission = Services.perms.testPermission(browser.currentURI, permissionString);
     }
 
     return !objLoadingContent.activated &&
            pluginPermission != Ci.nsIPermissionManager.DENY_ACTION &&
-           objLoadingContent.pluginFallbackType !== Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW;
+           objLoadingContent.pluginFallbackType >= Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY &&
+           objLoadingContent.pluginFallbackType <= Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE;
   },
 
   activatePlugins: function PH_activatePlugins(aContentWindow) {
     let browser = gBrowser.getBrowserForDocument(aContentWindow.document);
     browser._clickToPlayPluginsActivated = true;
     let cwu = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                             .getInterface(Ci.nsIDOMWindowUtils);
     let plugins = cwu.plugins;
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -241,16 +241,17 @@ endif
                  plugin_alternate_content.html \
                  plugin_both.html \
                  plugin_both2.html \
                  plugin_bug743421.html \
                  plugin_clickToPlayAllow.html \
                  plugin_clickToPlayDeny.html \
                  plugin_bug749455.html \
                  plugin_bug797677.html \
+                 plugin_bug818009.html \
                  plugin_hidden_to_visible.html \
                  plugin_two_types.html \
                  alltabslistener.html \
                  zoom_test.html \
                  dummy_page.html \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
                  browser_aboutHome.js \
@@ -267,16 +268,17 @@ endif
                  browser_minimize.js \
                  browser_aboutSyncProgress.js \
                  browser_middleMouse_inherit.js \
                  redirect_bug623155.sjs \
                  browser_tabDrop.js \
                  browser_lastAccessedTab.js \
                  browser_bug734076.js \
                  browser_bug812562.js \
+                 browser_bug818009.js \
                  blockPluginVulnerableUpdatable.xml \
                  blockPluginVulnerableNoUpdate.xml \
                  blockNoPlugins.xml \
                  browser_utilityOverlay.js \
                  browser_social.js \
                  browser_social_toolbar.js \
                  browser_social_shareButton.js \
                  browser_social_sidebar.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug818009.js
@@ -0,0 +1,47 @@
+var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
+var gTestBrowser = null;
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+function test() {
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    Services.prefs.clearUserPref("plugins.click_to_play");
+    gTestBrowser.removeEventListener("load", pageLoad, true);
+  });
+  Services.prefs.setBoolPref("plugins.click_to_play", true);
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  gTestBrowser = gBrowser.selectedBrowser;
+  gTestBrowser.addEventListener("load", pageLoad, true);
+  gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug818009.html";
+}
+
+function pageLoad() {
+  // The plugin events are async dispatched and can come after the load event
+  // This just allows the events to fire before we then go on to test the states
+  executeSoon(actualTest);
+}
+
+function actualTest() {
+  var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
+  ok(notification, "should have a click-to-play notification");
+  is(notification.options.centerActions.length, 1, "should have only one type of plugin in the notification");
+  is(notification.options.centerActions[0].message, "Test", "the one type of plugin should be the 'Test' plugin");
+
+  var doc = gTestBrowser.contentDocument;
+  var inner = doc.getElementById("inner");
+  ok(inner, "should have 'inner' plugin");
+  var innerObjLC = inner.QueryInterface(Ci.nsIObjectLoadingContent);
+  ok(!innerObjLC.activated, "inner plugin shouldn't be activated");
+  is(innerObjLC.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "inner plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
+  var outer = doc.getElementById("outer");
+  ok(outer, "should have 'outer' plugin");
+  var outerObjLC = outer.QueryInterface(Ci.nsIObjectLoadingContent);
+  ok(!outerObjLC.activated, "outer plugin shouldn't be activated");
+  is(outerObjLC.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_ALTERNATE, "outer plugin fallback type should be PLUGIN_ALTERNATE");
+
+  gBrowser.removeCurrentTab();
+  window.focus();
+  finish();
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugin_bug818009.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<head><meta charset="utf8"/></head>
+<body>
+<object id="outer" width="200" height="200">
+  <embed id="inner" width="200" height="200" type="application/x-test"/>
+</object>
+</body>
+</html>
--- a/content/base/public/nsIObjectLoadingContent.idl
+++ b/content/base/public/nsIObjectLoadingContent.idl
@@ -46,16 +46,18 @@ interface nsIObjectLoadingContent : nsIS
   // The plugin has crashed
   const unsigned long PLUGIN_CRASHED              = 5;
   // Suppressed by security policy
   const unsigned long PLUGIN_SUPPRESSED           = 6;
   // Blocked by content policy
   const unsigned long PLUGIN_USER_DISABLED        = 7;
   /// ** All values >= PLUGIN_CLICK_TO_PLAY are plugin placeholder types that
   ///    would be replaced by a real plugin if activated (playPlugin())
+  /// ** Furthermore, values >= PLUGIN_CLICK_TO_PLAY and
+  ///    <= PLUGIN_VULNERABLE_NO_UPDATE are click-to-play types.
   // The plugin is disabled until the user clicks on it
   const unsigned long PLUGIN_CLICK_TO_PLAY        = 8;
   // The plugin is vulnerable (update available)
   const unsigned long PLUGIN_VULNERABLE_UPDATABLE = 9;
   // The plugin is vulnerable (no update available)
   const unsigned long PLUGIN_VULNERABLE_NO_UPDATE = 10;
   // The plugin is in play preview mode
   const unsigned long PLUGIN_PLAY_PREVIEW         = 11;
--- a/content/base/src/nsObjectLoadingContent.h
+++ b/content/base/src/nsObjectLoadingContent.h
@@ -74,16 +74,18 @@ class nsObjectLoadingContent : public ns
       // The plugin has crashed
       eFallbackCrashed = nsIObjectLoadingContent::PLUGIN_CRASHED,
       // Suppressed by security policy
       eFallbackSuppressed = nsIObjectLoadingContent::PLUGIN_SUPPRESSED,
       // Blocked by content policy
       eFallbackUserDisabled = nsIObjectLoadingContent::PLUGIN_USER_DISABLED,
       /// ** All values >= eFallbackClickToPlay are plugin placeholder types
       ///    that would be replaced by a real plugin if activated (PlayPlugin())
+      /// ** Furthermore, values >= eFallbackClickToPlay and
+      ///    <= eFallbackVulnerableNoUpdate are click-to-play types.
       // The plugin is disabled until the user clicks on it
       eFallbackClickToPlay = nsIObjectLoadingContent::PLUGIN_CLICK_TO_PLAY,
       // The plugin is vulnerable (update available)
       eFallbackVulnerableUpdatable = nsIObjectLoadingContent::PLUGIN_VULNERABLE_UPDATABLE,
       // The plugin is vulnerable (no update available)
       eFallbackVulnerableNoUpdate = nsIObjectLoadingContent::PLUGIN_VULNERABLE_NO_UPDATE,
       // The plugin is disabled and play preview content is displayed until
       // the extension code enables it by sending the MozPlayPlugin event