Replace browser conditions by preprocessed conditions
The extension used to rely on the isFirefox method to check whether the
browser is Firefox or Chromium-based. This CL removes this function and
replaces the conditions based in this function by conditions which are
pre-processed at compile time.
Change-Id: Id7280e6c8fb3dfd3fabbc05339ef3791822aa6ac
diff --git a/src/common/extUtils.js b/src/common/extUtils.js
index 1777c87..e47a74c 100644
--- a/src/common/extUtils.js
+++ b/src/common/extUtils.js
@@ -1,11 +1,3 @@
-// This method is based on the fact that when building the extension for Firefox
-// the browser_specific_settings.gecko entry is included.
-export function isFirefox() {
- var manifest = chrome.runtime.getManifest();
- return manifest.browser_specific_settings !== undefined &&
- manifest.browser_specific_settings.gecko !== undefined;
-}
-
// Returns whether the extension is a release version.
export function isReleaseVersion() {
var manifest = chrome.runtime.getManifest();
diff --git a/src/common/optionsPrototype.json5 b/src/common/optionsPrototype.json5
index 38cfaca..824b754 100644
--- a/src/common/optionsPrototype.json5
+++ b/src/common/optionsPrototype.json5
@@ -75,11 +75,13 @@
context: 'options',
killSwitchType: 'option',
},
+ // #!if ['chromium', 'chromium_mv3'].includes(browser_target)
'ccdragndropfix': {
defaultValue: false,
context: 'options',
killSwitchType: 'option',
},
+ // #!endif
'batchlock': {
defaultValue: false,
context: 'options',
diff --git a/src/common/specialOptions.json5 b/src/common/specialOptions.json5
index 55dde20..37b69fa 100644
--- a/src/common/specialOptions.json5
+++ b/src/common/specialOptions.json5
@@ -2,5 +2,4 @@
'profileindicatoralt_months',
'ccdarktheme_mode',
'ccdarktheme_switch_enabled',
- 'ccdragndropfix',
]
diff --git a/src/contentScripts/communityConsole/main.js b/src/contentScripts/communityConsole/main.js
index fe075d9..cc55aa4 100644
--- a/src/contentScripts/communityConsole/main.js
+++ b/src/contentScripts/communityConsole/main.js
@@ -5,7 +5,9 @@
import AvatarsHandler from './avatars.js';
import {batchLock} from './batchLock.js';
import {injectDarkModeButton, isDarkThemeOn} from './darkMode.js';
+// #!if ['chromium', 'chromium_mv3'].includes(browser_target)
import {applyDragAndDropFixIfEnabled} from './dragAndDropFix.js';
+// #!endif
import {unifiedProfilesFix} from './unifiedProfiles.js';
var mutationObserver, intersectionObserver, intersectionOptions, options,
@@ -94,6 +96,7 @@
/* isCommunityConsole = */ true);
}
+ // #!if ['chromium', 'chromium_mv3'].includes(browser_target)
// Fix the drag&drop issue with the rich text editor if the option is
// currently enabled.
//
@@ -107,6 +110,7 @@
node.tagName == 'EC-RICH-TEXT-EDITOR')) {
applyDragAndDropFixIfEnabled(node);
}
+ // #!endif
// Inject the batch lock button in the thread list if the option is
// currently enabled.
diff --git a/src/killSwitch/index.js b/src/killSwitch/index.js
index 1456a51..f0b1294 100644
--- a/src/killSwitch/index.js
+++ b/src/killSwitch/index.js
@@ -1,6 +1,6 @@
import {compareLoose} from 'semver';
-import {getExtVersion, isFirefox} from '../common/extUtils.js';
+import {getExtVersion} from '../common/extUtils.js';
import * as commonPb from './api_proto/common_pb.js';
import {KillSwitchServicePromiseClient} from './api_proto/kill_switch_grpc_web_pb.js';
@@ -16,8 +16,11 @@
}
getCurrentBrowser() {
- if (isFirefox()) return commonPb.Environment.Browser.BROWSER_GECKO;
+ // #!if browser_target == 'gecko'
+ return commonPb.Environment.Browser.BROWSER_GECKO;
+ // #!else
return commonPb.Environment.Browser.BROWSER_CHROMIUM;
+ // #!endif
}
updateKillSwitchStatus() {
diff --git a/src/options/optionsCommon.js b/src/options/optionsCommon.js
index bd40416..863232d 100644
--- a/src/options/optionsCommon.js
+++ b/src/options/optionsCommon.js
@@ -1,4 +1,4 @@
-import {getExtVersion, isFirefox, isReleaseVersion} from '../common/extUtils.js';
+import {getExtVersion, isReleaseVersion} from '../common/extUtils.js';
import {ensureOptPermissions, grantedOptPermissions, missingPermissions} from '../common/optionsPermissions.js';
import {cleanUpOptions, optionsPrototype, specialOptions} from '../common/optionsUtils.js';
@@ -35,9 +35,6 @@
case 'ccdarktheme_mode':
return document.getElementById(opt).value || 'switch';
- case 'ccdragndropfix':
- return document.getElementById(opt).checked || false;
-
default:
console.warn('Unrecognized option: ' + opt);
return undefined;
@@ -232,19 +229,6 @@
.appendChild(select);
break;
- // Firefox doesn't support drag and dropping bookmarks into the text
- // editor while preserving the bookmark title.
- case 'ccdragndropfix':
- var showOption = !isFirefox();
- if (showOption) {
- document.getElementById('dragndrop-wrapper')
- .removeAttribute('hidden');
-
- if (items[opt] === true)
- document.getElementById(opt).checked = true;
- }
- break;
-
default:
console.warn('Unrecognized option: ' + opt);
break;
diff --git a/src/options/optionsPage.json5 b/src/options/optionsPage.json5
index 24bafdd..a06819a 100644
--- a/src/options/optionsPage.json5
+++ b/src/options/optionsPage.json5
@@ -36,7 +36,9 @@
{codename: 'increasecontrast'},
{codename: 'stickysidebarheaders'},
{codename: 'ccforcehidedrawer'},
- {codename: 'ccdragndropfix', customHTML: '<div id="dragndrop-wrapper" class="option" hidden><input type="checkbox" id="ccdragndropfix"> <label for="ccdragndropfix" data-i18n="ccdragndropfix"></label></div>'},
+ // #!if ['chromium', 'chromium_mv3'].includes(browser_target)
+ {codename: 'ccdragndropfix'},
+ // #!endif
{codename: 'enhancedannouncementsdot'},
{codename: 'repositionexpandthread', experimental: true},
{codename: 'imagemaxheight'},