Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (nativeMsBrowser) {
- var nativeJSON = window.JSON;
- // These values should never be touched.
- const componentId_extensionTrident = 1;
- const componentId_backgroundHost = 2;
- const componentId_proxy = 3;
- const componentId_manager = 4;
- const componentId_ambassador = 5;
- const componentId_frame = 6;
- const componentId_frameTab = 7;
- const componentId_browserTab = 8;
- const componentId_tabTrident = 9;
- const componentId_contentScript = 10;
- const componentId_webRequest = 11;
- const Bhx_Broadcast = -2;
- const Bhx_TopMost = -3;
- const Bhx_Parent = -4;
- // These values are pulled from bhxmessages.h. You may notice they are in alphabetical order (hint, hint).
- const BHX_MSGTYPE_COURIER_START = 4092;
- const messageId_ReplyId = BHX_MSGTYPE_COURIER_START;
- const eventId_browserActionOnClicked = 9;
- const eventId_contextMenusOnClicked = 11;
- const eventId_pageActionOnClicked = 10;
- const eventId_pageEntitiesOnClicked = 3;
- const eventId_pageEntitiesOnDetected = 2;
- const eventId_storageOnChanged = 8;
- const eventId_tabsOnActivated = 1;
- const eventId_tabsOnCreated = 0;
- const eventId_tabsOnUpdated = 5;
- const eventId_windowsOnCreated = 4;
- const eventId_windowsOnRemoved = 6;
- const eventId_windowsOnFocusChanged = 7;
- const functionId_browserActionFrameDisable = BHX_MSGTYPE_COURIER_START + 19;
- const functionId_browserActionFrameEnable = BHX_MSGTYPE_COURIER_START + 18;
- const functionId_browserActionFrameTabDisable = BHX_MSGTYPE_COURIER_START + 12;
- const functionId_browserActionFrameTabEnable = BHX_MSGTYPE_COURIER_START + 11;
- const functionId_browserActionSetMultipleIcons = BHX_MSGTYPE_COURIER_START + 16;
- const functionId_contextMenusCreate = BHX_MSGTYPE_COURIER_START + 14;
- const functionId_detectLanguage = BHX_MSGTYPE_COURIER_START + 9;
- const functionId_getAllFrames = BHX_MSGTYPE_COURIER_START + 8;
- const functionId_getFrame = BHX_MSGTYPE_COURIER_START + 7;
- const functionId_notifyEventListener = BHX_MSGTYPE_COURIER_START + 10;
- const functionId_pageActionGetPopup = BHX_MSGTYPE_COURIER_START + 7;
- const functionId_pageActionGetTitle = BHX_MSGTYPE_COURIER_START + 5;
- const functionId_pageActionHide = BHX_MSGTYPE_COURIER_START + 3;
- const functionId_pageActionSetMultipleIcons = BHX_MSGTYPE_COURIER_START + 9;
- const functionId_pageActionSetPopup = BHX_MSGTYPE_COURIER_START + 6;
- const functionId_pageActionSetTitle = BHX_MSGTYPE_COURIER_START + 4;
- const functionId_pageActionShow = BHX_MSGTYPE_COURIER_START + 2;
- const functionId_storageLocalGet = BHX_MSGTYPE_COURIER_START + 17;
- const functionId_storageLocalRemove = BHX_MSGTYPE_COURIER_START + 24;
- const functionId_storageLocalSet = BHX_MSGTYPE_COURIER_START + 18;
- const functionId_tabsCreate = BHX_MSGTYPE_COURIER_START + 4;
- const functionId_tabsExecuteScriptResource = BHX_MSGTYPE_COURIER_START + 2;
- const functionId_tabsExecuteScriptSnippet = BHX_MSGTYPE_COURIER_START + 3;
- const functionId_tabsGet = BHX_MSGTYPE_COURIER_START + 8;
- const functionId_tabsInjectCssResource = BHX_MSGTYPE_COURIER_START + 4;
- const functionId_tabsInjectCssSnippet = BHX_MSGTYPE_COURIER_START + 5;
- const functionId_tabsQuery = BHX_MSGTYPE_COURIER_START + 7;
- const functionId_tabsQueryMultiple = BHX_MSGTYPE_COURIER_START + 13;
- const functionId_tabsRemove = BHX_MSGTYPE_COURIER_START + 10;
- const functionId_tabsRemoveMultiple = BHX_MSGTYPE_COURIER_START + 20;
- const functionId_tabsSendMessage = BHX_MSGTYPE_COURIER_START + 1;
- const functionId_windowsGet = BHX_MSGTYPE_COURIER_START + 8;
- const functionId_windowsGetAll = BHX_MSGTYPE_COURIER_START + 19;
- const functionId_windowsUpdate = BHX_MSGTYPE_COURIER_START + 17;
- // Synchronous function are from syncmethodhandler.h. They should also be kept in alphabetical order.
- const functionId_contextMenus_getNewMenuId = 1;
- const functionId_getIsInPrivate = 2;
- const functionId_getMessage = 3;
- const functionId_getUILanguage = 4;
- const functionId_permissionsCheckInternal = 5;
- const permissionId_contextMenus = 6;
- const permissionId_storage = 14;
- const permissionId_tabs = 10;
- const permissionId_webNavigation = 12;
- const permissionId_webRequest = 11;
- const permissionId_webRequestBlocking = 13;
- // API used constants
- const i18n_maxAllowedSubstitutions = 9;
- var storedCallbacks = [];
- var nextCallback = 0;
- var storedHandlers = [];
- Object.defineProperty(window, "msBrowser", {
- get: delayInitMsBrowser,
- configurable: true,
- enumerable: true
- });
- function delayInitMsBrowser() {
- var wrapMsBrowser = Object.defineProperties({}, {
- "browserAction": {
- get: delayInitBrowserAction,
- configurable: true,
- enumerable: true
- },
- "contextMenus": {
- get: delayInitContextMenus,
- configurable: true,
- enumerable: true
- },
- "extension": {
- get: delayInitExtension,
- configurable: true,
- enumerable: true
- },
- "i18n": {
- get: delayInitI18n,
- configurable: true,
- enumerable: true
- },
- "pageAction": {
- get: delayInitPageAction,
- configurable: true,
- enumerable: true
- },
- "pageEntities": {
- get: delayInitPageEntities,
- configurable: true,
- enumerable: true
- },
- "runtime": {
- get: delayInitRuntime,
- configurable: true,
- enumerable: true
- },
- "storage": {
- get: delayInitStorage,
- configurable: true,
- enumerable: true
- },
- "tabs": {
- get: delayInitTabs,
- configurable: true,
- enumerable: true
- },
- "windows": {
- get: delayInitWindows,
- configurable: true,
- enumerable: true
- },
- "webNavigation": {
- get: delayInitWebNavigation,
- configurable: true,
- enumerable: true
- },
- "webRequest": {
- get: delayInitWebRequest,
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window, "msBrowser", {
- value: wrapMsBrowser,
- configurable: true,
- enumerable: true
- });
- return wrapMsBrowser;
- }
- function delayInitBrowserAction()
- {
- var wrapBrowserAction = Object.defineProperties({}, {
- "setIcon": {
- value: browserAction_setIcon_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "enable": {
- value: browserAction_enable_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "disable": {
- value: browserAction_disable_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "onClicked": {
- get: delayInitOnClicked,
- configurable: true,
- enumerable: true
- }
- });
- function browserAction_setIcon_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("browserAction.setIcon", arguments, expectedArguments);
- var expectedProperties = [
- { type: "object", name: "imageData", optional: true },
- { type: "string or object", name: "path", optional: true, validator: function (value) {
- if (typeof(value) === "object") {
- var invalidProperties = "";
- var invalidValues = "";
- var propertyVerb = "is not a valid property";
- var valueVerb = "is not a string";
- for (var prop in value) {
- if (prop !== "19" && prop !== "20" && prop !== "25" && prop !== "30" && prop !== "38" && prop !== "40") {
- if (invalidProperties.length > 0) {
- invalidProperties += ", ";
- propertyVerb = "are not valid properties";
- }
- invalidProperties += "'" + prop + "'";
- } else if (typeof(value[prop]) !== "string") {
- if (invalidValues.length > 0) {
- invalidValues += ", ";
- valueVerb = "are not strings";
- }
- invalidValues += "'" + prop + "'";
- }
- }
- if (invalidProperties.length > 0) {
- invalidProperties += " " + propertyVerb + " in the dictionary";
- if (invalidValues.length > 0) {
- invalidProperties += " and ";
- }
- }
- if (invalidValues.length > 0) {
- invalidValues += " " + valueVerb;
- }
- if (invalidProperties.length > 0 || invalidValues.length > 0) {
- return invalidProperties + invalidValues;
- }
- }
- }},
- { type: "integer", name: "tabId", optional: true, validator: function (index) { if (index < 0) return "Value must not be less than 0"; } }];
- TestObjectProperties(0, arguments[0], expectedProperties);
- if (arguments[0].imageData && arguments[0].path) {
- throw "Error: Only one of imageData or path may be specified.";
- } else if (!(arguments[0].imageData) && !(arguments[0].path)) {
- throw "Error: One of imageData or path must be specified.";
- }
- var parameters;
- if (arguments[0].path && GetTypeName(arguments[0].path) === "object") {
- parameters = arguments[0].path;
- } else {
- parameters = { "20" : arguments[0].path };
- }
- if ("tabId" in arguments[0]) {
- parameters["tabId"] = arguments[0].tabId;
- }
- var destination = {};
- destination.component = componentId_frame;
- destination.frameId = Bhx_Broadcast;
- return ExecuteGenericFunction(functionId_browserActionSetMultipleIcons, destination, parameters, arguments.length == 2 ? arguments[1] : null);
- }
- function browserAction_enable_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId", optional: true } ];
- TestParameterTypes("browserAction.enable", arguments, expectedArguments);
- var parameters;
- var functionId;
- var destination = {};
- if (arguments && arguments.length == 1 && GetTypeName(arguments[0]) === "integer") {
- if (arguments[0] < 0) {
- ThrowArgumentError(0, "Value must not be less than 0");
- }
- parameters = { "tabId" : arguments[0] };
- functionId = functionId_browserActionFrameTabEnable;
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- destination.frameId = Bhx_Parent;
- } else {
- functionId = functionId_browserActionFrameEnable;
- destination.component = componentId_frame;
- destination.frameId = Bhx_Broadcast;
- }
- return ExecuteGenericFunction(functionId, destination, parameters, null);
- }
- function browserAction_disable_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId", optional: true } ];
- TestParameterTypes("browserAction.disable", arguments, expectedArguments);
- var parameters;
- var functionId;
- var destination = {};
- if (arguments && arguments.length == 1 && GetTypeName(arguments[0]) === "integer") {
- if (arguments[0] < 0) {
- ThrowArgumentError(0, "Value must not be less than 0");
- }
- parameters = { "tabId" : arguments[0] };
- functionId = functionId_browserActionFrameTabDisable;
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- destination.frameId = Bhx_Parent;
- } else {
- functionId = functionId_browserActionFrameDisable;
- destination.component = componentId_frame;
- destination.frameId = Bhx_Broadcast;
- }
- return ExecuteGenericFunction(functionId, destination, parameters, null);
- }
- function delayInitOnClicked() {
- var onClickedObject = StoreNoFilterHandler(eventId_browserActionOnClicked, function (sender, tabData, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](tabData);
- }
- }
- });
- var wrapOnClicked = Object.defineProperties({}, {
- "addListener": {
- value: onClickedObject.addListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onClickedObject.removeListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onClickedObject.hasListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.browserAction, "onClicked", {
- value: wrapOnClicked,
- configurable: true,
- enumerable: true
- });
- return wrapOnClicked;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "browserAction", {
- value: wrapBrowserAction,
- configurable: true,
- enumerable: true
- });
- return wrapBrowserAction;
- }
- function delayInitContextMenus() {
- var wrapContextMenus;
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_contextMenus);
- if (typeof(hasPermission) == "boolean" && hasPermission) {
- wrapContextMenus = Object.defineProperties({}, {
- "create": {
- value: contextMenus_create_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "onClicked": {
- get: delayInitOnClicked,
- configurable: true,
- enumerable: true
- },
- "ACTION_MENU_TOP_LEVEL_LIMIT": {
- value: 6,
- configurable: true,
- enumerable: true
- }
- });
- }
- function contextMenus_create_indirect() {
- var createProperties = arguments[0];
- var callback = arguments[1];
- var expectedArguments = [
- { type: "object", name: "createProperties" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("contextMenus.create", arguments, expectedArguments);
- var expectedProperties = [
- { type: "string", name: "type", optional: true, validator: function (value) {
- if (value !== "normal" && value !== "checkbox" && value !== "radio" && value !== "separator") {
- return "Value must be one of: [normal, checkbox, radio, separator]";
- }
- }},
- { type: "string", name: "id", optional: true },
- { type: "string", name: "title", optional: true },
- { type: "boolean", name: "checked", optional: true },
- { type: "array", name: "contexts", optional: true, validator: function (value) {
- if (value.length == 0) {
- return "contexts cannot be an empty array"
- }
- var valueError = false;
- for (var i = 0; i < value.length; i++) {
- if (typeof(value[i]) !== "string") {
- return "All items in the array must be strings";
- } else if (value[i] !== "all" && value[i] !== "page" && value[i] !== "frame" && value[i] !== "selection" &&
- value[i] !== "link" && value[i] !== "editable" && value[i] !== "image" && value[i] !== "video" &&
- value[i] !== "audio" && value[i] !== "launcher" && value[i] !== "browser_action" && value[i] !== "page_action") {
- valueError = true;
- }
- }
- if (valueError) {
- return "Each item's value must be one of: [all, page, frame, selection, link, editable, image, video, audio, launcher, browser_action, page_action]";
- }
- }},
- { type: "function", name: "onclick", optional: true },
- { type: "integer or string", name: "parentId", optional: true },
- { type: "array", name: "documentUrlPatterns", optional: true, validator: function (value) {
- for (var i = 0; i < value.length; i++) {
- if (typeof (value[i]) !== "string") {
- return "All items in the array must be strings";
- }
- else {
- try
- {
- validateUrlMatchPattern(value[i]);
- }
- catch (e) {
- return "Invalid url pattern '" + value[i] + "'";
- }
- }
- }
- }},
- { type: "array", name: "targetUrlPatterns", optional: true, validator: function (value) {
- for (var i = 0; i < value.length; i++) {
- if (typeof(value[i]) !== "string") {
- return "All items in the array must be strings";
- }
- else {
- try
- {
- validateUrlMatchPattern(value[i]);
- }
- catch (e) {
- return "Invalid url pattern '" + value[i] + "'";
- }
- }
- }
- }},
- { type: "boolean", name: "enabled", optional: true } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- if (arguments[0].type !== "separator" && !(arguments[0].title)) {
- throw "Error: A title must be set unless the type is separator.";
- }
- var menuItemId;
- if (createProperties.id)
- {
- menuItemId = createProperties.id;
- }
- else
- {
- var syncFunctionId = functionId_contextMenus_getNewMenuId;
- menuItemId = ExecuteGenericSynchronousFunction(syncFunctionId, null);
- if (menuItemId == 0) {
- throw "Error: Extensions using event pages must pass an id parameter to msBrowser.contextMenus.create.";
- }
- }
- createProperties.id = nativeJSON.stringify(menuItemId);
- if (createProperties.parentId)
- {
- createProperties.parentId = nativeJSON.stringify(createProperties.parentId);
- }
- var onclick = createProperties.onclick;
- if (onclick) {
- var onClickIndirect = function (info, tab) {
- if (info && info.menuItemId === menuItemId) {
- onclick(info, tab);
- }
- };
- window.msBrowser.contextMenus.onClicked.addListener(onClickIndirect);
- delete createProperties.onclick;
- }
- var destination = {};
- destination.component = componentId_manager;
- var parameters = createProperties;
- var functionId = functionId_contextMenusCreate;
- ExecuteGenericFunction(functionId, destination, parameters, arguments.length == 2 ? arguments[1] : null);
- return menuItemId;
- }
- function delayInitOnClicked() {
- var onClickedObject = StoreNoFilterHandler(eventId_contextMenusOnClicked, function (sender, allOnClickData, listeners) {
- var tab = nativeJSON.parse(allOnClickData.tabData);
- var tabOnClickData = nativeJSON.parse(allOnClickData.tabOnClickData);
- var menuItemOnClickData = nativeJSON.parse(allOnClickData.menuItemOnClickData);
- var info = {};
- info.menuItemId = nativeJSON.parse(menuItemOnClickData.menuItemId);
- if (menuItemOnClickData.parentMenuItemId) {
- info.parentMenuItemId = nativeJSON.parse(menuItemOnClickData.parentMenuItemId);
- }
- if (tabOnClickData.mediaType) {
- info.mediaType = tabOnClickData.mediaType;
- }
- if (tabOnClickData.linkUrl) {
- info.linkUrl = tabOnClickData.linkUrl;
- }
- if (tabOnClickData.srcUrl) {
- info.srcUrl = tabOnClickData.srcUrl;
- }
- if (tabOnClickData.pageUrl) {
- info.pageUrl = tabOnClickData.pageUrl;
- }
- if (tabOnClickData.frameUrl) {
- info.frameUrl = tabOnClickData.frameUrl;
- }
- if (tabOnClickData.selectionText) {
- info.selectionText = tabOnClickData.selectionText;
- }
- if (tabOnClickData.editable) {
- info.editable = tabOnClickData.editable;
- }
- if (typeof (menuItemOnClickData.wasChecked) !== "undefined") {
- info.wasChecked = nativeJSON.parse(menuItemOnClickData.wasChecked);
- }
- if (typeof (menuItemOnClickData.checked) !== "undefined") {
- info.checked = nativeJSON.parse(menuItemOnClickData.checked);
- }
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](info, tab);
- }
- }
- });
- var wrapOnClicked = Object.defineProperties({}, {
- "addListener": {
- value: onClickedObject.addListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onClickedObject.removeListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onClickedObject.hasListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.contextMenus, "onClicked", {
- value: wrapOnClicked,
- configurable: true,
- enumerable: true
- });
- return wrapOnClicked;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "contextMenus", {
- value: wrapContextMenus,
- configurable: true,
- enumerable: true
- });
- return wrapContextMenus;
- }
- function delayInitExtension() {
- var wrapExtension = Object.defineProperties({}, {
- "getURL": {
- value: extension_getURL_indirect.bind(nativeMsBrowser.extension),
- configurable: true,
- enumerable: true
- },
- "inPrivateContext": {
- get: extension_inPrivateContext_indirect,
- configurable: true,
- enumerable: true
- }
- });
- function extension_getURL_indirect() {
- var expectedArguments = [
- { type: "string", name: "path" } ];
- TestParameterTypes("extension.getURL", arguments, expectedArguments);
- return getURL_indirect.apply(this, arguments);
- }
- function extension_inPrivateContext_indirect() {
- var isInPrivate = false;
- var undef;
- var syncValue = ExecuteGenericSynchronousFunction(functionId_getIsInPrivate, undef);
- if (typeof(syncValue) == "boolean") {
- isInPrivate = syncValue;
- }
- return isInPrivate;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "extension", {
- value: wrapExtension,
- configurable: true,
- enumerable: true
- });
- return wrapExtension;
- }
- function delayInitI18n() {
- var wrapI18n = Object.defineProperties({}, {
- "getUILanguage": {
- get: i18n_getUILanguage_indirect,
- configurable: true,
- enumerable: true
- },
- "getMessage": {
- value: i18n_getMessage_indirect,
- configurable: true,
- enumerable: true
- }
- });
- function i18n_getUILanguage_indirect() {
- var UILanguage = "";
- var undef;
- var syncValue = ExecuteGenericSynchronousFunction(functionId_getUILanguage, undef);
- if (typeof (syncValue) == "string") {
- UILanguage = syncValue;
- }
- return UILanguage;
- }
- function i18n_getMessage_indirect() {
- var expectedArguments = [
- { type: "string", name: "messageName" },
- { type: "string or array", name: "substitutions", optional: true }];
- TestParameterTypes("i18n.getMessage", arguments, expectedArguments);
- var message = "";
- var messageName = null;
- var substCount = 0; // 0 if there's no substring
- if (arguments.length == 2) {
- if (GetTypeName(arguments[1]) === "array") {
- substCount = arguments[1].length;
- if (substCount > i18n_maxAllowedSubstitutions) {
- throw "Error: Substitution strings exceed maximum allowance";
- }
- for (var i = 0; i < substCount; i++) {
- if (typeof (arguments[0][i]) !== "string") {
- throw "Error: Invalid value for argument 1. All items in the array must be strings.";
- }
- }
- }
- else if (GetTypeName(arguments[1]) === "string") {
- substCount = 1;
- }
- }
- var parameters = {};
- parameters.messageName = arguments[0];
- parameters.substCount = substCount;
- parameters.substitutions = (substCount > 0) ? arguments[1] : null;
- var messageValue = ExecuteGenericSynchronousFunction(functionId_getMessage, parameters);
- if (typeof (messageValue) == "string") {
- message = messageValue;
- }
- return message;
- };
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "i18n", {
- value: wrapI18n,
- configurable: true,
- enumerable: true
- });
- return wrapI18n;
- }
- function delayInitPageAction()
- {
- var wrapPageAction = Object.defineProperties({}, {
- "getPopup": {
- value: pageAction_getPopup_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "getTitle": {
- value: pageAction_getTitle_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "hide": {
- value: pageAction_hide_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "setIcon": {
- value: pageAction_setIcon_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "setPopup": {
- value: pageAction_setPopup_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "setTitle": {
- value: pageAction_setTitle_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "show": {
- value: pageAction_show_indirect.bind(nativeMsBrowser.pageAction),
- configurable: true,
- enumerable: true
- },
- "onClicked": {
- get: delayInitOnClicked,
- configurable: true,
- enumerable: true
- }
- });
- function pageAction_getPopup_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback" } ];
- TestParameterTypes("pageAction.getPopup", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "tabId", validator: function (index) { if (index < 0) return "Value must not be less than 0"; } } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0].tabId;
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionGetPopup, destination, null, arguments[1]);
- }
- function pageAction_getTitle_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback" } ];
- TestParameterTypes("pageAction.getTitle", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "tabId", validator: function (index) { if (index < 0) return "Value must not be less than 0"; } } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0].tabId;
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionGetTitle, destination, null, arguments[1]);
- }
- function pageAction_hide_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId" } ];
- TestParameterTypes("pageAction.hide", arguments, expectedArguments);
- if (arguments[0] < 0) {
- throw "Error: Invalid value for argument 1. Value must not be less than 0."
- }
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionHide, destination, null, null);
- }
- function pageAction_setIcon_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("pageAction.setIcon", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "tabId", validator: function (index) { if (index < 0) return "Value must not be less than 0"; } },
- { type: "object", name: "imageData", optional: true },
- { type: "string or object", name: "path", optional: true, validator: function (value) {
- if (typeof(value) === "object") {
- var invalidProperties = "";
- var invalidValues = "";
- var propertyVerb = "is not a valid property";
- var valueVerb = "is not a string";
- for (var prop in value) {
- if (prop !== "19" && prop !== "20" && prop !== "25" && prop !== "30" && prop !== "38" && prop !== "40") {
- if (invalidProperties.length > 0) {
- invalidProperties += ", ";
- propertyVerb = "are not valid properties";
- }
- invalidProperties += "'" + prop + "'";
- } else if (typeof(value[prop]) !== "string") {
- if (invalidValues.length > 0) {
- invalidValues += ", ";
- valueVerb = "are not strings";
- }
- invalidValues += "'" + prop + "'";
- }
- }
- if (invalidProperties.length > 0) {
- invalidProperties += " " + propertyVerb + " in the dictionary";
- if (invalidValues.length > 0) {
- invalidProperties += " and ";
- }
- }
- if (invalidValues.length > 0) {
- invalidValues += " " + valueVerb;
- }
- if (invalidProperties.length > 0 || invalidValues.length > 0) {
- return invalidProperties + invalidValues;
- }
- }
- }},
- { type: "integer", name: "iconIndex", optional: true } ]; // Note: Does nothing in Microsoft Edge; required for compatibility
- TestObjectProperties(0, arguments[0], expectedProperties);
- if (arguments[0].imageData && arguments[0].path) {
- throw "Error: Only one of imageData or path may be specified.";
- } else if (!(arguments[0].imageData) && !(arguments[0].path)) {
- throw "Error: One of imageData or path must be specified.";
- }
- var parameters;
- if (arguments[0].path && GetTypeName(arguments[0].path) === "object") {
- parameters = arguments[0].path;
- } else {
- parameters = { "20" : arguments[0].path };
- }
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0].tabId;
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionSetMultipleIcons, destination, parameters, arguments.length == 2 ? arguments[1] : null);
- }
- function pageAction_setPopup_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" } ];
- TestParameterTypes("pageAction.setPopup", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "tabId", validator: function (index) { if (index < 0) return "Value must not be less than 0"; } },
- { type: "string", name: "popup" } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0].tabId;
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionSetPopup, destination, arguments[0].popup, null);
- }
- function pageAction_setTitle_indirect() {
- var expectedArguments = [
- { type: "object", name: "details" } ];
- TestParameterTypes("pageAction.setTitle", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "tabId", validator: function (index) { if (index < 0) return "Value must not be less than 0"; } },
- { type: "string", name: "title" } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0].tabId;
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionSetTitle, destination, arguments[0].title, null);
- }
- function pageAction_show_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId" } ];
- TestParameterTypes("pageAction.show", arguments, expectedArguments);
- if (arguments[0] < 0) {
- throw "Error: Invalid value for argument 1. Value must not be less than 0."
- }
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- destination.frameId = Bhx_Parent;
- return ExecuteGenericFunction(functionId_pageActionShow, destination, null, null);
- }
- function delayInitOnClicked() {
- var onClickedObject = StoreNoFilterHandler(eventId_pageActionOnClicked, function (sender, tabData, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](tabData);
- }
- }
- });
- var wrapOnClicked = Object.defineProperties({}, {
- "addListener": {
- value: onClickedObject.addListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onClickedObject.removeListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onClickedObject.hasListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.pageAction, "onClicked", {
- value: wrapOnClicked,
- configurable: true,
- enumerable: true
- });
- return wrapOnClicked;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "pageAction", {
- value: wrapPageAction,
- configurable: true,
- enumerable: true
- });
- return wrapPageAction;
- }
- function delayInitPageEntities() {
- var wrapPageEntities = Object.defineProperties({}, {
- "onClicked": {
- get: delayInitOnClicked,
- configurable: true,
- enumerable: true
- },
- "onDetected": {
- get: delayInitOnDetected,
- configurable: true,
- enumerable: true
- }
- });
- function delayInitOnClicked() {
- var onClickedObject = StoreNoFilterHandler(eventId_pageEntitiesOnClicked, function (sender, data, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](sender.tabId, data.entity, data.hitRect);
- }
- }
- });
- var wrapOnClicked = Object.defineProperties({}, {
- "addListener": {
- value: onClickedObject.addListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onClickedObject.removeListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onClickedObject.hasListener.bind(onClickedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.pageEntities, "onClicked", {
- value: wrapOnClicked,
- configurable: true,
- enumerable: true
- });
- return wrapOnClicked;
- };
- function delayInitOnDetected() {
- var onDetectedObject = StoreNoFilterHandler(eventId_pageEntitiesOnDetected, function (sender, data, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](sender.tabId, data);
- }
- }
- });
- var wrapOnDetected = Object.defineProperties({}, {
- "addListener": {
- value: onDetectedObject.addListener.bind(onDetectedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onDetectedObject.removeListener.bind(onDetectedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onDetectedObject.hasListener.bind(onDetectedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.pageEntities, "onDetected", {
- value: wrapOnDetected,
- configurable: true,
- enumerable: true
- });
- return wrapOnDetected;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "pageEntities", {
- value: wrapPageEntities,
- configurable: true,
- enumerable: true
- });
- return wrapPageEntities;
- }
- function delayInitRuntime() {
- var wrapRuntime = Object.defineProperties({}, {
- "getURL": {
- value: runtime_getURL_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "lastError": {
- get: runtime_lastError,
- configurable: true,
- enumerable: true
- },
- "onMessageExternal": {
- get: delayInitOnMessageExternal,
- configurable: true,
- enumerable: true
- },
- "sendMessage": {
- value: runtime_sendMessage_indirect.bind(nativeMsBrowser.runtime),
- configurable: true,
- enumerable: true
- },
- "onMessage": {
- get: delayInitOnMessage,
- configurable: true,
- enumerable: true
- }
- });
- function runtime_getURL_indirect() {
- var expectedArguments = [
- { type: "string", name: "path" } ];
- TestParameterTypes("runtime.getURL", arguments, expectedArguments);
- return getURL_indirect.apply(this, arguments);
- }
- function runtime_lastError() {
- return nativeMsBrowser.runtime.lastError;
- }
- function runtime_sendMessage_createCallback(responseCallback) {
- return function () {
- var jsonResponse = arguments[0];
- var response; // This is initialized to undefined.
- if (typeof(jsonResponse) !== "undefined" && jsonResponse !== "undefined") {
- // JSON.stringify(undefined) === undefined is packed for courier messaging as 'undefined' but JSON.parse('undefined') throws javascript error.
- // A response of "undefined" (type string) is packed for courier messaging as '"undefined"', hence will not conflict with a response of undefined (type undefined).
- response = nativeJSON.parse(jsonResponse);
- }
- responseCallback(response);
- }
- }
- function runtime_sendMessage_indirect() {
- var expectedArguments = [
- { type: "string", name: "extensionId", optional: true },
- { type: "any", name: "message" },
- { type: "object", name: "options", optional: true },
- { type: "function", name: "responseCallback", optional: true } ];
- TestParameterTypes("runtime.sendMessage", arguments, expectedArguments);
- var index = arguments.length - 1;
- var responseCallback = null;
- if (typeof arguments[index] === "function") {
- responseCallback = runtime_sendMessage_createCallback(arguments[index]);
- --index;
- }
- var options = null;
- if (index >= 2) {
- // More than two arguments remain so options param must be present.
- options = arguments[index];
- --index;
- } else if (index === 1) {
- // The logic: assume that the first param is the optional extension id if it is present and is a string, hence no options argument in this case.
- if (!TestArgumentType(typeof(arguments[0]), "string or null or undefined")) {
- options = arguments[index];
- --index;
- }
- }
- if (options) {
- var expectedProperties = [
- { type: "boolean", name: "includeTlsChannelId", optional: true } ]; // Note: Does nothing in Microsoft Edge; required for compatibility
- TestObjectProperties(index, options, expectedProperties);
- }
- var message = arguments[index]; // Must be present.
- --index;
- var extensionId = null;
- if (index >= 0) {
- extensionId = arguments[index];
- --index;
- }
- if (index !== -1) {
- // This should have been caught by TestParameterTypes, but don't leave the developer hanging.
- ThrowTypeError("runtime.sendMessage", arguments, expectedArguments);
- } else {
- // Always stringify on sendMessage side and always parse on the callback side.
- // Otherwise, callback cannot distinuish between a message sending an object and another message sending its string equivalent.
- return nativeMsBrowser.runtime.sendMessage(extensionId, nativeJSON.stringify(message), options, responseCallback);
- }
- }
- function runtime_messagingListener_createCallback(callback) {
- return function () {
- var result = {};
- function sendResponse(response) {
- result.response = nativeJSON.stringify(response);
- }
- var msg = nativeJSON.parse(arguments[0]);
- result.async = callback(msg, arguments[1], sendResponse.bind(window)) ? true : false;
- return result;
- // Need to handle sending the response async - http://osgvsowi/674353
- }
- }
- function delayInitOnMessage() {
- var wrapOnMessage = Object.defineProperties({}, {
- "addListener": {
- value: runtime_onMessage_addListener_indirect.bind(nativeMsBrowser.runtime.onMessage),
- configurable: true,
- enumerable: true
- }
- });
- function runtime_onMessage_addListener_indirect(callback) {
- TestListenerArguments(arguments);
- nativeMsBrowser.runtime.onMessage.addListener(runtime_messagingListener_createCallback(callback));
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.runtime, "onMessage", {
- value: wrapOnMessage,
- configurable: true,
- enumerable: true
- });
- return wrapOnMessage;
- }
- function delayInitOnMessageExternal() {
- var wrapOnMessageExternal = Object.defineProperties({}, {
- "addListener": {
- value: runtime_onMessageExternal_addListener_indirect.bind(nativeMsBrowser.runtime.onMessageExternal),
- configurable: true,
- enumerable: true
- }
- });
- function runtime_onMessageExternal_addListener_indirect(callback) {
- TestListenerArguments(arguments);
- nativeMsBrowser.runtime.onMessageExternal.addListener(runtime_messagingListener_createCallback(callback));
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.runtime, "onMessageExternal", {
- value: wrapOnMessageExternal,
- configurable: true,
- enumerable: true
- });
- return wrapOnMessageExternal;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "runtime", {
- value: wrapRuntime,
- configurable: true,
- enumerable: true
- });
- return wrapRuntime;
- }
- function delayInitStorage() {
- var wrapStorage;
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_storage);
- if (typeof(hasPermission) == "boolean" && hasPermission) {
- wrapStorage = Object.defineProperties({}, {
- "local": {
- get: delayInitLocal,
- configurable: true,
- enumerable: true
- },
- "onChanged": {
- get: delayInitOnChanged,
- configurable: true,
- enumerable: true
- }
- });
- }
- function parseValueFromStorage(value) {
- // TODO: handle regex http://osgvsowi/2521658
- if ((typeof (value) === "string") && (value.substr(0, 5) === "Date:")) {
- return new Date(JSON.parse(value.substr(5)));
- } else if (typeof (value) === "string") {
- // Everything else uses JSON
- return JSON.parse(value);
- }
- // implicitly return undefined if value wasn't a string
- }
- function delayInitLocal() {
- var wrapLocal = Object.defineProperties({}, {
- "clear": {
- value: storage_local_clear_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "get": {
- value: storage_local_get_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "getBytesInUse": {
- value: storage_local_getBytesInUse_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "remove": {
- value: storage_local_remove_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "set": {
- value: storage_local_set_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- }
- });
- function TransformValuesForManager(items) {
- var keys = Object.keys(items);
- var values = {};
- for (var i = 0; i < keys.length; i++) {
- var value = items[keys[i]];
- // TODO: handle regex http://osgvsowi/2521658
- if (value instanceof Date) {
- values[keys[i]] = "Date:" + JSON.stringify(value);
- } else if (typeof value === "function") {
- // Handle functions
- values[keys[i]] = "{}";
- } else {
- // All others use JSON
- values[keys[i]] = JSON.stringify(value);
- }
- }
- return values;
- }
- function storage_local_clear_indirect() {
- // TODO (brentcou): http://osgvsowi/319342, implement storage.local.clear
- }
- function storage_local_get_indirect() {
- var expectedArguments = [
- { type: "string or array or object", name: "keys", optional: true },
- { type: "function", name: "callback" }];
- TestParameterTypes("storage.local.get", arguments, expectedArguments);
- if (GetTypeName(arguments[0]) === "array") {
- for (var i = 0; i < arguments[0].length; i++) {
- if (typeof (arguments[0][i]) !== "string") {
- ThrowArgumentError(0, "All items in the array must be strings");
- }
- }
- }
- var keys = null;
- var callbackIndex = 0;
- if (arguments.length == 2) {
- keys = arguments[0];
- callbackIndex = 1;
- }
- if (GetTypeName(keys) === "string") {
- // convert the single string case to an array with one element to simplify back end processing
- keys = [keys];
- }
- if (GetTypeName(keys) === "object") {
- // if it is an object, then the values need transforming the same way they do on set.
- keys = TransformValuesForManager(keys);
- }
- var callback = arguments[callbackIndex];
- var getCallbackWrapper = function (serializedItems) {
- var items = {};
- for (var key in serializedItems) {
- items[key] = parseValueFromStorage(serializedItems[key]);
- }
- callback(items);
- }
- return ExecuteGenericFunction(
- functionId_storageLocalGet,
- { component: componentId_manager },
- keys,
- getCallbackWrapper);
- };
- function storage_local_getBytesInUse_indirect() {
- // TODO (brentcou): http://osgvsowi/319318, implement storage.local.getBytesInUse
- }
- function storage_local_remove_indirect() {
- var expectedArguments = [
- { type: "string or array", name: "keys" },
- { type: "function", name: "callback", optional: true }];
- TestParameterTypes("storage.local.remove", arguments, expectedArguments);
- if (GetTypeName(arguments[0]) === "array") {
- for (var i = 0; i < arguments[0].length; i++) {
- if (typeof (arguments[0][i]) !== "string") {
- ThrowArgumentError(0, "All items in the array must be strings");
- }
- }
- }
- var keys = arguments[0];
- if (GetTypeName(keys) === "string") {
- // convert the single string case to an array with one element to simplify back end processing
- keys = [keys];
- }
- var responseCallback = arguments.length > 1 ? arguments[1] : null;
- return ExecuteGenericFunction(
- functionId_storageLocalRemove,
- { component: componentId_manager },
- keys,
- responseCallback);
- }
- function storage_local_set_indirect() {
- var expectedArguments = [
- { type: "object", name: "items" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("storage.local.set", arguments, expectedArguments);
- var values = TransformValuesForManager(arguments[0]);
- var responseCallback = arguments.length > 1 ? arguments[1] : null;
- return ExecuteGenericFunction(
- functionId_storageLocalSet,
- { component: componentId_manager },
- values,
- responseCallback);
- };
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.storage, "local", {
- value: wrapLocal,
- configurable: true,
- enumerable: true
- });
- return wrapLocal;
- }
- function delayInitOnChanged() {
- var onChangedObject = StoreNoFilterHandler(eventId_storageOnChanged, function (sender, storageChangeData, listeners) {
- var changes = {};
- for (var key in storageChangeData.changes) {
- var changeData = storageChangeData.changes[key];
- var parsedChangeData = {};
- parsedChangeData.oldValue = parseValueFromStorage(changeData.oldValue);
- parsedChangeData.newValue = parseValueFromStorage(changeData.newValue);
- changes[key] = parsedChangeData;
- }
- for (var i = 0; i < listeners.length; i++) {
- if (typeof (listeners[i]) == "function") {
- listeners[i](changes, "local");
- }
- }
- });
- var wrapOnChanged = Object.defineProperties({}, {
- "addListener": {
- value: onChangedObject.addListener.bind(onChangedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onChangedObject.removeListener.bind(onChangedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onChangedObject.hasListener.bind(onChangedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.storage, "onChanged", {
- value: wrapOnChanged,
- configurable: true,
- enumerable: true
- });
- return wrapOnChanged;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "storage", {
- value: wrapStorage,
- configurable: true,
- enumerable: true
- });
- return wrapStorage;
- }
- function delayInitTabs() {
- var wrapTabs = Object.defineProperties({}, {
- "create": {
- value: tabs_create_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "executeScript": {
- value: tabs_executeScript_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "get": {
- value: tabs_get_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "getCurrent": {
- value: tabs_getCurrent_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "insertCSS": {
- value: tabs_insertCSS_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "query": {
- value: tabs_query_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "remove": {
- value: tabs_remove_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "sendMessage": {
- value: tabs_sendMessage_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "detectLanguage": {
- value: tabs_detectLanguage_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "onActivated": {
- get: delayInitOnActivated,
- configurable: true,
- enumerable: true
- },
- "onCreated": {
- get: delayInitOnCreated,
- configurable: true,
- enumerable: true
- },
- "onUpdated": {
- get: delayInitOnUpdated,
- configurable: true,
- enumerable: true
- }
- });
- function tabs_create_indirect() {
- var expectedArguments = [
- { type: "object", name: "createProperties" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("tabs.create", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "windowId", optional: true, validator: function (index) { if (index < -2) return "Value must not be less than -2"; } },
- { type: "integer", name: "index", optional: true, validator: function (index) { if (index < 0) return "Value must not be less than 0"; } },
- { type: "string", name: "url", optional: true },
- { type: "boolean", name: "active", optional: true },
- { type: "boolean", name: "selected", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "boolean", name: "pinned", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "integer", name: "openerTabId", optional: true } ]; // Note: Does nothing in Microsoft Edge; required for compatibility
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- destination.component = componentId_frame;
- if (arguments[0].windowId && arguments[0].windowId > -2) {
- destination.frameId = arguments[0].windowId;
- }
- var parameters = {};
- parameters.url = arguments[0].url || null;
- parameters.active = (GetTypeName(arguments[0].active) === "boolean" ? arguments[0].active : true);
- parameters.index = (GetTypeName(arguments[0].index) === "integer" ? arguments[0].index : -1);
- return ExecuteGenericFunction(functionId_tabsCreate, destination, parameters, arguments.length == 2 ? arguments[1] : null);
- }
- function tabs_detectLanguage_indirect(tabId, callback) {
- var tabId = arguments[0];
- var callback = arguments[1];
- var expectedArguments = [
- { type: "integer", name: "tabId" },
- { type: "function", name: "callback" }];
- TestParameterTypes("tabs.get", arguments, expectedArguments);
- if (arguments[0] < 0) {
- throw "Error: Invalid value for argument 1. Value must not be less than 0.";
- }
- // Setup the message to native code and register the JS callback function
- var destination = {};
- destination.component = componentId_tabTrident;
- destination.tabId = tabId;
- destination.frameId = Bhx_Parent;
- var parameters; // detectLanguages only needs the tabId
- var functionId = functionId_detectLanguage;
- return ExecuteGenericFunction(functionId, destination, parameters, callback);
- }
- function tabs_executeScript_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId", optional: true },
- { type: "object", name: "details" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("tabs.executeScript", arguments, expectedArguments);
- // This is required because there are optional arguments followed by mandatory ones.
- var detailsIndex = 1;
- if (arguments.length === 1 || GetTypeName(arguments[0]) === "object") {
- // If there is only one argument, or the first argument is an object, we should assume it is the details.
- detailsIndex = 0;
- }
- var details = arguments[detailsIndex];
- var tabId = detailsIndex > 0 ? arguments[detailsIndex - 1] : null;
- var callback = detailsIndex + 1 < arguments.length ? arguments[detailsIndex + 1] : null;
- if (GetTypeName(tabId) === "integer" && tabId < 0) {
- ThrowArgumentError(detailsIndex - 1, "Value must not be less than 0")
- }
- var expectedProperties = [
- { type: "string", name: "code", optional: true },
- { type: "string", name: "file", optional: true },
- { type: "boolean", name: "allFrames", optional: true },
- { type: "boolean", name: "matchAboutBlank", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "string", name: "runAt", optional: true, validator: function (value) {
- if (value !== "document_start" && value !== "document_end" && value !== "document_idle") {
- return "Value must be one of: [document_start, document_end, document_idle]";
- }
- }}];
- TestObjectProperties(detailsIndex, details, expectedProperties);
- var destination = {};
- destination.component = componentId_contentScript;
- destination.tabId = tabId;
- destination.frameId = GetTypeName(tabId) === "integer" ? Bhx_Parent : null;
- destination.extensionId = nativeMsBrowser.getExtensionId();
- var parameters = {};
- parameters.allFrames = details.allFrames || false;
- // Note: we ignore the run-at, since we always inject immediately
- if (details["file"] && details["code"]) {
- throw "Error: Code and file should not be specified at the same time in the second argument.";
- } else if ("file" in details) {
- parameters.file = details.file;
- ExecuteGenericFunction(functionId_tabsExecuteScriptResource, destination, parameters, callback);
- } else if ("code" in details) {
- parameters.code = details.code;
- ExecuteGenericFunction(functionId_tabsExecuteScriptSnippet, destination, parameters, callback);
- } else {
- throw "Error: No source code or file specified.";
- }
- }
- function tabs_get_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId" },
- { type: "function", name: "callback" } ];
- TestParameterTypes("tabs.get", arguments, expectedArguments);
- if (arguments[0] < 0) {
- throw "Error: Invalid value for argument 1. Value must not be less than 0.";
- }
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- destination.frameId = Bhx_Parent;
- var parameter;
- return ExecuteGenericFunction(functionId_tabsGet, destination, parameter, arguments[1]);
- }
- function tabs_getCurrent_indirect() {
- var expectedArguments = [
- { type: "function", name: "callback" } ];
- TestParameterTypes("tabs.getCurrent", arguments, expectedArguments);
- var destination = {};
- destination.component = componentId_frameTab;
- destination.tabId = Bhx_Parent;
- destination.frameId = Bhx_Parent;
- var parameter;
- return ExecuteGenericFunction(functionId_tabsGet, destination, parameter, arguments[0]);
- }
- function tabs_insertCSS_indirect() {
- var expectedArguments = [
- { type: "integer", name: "tabId", optional: true },
- { type: "object", name: "details" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("tabs.insertCSS", arguments, expectedArguments);
- // This is required because there are optional arguments followed by mandatory ones.
- var detailsIndex = 1;
- if (arguments.length === 1 || GetTypeName(arguments[0]) === "object") {
- // If there is only one argument, or the first argument is an object, we should assume it is the details.
- detailsIndex = 0;
- }
- var details = arguments[detailsIndex];
- var tabId = detailsIndex > 0 ? arguments[detailsIndex - 1] : null;
- var callback = detailsIndex + 1 < arguments.length ? arguments[detailsIndex + 1] : null;
- if (GetTypeName(tabId) === "integer" && tabId < 0) {
- ThrowArgumentError(detailsIndex - 1, "Value must not be less than 0")
- }
- var expectedProperties = [
- { type: "string", name: "code", optional: true },
- { type: "string", name: "file", optional: true },
- { type: "boolean", name: "allFrames", optional: true },
- { type: "boolean", name: "matchAboutBlank", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "string", name: "runAt", optional: true, validator: function (value) {
- if (value !== "document_start" && value !== "document_end" && value !== "document_idle") {
- return "Value must be one of: [document_start, document_end, document_idle]";
- }
- }}];
- TestObjectProperties(detailsIndex, details, expectedProperties);
- var destination = {};
- destination.component = componentId_contentScript;
- destination.tabId = tabId;
- destination.frameId = GetTypeName(tabId) === "integer" ? Bhx_Parent : null;
- destination.extensionId = nativeMsBrowser.getExtensionId();
- var parameters = {};
- parameters.allFrames = details.allFrames || false;
- // Note: we ignore the run-at, since we always inject immediately
- if (details["file"] && details["code"]) {
- throw "Error: Code and file should not be specified at the same time in the second argument.";
- } else if ("file" in details) {
- parameters.file = details.file;
- ExecuteGenericFunction(functionId_tabsInjectCssResource, destination, parameters, callback);
- } else if ("code" in details) {
- parameters.code = details.code;
- ExecuteGenericFunction(functionId_tabsInjectCssSnippet, destination, parameters, callback);
- } else {
- throw "Error: No source code or file specified.";
- }
- }
- function tabs_query_indirect() {
- var expectedArguments = [
- { type: "object", name: "queryInfo" },
- { type: "function", name: "callback" } ];
- TestParameterTypes("tabs.query", arguments, expectedArguments);
- var expectedProperties = [
- { type: "boolean", name: "active", optional: true },
- { type: "boolean", name: "pinned", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "boolean", name: "highlighted", optional: true }, // Note: Does nothing in Microsoft Edge; required for compatibility
- { type: "boolean", name: "currentWindow", optional: true },
- { type: "boolean", name: "lastFocusedWindow", optional: true },
- { type: "string", name: "status", optional: true, validator: function (value) {
- if (value !== "loading" && value !== "complete") {
- return "Value must be one of: [loading, complete]";
- }
- }},
- { type: "string", name: "title", optional: true },
- { type: "string or array", name: "url", optional: true, validator: function (value) {
- if (typeof(value) !== "string") {
- for (var i = 0; i < value.length; i++) {
- if (typeof(value[i]) !== "string") {
- return "All items in the array must be strings";
- }
- }
- }
- }},
- { type: "integer", name: "windowId", optional: true, validator: function (index) { if (index < -2) return "Value must not be less than -2"; } },
- { type: "string", name: "windowType", optional: true, validator: function (value) {
- if (value !== "normal" && value !== "popup" && value !== "panel" && value !== "app") {
- return "Value must be one of: [normal, popup, panel, app]";
- }
- }},
- { type: "integer", name: "index", optional: true, validator: function (index) { if (index < 0) return "Value must not be less than 0"; } } ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- var destination = {};
- var windowIdWantsCurrentWindow = false;
- if (GetTypeName(arguments[0].windowId) === "integer") {
- if (arguments[0].windowId == -2) {
- windowIdWantsCurrentWindow = true;
- } else if (arguments[0].windowId >= 0) {
- destination.frameId = arguments[0].windowId;
- }
- }
- var parameters = {};
- if (GetTypeName(arguments[0].lastFocusedWindow) === "boolean") {
- parameters.lastFocusedWindow = arguments[0].lastFocusedWindow;
- }
- // Check for any contradictions.
- var contradictionFound = false;
- if (GetTypeName(arguments[0].currentWindow) === "boolean" || windowIdWantsCurrentWindow) {
- if (GetTypeName(arguments[0].currentWindow) === "boolean" && !(arguments[0].currentWindow) && windowIdWantsCurrentWindow) {
- contradictionFound = true;
- } else {
- var currentWindowId = nativeMsBrowser.currentWindowId();
- if (windowIdWantsCurrentWindow || arguments[0].currentWindow) {
- if (currentWindowId == Bhx_TopMost) {
- // This means we're looking for the last focused window.
- if (parameters.hasOwnProperty("lastFocusedWindow") && !parameters.lastFocusedWindow) {
- contradictionFound = true;
- } else {
- parameters.lastFocusedWindow = true;
- }
- } else {
- // We want a specific window.
- if (currentWindowId != destination.frameId) {
- contradictionFound = true;
- } else {
- destination.frameId = currentWindowId;
- }
- }
- } else {
- if (currentWindowId == Bhx_TopMost) {
- // This means we're avoiding the last focused window.
- if (parameters.hasOwnProperty("lastFocusedWindow") && parameters.lastFocusedWindow) {
- contradictionFound = true;
- } else {
- parameters.lastFocusedWindow = false;
- }
- } else {
- // We're avoiding a specific window.
- if (!(destination.hasOwnProperty("frameId"))) {
- parameters.windowToAvoid = currentWindowId;
- } else if (currentWindowId == destination.frameId) {
- contradictionFound = true;
- }
- }
- }
- }
- }
- if (contradictionFound) {
- // If we've found a contradiction return an empty array.
- arguments[1]([]);
- return;
- }
- if (GetTypeName(arguments[0].windowType) === "string") {
- if (arguments[0].windowType == "panel" || arguments[0].windowType == "app") {
- // These window types don't exist for Microsoft Edge. They will find no tabs.
- arguments[1]([]);
- return;
- } else {
- parameters.inPopupWindow = (arguments[0].windowType == "popup");
- }
- }
- if (GetTypeName(arguments[0].active) === "boolean") {
- parameters.active = arguments[0].active;
- }
- if (GetTypeName(arguments[0].status) === "string") {
- parameters.isLoading = (arguments[0].status == "loading");
- }
- if (GetTypeName(arguments[0].index) === "integer") {
- parameters.index = arguments[0].index;
- }
- callbackCheckParameters = {};
- if (GetTypeName(arguments[0].url) === "string") {
- callbackCheckParameters.url = [ arguments[0].url ];
- } else if (GetTypeName(arguments[0].url) === "array") {
- callbackCheckParameters.url = arguments[0].url;
- }
- if (GetTypeName(arguments[0].title) === "string") {
- callbackCheckParameters.title = arguments[0].title;
- }
- var functionId;
- if (destination.hasOwnProperty("frameId")) {
- destination.component = componentId_frame;
- functionId = functionId_tabsQuery;
- } else if (parameters.lastFocusedWindow) {
- // It must be both existent and true.
- destination.component = componentId_frame;
- destination.frameId = Bhx_TopMost;
- functionId = functionId_tabsQuery;
- delete parameters.lastFocusedWindow;
- } else {
- destination.component = componentId_manager;
- functionId = functionId_tabsQueryMultiple;
- }
- var callback = arguments[1];
- var callbackWrapper = function (tabArray) {
- if (tabArray) {
- if (callbackCheckParameters.url) {
- for (var i = 0; i < callbackCheckParameters.url.length; i++) {
- for (var j = tabArray.length - 1; j >= 0; j--) {
- if (!nativeMsBrowser.checkMatchesUriExpression(callbackCheckParameters.url[i], tabArray[j].url)) {
- tabArray.splice(j, 1);
- }
- }
- }
- }
- if (callbackCheckParameters.title) {
- for (var j = tabArray.length - 1; j >= 0; j--) {
- if (!nativeMsBrowser.checkMatchesGlobExpression(callbackCheckParameters.title, tabArray[j].title)) {
- tabArray.splice(j, 1);
- }
- }
- }
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_tabs);
- if (typeof(hasPermission) != "boolean" || !hasPermission) {
- for (var j = tabArray.length - 1; j >= 0; j--) {
- delete tabArray[j].title;
- delete tabArray[j].url;
- }
- }
- }
- callback(tabArray);
- };
- return ExecuteGenericFunction(functionId, destination, parameters, callbackWrapper);
- }
- function tabs_remove_indirect() {
- var expectedArguments = [
- { type: "integer or array", name: "tabIds" },
- { type: "function", name: "callback", optional: true } ];
- TestParameterTypes("tabs.remove", arguments, expectedArguments);
- if (GetTypeName(arguments[0]) === "integer") {
- if (arguments[0] < 0) {
- throw "Error: Invalid value for argument 1. Value must not be less than 0.";
- }
- } else {
- for (var i = 0; i < arguments[0].length; i++) {
- if (GetTypeName(arguments[0][i]) !== "integer" || arguments[0][i] < 0) {
- throw "Error: Invalid value for argument 1. Each tab id must be a positive integer.";
- }
- }
- }
- var destination = {};
- var parameters;
- var functionId;
- if (GetTypeName(arguments[0]) === "integer") {
- destination.component = componentId_frameTab;
- destination.tabId = arguments[0];
- functionId = functionId_tabsRemove;
- } else {
- destination.component = componentId_manager;
- parameters = arguments[0]; // The manager will need to handle this. http://osgvsowi/3629377
- functionId = functionId_tabsRemoveMultiple;
- }
- return ExecuteGenericFunction(functionId, destination, parameters, arguments.length == 2 ? arguments[1] : null);
- }
- function tabs_sendMessage_createCallback(responseCallback) {
- return function () {
- var jsonResponse = arguments[0];
- var response; // This is initialized to undefined.
- if (jsonResponse && jsonResponse !== 'undefined') {
- // JSON.stringify(undefined) === undefined is packed for courier messaging as 'undefined' but JSON.parse('undefined') throws javascript error.
- // A response of "undefined" (type string) is packed for courier messaging as '"undefined"', hence will not conflict with a response of undefined (type undefined).
- response = nativeJSON.parse(jsonResponse);
- }
- responseCallback(response);
- }
- }
- function tabs_sendMessage_indirect(tabId, message, options, callback) {
- var expectedArguments = [
- { type: "integer", name: "tabId" },
- { type: "any", name: "message" },
- { type: "object", name: "options", optional: true },
- { type: "function", name: "responseCallback", optional: true } ];
- TestParameterTypes("tabs.executeScript", arguments, expectedArguments);
- if (typeof options === "function")
- {
- callback = options;
- options = null;
- }
- var responseCallback;
- if (typeof callback === "function")
- {
- responseCallback = tabs_sendMessage_createCallback(callback);
- }
- if (options) {
- var expectedProperties = [
- { type: "integer", name: "frameId", optional: true } ];
- TestObjectProperties(2, options, expectedProperties);
- }
- var destination = {};
- destination.component = componentId_contentScript;
- destination.tabId = tabId;
- destination.frameId = Bhx_Parent;
- destination.extensionId = nativeMsBrowser.getExtensionId();
- messageData = {};
- messageData.msg = nativeJSON.stringify(message);
- messageData.sender = { id: nativeMsBrowser.getExtensionId() };
- parameters = {};
- parameters.message = nativeJSON.stringify(messageData);
- if (options && GetTypeName(options.frameId) === "integer") {
- parameters.frameId = options.frameId;
- }
- ExecuteGenericFunction(functionId_tabsSendMessage, destination, parameters, responseCallback);
- }
- function delayInitOnActivated() {
- var onActivatedObject = StoreNoFilterHandler(eventId_tabsOnActivated, function (sender, tabId, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](tabId);
- }
- }
- });
- var wrapOnActivated = Object.defineProperties({}, {
- "addListener": {
- value: onActivatedObject.addListener.bind(onActivatedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onActivatedObject.removeListener.bind(onActivatedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onActivatedObject.hasListener.bind(onActivatedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.tabs, "onActivated", {
- value: wrapOnActivated,
- configurable: true,
- enumerable: true
- });
- return wrapOnActivated;
- }
- function delayInitOnCreated() {
- var onCreatedObject = StoreNoFilterHandler(eventId_tabsOnCreated, function (sender, tabData, listeners) {
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_tabs);
- if (typeof(hasPermission) != "boolean" || !hasPermission) {
- delete tabData.title;
- delete tabData.url;
- }
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](tabData);
- }
- }
- });
- var wrapOnCreated = Object.defineProperties({}, {
- "addListener": {
- value: onCreatedObject.addListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onCreatedObject.removeListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onCreatedObject.hasListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.tabs, "onCreated", {
- value: wrapOnCreated,
- configurable: true,
- enumerable: true
- });
- return wrapOnCreated;
- }
- function delayInitOnUpdated() {
- var onUpdatedObject = StoreNoFilterHandler(eventId_tabsOnUpdated, function (sender, updateData, listeners) {
- if (updateData.tabData && updateData.changeType) {
- var changeInfo = {};
- if (updateData.changeType === "url") {
- changeInfo.url = updateData.tabData.url;
- } else if (updateData.changeType === "status") {
- changeInfo.status = updateData.tabData.status;
- }
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_tabs);
- if (typeof(hasPermission) != "boolean" || !hasPermission) {
- delete updateData.tabData.title;
- delete updateData.tabData.url;
- }
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](updateData.tabData.id, changeInfo, updateData.tabData);
- }
- }
- }
- });
- var wrapOnUpdated = Object.defineProperties({}, {
- "addListener": {
- value: onUpdatedObject.addListener.bind(onUpdatedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onUpdatedObject.removeListener.bind(onUpdatedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onUpdatedObject.hasListener.bind(onUpdatedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.tabs, "onUpdated", {
- value: wrapOnUpdated,
- configurable: true,
- enumerable: true
- });
- return wrapOnUpdated;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "tabs", {
- value: wrapTabs,
- configurable: true,
- enumerable: true
- });
- return wrapTabs;
- }
- function delayInitWindows()
- {
- var wrapWindows = Object.defineProperties({}, {
- "get": {
- value: windows_get_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "getCurrent": {
- value: windows_getCurrent_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "getLastFocused": {
- value: windows_getLastFocused_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "getAll": {
- value: windows_getAll_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "create": {
- value: windows_create_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "update": {
- value: windows_update_indirect.bind(nativeMsBrowser),
- configurable: true,
- enumerable: true
- },
- "onCreated": {
- get: delayInitOnCreated,
- configurable: true,
- enumerable: true
- },
- "onRemoved": {
- get: delayInitOnRemoved,
- configurable: true,
- enumerable: true
- },
- "onFocusChanged": {
- get: delayInitOnFocusChanged,
- configurable: true,
- enumerable: true
- },
- "WINDOW_ID_NONE": {
- value: -1,
- configurable: true,
- enumerable: true
- },
- "WINDOW_ID_CURRENT": {
- value: -2,
- configurable: true,
- enumerable: true
- }
- });
- function windows_get_indirect() {
- var expectedArguments = [
- { type: "integer", name: "windowId" },
- { type: "object", name: "getInfo", optional: true },
- { type: "function", name: "callback" } ];
- TestParameterTypes("windows.get", arguments, expectedArguments);
- var callback = arguments[1];
- var parameters = null;
- if (GetTypeName(arguments[1]) === "object") {
- var expectedProperties = [
- { type: "boolean", name: "populate", optional: true }];
- TestObjectProperties(1, arguments[1], expectedProperties);
- callback = arguments[2];
- parameters = arguments[1];
- }
- var destination = {};
- destination.component = componentId_frame;
- destination.frameId = arguments[0];
- return ExecuteGenericFunction(functionId_windowsGet, destination, parameters, callback);
- }
- function windows_getCurrent_indirect() {
- var expectedArguments = [
- { type: "object", name: "getInfo", optional: true },
- { type: "function", name: "callback" } ];
- TestParameterTypes("windows.getCurrent", arguments, expectedArguments);
- var callback = arguments[0];
- var parameters = null;
- if (GetTypeName(arguments[0]) === "object") {
- var expectedProperties = [
- { type: "boolean", name: "populate", optional: true }];
- TestObjectProperties(0, arguments[0], expectedProperties);
- callback = arguments[1];
- parameters = arguments[0];
- }
- var destination = {};
- destination.component = componentId_frame;
- destination.frameId = nativeMsBrowser.currentWindowId();
- return ExecuteGenericFunction(functionId_windowsGet, destination, parameters, callback);
- }
- function windows_getLastFocused_indirect() {
- var expectedArguments = [
- { type: "object", name: "getInfo", optional: true },
- { type: "function", name: "callback" } ];
- TestParameterTypes("windows.getCurrent", arguments, expectedArguments);
- var callback = arguments[0];
- var parameters = null;
- if (GetTypeName(arguments[0]) === "object") {
- var expectedProperties = [
- { type: "boolean", name: "populate", optional: true }];
- TestObjectProperties(0, arguments[0], expectedProperties);
- callback = arguments[1];
- parameters = arguments[0];
- }
- var destination = {};
- destination.component = componentId_frame;
- destination.frameId = Bhx_TopMost;
- return ExecuteGenericFunction(functionId_windowsGet, destination, parameters, callback);
- }
- function windows_getAll_indirect() {
- var expectedArguments = [
- { type: "object", name: "getInfo", optional: true },
- { type: "function", name: "callback" }];
- TestParameterTypes("windows.getAll", arguments, expectedArguments);
- var callback = arguments[0];
- var parameters = null;
- if (GetTypeName(arguments[0]) === "object") {
- var expectedProperties = [
- { type: "boolean", name: "populate", optional: true }];
- TestObjectProperties(0, arguments[0], expectedProperties);
- callback = arguments[1];
- parameters = arguments[0];
- }
- var destination = {};
- destination.component = componentId_manager;
- return ExecuteGenericFunction(functionId_windowsGetAll, destination, parameters, callback);
- }
- function windows_create_indirect() {
- var expectedArguments = [
- { type: "object", name: "createData", optional: true },
- { type: "function", name: "callback", optional: true }];
- TestParameterTypes("windows.create", arguments, expectedArguments);
- if (arguments[0] != nullptr && GetTypeName(arguments[0]) === "object") {
- var expectedProperties = [
- { type: "array", name: "url", optional: true },
- { type: "integer", name: "tabId", optional: true, validator: function (value) { if (value < 0) return "Value must be non-negative integer."; } },
- { type: "integer", name: "left", optional: true },
- { type: "integer", name: "top", optional: true },
- { type: "integer", name: "width", optional: true, validator: function (value) { if (value <= 0) return "Value must be positive integer."; } },
- { type: "integer", name: "height", optional: true, validator: function (value) { if (value <= 0) return "Value must be positive integer."; } },
- { type: "boolean", name: "focused", optional: true },
- { type: "boolean", name: "inPrivate", optional: true },
- { type: "string", name: "type", optional: true, validator: function (value) {
- if (value != "normal" && value != "popup") {
- return "Value must be one of: [normal, popup]";
- }
- }},
- { type: "string", name: "state", optional: true, validator: function (value) {
- if (value != "normal" && value != "minimized" && value != "maximized" && value != "fullscreen") {
- return "Value must be one of: [normal, minimized, maximized, fullscreen]";
- }
- }} ];
- TestObjectProperties(0, arguments[0], expectedProperties);
- }
- // TODO: Implement windows.Create http://osgvsowi/3418411
- }
- function windows_update_indirect() {
- var expectedArguments = [
- { type: "integer", name: "windowId" },
- { type: "object", name: "updateData", optional: true },
- { type: "function", name: "callback", optional: true }];
- TestParameterTypes("windows.update", arguments, expectedArguments);
- var expectedProperties = [
- { type: "integer", name: "left", optional: true },
- { type: "integer", name: "top", optional: true },
- { type: "integer", name: "width", optional: true, validator: function (value) { if (value <= 0) return "Value must be positive integer."; } },
- { type: "integer", name: "height", optional: true, validator: function (value) { if (value <= 0) return "Value must be positive integer."; } },
- { type: "boolean", name: "focused", optional: true },
- { type: "boolean", name: "drawAttention", optional: true },
- { type: "string", name: "state", optional: true, validator: function (value) {
- if (value != "normal" && value != "minimized" && value != "maximized" && value != "fullscreen") {
- return "Value must be one of: [normal, minimized, maximized, fullscreen]";
- }
- }} ];
- TestObjectProperties(1, arguments[1], expectedProperties);
- var destination = {};
- destination.component = componentId_frame;
- destination.frameId = arguments[0];
- return ExecuteGenericFunction(functionId_windowsUpdate, destination, arguments[1], arguments.length == 3 ? arguments[2] : null);
- }
- function delayInitOnCreated() {
- var onCreatedObject = StoreNoFilterHandler(eventId_windowsOnCreated, function (sender, windowData, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](windowData);
- }
- }
- });
- var wrapOnCreated = Object.defineProperties({}, {
- "addListener": {
- value: onCreatedObject.addListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onCreatedObject.removeListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onCreatedObject.hasListener.bind(onCreatedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.windows, "onCreated", {
- value: wrapOnCreated,
- configurable: true,
- enumerable: true
- });
- return wrapOnCreated;
- }
- function delayInitOnRemoved() {
- var onRemovedObject = StoreNoFilterHandler(eventId_windowsOnRemoved, function (sender, windowData, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](windowData);
- }
- }
- });
- var wrapOnRemoved = Object.defineProperties({}, {
- "addListener": {
- value: onRemovedObject.addListener.bind(onRemovedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onRemovedObject.removeListener.bind(onRemovedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onRemovedObject.hasListener.bind(onRemovedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.windows, "onRemoved", {
- value: wrapOnRemoved,
- configurable: true,
- enumerable: true
- });
- return wrapOnRemoved;
- }
- function delayInitOnFocusChanged() {
- var onFocusChangedObject = StoreNoFilterHandler(eventId_windowsOnFocusChanged, function (sender, windowData, listeners) {
- for (var i = 0; i < listeners.length; i++) {
- if (typeof(listeners[i]) == "function") {
- listeners[i](windowData);
- }
- }
- });
- var wrapOnFocusChanged = Object.defineProperties({}, {
- "addListener": {
- value: onFocusChangedObject.addListener.bind(onFocusChangedObject),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: onFocusChangedObject.removeListener.bind(onFocusChangedObject),
- configurable: true,
- enumerable: true
- },
- "hasListener": {
- value: onFocusChangedObject.hasListener.bind(onFocusChangedObject),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.windows, "onFocusChanged", {
- value: wrapOnFocusChanged,
- configurable: true,
- enumerable: true
- });
- return wrapOnFocusChanged;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "windows", {
- value: wrapWindows,
- configurable: true,
- enumerable: true
- });
- return wrapWindows;
- }
- function delayInitWebNavigation() {
- var wrapWebNavigation;
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_webNavigation);
- if (typeof(hasPermission) == "boolean" && hasPermission) {
- wrapWebNavigation = Object.defineProperties({}, {
- "getFrame": {
- value: webNavigation_getFrame_indirect.bind(nativeMsBrowser.webNavigation),
- configurable: true,
- enumerable: true
- },
- "getAllFrames": {
- value: webNavigation_getAllFrames_indirect.bind(nativeMsBrowser.webNavigation),
- configurable: true,
- enumerable: true
- },
- "onBeforeNavigate": {
- get: delayInitOnBeforeNavigate,
- configurable: true,
- enumerable: true
- }
- });
- }
- function webNavigation_getFrame_indirect(details, callback) {
- // Test number of arguments and their types
- const expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback" }
- ];
- TestParameterTypes("webNavigation.getFrame", arguments, expectedArguments);
- // Verify the types and presence of the 'details' objects properties.
- const expectedProperties = [
- { type: "integer", name: "tabId" },
- { type: "integer", name: "processId" },
- { type: "integer", name: "frameId" }
- ];
- TestObjectProperties(0, details, expectedProperties);
- // Setup the message to native code and register the JavaScript callback function.
- const destination = {
- component: componentId_tabTrident,
- tabId: details.tabId,
- frameId: Bhx_Parent
- };
- // The only data needed as parameters are the 'frameId' and 'processId'.
- // This 'frameId' refers to frames such as iFrames in the page.
- const parameters = {
- frameId: details.frameId,
- processId: details.processId
- };
- // Documentation states that the result should be null when the frame doesn't exist or there is another error.
- const wrapCallback = function (details) {
- callback(details || null);
- }
- return ExecuteGenericFunction(functionId_getFrame, destination, parameters, wrapCallback);
- }
- function webNavigation_getAllFrames_indirect(details, callback) {
- // Test number of arguments and their types
- const expectedArguments = [
- { type: "object", name: "details" },
- { type: "function", name: "callback" }
- ];
- TestParameterTypes("webNavigation.getAllFrames", arguments, expectedArguments);
- // Verify the types and presence of the 'details' objects properties.
- const expectedProperties = [
- { type: "integer", name: "tabId" }
- ];
- TestObjectProperties(0, details, expectedProperties);
- // Setup the message to native code and register the JavaScript callback function.
- const destination = {
- component: componentId_tabTrident,
- tabId: details.tabId,
- frameId: Bhx_Parent
- };
- var parameters; // "getAllFrames" only needs the tabId which has already been represented in the "destination" address.
- // Documentation states that the result should be null when the frame doesn't exist or there is another error.
- const wrapCallback = function (details) {
- callback(details || null);
- }
- return ExecuteGenericFunction(functionId_getAllFrames, destination, parameters, wrapCallback);
- }
- function delayInitOnBeforeNavigate() {
- var wrapOnBeforeNavigate = Object.defineProperties({}, {
- "addListener": {
- value: nativeMsBrowser.webNavigation.onBeforeNavigate.addListener.bind(nativeMsBrowser.webNavigation.onBeforeNavigate),
- configurable: true,
- enumerable: true
- }
- });
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser.webNavigation, "onBeforeNavigate", {
- value: wrapOnBeforeNavigate,
- configurable: true,
- enumerable: true
- });
- return wrapOnBeforeNavigate;
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.msBrowser, "webNavigation", {
- value: wrapWebNavigation,
- configurable: true,
- enumerable: true
- });
- return wrapWebNavigation;
- }
- // BEGINE WebRequestCode
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function delayInitWebRequest() {
- var wrapWebRequest;
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_webRequest);
- if (typeof(hasPermission) == "boolean" && hasPermission) {
- wrapWebRequest = Object.defineProperties({}, {
- "onBeforeRequest": {
- get: delayInitOnBeforeRequest.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onBeforeSendHeaders": {
- get: delayInitOnBeforeSendHeaders.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onSendHeaders": {
- get: delayInitOnSendHeaders.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onHeadersReceived": {
- get: delayInitOnHeadersReceived.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onAuthRequired": {
- get: delayInitOnAuthRequired.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onResponseStarted": {
- get: delayInitOnResponseStarted.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onBeforeRedirect": {
- get: delayInitOnBeforeRedirect.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onCompleted": {
- get: delayInitOnCompleted.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "onErrorOccurred": {
- get: delayInitonErrorOccurred.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "handlerBehaviorChanged": {
- value: webRequest_HandlerBehaviorChanged.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- },
- "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES": {
- get:webRequest_MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.bind(nativeMsBrowser.webRequest),
- set:webRequest_MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.bind(nativeMsBrowser.webRequest),
- configurable: true,
- enumerable: true
- }
- });
- }
- // Expected extraSpecInfo for respective WebRequest event
- var expectedWebRequstTypesForEvent = {
- onBeforeRequest: ["blocking", "requestBody"],
- onBeforeSendHeaders: ["blocking", "requestHeaders"],
- onSendHeaders: ["requestHeaders"],
- onHeadersReceived: ["blocking", "responseHeaders"],
- onAuthRequired: ["blocking", "responseHeaders", "asyncBlocking"],
- onResponseStarted: ["responseHeaders"],
- onBeforeRedirect: ["responseHeaders"],
- onCompleted: ["responseHeaders"],
- onErrorOccurred: [],
- }
- // Expected eventDetails for respective WebRequest event
- var expectedWebRuestEventDetails = {
- onBeforeRequest: ["requestId", "url", "method", "frameId", "parentFrameId", "requestBody", "tabId", "type", "timeStamp"],
- onBeforeSendHeaders: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "requestHeaders"],
- onSendHeaders: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "requestHeaders"],
- onHeadersReceived: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "statusLine", "requestHeaders", "statusCode"],
- onAuthRequired: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "scheme", "realm", "challenger", "isProxy", "requestHeaders", "statusLine", "statusCode"],
- onBeforeRedirect: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "ip", "fromCache", "requestHeaders", "statusLine", "statusCode"],
- onResponseStarted: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "ip", "fromCache", "requestHeaders", "statusLine", "statusCode", "redirectUrl"],
- onCompleted: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "ip", "fromCache", "requestHeaders", "statusLine", "statusCode"],
- onErrorOccurred: ["requestId", "url", "method", "frameId", "parentFrameId", "tabId", "type", "timeStamp", "ip", "fromCache", "error"]
- }
- // Expected blocking response for respective WebRequest event
- var expectedWebRequestBlockingResponse = {
- onBeforeRequest: ["cancel", "redirectUrl"],
- onBeforeSendHeaders: ["cancel", "requestHeaders"],
- onSendHeaders: ["cancel"],
- onHeadersReceived: ["redirectUrl", "responseHeaders"],
- onAuthRequired: ["authCredentials"],
- onBeforeRedirect: [],
- onResponseStarted: [],
- onCompleted: [],
- onErrorOccurred: []
- }
- // Expected callback blocking response by its events name
- var expectedWebRequestEventsForBlockingResponse = {
- cancel: ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders"],
- redirectUrl: ["onBeforeRequest", "onHeadersReceived"],
- requestHeaders: ["onBeforeSendHeaders"],
- responseHeaders: ["onHeadersReceived"],
- authCredentials: ["onAuthRequired"]
- }
- // The below order should be match with WebRequestEventId, BhxMessage.h.
- var webRequestEvents = ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", "onHeadersReceived", "onAuthRequired",
- "onBeforeRedirect", "onResponseStarted", "onCompleted", "onErrorOccurred"];
- // BEGIN Events INIT
- //////////////////////////////////////////////////////////////////////////////////////////////
- function delayInitOnBeforeRequest() {
- var wrapOnBeforeRequest = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onBeforeRequest_addListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeRequest),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onBeforeRequest_removeListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeRequest),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onBeforeRequest_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onBeforeRequest.addListener", arguments, expectedWebRequstTypesForEvent["onBeforeRequest"]);
- webRequest_addListener_indirect("onBeforeRequest", arguments);
- }
- function webRequest_onBeforeRequest_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onBeforeRequest.removeListener", arguments);
- webRequest_removeListener_indirect("onBeforeRequest", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onBeforeRequest", {
- value: wrapOnBeforeRequest,
- configurable: true,
- enumerable: true
- });
- return wrapOnBeforeRequest;
- }
- function delayInitOnBeforeSendHeaders() {
- var wrapOnBeforeSendHeaders = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onBeforeSendHeaders_addListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeSendHeaders),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onBeforeSendHeaders_removeListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeSendHeaders),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onBeforeSendHeaders_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onBeforeSendHeaders.addListener", arguments, expectedWebRequstTypesForEvent["onBeforeSendHeaders"]);
- webRequest_addListener_indirect("onBeforeSendHeaders", arguments);
- }
- function webRequest_onBeforeSendHeaders_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onBeforeSendHeaders.removeListener", arguments);
- webRequest_removeListener_indirect("onBeforeSendHeaders", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onBeforeSendHeaders", {
- value: wrapOnBeforeSendHeaders,
- configurable: true,
- enumerable: true
- });
- return wrapOnBeforeSendHeaders;
- }
- function delayInitOnSendHeaders() {
- var wrapOnSendHeaders = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onSendHeaders_addListener_indirect.bind(nativeMsBrowser.webRequest.onSendHeaders),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onSendHeaders_removeListener_indirect.bind(nativeMsBrowser.webRequest.onSendHeaders),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onSendHeaders_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onSendHeaders.addListener", arguments, expectedWebRequstTypesForEvent["onSendHeaders"]);
- webRequest_addListener_indirect("onSendHeaders", arguments);
- }
- function webRequest_onSendHeaders_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onSendHeaders.removeListener", arguments);
- webRequest_removeListener_indirect("onSendHeaders", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onSendHeaders", {
- value: wrapOnSendHeaders,
- configurable: true,
- enumerable: true
- });
- return wrapOnSendHeaders;
- }
- function delayInitOnHeadersReceived() {
- var wrapOnHeadersReceived = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onHeadersReceived_addListener_indirect.bind(nativeMsBrowser.webRequest.onHeadersReceived),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onHeadersReceived_removeListener_indirect.bind(nativeMsBrowser.webRequest.onHeadersReceived),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onHeadersReceived_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onHeadersReceived.addListener", arguments, expectedWebRequstTypesForEvent["onHeadersReceived"]);
- webRequest_addListener_indirect("onHeadersReceived", arguments);
- }
- function webRequest_onHeadersReceived_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onHeadersReceived.removeListener", arguments);
- webRequest_removeListener_indirect("onHeadersReceived", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onHeadersReceived", {
- value: wrapOnHeadersReceived,
- configurable: true,
- enumerable: true
- });
- return wrapOnHeadersReceived;
- }
- function delayInitOnAuthRequired() {
- var wrapOnAuthRequired = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onAuthRequired_addListener_indirect.bind(nativeMsBrowser.webRequest.onAuthRequired),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onAuthRequired_removeListener_indirect.bind(nativeMsBrowser.webRequest.onAuthRequired),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onAuthRequired_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onAuthRequired.addListener", arguments, expectedWebRequstTypesForEvent["onAuthRequired"]);
- webRequest_addListener_indirect("onAuthRequired", arguments);
- }
- function webRequest_onAuthRequired_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onAuthRequired.removeListener", arguments);
- webRequest_removeListener_indirect("onAuthRequired", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onAuthRequired", {
- value: wrapOnAuthRequired,
- configurable: true,
- enumerable: true
- });
- return wrapOnAuthRequired;
- }
- function delayInitOnResponseStarted() {
- var wrapOnResponseStarted = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onResponseStarted_addListener_indirect.bind(nativeMsBrowser.webRequest.onResponseStarted),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onResponseStarted_removeListener_indirect.bind(nativeMsBrowser.webRequest.onResponseStarted),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onResponseStarted_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onResponseStarted.addListener", arguments, expectedWebRequstTypesForEvent["onResponseStarted"]);
- webRequest_addListener_indirect("onResponseStarted", arguments);
- }
- function webRequest_onResponseStarted_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onResponseStarted.removeListener", arguments);
- webRequest_removeListener_indirect("onResponseStarted", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onResponseStarted", {
- value: wrapOnResponseStarted,
- configurable: true,
- enumerable: true
- });
- return wrapOnResponseStarted;
- }
- function delayInitOnBeforeRedirect() {
- var wrapOnBeforeRedirect = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onBeforeRedirect_addListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeRedirect),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onBeforeRedirect_removeListener_indirect.bind(nativeMsBrowser.webRequest.onBeforeRedirect),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onBeforeRedirect_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onBeforeRedirect.addListener", arguments, expectedWebRequstTypesForEvent["onBeforeRedirect"]);
- webRequest_addListener_indirect("onBeforeRedirect", arguments);
- }
- function webRequest_onBeforeRedirect_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onBeforeRedirect.removeListener", arguments);
- webRequest_removeListener_indirect("onBeforeRequest", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onBeforeRedirect", {
- value: wrapOnBeforeRedirect,
- configurable: true,
- enumerable: true
- });
- return wrapOnBeforeRedirect;
- }
- function delayInitOnCompleted() {
- var wrapOnCompleted = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onCompleted_addListener_indirect.bind(nativeMsBrowser.webRequest.onCompleted),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onCompleted_removeListener_indirect.bind(nativeMsBrowser.webRequest.onCompleted),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onCompleted_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onCompleted.addListener", arguments, expectedWebRequstTypesForEvent["onCompleted"]);
- webRequest_addListener_indirect("onCompleted", arguments);
- }
- function webRequest_onCompleted_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onCompleted.removeListener", arguments);
- webRequest_removeListener_indirect("onCompleted", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onCompleted", {
- value: wrapOnCompleted,
- configurable: true,
- enumerable: true
- });
- return wrapOnCompleted;
- }
- function delayInitonErrorOccurred() {
- var wrapOnErrorOccurred = Object.defineProperties({}, {
- "addListener": {
- value: webRequest_onErrorOccurred_addListener_indirect.bind(nativeMsBrowser.webRequest.onErrorOccurred),
- configurable: true,
- enumerable: true
- },
- "removeListener": {
- value: webRequest_onErrorOccurred_removeListener_indirect.bind(nativeMsBrowser.webRequest.onErrorOccurred),
- configurable: true,
- enumerable: true
- }
- });
- function webRequest_onErrorOccurred_addListener_indirect() {
- TestFilteredEventListenerParameters("webRequest.onErrorOccurred.addListener", arguments, expectedWebRequstTypesForEvent["onErrorOccurred"]);
- webRequest_addListener_indirect("onErrorOccurred", arguments);
- }
- function webRequest_onErrorOccurred_removeListener_indirect() {
- TestFilteredEventRemoveListenerParameters("webRequest.onErrorOccurred.removeListener", arguments);
- webRequest_removeListener_indirect("onErrorOccurred", arguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window.webRequest, "onErrorOccurred", {
- value: wrapOnErrorOccurred,
- configurable: true,
- enumerable: true
- });
- return wrapOnErrorOccurred;
- }
- function webRequest_HandlerBehaviorChanged() {
- var expectedArguments = [{ type: "function", name: "callback", optional: true }];
- TestParameterTypes("webRequest.HandlerBehaviorChanged", arguments, expectedArguments);
- // It does nothing more than making effective of the removeListener calling,
- if (arguments[0]) {
- setImmediate(arguments[0]); // call callback function immediately to comply with spec.
- }
- }
- var MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES = 20;
- function webRequest_MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES(value) {
- // Our current implementation of HandlerBehaviorChanged doesn't require calling
- // handlerBehaviorChanged to make listener changes effective and therefore our implementation doesn't
- // really need handlerBehaviorChanged and MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
- // We implement this just to allow developers to migrate extension to our system without changing their code.
- if (value){
- MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES = value;
- } else {
- return MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
- }
- }
- function webRequest_addListener_indirect(eventName, providedArguments) {
- // Append extraInfoSpec argument to the filters
- var eventIndex = webRequestEvents.indexOf(eventName);
- if (eventIndex == -1) {
- throw "unexpected eventName: " + eventName + ", or internal error";
- }
- var nativeFilteredEvent = nativeMsBrowser.webRequest.getFilteredEvent(eventIndex);
- if (!nativeFilteredEvent) {
- throw "unexpected eventName: " + eventName + ", or internal error";
- }
- function clone(filter) {
- // filter always exist for the webRequest requestFilters
- var copy = {};
- for (var property in filter) {
- if (filter.hasOwnProperty(property)) {
- copy[property] = filter[property];
- }
- }
- return copy;
- }
- var copyFilters = clone(providedArguments[1]);
- if (copyFilters && providedArguments[2]) {
- copyFilters.extraInfoSpec = providedArguments[2];
- }
- // call native AddListener
- // - wrapper listener, which is callback for dispatch
- // - real listern, which is used for removeListner key
- // - copyFilters if exist
- var realListener = providedArguments[0];
- if (copyFilters) {
- nativeFilteredEvent.addListener(webRequest_messagingListener_createCallback(eventName, realListener, copyFilters), realListener, JSON.stringify(copyFilters));
- } else {
- nativeFilteredEvent.addListener(webRequest_messagingListener_createCallback(eventName, realListener, copyFilters), realListener);
- }
- }
- function webRequest_removeListener_indirect(eventName, providedArguments) {
- // Append extraInfoSpec argument to the filters
- var eventIndex = webRequestEvents.indexOf(eventName);
- if (eventIndex == -1) {
- throw "unexpected eventName: " + eventName + ", or internal error";
- }
- var nativeFilteredEvent = nativeMsBrowser.webRequest.getFilteredEvent(eventIndex);
- if (!nativeFilteredEvent) {
- throw "unexpected eventName: " + eventName + ", or internal error";
- }
- var realListener = providedArguments[0];
- nativeFilteredEvent.removeListener(realListener);
- }
- function webRequest_messagingListener_createCallback(eventName, realListener, filters) {
- // The function is callback from the native webRequest event.
- function isExtraInfoSpecExist(info, extraInfoSpec) {
- var exist = false;
- if (extraInfoSpec) {
- for (var i = 0; i < extraInfoSpec.length; i++) {
- if (extraInfoSpec[i] === info) {
- exist = true;
- break;
- }
- }
- }
- return exist;
- }
- filters = filters || {};
- // Save blocking/asyncBlocking info
- var blocking = isExtraInfoSpecExist('blocking', filters.extraInfoSpec);
- var asyncBlocking = isExtraInfoSpecExist('asyncBlocking', filters.extraInfoSpec);
- // Pass callback function from native dispatch.
- return function (jsonEventDetails, context, tabId, frameId) {
- // Callback from the native dispatch
- //
- // Filtering based on the input tablId and windowId.
- // If these values exist, callback function will be forwarded to caller only when it is match.
- var skipCallback = false;
- if (filters.tabId) {
- skipCallback = (filters.tabId !== tabId);
- }
- if (filters.windowId) {
- skipCallback = (filters.windowId !== frameId);
- }
- if (!skipCallback) {
- var eventDetails = {};
- if (jsonEventDetails) {
- eventDetails = nativeJSON.parse(jsonEventDetails);
- }
- // Filtering eventDetails by its expected properties
- var trimmedEventDetails = {};
- var allowedEventDetails = expectedWebRuestEventDetails[eventName];
- var eventProperties = Object.keys(eventDetails);
- for (var i = 0; i < eventProperties.length; i++) {
- if (allowedEventDetails.indexOf(eventProperties[i]) !== -1) {
- // Property is expected for given event
- trimmedEventDetails[eventProperties[i]] = eventDetails[eventProperties[i]];
- }
- }
- // Callback to app listener handler
- var retVal;
- if (asyncBlocking) {
- try {
- realListener(trimmedEventDetails, function asyncCallback(authDetails) {
- // Callback from app for onAuthRequired
- var authDetails = authDetails || {};
- // Send message directly to the tab process (destination)
- var destination = {};
- destination.component = componentId_webRequest;
- destination.tabId = tabId;
- destination.frameId = frameId;
- // Polyfill pass 'async' keyword and extension will collect all async returns and
- // pass counts to the tab process so it can handle all blocking and async blockings together for
- // single dispatch reply.
- context = context | (1 << 63); // toggle MSB for async response identification.
- ExecuteGenericFunction(messageId_ReplyId, destination, authDetails, context);
- });
- retVal = "async";
- } catch (e) {
- // swallow exception from the app code and return as 'noReturn' so tab process doesn't have to wait async callback.
- retVal = "noReturn";
- }
- } else {
- try {
- if (blocking) {
- retVal = realListener(trimmedEventDetails);
- } else {
- realListener(trimmedEventDetails);
- }
- } catch (e) {
- // swallow exception from the app code
- retVal = null;
- }
- // Validate retValue if it exist
- if (blocking && retVal) {
- var responseKeys = Object.keys(retVal);
- var invalidResponse = false;
- var errorMsg = "";
- for (var i = 0; i < responseKeys.length; i++) {
- if (!expectedWebRequestEventsForBlockingResponse[responseKeys[i]]) { // If key is blockResource properties
- invalidResponse = true;
- errorMsg = "Response error: Invalid property name for blocking response: " + "[" + responseKeys[i] + "]. " + "expected properties are" + Object.keys(expectedWebRequestEventsForBlockingResponse).toString();
- } else if (expectedWebRequestEventsForBlockingResponse[responseKeys[i]].indexOf(eventName) === -1) {
- invalidResponse = true;
- errorMsg = "Response error: Unexpected property name for blocking response on given event. Value must be " + "[" + expectedWebRequestBlockingResponse[eventName].toString() + "]";
- } else {
- // validate redirectUri value
- if (responseKeys[i] === 'redirectUrl') {
- try {
- var url = new URL(retVal['redirectUrl']);
- } catch (e) {
- invalidResponse = true;
- errorMsg = "Response error: Invalid value of redirectUrl: " + retVal['redirectUrl'] + " is not a valid URL.";
- }
- }
- }
- if (invalidResponse) {
- // It log an error instead of throw exception as developer do not expect exception when they return from the handler.
- console.error(errorMsg);
- // Return no return results due to invalid response block
- retVal = null;
- break;
- }
- }
- }
- }
- }
- // no return value, it set the 'noReturn'
- retVal = retVal || "noReturn";
- return nativeJSON.stringify(retVal);
- }
- }
- function TestFilteredEventListenerParameters(functionName, functionArguments, exptecedProperties) {
- function TestRequestFilters(filters) {
- var valid = true;
- var expectedFilterProperties = [
- {
- type: "array", name: "urls", optional: false, canValidate: false, validator: function (urls) {
- // Validate URLs
- for (var i = 0; i < urls.length; i++) {
- validateUrlMatchPattern(urls[i]);
- }
- }
- },
- {
- type: "array", name: "types", optional: true, canValidate: true, validator: function (providedProperties) {
- var expectedTypeProperties = ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
- var valid = true;
- for (var i = 0, length = providedProperties.length; i < length; i++) {
- if (expectedTypeProperties.indexOf(providedProperties[i]) === -1) {
- ThrowArgumentError(1, "Property 'types': Value must be one of: " + "[" + expectedTypeProperties.toString() + "]");
- }
- }
- }
- },
- {
- type: "integer", name: "tabId", optional: true, canValidate: true
- },
- {
- type: "integer", name: "windowId", optional: true, canValidate: true
- },
- ]
- TestObjectProperties(1, filters, expectedFilterProperties);
- }
- function TestExtraInfoSpec(providedExtraInfo, exptecedProperties) {
- for (var i = 0; i < providedExtraInfo.length; i++) {
- var found = false;
- if (exptecedProperties.indexOf(providedExtraInfo[i]) === -1) {
- ThrowArgumentError(2, "Value must be one of: " + "[" + exptecedProperties.toString() + "]");
- }
- if (providedExtraInfo[i] == "blocking") {
- var hasPermission = ExecuteGenericSynchronousFunction(functionId_permissionsCheckInternal, permissionId_webRequestBlocking);
- if (typeof(hasPermission) != "boolean" || !hasPermission) {
- ThrowArgumentError(2, "The extension requires the blocking web request permission to add blocking listeners.");
- }
- }
- }
- }
- var expectedArguments = [
- { type: "function", name: "callback", optional: false },
- { type: "object", name: "filters", optional: false },
- { type: "array", name: "extraInfoSpec", optional: true }];
- TestParameterTypes(functionName, functionArguments, expectedArguments);
- if (functionArguments[1]) {
- // filter parameter is not optional for filtered event listener
- TestRequestFilters(functionArguments[1]);
- } else {
- throw "filter argument is needed";
- }
- if (functionArguments[2]) {
- TestExtraInfoSpec(functionArguments[2], exptecedProperties);
- }
- }
- function TestFilteredEventRemoveListenerParameters(functionName, functionArguments) {
- var expectedArguments = [
- { type: "function", name: "callback", optional: false },
- ];
- TestParameterTypes(functionName, functionArguments, expectedArguments);
- }
- // Replace delayInit with the initialized object to avoid repeated calls to delayInit.
- Object.defineProperty(window, "webRequest", {
- value: wrapWebRequest,
- configurable: true,
- enumerable: true
- });
- return wrapWebRequest;
- }
- // END WebRequestCode
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function getURL_indirect(resource) {
- var extensionId = nativeMsBrowser.getExtensionId();
- var url = "ms-browser-extension://" + extensionId;
- if (resource.substr(0, 1) !== "/") {
- url += "/";
- }
- url += resource;
- return url;
- }
- // The functions below are for parameter validation.
- function validateUrlMatchPattern(url) {
- // check if all urls success
- if (url === "<all_urls>") {
- return;
- }
- // check
- var index = url.search("://");
- if (index === -1) {
- ThrowArgumentError(1, "Property 'urls': Invalid url syntax " + url);
- } else {
- function validateScheme(scheme) {
- // input: "http://", "https://"
- var expectedSchemes = ["http://", "https://", "file://", "ftp://", "*://"];
- if (expectedSchemes.indexOf(scheme) === -1) {
- ThrowArgumentError(1, "Property 'urls': Invalid url scheme: " + scheme);
- }
- }
- function checkLocalHost(hostAndPath) {
- var pathIndex = hostAndPath.indexOf("/");
- if (pathIndex === 0) {
- // Only file scheme allow local host: file:///
- if (scheme !== "file://") {
- ThrowArgumentError(1, "Property 'urls': Local host is not allowed for given scheme: " + scheme);
- } else {
- return;
- }
- }
- }
- function validateHost(hostAndPath, pathIndex) {
- var starIndex = hostAndPath.indexOf("*");
- if (starIndex !== -1 && starIndex < pathIndex) {
- // star exist inside a host name
- if (starIndex !== 0 ||
- (hostAndPath[1] !== "." && hostAndPath[1] !== "/")) {
- // valid host name with the star is only that "*.", "*"
- ThrowArgumentError(1, "Property 'urls': Invalid url host name: " + hostAndPath.substr(0, hostAndPath.indexOf("/")));
- }
- }
- }
- var hostAndPathIndex = index + "://".length;
- var scheme = url.substring(0, hostAndPathIndex);
- validateScheme(scheme); // get the scheme name with "://"
- var hostAndPath = url.substring(hostAndPathIndex); // hostAndPath: eg. "www.bing.com/default.html", "*/", "*abc/*"
- checkLocalHost(hostAndPath);
- var pathIndex = hostAndPath.indexOf("/");
- if (pathIndex === -1) {
- // no path delimieter
- ThrowArgumentError(1, "Property 'urls': Invalid url, no path exist: " + url);
- }
- validateHost(hostAndPath, pathIndex);
- }
- }
- function GetTypeName(argument) {
- var type = typeof(argument);
- if (type === "number") {
- if (parseFloat(argument) == parseInt(argument)) {
- type = "integer";
- }
- } else if (type === "object") {
- if (!argument) {
- type = "null";
- } else if (Array.isArray(argument)) {
- type = "array";
- }
- }
- return type;
- }
- function TestArgumentType(argumentType, expectedArgumentType) {
- if (expectedArgumentType === "any") {
- return true;
- } else {
- var splitArgumentTypes = expectedArgumentType.split(" or ");
- for (var i = 0; i < splitArgumentTypes.length; i++) {
- if (argumentType === splitArgumentTypes[i]) {
- return true;
- }
- }
- }
- return false;
- }
- function ThrowTypeError(functionName, providedArguments, expectedArguments) {
- var argumentString = "";
- for (var i = 0; i < providedArguments.length; i++) {
- if (i > 0) {
- argumentString += ", ";
- }
- argumentString += GetTypeName(providedArguments[i]);
- }
- var expectedArgumentString = "";
- for (var i = 0; i < expectedArguments.length; i++) {
- if (i > 0) {
- expectedArgumentString += ", ";
- }
- if (expectedArguments[i].optional) {
- expectedArgumentString += "optional ";
- }
- expectedArgumentString += expectedArguments[i].type + " " + expectedArguments[i].name;
- }
- throw "Error: Invocation of form " + functionName + "(" + argumentString + ") doesn't match definition " + functionName + "(" + expectedArgumentString + ").";
- }
- function TestParameterTypes(functionName, providedArguments, expectedArguments) {
- var valid = false;
- var skipBits = 0;
- var optionalParameterChecked = true;
- while (!valid && optionalParameterChecked)
- {
- var currentArgumentIndex = 0;
- var currentExpectedIndex = 0;
- var optionalParameterIndex = 0;
- optionalParameterChecked = false;
- valid = true; // Innocent until proven guilty.
- for (var currentExpectedIndex = 0; currentExpectedIndex < expectedArguments.length && currentArgumentIndex < providedArguments.length && valid; currentExpectedIndex++) {
- if (expectedArguments[currentExpectedIndex].optional) {
- var bitToCheck = 1 << optionalParameterIndex;
- optionalParameterIndex++;
- if (skipBits & bitToCheck === bitToCheck) {
- continue;
- } else {
- optionalParameterChecked = true;
- }
- }
- var argType = GetTypeName(providedArguments[currentArgumentIndex]);
- if (TestArgumentType(argType, expectedArguments[currentExpectedIndex].type)) {
- currentArgumentIndex++;
- } else if (!expectedArguments[currentExpectedIndex].optional) {
- valid = false;
- break;
- } else if (argType === "null" || argType === "undefined") {
- // optional arguments can have null or undefined in their place.
- currentArgumentIndex++;
- }
- }
- if (valid) {
- for (; currentExpectedIndex < expectedArguments.length; currentExpectedIndex++) {
- if (!expectedArguments[currentExpectedIndex].optional) {
- valid = false;
- break;
- }
- }
- }
- if (valid && currentArgumentIndex < providedArguments.length)
- {
- valid = false;
- }
- skipBits++;
- }
- if (!valid) {
- ThrowTypeError(functionName, providedArguments, expectedArguments);
- }
- return valid;
- }
- function ThrowArgumentError(argumentIndex, errorString)
- {
- throw "Error: Invalid value for argument " + (argumentIndex + 1) + ". " + errorString + ".";
- }
- function TestObjectProperties(argumentIndex, objectToTest, propertyInformation)
- {
- var errorString = "";
- var valid = true; // Innocent until proven guilty.
- var requiredProperties = {};
- for (var i = 0; i < propertyInformation.length; i++) {
- if (!propertyInformation[i].optional) {
- requiredProperties[propertyInformation[i].name] = true;
- }
- }
- var stringPrefix = "";
- for (var prop in objectToTest) {
- var found = false;
- for (var i = 0; i < propertyInformation.length; i++) {
- if (prop === propertyInformation[i].name) {
- if (!propertyInformation[i].optional) {
- requiredProperties[propertyInformation[i].name] = false;
- }
- var argType = GetTypeName(objectToTest[prop]);
- if (TestArgumentType(argType, propertyInformation[i].type)) {
- if (propertyInformation[i].validator) {
- var validationError = propertyInformation[i].validator(objectToTest[prop]);
- if (validationError) {
- errorString += stringPrefix + "Property '" + prop + "': " + validationError;
- stringPrefix = ", ";
- valid = false;
- }
- }
- } else if (!propertyInformation[i].optional || (argType !== "null" && argType !== "undefined")) {
- if (propertyInformation[i].type.indexOf(" or ") === -1) {
- errorString += stringPrefix + "Property '" + prop + "': Expected '" + propertyInformation[i].type + "' but got '" + GetTypeName(objectToTest[prop]) + "'";
- } else {
- errorString += stringPrefix + "Property '" + prop + "': Value does not match any valid type choices";
- }
- stringPrefix = ", ";
- valid = false;
- }
- found = true;
- break;
- }
- }
- if (!found) {
- errorString += stringPrefix + "Property '" + prop + "': Unexpected property";
- stringPrefix = ", ";
- valid = false;
- }
- }
- for (var prop in requiredProperties) {
- if (requiredProperties[prop]) {
- errorString += stringPrefix + "Property '" + prop + "': Property is required";
- stringPrefix = ", ";
- valid = false;
- }
- }
- if (!valid)
- {
- ThrowArgumentError(argumentIndex, errorString);
- }
- return valid;
- }
- function TestListenerArguments(functionArguments)
- {
- if (functionArguments.length > 1)
- {
- throw "Error: This event does not support filters.";
- return false;
- }
- return true;
- }
- function StoreCallback(callback)
- {
- var storedId = nextCallback;
- storedCallbacks[nextCallback++] = callback;
- return storedId;
- }
- function InvokeCallback(callbackId, parameterString)
- {
- if (callbackId < storedCallbacks.length && storedCallbacks[callbackId]) {
- var parameters;
- if (parameterString) {
- parameters = nativeJSON.parse(parameterString);
- }
- storedCallbacks[callbackId](parameters);
- storedCallbacks[callbackId] = null;
- }
- }
- function StoreNoFilterHandler(eventId, handlerFunc)
- {
- var listenerHolder = { event: eventId, handler: handlerFunc, listeners: [],
- addListener: function (listener) {
- if (arguments.length > 1) {
- throw "Error: This event does not support filters.";
- }
- this.listeners.push(listener);
- if (this.listeners.length == 1) {
- ExecuteGenericFunction(functionId_notifyEventListener, { component: componentId_manager }, this.event);
- }
- },
- removeListener: function (listener) {
- for (var i = 0; i < this.listeners.length; i++) {
- if (this.listeners[i] === listener) {
- this.listeners.splice(i, 1);
- }
- }
- },
- hasListener: function (listener) {
- for (var i = 0; i < this.listeners.length; i++) {
- if (this.listeners[i] === listener) {
- return true;
- }
- }
- return false;
- } };
- storedHandlers.push(listenerHolder);
- return listenerHolder;
- }
- function InvokeHandler(eventId, sender, parameterString)
- {
- for (var i = 0; i < storedHandlers.length; i++) {
- if (eventId === storedHandlers[i].event) {
- var handler = storedHandlers[i].handler;
- var parameters;
- if (parameterString) {
- parameters = nativeJSON.parse(parameterString);
- }
- handler(sender, parameters, storedHandlers[i].listeners);
- return true;
- }
- }
- return false;
- }
- function ExecuteGenericFunction(functionId, destination, parameters, callback)
- {
- if (!callback && typeof(parameters) === "function") {
- callback = parameters;
- parameters = null;
- }
- var callbackId;
- if (callback) {
- callbackId = StoreCallback(callback);
- }
- var stringifiedParameters;
- if (GetTypeName(parameters) != "undefined") {
- stringifiedParameters = nativeJSON.stringify(parameters);
- }
- nativeMsBrowser.genericFunction(functionId, destination, stringifiedParameters, callbackId);
- }
- function ExecuteGenericSynchronousFunction(functionId, parameters)
- {
- var syncReturnValue;
- var stringifiedParameters;
- if (GetTypeName(parameters) != "undefined") {
- stringifiedParameters = nativeJSON.stringify(parameters);
- }
- var syncReturnString = nativeMsBrowser.genericSynchronousFunction(functionId, stringifiedParameters);
- if (syncReturnString) {
- syncReturnValue = nativeJSON.parse(syncReturnString);
- }
- return syncReturnValue;
- }
- nativeMsBrowser.registerGenericFunctionCallbackHandler(InvokeCallback);
- nativeMsBrowser.registerGenericListenerHandler(InvokeHandler);
- })(window.msBrowser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement