2019-03-14 16:51:20 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let scope;
|
2019-03-14 16:51:20 +01:00
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
scope = require.register("./extension", {});
|
|
|
|
}
|
|
|
|
|
2019-04-19 14:09:56 +02:00
|
|
|
const browserAvailable = typeof browser !== "undefined";
|
|
|
|
|
|
|
|
scope.inBackgroundScript = !!(
|
|
|
|
browserAvailable &&
|
|
|
|
browser.extension.getBackgroundPage &&
|
|
|
|
browser.extension.getBackgroundPage() === window
|
|
|
|
);
|
|
|
|
|
2019-04-30 23:39:40 +02:00
|
|
|
scope.getTranslation = browserAvailable? function getTranslation(id){
|
2019-03-14 16:51:20 +01:00
|
|
|
return browser.i18n.getMessage(id);
|
2019-04-30 23:39:40 +02:00
|
|
|
}: function(id){
|
|
|
|
return id;
|
2019-03-14 16:51:20 +01:00
|
|
|
};
|
|
|
|
|
2019-04-30 23:39:40 +02:00
|
|
|
scope.extensionID = browserAvailable? browser.extension.getURL(""): "extensionID";
|
2019-03-14 16:51:20 +01:00
|
|
|
|
2019-04-30 23:39:40 +02:00
|
|
|
scope.inIncognitoContext = browserAvailable? browser.extension.inIncognitoContext: false;
|
2019-03-14 16:51:20 +01:00
|
|
|
|
|
|
|
scope.message = {
|
2019-04-30 23:39:40 +02:00
|
|
|
on: browserAvailable? function(callback){
|
2019-03-14 16:51:20 +01:00
|
|
|
return browser.runtime.onMessage.addListener(callback);
|
2019-04-30 23:39:40 +02:00
|
|
|
}: function(){
|
|
|
|
return false;
|
2019-03-14 16:51:20 +01:00
|
|
|
},
|
2019-04-30 23:39:40 +02:00
|
|
|
send: browserAvailable? function(data){
|
2019-03-14 16:51:20 +01:00
|
|
|
return browser.runtime.sendMessage(data);
|
2019-04-30 23:39:40 +02:00
|
|
|
}: function(){
|
|
|
|
return false;
|
2019-03-14 16:51:20 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Object.seal(scope.message);
|
|
|
|
|
2019-12-12 00:09:53 +01:00
|
|
|
scope.getWrapped = function getWrapped(obj){
|
|
|
|
return obj && (obj.wrappedJSObject || obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
scope.exportFunctionWithName = function exportFunctionWithName(func, context, name){
|
2019-12-29 23:40:39 +01:00
|
|
|
const exportedTry = exportFunction(func, context, {allowCrossOriginArguments: true});
|
2019-12-12 00:09:53 +01:00
|
|
|
if (exportedTry.name === name){
|
|
|
|
return exportedTry;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const wrappedContext = scope.getWrapped(context);
|
|
|
|
const options = {
|
2019-12-29 23:40:39 +01:00
|
|
|
allowCrossOriginArguments: true,
|
2019-12-12 00:09:53 +01:00
|
|
|
defineAs: name
|
|
|
|
};
|
|
|
|
const oldDescriptor = Object.getOwnPropertyDescriptor(wrappedContext, name);
|
|
|
|
const exported = exportFunction(func, context, options);
|
|
|
|
if (oldDescriptor){
|
|
|
|
Object.defineProperty(wrappedContext, name, oldDescriptor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete wrappedContext[name];
|
|
|
|
}
|
|
|
|
return exported;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-14 16:51:20 +01:00
|
|
|
Object.seal(scope);
|
|
|
|
}());
|