OLD | NEW |
1 // Copyright (c) 2009 The chrome Authors. All rights reserved. | 1 // Copyright (c) 2009 The chrome 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 // ----------------------------------------------------------------------------- | 5 // ----------------------------------------------------------------------------- |
6 // NOTE: If you change this file you need to touch renderer_resources.grd to | 6 // NOTE: If you change this file you need to touch renderer_resources.grd to |
7 // have your change take effect. | 7 // have your change take effect. |
8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
9 | 9 |
10 // This script contains privileged chrome extension related javascript APIs. | 10 // This script contains privileged chrome extension related javascript APIs. |
11 // It is loaded by pages whose URL has the chrome-extension protocol. | 11 // It is loaded by pages whose URL has the chrome-extension protocol. |
12 | 12 |
13 var chrome = chrome || {}; | 13 var chrome = chrome || {}; |
14 (function() { | 14 (function() { |
15 native function GetExtensionAPIDefinition(); | 15 native function GetExtensionAPIDefinition(); |
16 native function StartRequest(); | 16 native function StartRequest(); |
17 native function GetCurrentPageActions(extensionId); | 17 native function GetCurrentPageActions(extensionId); |
18 native function GetExtensionViews(); | 18 native function GetExtensionViews(); |
19 native function GetChromeHidden(); | 19 native function GetChromeHidden(); |
20 native function GetNextRequestId(); | 20 native function GetNextRequestId(); |
21 native function OpenChannelToTab(); | 21 native function OpenChannelToTab(); |
| 22 native function ExecuteScript(); |
| 23 native function ExecuteScriptWithUrl(); |
22 | 24 |
23 if (!chrome) | 25 if (!chrome) |
24 chrome = {}; | 26 chrome = {}; |
25 | 27 |
26 var chromeHidden = GetChromeHidden(); | 28 var chromeHidden = GetChromeHidden(); |
27 | 29 |
28 // Validate arguments. | 30 // Validate arguments. |
29 chromeHidden.validationTypes = []; | 31 chromeHidden.validationTypes = []; |
30 chromeHidden.validate = function(args, schemas) { | 32 chromeHidden.validate = function(args, schemas) { |
31 if (args.length > schemas.length) | 33 if (args.length > schemas.length) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return GetExtensionViews(windowId, "TOOLSTRIP"); | 276 return GetExtensionViews(windowId, "TOOLSTRIP"); |
275 } | 277 } |
276 | 278 |
277 apiFunctions["extension.getTabContentses"].handleRequest = | 279 apiFunctions["extension.getTabContentses"].handleRequest = |
278 function(windowId) { | 280 function(windowId) { |
279 if (typeof(windowId) == "undefined") | 281 if (typeof(windowId) == "undefined") |
280 windowId = -1; | 282 windowId = -1; |
281 return GetExtensionViews(windowId, "TAB"); | 283 return GetExtensionViews(windowId, "TAB"); |
282 } | 284 } |
283 | 285 |
| 286 apiFunctions["extension.executeScriptCode"].handleRequest = |
| 287 function(scriptCode) { |
| 288 return ExecuteScript(scriptCode); |
| 289 } |
| 290 |
| 291 apiFunctions["extension.executeScriptWithUrl"].handleRequest = |
| 292 function(scriptUrl) { |
| 293 var requestId = GetNextRequestId(); |
| 294 var executeScriptCodeCallback = function(scriptCode) { |
| 295 return ExecuteScript(scriptCode); |
| 296 } |
| 297 callbacks[requestId] = executeScriptCodeCallback; |
| 298 return ExecuteScriptWithUrl(requestId, JSON.stringify(scriptUrl)); |
| 299 } |
| 300 |
284 apiFunctions["devtools.getTabEvents"].handleRequest = function(tabId) { | 301 apiFunctions["devtools.getTabEvents"].handleRequest = function(tabId) { |
285 var tabIdProxy = {}; | 302 var tabIdProxy = {}; |
286 forEach(["onPageEvent", "onTabUrlChange", "onTabClose"], | 303 forEach(["onPageEvent", "onTabUrlChange", "onTabClose"], |
287 function(name) { | 304 function(name) { |
288 // Event disambiguation is handled by name munging. See | 305 // Event disambiguation is handled by name munging. See |
289 // chrome/browser/extensions/extension_devtools_events.h for the C++ | 306 // chrome/browser/extensions/extension_devtools_events.h for the C++ |
290 // equivalent of this logic. | 307 // equivalent of this logic. |
291 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); | 308 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); |
292 }); | 309 }); |
293 return tabIdProxy; | 310 return tabIdProxy; |
294 } | 311 } |
295 | 312 |
296 setupPageActionEvents(extensionId); | 313 setupPageActionEvents(extensionId); |
297 }); | 314 }); |
298 })(); | 315 })(); |
OLD | NEW |