OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
7 | 7 |
8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
9 (function() { | 9 (function() { |
10 native function GetChromeHidden(); | 10 native function GetChromeHidden(); |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 // Setup the ChromeSetting class so we can use it to construct | 631 // Setup the ChromeSetting class so we can use it to construct |
632 // ChromeSetting objects from the API definition. | 632 // ChromeSetting objects from the API definition. |
633 setupChromeSetting(); | 633 setupChromeSetting(); |
634 | 634 |
635 // Ditto ContentSetting. | 635 // Ditto ContentSetting. |
636 setupContentSetting(); | 636 setupContentSetting(); |
637 | 637 |
638 // Ditto StorageNamespace. | 638 // Ditto StorageNamespace. |
639 setupStorageNamespace(); | 639 setupStorageNamespace(); |
640 | 640 |
641 // |apiFunctions| is a hash of name -> object that stores the | 641 // Stores the name and definition of each API function, with methods to |
642 // name & definition of the apiFunction. Custom handling of api functions | 642 // modify their behaviour (such as a custom way to handle requests to the |
643 // is implemented by adding a "handleRequest" function to the object. | 643 // API, a custom callback, etc). |
644 var apiFunctions = {}; | 644 function APIFunctions() { |
| 645 this.apiFunctions_ = {}; |
| 646 } |
| 647 APIFunctions.prototype.register = function(apiName, apiFunction) { |
| 648 this.apiFunctions_[apiName] = apiFunction; |
| 649 }; |
| 650 APIFunctions.prototype.setProperty = |
| 651 function(apiName, propertyName, customizedFunction) { |
| 652 // TODO(kalman): later, when this is asynchronous and we're only |
| 653 // customizing exactly what we need, these should be held onto until |
| 654 // this api function is registered. |
| 655 if (this.apiFunctions_.hasOwnProperty(apiName)) |
| 656 this.apiFunctions_[apiName][propertyName] = customizedFunction; |
| 657 }; |
| 658 APIFunctions.prototype.setHandleRequest = |
| 659 function(apiName, customizedFunction) { |
| 660 return this.setProperty(apiName, 'handleRequest', customizedFunction); |
| 661 }; |
| 662 APIFunctions.prototype.setUpdateArgumentsPostValidate = |
| 663 function(apiName, customizedFunction) { |
| 664 return this.setProperty( |
| 665 apiName, 'updateArgumentsPostValidate', customizedFunction); |
| 666 }; |
| 667 APIFunctions.prototype.setUpdateArgumentsPreValidate = |
| 668 function(apiName, customizedFunction) { |
| 669 return this.setProperty( |
| 670 apiName, 'updateArgumentsPreValidate', customizedFunction); |
| 671 }; |
| 672 APIFunctions.prototype.setCustomCallback = |
| 673 function(apiName, customizedFunction) { |
| 674 return this.setProperty(apiName, 'customCallback', customizedFunction); |
| 675 }; |
| 676 |
| 677 var apiFunctions = new APIFunctions(); |
645 | 678 |
646 // Read api definitions and setup api functions in the chrome namespace. | 679 // Read api definitions and setup api functions in the chrome namespace. |
647 // TODO(rafaelw): Consider defining a json schema for an api definition | 680 // TODO(rafaelw): Consider defining a json schema for an api definition |
648 // and validating either here, in a unit_test or both. | 681 // and validating either here, in a unit_test or both. |
649 // TODO(rafaelw): Handle synchronous functions. | 682 // TODO(rafaelw): Handle synchronous functions. |
650 // TODO(rafaelw): Consider providing some convenient override points | 683 // TODO(rafaelw): Consider providing some convenient override points |
651 // for api functions that wish to insert themselves into the call. | 684 // for api functions that wish to insert themselves into the call. |
652 var apiDefinitions = GetExtensionAPIDefinition(); | 685 var apiDefinitions = GetExtensionAPIDefinition(); |
653 var platform = getPlatform(); | 686 var platform = getPlatform(); |
654 | 687 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 apiDef.functions.forEach(function(functionDef) { | 730 apiDef.functions.forEach(function(functionDef) { |
698 if (functionDef.name in module || | 731 if (functionDef.name in module || |
699 addUnprivilegedAccessGetter(module, functionDef.name, | 732 addUnprivilegedAccessGetter(module, functionDef.name, |
700 functionDef.unprivileged)) { | 733 functionDef.unprivileged)) { |
701 return; | 734 return; |
702 } | 735 } |
703 | 736 |
704 var apiFunction = {}; | 737 var apiFunction = {}; |
705 apiFunction.definition = functionDef; | 738 apiFunction.definition = functionDef; |
706 apiFunction.name = apiDef.namespace + "." + functionDef.name; | 739 apiFunction.name = apiDef.namespace + "." + functionDef.name; |
707 apiFunctions[apiFunction.name] = apiFunction; | 740 apiFunctions.register(apiFunction.name, apiFunction); |
708 | 741 |
709 module[functionDef.name] = (function() { | 742 module[functionDef.name] = (function() { |
710 var args = arguments; | 743 var args = arguments; |
711 if (this.updateArgumentsPreValidate) | 744 if (this.updateArgumentsPreValidate) |
712 args = this.updateArgumentsPreValidate.apply(this, args); | 745 args = this.updateArgumentsPreValidate.apply(this, args); |
713 chromeHidden.validate(args, this.definition.parameters); | 746 chromeHidden.validate(args, this.definition.parameters); |
714 if (this.updateArgumentsPostValidate) | 747 if (this.updateArgumentsPostValidate) |
715 args = this.updateArgumentsPostValidate.apply(this, args); | 748 args = this.updateArgumentsPostValidate.apply(this, args); |
716 | 749 |
717 var retval; | 750 var retval; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 | 839 |
807 // getTabContentses is retained for backwards compatibility | 840 // getTabContentses is retained for backwards compatibility |
808 // See http://crbug.com/21433 | 841 // See http://crbug.com/21433 |
809 chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; | 842 chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; |
810 // TOOD(mihaip): remove this alias once the webstore stops calling | 843 // TOOD(mihaip): remove this alias once the webstore stops calling |
811 // beginInstallWithManifest2. | 844 // beginInstallWithManifest2. |
812 // See http://crbug.com/100242 | 845 // See http://crbug.com/100242 |
813 chrome.webstorePrivate.beginInstallWithManifest2 = | 846 chrome.webstorePrivate.beginInstallWithManifest2 = |
814 chrome.webstorePrivate.beginInstallWithManifest3; | 847 chrome.webstorePrivate.beginInstallWithManifest3; |
815 | 848 |
816 apiFunctions["tabs.connect"].handleRequest = function(tabId, connectInfo) { | 849 apiFunctions.setHandleRequest("tabs.connect", function(tabId, connectInfo) { |
817 var name = ""; | 850 var name = ""; |
818 if (connectInfo) { | 851 if (connectInfo) { |
819 name = connectInfo.name || name; | 852 name = connectInfo.name || name; |
820 } | 853 } |
821 var portId = OpenChannelToTab(tabId, chromeHidden.extensionId, name); | 854 var portId = OpenChannelToTab(tabId, chromeHidden.extensionId, name); |
822 return chromeHidden.Port.createPort(portId, name); | 855 return chromeHidden.Port.createPort(portId, name); |
823 }; | 856 }); |
824 | 857 |
825 apiFunctions["tabs.sendRequest"].handleRequest = | 858 apiFunctions.setHandleRequest("tabs.sendRequest", |
826 function(tabId, request, responseCallback) { | 859 function(tabId, request, responseCallback) { |
827 var port = chrome.tabs.connect(tabId, | 860 var port = chrome.tabs.connect(tabId, |
828 {name: chromeHidden.kRequestChannel}); | 861 {name: chromeHidden.kRequestChannel}); |
829 port.postMessage(request); | 862 port.postMessage(request); |
830 port.onDisconnect.addListener(function() { | 863 port.onDisconnect.addListener(function() { |
831 // For onDisconnects, we only notify the callback if there was an error. | 864 // For onDisconnects, we only notify the callback if there was an error. |
832 if (chrome.extension.lastError && responseCallback) | 865 if (chrome.extension.lastError && responseCallback) |
833 responseCallback(); | 866 responseCallback(); |
834 }); | 867 }); |
835 port.onMessage.addListener(function(response) { | 868 port.onMessage.addListener(function(response) { |
836 try { | 869 try { |
837 if (responseCallback) | 870 if (responseCallback) |
838 responseCallback(response); | 871 responseCallback(response); |
839 } finally { | 872 } finally { |
840 port.disconnect(); | 873 port.disconnect(); |
841 port = null; | 874 port = null; |
842 } | 875 } |
843 }); | 876 }); |
844 }; | 877 }); |
845 | 878 |
846 apiFunctions["pageCapture.saveAsMHTML"].customCallback = | 879 apiFunctions.setCustomCallback("pageCapture.saveAsMHTML", |
847 function(name, request, response) { | 880 function(name, request, response) { |
848 var params = chromeHidden.JSON.parse(response); | 881 var params = chromeHidden.JSON.parse(response); |
849 var path = params.mhtmlFilePath; | 882 var path = params.mhtmlFilePath; |
850 var size = params.mhtmlFileLength; | 883 var size = params.mhtmlFileLength; |
851 | 884 |
852 if (request.callback) | 885 if (request.callback) |
853 request.callback(CreateBlob(path, size)); | 886 request.callback(CreateBlob(path, size)); |
854 request.callback = null; | 887 request.callback = null; |
855 | 888 |
856 // Notify the browser. Now that the blob is referenced from JavaScript, | 889 // Notify the browser. Now that the blob is referenced from JavaScript, |
857 // the browser can drop its reference to it. | 890 // the browser can drop its reference to it. |
858 SendResponseAck(request.id); | 891 SendResponseAck(request.id); |
859 }; | 892 }); |
860 | 893 |
861 apiFunctions["fileBrowserPrivate.requestLocalFileSystem"].customCallback = | 894 apiFunctions.setCustomCallback("fileBrowserPrivate.requestLocalFileSystem", |
862 function(name, request, response) { | 895 function(name, request, response) { |
863 var resp = response ? [chromeHidden.JSON.parse(response)] : []; | 896 var resp = response ? [chromeHidden.JSON.parse(response)] : []; |
864 var fs = null; | 897 var fs = null; |
865 if (!resp[0].error) | 898 if (!resp[0].error) |
866 fs = GetLocalFileSystem(resp[0].name, resp[0].path); | 899 fs = GetLocalFileSystem(resp[0].name, resp[0].path); |
867 if (request.callback) | 900 if (request.callback) |
868 request.callback(fs); | 901 request.callback(fs); |
869 request.callback = null; | 902 request.callback = null; |
870 }; | 903 }); |
871 | 904 |
872 apiFunctions["chromePrivate.decodeJPEG"].handleRequest = | 905 apiFunctions.setHandleRequest("chromePrivate.decodeJPEG", |
873 function(jpeg_image) { | 906 function(jpeg_image) { |
874 return DecodeJPEG(jpeg_image); | 907 return DecodeJPEG(jpeg_image); |
875 }; | 908 }); |
876 | 909 |
877 apiFunctions["extension.getViews"].handleRequest = function(properties) { | 910 apiFunctions.setHandleRequest("extension.getViews", function(properties) { |
878 var windowId = -1; | 911 var windowId = -1; |
879 var type = "ALL"; | 912 var type = "ALL"; |
880 if (typeof(properties) != "undefined") { | 913 if (typeof(properties) != "undefined") { |
881 if (typeof(properties.type) != "undefined") { | 914 if (typeof(properties.type) != "undefined") { |
882 type = properties.type; | 915 type = properties.type; |
883 } | 916 } |
884 if (typeof(properties.windowId) != "undefined") { | 917 if (typeof(properties.windowId) != "undefined") { |
885 windowId = properties.windowId; | 918 windowId = properties.windowId; |
886 } | 919 } |
887 } | 920 } |
888 return GetExtensionViews(windowId, type) || null; | 921 return GetExtensionViews(windowId, type) || null; |
889 }; | 922 }); |
890 | 923 |
891 apiFunctions["extension.getBackgroundPage"].handleRequest = function() { | 924 apiFunctions.setHandleRequest("extension.getBackgroundPage", function() { |
892 return GetExtensionViews(-1, "BACKGROUND")[0] || null; | 925 return GetExtensionViews(-1, "BACKGROUND")[0] || null; |
893 }; | 926 }); |
894 | 927 |
895 apiFunctions["extension.getExtensionTabs"].handleRequest = | 928 apiFunctions.setHandleRequest("extension.getExtensionTabs", |
896 function(windowId) { | 929 function(windowId) { |
897 if (typeof(windowId) == "undefined") | 930 if (typeof(windowId) == "undefined") |
898 windowId = -1; | 931 windowId = -1; |
899 return GetExtensionViews(windowId, "TAB"); | 932 return GetExtensionViews(windowId, "TAB"); |
900 }; | 933 }); |
901 | 934 |
902 apiFunctions["devtools.getTabEvents"].handleRequest = function(tabId) { | 935 apiFunctions.setHandleRequest("devtools.getTabEvents", function(tabId) { |
903 var tabIdProxy = {}; | 936 var tabIdProxy = {}; |
904 var functions = ["onPageEvent", "onTabClose"]; | 937 var functions = ["onPageEvent", "onTabClose"]; |
905 functions.forEach(function(name) { | 938 functions.forEach(function(name) { |
906 // Event disambiguation is handled by name munging. See | 939 // Event disambiguation is handled by name munging. See |
907 // chrome/browser/extensions/extension_devtools_events.h for the C++ | 940 // chrome/browser/extensions/extension_devtools_events.h for the C++ |
908 // equivalent of this logic. | 941 // equivalent of this logic. |
909 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); | 942 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); |
910 }); | 943 }); |
911 return tabIdProxy; | 944 return tabIdProxy; |
912 }; | 945 }); |
913 | 946 |
914 var canvas; | 947 var canvas; |
915 function setIconCommon(details, name, parameters, actionType, iconSize, | 948 function setIconCommon(details, name, parameters, actionType, iconSize, |
916 nativeFunction) { | 949 nativeFunction) { |
917 if ("iconIndex" in details) { | 950 if ("iconIndex" in details) { |
918 sendRequest(name, [details], parameters); | 951 sendRequest(name, [details], parameters); |
919 } else if ("imageData" in details) { | 952 } else if ("imageData" in details) { |
920 // Verify that this at least looks like an ImageData element. | 953 // Verify that this at least looks like an ImageData element. |
921 // Unfortunately, we cannot use instanceof because the ImageData | 954 // Unfortunately, we cannot use instanceof because the ImageData |
922 // constructor is not public. | 955 // constructor is not public. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 } | 999 } |
967 } | 1000 } |
968 | 1001 |
969 function setExtensionActionIconCommon(details, name, parameters, | 1002 function setExtensionActionIconCommon(details, name, parameters, |
970 actionType) { | 1003 actionType) { |
971 var EXTENSION_ACTION_ICON_SIZE = 19; | 1004 var EXTENSION_ACTION_ICON_SIZE = 19; |
972 setIconCommon(details, name, parameters, actionType, | 1005 setIconCommon(details, name, parameters, actionType, |
973 EXTENSION_ACTION_ICON_SIZE, SetIconCommon); | 1006 EXTENSION_ACTION_ICON_SIZE, SetIconCommon); |
974 } | 1007 } |
975 | 1008 |
976 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { | 1009 apiFunctions.setHandleRequest("browserAction.setIcon", function(details) { |
977 setExtensionActionIconCommon( | 1010 setExtensionActionIconCommon( |
978 details, this.name, this.definition.parameters, "browser action"); | 1011 details, this.name, this.definition.parameters, "browser action"); |
979 }; | 1012 }); |
980 | 1013 |
981 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { | 1014 apiFunctions.setHandleRequest("pageAction.setIcon", function(details) { |
982 setExtensionActionIconCommon( | 1015 setExtensionActionIconCommon( |
983 details, this.name, this.definition.parameters, "page action"); | 1016 details, this.name, this.definition.parameters, "page action"); |
984 }; | 1017 }); |
985 | 1018 |
986 apiFunctions["experimental.sidebar.setIcon"].handleRequest = | 1019 apiFunctions.setHandleRequest("experimental.sidebar.setIcon", |
987 function(details) { | 1020 function(details) { |
988 var SIDEBAR_ICON_SIZE = 16; | 1021 var SIDEBAR_ICON_SIZE = 16; |
989 setIconCommon( | 1022 setIconCommon( |
990 details, this.name, this.definition.parameters, "sidebar", | 1023 details, this.name, this.definition.parameters, "sidebar", |
991 SIDEBAR_ICON_SIZE, SetIconCommon); | 1024 SIDEBAR_ICON_SIZE, SetIconCommon); |
992 }; | 1025 }); |
993 | 1026 |
994 apiFunctions["contextMenus.create"].handleRequest = | 1027 apiFunctions.setHandleRequest("contextMenus.create", |
995 function() { | 1028 function() { |
996 var args = arguments; | 1029 var args = arguments; |
997 var id = GetNextContextMenuId(); | 1030 var id = GetNextContextMenuId(); |
998 args[0].generatedId = id; | 1031 args[0].generatedId = id; |
999 sendRequest(this.name, args, this.definition.parameters, | 1032 sendRequest(this.name, args, this.definition.parameters, |
1000 {customCallback: this.customCallback}); | 1033 {customCallback: this.customCallback}); |
1001 return id; | 1034 return id; |
1002 }; | 1035 }); |
1003 | 1036 |
1004 apiFunctions["omnibox.setDefaultSuggestion"].handleRequest = | 1037 apiFunctions.setHandleRequest("omnibox.setDefaultSuggestion", |
1005 function(details) { | 1038 function(details) { |
1006 var parseResult = parseOmniboxDescription(details.description); | 1039 var parseResult = parseOmniboxDescription(details.description); |
1007 sendRequest(this.name, [parseResult], this.definition.parameters); | 1040 sendRequest(this.name, [parseResult], this.definition.parameters); |
1008 }; | 1041 }); |
1009 | 1042 |
1010 apiFunctions["webRequest.addEventListener"].handleRequest = | 1043 apiFunctions.setHandleRequest("webRequest.addEventListener", |
1011 function() { | 1044 function() { |
1012 var args = Array.prototype.slice.call(arguments); | 1045 var args = Array.prototype.slice.call(arguments); |
1013 sendRequest(this.name, args, this.definition.parameters, | 1046 sendRequest(this.name, args, this.definition.parameters, |
1014 {forIOThread: true}); | 1047 {forIOThread: true}); |
1015 }; | 1048 }); |
1016 | 1049 |
1017 apiFunctions["webRequest.eventHandled"].handleRequest = | 1050 apiFunctions.setHandleRequest("webRequest.eventHandled", |
1018 function() { | 1051 function() { |
1019 var args = Array.prototype.slice.call(arguments); | 1052 var args = Array.prototype.slice.call(arguments); |
1020 sendRequest(this.name, args, this.definition.parameters, | 1053 sendRequest(this.name, args, this.definition.parameters, |
1021 {forIOThread: true}); | 1054 {forIOThread: true}); |
1022 }; | 1055 }); |
1023 | 1056 |
1024 apiFunctions["webRequest.handlerBehaviorChanged"]. | 1057 apiFunctions.setHandleRequest("webRequest.handlerBehaviorChanged", |
1025 handleRequest = function() { | 1058 function() { |
1026 var args = Array.prototype.slice.call(arguments); | 1059 var args = Array.prototype.slice.call(arguments); |
1027 sendRequest(this.name, args, this.definition.parameters, | 1060 sendRequest(this.name, args, this.definition.parameters, |
1028 {forIOThread: true}); | 1061 {forIOThread: true}); |
1029 }; | 1062 }); |
1030 | 1063 |
1031 apiFunctions["contextMenus.create"].customCallback = | 1064 apiFunctions.setCustomCallback("contextMenus.create", |
1032 function(name, request, response) { | 1065 function(name, request, response) { |
1033 if (chrome.extension.lastError) { | 1066 if (chrome.extension.lastError) { |
1034 return; | 1067 return; |
1035 } | 1068 } |
1036 | 1069 |
1037 var id = request.args[0].generatedId; | 1070 var id = request.args[0].generatedId; |
1038 | 1071 |
1039 // Set up the onclick handler if we were passed one in the request. | 1072 // Set up the onclick handler if we were passed one in the request. |
1040 var onclick = request.args.length ? request.args[0].onclick : null; | 1073 var onclick = request.args.length ? request.args[0].onclick : null; |
1041 if (onclick) { | 1074 if (onclick) { |
1042 chromeHidden.contextMenus.ensureListenerSetup(); | 1075 chromeHidden.contextMenus.ensureListenerSetup(); |
1043 chromeHidden.contextMenus.handlers[id] = onclick; | 1076 chromeHidden.contextMenus.handlers[id] = onclick; |
1044 } | 1077 } |
1045 }; | 1078 }); |
1046 | 1079 |
1047 apiFunctions["contextMenus.remove"].customCallback = | 1080 apiFunctions.setCustomCallback("contextMenus.remove", |
1048 function(name, request, response) { | 1081 function(name, request, response) { |
1049 if (chrome.extension.lastError) { | 1082 if (chrome.extension.lastError) { |
1050 return; | 1083 return; |
1051 } | 1084 } |
1052 var id = request.args[0]; | 1085 var id = request.args[0]; |
1053 delete chromeHidden.contextMenus.handlers[id]; | 1086 delete chromeHidden.contextMenus.handlers[id]; |
1054 }; | 1087 }); |
1055 | 1088 |
1056 apiFunctions["contextMenus.update"].customCallback = | 1089 apiFunctions.setCustomCallback("contextMenus.update", |
1057 function(name, request, response) { | 1090 function(name, request, response) { |
1058 if (chrome.extension.lastError) { | 1091 if (chrome.extension.lastError) { |
1059 return; | 1092 return; |
1060 } | 1093 } |
1061 var id = request.args[0]; | 1094 var id = request.args[0]; |
1062 if (request.args[1].onclick) { | 1095 if (request.args[1].onclick) { |
1063 chromeHidden.contextMenus.handlers[id] = request.args[1].onclick; | 1096 chromeHidden.contextMenus.handlers[id] = request.args[1].onclick; |
1064 } | 1097 } |
1065 }; | 1098 }); |
1066 | 1099 |
1067 apiFunctions["contextMenus.removeAll"].customCallback = | 1100 apiFunctions.setCustomCallback("contextMenus.removeAll", |
1068 function(name, request, response) { | 1101 function(name, request, response) { |
1069 if (chrome.extension.lastError) { | 1102 if (chrome.extension.lastError) { |
1070 return; | 1103 return; |
1071 } | 1104 } |
1072 chromeHidden.contextMenus.handlers = {}; | 1105 chromeHidden.contextMenus.handlers = {}; |
1073 }; | 1106 }); |
1074 | 1107 |
1075 apiFunctions["tabs.captureVisibleTab"].updateArgumentsPreValidate = | 1108 apiFunctions.setUpdateArgumentsPreValidate("tabs.captureVisibleTab", |
1076 function() { | 1109 function() { |
1077 // Old signature: | 1110 // Old signature: |
1078 // captureVisibleTab(int windowId, function callback); | 1111 // captureVisibleTab(int windowId, function callback); |
1079 // New signature: | 1112 // New signature: |
1080 // captureVisibleTab(int windowId, object details, function callback); | 1113 // captureVisibleTab(int windowId, object details, function callback); |
1081 // | 1114 // |
1082 // TODO(skerner): The next step to omitting optional arguments is the | 1115 // TODO(skerner): The next step to omitting optional arguments is the |
1083 // replacement of this code with code that matches arguments by type. | 1116 // replacement of this code with code that matches arguments by type. |
1084 // Once this is working for captureVisibleTab() it can be enabled for | 1117 // Once this is working for captureVisibleTab() it can be enabled for |
1085 // the rest of the API. See crbug/29215 . | 1118 // the rest of the API. See crbug/29215 . |
1086 if (arguments.length == 2 && typeof(arguments[1]) == "function") { | 1119 if (arguments.length == 2 && typeof(arguments[1]) == "function") { |
1087 // If the old signature is used, add a null details object. | 1120 // If the old signature is used, add a null details object. |
1088 newArgs = [arguments[0], null, arguments[1]]; | 1121 newArgs = [arguments[0], null, arguments[1]]; |
1089 } else { | 1122 } else { |
1090 newArgs = arguments; | 1123 newArgs = arguments; |
1091 } | 1124 } |
1092 return newArgs; | 1125 return newArgs; |
1093 }; | 1126 }); |
1094 | 1127 |
1095 apiFunctions["omnibox.sendSuggestions"].updateArgumentsPostValidate = | 1128 apiFunctions.setUpdateArgumentsPostValidate("omnibox.sendSuggestions", |
1096 function(requestId, userSuggestions) { | 1129 function(requestId, userSuggestions) { |
1097 var suggestions = []; | 1130 var suggestions = []; |
1098 for (var i = 0; i < userSuggestions.length; i++) { | 1131 for (var i = 0; i < userSuggestions.length; i++) { |
1099 var parseResult = parseOmniboxDescription( | 1132 var parseResult = parseOmniboxDescription( |
1100 userSuggestions[i].description); | 1133 userSuggestions[i].description); |
1101 parseResult.content = userSuggestions[i].content; | 1134 parseResult.content = userSuggestions[i].content; |
1102 suggestions.push(parseResult); | 1135 suggestions.push(parseResult); |
1103 } | 1136 } |
1104 return [requestId, suggestions]; | 1137 return [requestId, suggestions]; |
1105 }; | 1138 }); |
1106 | 1139 |
1107 apiFunctions["tts.speak"].handleRequest = function() { | 1140 apiFunctions.setHandleRequest("tts.speak", function() { |
1108 var args = arguments; | 1141 var args = arguments; |
1109 if (args.length > 1 && args[1] && args[1].onEvent) { | 1142 if (args.length > 1 && args[1] && args[1].onEvent) { |
1110 var id = GetNextTtsEventId(); | 1143 var id = GetNextTtsEventId(); |
1111 args[1].srcId = id; | 1144 args[1].srcId = id; |
1112 chromeHidden.tts.handlers[id] = args[1].onEvent; | 1145 chromeHidden.tts.handlers[id] = args[1].onEvent; |
1113 } | 1146 } |
1114 sendRequest(this.name, args, this.definition.parameters); | 1147 sendRequest(this.name, args, this.definition.parameters); |
1115 return id; | 1148 return id; |
1116 }; | 1149 }); |
1117 | 1150 |
1118 apiFunctions["experimental.socket.create"].handleRequest = function() { | 1151 apiFunctions.setHandleRequest("experimental.socket.create", function() { |
1119 var args = arguments; | 1152 var args = arguments; |
1120 if (args.length > 1 && args[1] && args[1].onEvent) { | 1153 if (args.length > 1 && args[1] && args[1].onEvent) { |
1121 var id = GetNextSocketEventId(); | 1154 var id = GetNextSocketEventId(); |
1122 args[1].srcId = id; | 1155 args[1].srcId = id; |
1123 chromeHidden.socket.handlers[id] = args[1].onEvent; | 1156 chromeHidden.socket.handlers[id] = args[1].onEvent; |
1124 } | 1157 } |
1125 sendRequest(this.name, args, this.definition.parameters); | 1158 sendRequest(this.name, args, this.definition.parameters); |
1126 return id; | 1159 return id; |
1127 }; | 1160 }); |
1128 | 1161 |
1129 if (chrome.test) { | 1162 if (chrome.test) { |
1130 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 1163 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
1131 } | 1164 } |
1132 | 1165 |
1133 setupHiddenContextMenuEvent(extensionId); | 1166 setupHiddenContextMenuEvent(extensionId); |
1134 setupInputEvents(); | 1167 setupInputEvents(); |
1135 setupOmniboxEvents(); | 1168 setupOmniboxEvents(); |
1136 setupPageActionEvents(extensionId); | 1169 setupPageActionEvents(extensionId); |
1137 setupSocketEvents(); | 1170 setupSocketEvents(); |
1138 setupTtsEvents(); | 1171 setupTtsEvents(); |
1139 }); | 1172 }); |
1140 | 1173 |
| 1174 // TODO(kalman): these should all be unnecessary steps if we design the |
| 1175 // APIFunctions class correctly. |
| 1176 |
1141 if (!chrome.experimental) | 1177 if (!chrome.experimental) |
1142 chrome.experimental = {}; | 1178 chrome.experimental = {}; |
1143 | 1179 |
1144 if (!chrome.experimental.accessibility) | 1180 if (!chrome.experimental.accessibility) |
1145 chrome.experimental.accessibility = {}; | 1181 chrome.experimental.accessibility = {}; |
1146 | 1182 |
1147 if (!chrome.experimental.speechInput) | 1183 if (!chrome.experimental.speechInput) |
1148 chrome.experimental.speechInput = {}; | 1184 chrome.experimental.speechInput = {}; |
1149 | 1185 |
1150 if (!chrome.experimental.socket) | 1186 if (!chrome.experimental.socket) |
1151 chrome.experimental.socket = {}; | 1187 chrome.experimental.socket = {}; |
1152 | 1188 |
1153 if (!chrome.tts) | 1189 if (!chrome.tts) |
1154 chrome.tts = {}; | 1190 chrome.tts = {}; |
1155 | 1191 |
1156 if (!chrome.ttsEngine) | 1192 if (!chrome.ttsEngine) |
1157 chrome.ttsEngine = {}; | 1193 chrome.ttsEngine = {}; |
1158 | 1194 |
1159 if (!chrome.experimental.downloads) | 1195 if (!chrome.experimental.downloads) |
1160 chrome.experimental.downloads = {}; | 1196 chrome.experimental.downloads = {}; |
1161 })(); | 1197 })(); |
OLD | NEW |