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 GetExtensionAPIDefinition(); | 11 native function GetExtensionAPIDefinition(); |
11 native function StartRequest(); | |
12 native function GetChromeHidden(); | |
13 native function GetNextRequestId(); | 12 native function GetNextRequestId(); |
14 native function Print(); | 13 native function Print(); |
14 native function StartRequest(); | |
15 | 15 |
16 native function CreateBlob(filePath); | |
17 native function DecodeJPEG(jpegImage); | |
16 native function GetCurrentPageActions(extensionId); | 18 native function GetCurrentPageActions(extensionId); |
17 native function GetExtensionViews(); | 19 native function GetExtensionViews(); |
20 native function GetLocalFileSystem(name, path); | |
18 native function GetNextContextMenuId(); | 21 native function GetNextContextMenuId(); |
22 native function GetNextSocketEventId(); | |
19 native function GetNextTtsEventId(); | 23 native function GetNextTtsEventId(); |
24 native function GetRenderViewId(); | |
25 native function GetUniqueSubEventName(eventName); | |
20 native function OpenChannelToTab(); | 26 native function OpenChannelToTab(); |
21 native function GetRenderViewId(); | 27 native function SendResponseAck(requestId); |
22 native function SetIconCommon(); | 28 native function SetIconCommon(); |
23 native function GetUniqueSubEventName(eventName); | |
24 native function GetLocalFileSystem(name, path); | |
25 native function DecodeJPEG(jpegImage); | |
26 native function CreateBlob(filePath); | |
27 native function SendResponseAck(requestId); | |
28 | 29 |
29 var chromeHidden = GetChromeHidden(); | 30 var chromeHidden = GetChromeHidden(); |
30 | 31 |
31 if (!chrome) | 32 if (!chrome) |
32 chrome = {}; | 33 chrome = {}; |
33 | 34 |
34 function forEach(dict, f) { | 35 function forEach(dict, f) { |
35 for (key in dict) { | 36 for (key in dict) { |
36 if (dict.hasOwnProperty(key)) | 37 if (dict.hasOwnProperty(key)) |
37 f(key, dict[key]); | 38 f(key, dict[key]); |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 delete chromeHidden.tts.handlers[event.srcId]; | 581 delete chromeHidden.tts.handlers[event.srcId]; |
581 } | 582 } |
582 } | 583 } |
583 }); | 584 }); |
584 } catch (e) { | 585 } catch (e) { |
585 // This extension doesn't have permission to access TTS, so we | 586 // This extension doesn't have permission to access TTS, so we |
586 // can safely ignore this. | 587 // can safely ignore this. |
587 } | 588 } |
588 } | 589 } |
589 | 590 |
591 function setupSocketEvents() { | |
592 chromeHidden.socket = {}; | |
593 chromeHidden.socket.handlers = {}; | |
594 try { | |
595 chrome.experimental.socket.onEvent.addListener( | |
asargent_no_longer_on_chrome
2011/12/14 17:36:18
I vaguely recall that when I added the listeners f
| |
596 function(event) { | |
597 var eventHandler = chromeHidden.socket.handlers[event.srcId]; | |
598 if (eventHandler) { | |
599 eventHandler({ | |
600 type: event.type, | |
601 resultCode: event.resultCode, | |
602 }); | |
603 if (event.isFinalEvent) { | |
604 delete chromeHidden.socket.handlers[event.srcId]; | |
605 } | |
606 } | |
607 }); | |
608 } catch (e) { | |
609 console.error(e); | |
610 } | |
611 } | |
612 | |
590 // Get the platform from navigator.appVersion. | 613 // Get the platform from navigator.appVersion. |
591 function getPlatform() { | 614 function getPlatform() { |
592 var platforms = [ | 615 var platforms = [ |
593 [/CrOS Touch/, "chromeos touch"], | 616 [/CrOS Touch/, "chromeos touch"], |
594 [/CrOS/, "chromeos"], | 617 [/CrOS/, "chromeos"], |
595 [/Linux/, "linux"], | 618 [/Linux/, "linux"], |
596 [/Mac/, "mac"], | 619 [/Mac/, "mac"], |
597 [/Win/, "win"], | 620 [/Win/, "win"], |
598 ]; | 621 ]; |
599 | 622 |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 var args = arguments; | 1110 var args = arguments; |
1088 if (args.length > 1 && args[1] && args[1].onEvent) { | 1111 if (args.length > 1 && args[1] && args[1].onEvent) { |
1089 var id = GetNextTtsEventId(); | 1112 var id = GetNextTtsEventId(); |
1090 args[1].srcId = id; | 1113 args[1].srcId = id; |
1091 chromeHidden.tts.handlers[id] = args[1].onEvent; | 1114 chromeHidden.tts.handlers[id] = args[1].onEvent; |
1092 } | 1115 } |
1093 sendRequest(this.name, args, this.definition.parameters); | 1116 sendRequest(this.name, args, this.definition.parameters); |
1094 return id; | 1117 return id; |
1095 }; | 1118 }; |
1096 | 1119 |
1120 apiFunctions["experimental.socket.create"].handleRequest = function() { | |
1121 var args = arguments; | |
1122 if (args.length > 1 && args[1] && args[1].onEvent) { | |
1123 var id = GetNextSocketEventId(); | |
1124 args[1].srcId = id; | |
1125 chromeHidden.socket.handlers[id] = args[1].onEvent; | |
1126 } | |
1127 sendRequest(this.name, args, this.definition.parameters); | |
1128 return id; | |
1129 }; | |
1130 | |
1097 if (chrome.test) { | 1131 if (chrome.test) { |
1098 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 1132 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
1099 } | 1133 } |
1100 | 1134 |
1101 setupPageActionEvents(extensionId); | |
1102 setupHiddenContextMenuEvent(extensionId); | 1135 setupHiddenContextMenuEvent(extensionId); |
1103 setupInputEvents(); | 1136 setupInputEvents(); |
1104 setupOmniboxEvents(); | 1137 setupOmniboxEvents(); |
1138 setupPageActionEvents(extensionId); | |
1139 setupSocketEvents(); | |
1105 setupTtsEvents(); | 1140 setupTtsEvents(); |
1106 }); | 1141 }); |
1107 | 1142 |
1108 if (!chrome.experimental) | 1143 if (!chrome.experimental) |
1109 chrome.experimental = {}; | 1144 chrome.experimental = {}; |
1110 | 1145 |
1111 if (!chrome.experimental.accessibility) | 1146 if (!chrome.experimental.accessibility) |
1112 chrome.experimental.accessibility = {}; | 1147 chrome.experimental.accessibility = {}; |
1113 | 1148 |
1114 if (!chrome.experimental.speechInput) | 1149 if (!chrome.experimental.speechInput) |
1115 chrome.experimental.speechInput = {}; | 1150 chrome.experimental.speechInput = {}; |
1116 | 1151 |
1152 if (!chrome.experimental.socket) | |
1153 chrome.experimental.socket = {}; | |
1154 | |
1117 if (!chrome.tts) | 1155 if (!chrome.tts) |
1118 chrome.tts = {}; | 1156 chrome.tts = {}; |
1119 | 1157 |
1120 if (!chrome.ttsEngine) | 1158 if (!chrome.ttsEngine) |
1121 chrome.ttsEngine = {}; | 1159 chrome.ttsEngine = {}; |
1122 | 1160 |
1123 if (!chrome.experimental.downloads) | 1161 if (!chrome.experimental.downloads) |
1124 chrome.experimental.downloads = {}; | 1162 chrome.experimental.downloads = {}; |
1125 })(); | 1163 })(); |
OLD | NEW |