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 GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // opt_filter is specified, then the callback is only called for events that | 224 // opt_filter is specified, then the callback is only called for events that |
225 // match the given filters. If opt_extraInfo is specified, the given optional | 225 // match the given filters. If opt_extraInfo is specified, the given optional |
226 // info is sent to the callback. | 226 // info is sent to the callback. |
227 chrome.WebRequestEvent.prototype.addListener = | 227 chrome.WebRequestEvent.prototype.addListener = |
228 function(cb, opt_filter, opt_extraInfo) { | 228 function(cb, opt_filter, opt_extraInfo) { |
229 var subEventName = GetUniqueSubEventName(this.eventName_); | 229 var subEventName = GetUniqueSubEventName(this.eventName_); |
230 // Note: this could fail to validate, in which case we would not add the | 230 // Note: this could fail to validate, in which case we would not add the |
231 // subEvent listener. | 231 // subEvent listener. |
232 chromeHidden.validate(Array.prototype.slice.call(arguments, 1), | 232 chromeHidden.validate(Array.prototype.slice.call(arguments, 1), |
233 this.extraArgSchemas_); | 233 this.extraArgSchemas_); |
234 chrome.experimental.webRequest.addEventListener( | 234 chrome.webRequest.addEventListener( |
235 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); | 235 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); |
236 | 236 |
237 var subEvent = new chrome.Event(subEventName, this.argSchemas_); | 237 var subEvent = new chrome.Event(subEventName, this.argSchemas_); |
238 var subEventCallback = cb; | 238 var subEventCallback = cb; |
239 if (opt_extraInfo && opt_extraInfo.indexOf("blocking") >= 0) { | 239 if (opt_extraInfo && opt_extraInfo.indexOf("blocking") >= 0) { |
240 var eventName = this.eventName_; | 240 var eventName = this.eventName_; |
241 subEventCallback = function() { | 241 subEventCallback = function() { |
242 var requestId = arguments[0].requestId; | 242 var requestId = arguments[0].requestId; |
243 try { | 243 try { |
244 var result = cb.apply(null, arguments); | 244 var result = cb.apply(null, arguments); |
245 chrome.experimental.webRequest.eventHandled( | 245 chrome.webRequest.eventHandled( |
246 eventName, subEventName, requestId, result); | 246 eventName, subEventName, requestId, result); |
247 } catch (e) { | 247 } catch (e) { |
248 chrome.experimental.webRequest.eventHandled( | 248 chrome.webRequest.eventHandled( |
249 eventName, subEventName, requestId); | 249 eventName, subEventName, requestId); |
250 throw e; | 250 throw e; |
251 } | 251 } |
252 }; | 252 }; |
253 } else if (opt_extraInfo && opt_extraInfo.indexOf("asyncBlocking") >= 0) { | 253 } else if (opt_extraInfo && opt_extraInfo.indexOf("asyncBlocking") >= 0) { |
254 var eventName = this.eventName_; | 254 var eventName = this.eventName_; |
255 subEventCallback = function() { | 255 subEventCallback = function() { |
256 var details = arguments[0]; | 256 var details = arguments[0]; |
257 var requestId = details.requestId; | 257 var requestId = details.requestId; |
258 var handledCallback = function(response) { | 258 var handledCallback = function(response) { |
259 chrome.experimental.webRequest.eventHandled( | 259 chrome.webRequest.eventHandled( |
260 eventName, subEventName, requestId, response); | 260 eventName, subEventName, requestId, response); |
261 }; | 261 }; |
262 cb.apply(null, [details, handledCallback]); | 262 cb.apply(null, [details, handledCallback]); |
263 }; | 263 }; |
264 } | 264 } |
265 this.subEvents_.push( | 265 this.subEvents_.push( |
266 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback}); | 266 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback}); |
267 subEvent.addListener(subEventCallback); | 267 subEvent.addListener(subEventCallback); |
268 }; | 268 }; |
269 | 269 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 // Setup Events | 708 // Setup Events |
709 if (apiDef.events) { | 709 if (apiDef.events) { |
710 apiDef.events.forEach(function(eventDef) { | 710 apiDef.events.forEach(function(eventDef) { |
711 if (eventDef.name in module || | 711 if (eventDef.name in module || |
712 addUnprivilegedAccessGetter(module, eventDef.name, | 712 addUnprivilegedAccessGetter(module, eventDef.name, |
713 eventDef.unprivileged)) { | 713 eventDef.unprivileged)) { |
714 return; | 714 return; |
715 } | 715 } |
716 | 716 |
717 var eventName = apiDef.namespace + "." + eventDef.name; | 717 var eventName = apiDef.namespace + "." + eventDef.name; |
718 if (apiDef.namespace == "experimental.webRequest") { | 718 if (apiDef.namespace == "webRequest") { |
719 module[eventDef.name] = new chrome.WebRequestEvent(eventName, | 719 module[eventDef.name] = new chrome.WebRequestEvent(eventName, |
720 eventDef.parameters, eventDef.extraParameters); | 720 eventDef.parameters, eventDef.extraParameters); |
721 } else { | 721 } else { |
722 module[eventDef.name] = new chrome.Event(eventName, | 722 module[eventDef.name] = new chrome.Event(eventName, |
723 eventDef.parameters); | 723 eventDef.parameters); |
724 } | 724 } |
725 }); | 725 }); |
726 } | 726 } |
727 | 727 |
728 function addProperties(m, def) { | 728 function addProperties(m, def) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 {customCallback: this.customCallback}); | 971 {customCallback: this.customCallback}); |
972 return id; | 972 return id; |
973 }; | 973 }; |
974 | 974 |
975 apiFunctions["omnibox.setDefaultSuggestion"].handleRequest = | 975 apiFunctions["omnibox.setDefaultSuggestion"].handleRequest = |
976 function(details) { | 976 function(details) { |
977 var parseResult = parseOmniboxDescription(details.description); | 977 var parseResult = parseOmniboxDescription(details.description); |
978 sendRequest(this.name, [parseResult], this.definition.parameters); | 978 sendRequest(this.name, [parseResult], this.definition.parameters); |
979 }; | 979 }; |
980 | 980 |
981 apiFunctions["experimental.webRequest.addEventListener"].handleRequest = | 981 apiFunctions["webRequest.addEventListener"].handleRequest = |
982 function() { | 982 function() { |
983 var args = Array.prototype.slice.call(arguments); | 983 var args = Array.prototype.slice.call(arguments); |
984 sendRequest(this.name, args, this.definition.parameters, | 984 sendRequest(this.name, args, this.definition.parameters, |
985 {forIOThread: true}); | 985 {forIOThread: true}); |
986 }; | 986 }; |
987 | 987 |
988 apiFunctions["experimental.webRequest.eventHandled"].handleRequest = | 988 apiFunctions["webRequest.eventHandled"].handleRequest = |
989 function() { | 989 function() { |
990 var args = Array.prototype.slice.call(arguments); | 990 var args = Array.prototype.slice.call(arguments); |
991 sendRequest(this.name, args, this.definition.parameters, | 991 sendRequest(this.name, args, this.definition.parameters, |
992 {forIOThread: true}); | 992 {forIOThread: true}); |
993 }; | 993 }; |
994 | 994 |
995 apiFunctions["experimental.webRequest.handlerBehaviorChanged"]. | 995 apiFunctions["webRequest.handlerBehaviorChanged"]. |
996 handleRequest = function() { | 996 handleRequest = function() { |
997 var args = Array.prototype.slice.call(arguments); | 997 var args = Array.prototype.slice.call(arguments); |
998 sendRequest(this.name, args, this.definition.parameters, | 998 sendRequest(this.name, args, this.definition.parameters, |
999 {forIOThread: true}); | 999 {forIOThread: true}); |
1000 }; | 1000 }; |
1001 | 1001 |
1002 apiFunctions["contextMenus.create"].customCallback = | 1002 apiFunctions["contextMenus.create"].customCallback = |
1003 function(name, request, response) { | 1003 function(name, request, response) { |
1004 if (chrome.extension.lastError) { | 1004 if (chrome.extension.lastError) { |
1005 return; | 1005 return; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1108 |
1109 if (!chrome.tts) | 1109 if (!chrome.tts) |
1110 chrome.tts = {}; | 1110 chrome.tts = {}; |
1111 | 1111 |
1112 if (!chrome.ttsEngine) | 1112 if (!chrome.ttsEngine) |
1113 chrome.ttsEngine = {}; | 1113 chrome.ttsEngine = {}; |
1114 | 1114 |
1115 if (!chrome.experimental.downloads) | 1115 if (!chrome.experimental.downloads) |
1116 chrome.experimental.downloads = {}; | 1116 chrome.experimental.downloads = {}; |
1117 })(); | 1117 })(); |
OLD | NEW |