Bug 1581664 - use unlimited session length permission for 'Allow Now' for plugins, r=mconley,handyman
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 01 Oct 2019 22:23:17 +0000
changeset 495929 41f38d4062fc0385ce1dbfb7bf4dd91aa6dceb3b
parent 495928 95114b9893afbbbaae7bb945b42b38d5c8ad01f3
child 495930 c29af4939f66a53fc46856bb364e642cde752aad
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, handyman
bugs1581664
milestone71.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 1581664 - use unlimited session length permission for 'Allow Now' for plugins, r=mconley,handyman Differential Revision: https://phabricator.services.mozilla.com/D46938
browser/actors/PluginParent.jsm
dom/base/nsObjectLoadingContent.cpp
modules/libpref/init/all.js
--- a/browser/actors/PluginParent.jsm
+++ b/browser/actors/PluginParent.jsm
@@ -295,19 +295,16 @@ const PluginManager = {
    * Just Work.
    */
   mockResponse(browser, handler) {
     let { currentWindowGlobal } = browser.frameLoader.browsingContext;
     currentWindowGlobal.getActor("Plugin")._mockedResponder = handler;
   },
 };
 
-const PREF_SESSION_PERSIST_MINUTES =
-  "plugin.sessionPermissionNow.intervalInMinutes";
-
 class PluginParent extends JSWindowActorParent {
   constructor() {
     super();
     PluginManager.ensureInitialized();
   }
 
   receiveMessage(msg) {
     let browser = this.manager.rootFrameLoader.ownerElement;
@@ -422,47 +419,39 @@ class PluginParent extends JSWindowActor
    * aNewState should be one of:
    * - "allownow"
    * - "block"
    * - "continue"
    * - "continueblocking"
    */
   _updatePluginPermission(aBrowser, aActivationInfo, aNewState) {
     let permission;
-    let expireType;
-    let expireTime;
     let histogram = Services.telemetry.getHistogramById(
       "PLUGINS_NOTIFICATION_USER_ACTION_2"
     );
 
     let window = aBrowser.ownerGlobal;
     let notification = window.PopupNotifications.getNotification(
       kNotificationId,
       aBrowser
     );
 
     // Update the permission manager.
     // Also update the current state of activationInfo.fallbackType so that
     // subsequent opening of the notification shows the current state.
     switch (aNewState) {
       case "allownow":
         permission = Ci.nsIPermissionManager.ALLOW_ACTION;
-        expireType = Ci.nsIPermissionManager.EXPIRE_SESSION;
-        expireTime =
-          Date.now() +
-          Services.prefs.getIntPref(PREF_SESSION_PERSIST_MINUTES) * 60 * 1000;
         histogram.add(0);
         aActivationInfo.fallbackType = PLUGIN_ACTIVE;
         notification.options.extraAttr = "active";
         break;
 
       case "block":
         permission = Ci.nsIPermissionManager.PROMPT_ACTION;
-        expireType = Ci.nsIPermissionManager.EXPIRE_SESSION;
-        expireTime = 0;
         histogram.add(2);
         let pluginTag = PluginManager.getPluginTagById(aActivationInfo.id);
         switch (pluginTag.blocklistState) {
           case Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE:
             aActivationInfo.fallbackType = PLUGIN_VULNERABLE_UPDATABLE;
             break;
           case Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE:
             aActivationInfo.fallbackType = PLUGIN_VULNERABLE_NO_UPDATE;
@@ -494,18 +483,18 @@ class PluginParent extends JSWindowActor
     }
 
     if (aNewState != "continue" && aNewState != "continueblocking") {
       let { principal } = notification.options;
       Services.perms.addFromPrincipal(
         principal,
         aActivationInfo.permissionString,
         permission,
-        expireType,
-        expireTime
+        Ci.nsIPermissionManager.EXPIRE_SESSION,
+        0 // do not expire (only expire at the end of the session)
       );
     }
 
     this.sendAsyncMessage("PluginParent:ActivatePlugins", {
       activationInfo: aActivationInfo,
       newState: aNewState,
     });
   }
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -102,17 +102,16 @@
 #  ifdef CreateEvent
 #    undef CreateEvent
 #  endif
 #endif  // XP_WIN
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 static const char kPrefYoutubeRewrite[] = "plugins.rewrite_youtube_embeds";
-static const char kPrefBlockURIs[] = "browser.safebrowsing.blockedURIs.enabled";
 static const char kPrefFavorFallbackMode[] = "plugins.favorfallback.mode";
 static const char kPrefFavorFallbackRules[] = "plugins.favorfallback.rules";
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::net;
 
 static LogModule* GetObjectLog() {
@@ -2936,55 +2935,28 @@ uint32_t nsObjectLoadingContent::GetRunI
     // The plugin instance must not have a run ID, so we must
     // be running the plugin in-process.
     aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
     return 0;
   }
   return mRunID;
 }
 
-static bool sPrefsInitialized;
-static uint32_t sSessionTimeoutMinutes;
-static uint32_t sPersistentTimeoutDays;
-static bool sBlockURIs;
-
-static void initializeObjectLoadingContentPrefs() {
-  if (!sPrefsInitialized) {
-    Preferences::AddUintVarCache(
-        &sSessionTimeoutMinutes,
-        "plugin.sessionPermissionNow.intervalInMinutes", 60);
-    Preferences::AddUintVarCache(
-        &sPersistentTimeoutDays,
-        "plugin.persistentPermissionAlways.intervalInDays", 90);
-
-    Preferences::AddBoolVarCache(&sBlockURIs, kPrefBlockURIs, false);
-    sPrefsInitialized = true;
-  }
-}
-
 bool nsObjectLoadingContent::ShouldBlockContent() {
-  if (!sPrefsInitialized) {
-    initializeObjectLoadingContentPrefs();
-  }
-
   if (mContentBlockingEnabled && mURI && IsFlashMIME(mContentType) &&
-      sBlockURIs) {
+      StaticPrefs::browser_safebrowsing_blockedURIs_enabled()) {
     return true;
   }
 
   return false;
 }
 
 bool nsObjectLoadingContent::ShouldPlay(FallbackType& aReason) {
   nsresult rv;
 
-  if (!sPrefsInitialized) {
-    initializeObjectLoadingContentPrefs();
-  }
-
   if (BrowserTabsRemoteAutostart()) {
     bool shouldLoadInParent =
         nsPluginHost::ShouldLoadTypeInParent(mContentType);
     bool inParent = XRE_IsParentProcess();
 
     if (shouldLoadInParent != inParent) {
       // Plugins need to be locked to either the parent process or the content
       // process. If a plugin is locked to one process type, it can't be used in
@@ -3077,24 +3049,16 @@ bool nsObjectLoadingContent::ShouldPlay(
     nsAutoCString permissionString;
     rv = pluginHost->GetPermissionStringForType(
         mContentType, nsPluginHost::eExcludeNone, permissionString);
     NS_ENSURE_SUCCESS(rv, false);
     uint32_t permission;
     rv = permissionManager->TestPermissionFromPrincipal(
         topDoc->NodePrincipal(), permissionString, &permission);
     NS_ENSURE_SUCCESS(rv, false);
-    if (permission != nsIPermissionManager::UNKNOWN_ACTION) {
-      uint64_t nowms = PR_Now() / 1000;
-      permissionManager->UpdateExpireTime(
-          topDoc->NodePrincipal(), permissionString, false,
-          nowms + sSessionTimeoutMinutes * 60 * 1000,
-          nowms / 1000 +
-              uint64_t(sPersistentTimeoutDays) * 24 * 60 * 60 * 1000);
-    }
     switch (permission) {
       case nsIPermissionManager::ALLOW_ACTION:
         if (PreferFallback(false /* isPluginClickToPlay */)) {
           aReason = eFallbackAlternate;
           return false;
         }
 
         return true;
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2572,23 +2572,16 @@ pref("input_event_queue.default_duration
 pref("input_event_queue.count_for_prediction", 9);
 
 // This only supports one hidden ctp plugin, edit nsPluginArray.cpp if adding a second
 pref("plugins.navigator.hidden_ctp_plugin", "");
 
 // The default value for nsIPluginTag.enabledState (STATE_ENABLED = 2)
 pref("plugin.default.state", 2);
 
-// How long in minutes we will allow a plugin to work after the user has chosen
-// to allow it "now"
-pref("plugin.sessionPermissionNow.intervalInMinutes", 60);
-// How long in days we will allow a plugin to work after the user has chosen
-// to allow it persistently.
-pref("plugin.persistentPermissionAlways.intervalInDays", 90);
-
 // This pref can take 3 possible string values:
 // "always"     - always use favor fallback mode
 // "follow-ctp" - activate if ctp is active for the given
 //                plugin object (could be due to a plugin-wide
 //                setting or a site-specific setting)
 // "never"      - never use favor fallback mode
 pref("plugins.favorfallback.mode", "never");