From b1f04c79b024a993bd77a2ff222c6c1481c24f55 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 16 Sep 2017 10:55:28 -0400 Subject: [PATCH] code review: cleaner user-stylesheets support as proposed in https://issues.adblockplus.org/ticket/5695 --- platform/chromium/vapi-background.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 420bf94f6..492d5f823 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -47,22 +47,6 @@ var noopFunc = function(){}; /******************************************************************************/ -if ( - typeof browser === 'object' && - browser !== null && - browser.runtime instanceof Object && - typeof browser.runtime.getBrowserInfo === 'function' -) { - browser.runtime.getBrowserInfo().then(function(info) { - vAPI.supportsUserStylesheets = - info.name === 'Firefox' && - parseInt(info.version, 10) > 52; - - }); -} - -/******************************************************************************/ - vAPI.app = { name: manifest.name, version: manifest.version @@ -718,6 +702,13 @@ vAPI.messaging.onPortMessage = (function() { var messaging = vAPI.messaging, toAuxPending = {}; + // https://issues.adblockplus.org/ticket/5695 + // - Good idea, adopted: cleaner way to detect user-stylesheet support. + var supportsUserStylesheets = + chrome.extensionTypes instanceof Object && + chrome.extensionTypes.CSSOrigin instanceof Object && + 'USER' in chrome.extensionTypes.CSSOrigin; + // Use a wrapper to avoid closure and to allow reuse. var CallbackWrapper = function(port, request, timeout) { this.callback = this.proxy.bind(this); // bind once @@ -831,7 +822,7 @@ vAPI.messaging.onPortMessage = (function() { frameId: sender.frameId, matchAboutBlank: true }; - if ( vAPI.supportsUserStylesheets === true ) { + if ( supportsUserStylesheets ) { details.cssOrigin = 'user'; } var fn;