OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Custom binding for the extension API. | 5 // Custom binding for the extension API. |
6 | 6 |
7 var binding = require('binding').Binding.create('extension'); | 7 var binding = require('binding').Binding.create('extension'); |
8 | 8 |
9 var extensionNatives = requireNative('extension'); | 9 var extensionNatives = requireNative('extension'); |
10 var forEach = require('utils').forEach; | 10 var forEach = require('utils').forEach; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 var type = 'ALL'; | 44 var type = 'ALL'; |
45 if (properties) { | 45 if (properties) { |
46 if (properties.type != null) { | 46 if (properties.type != null) { |
47 type = properties.type; | 47 type = properties.type; |
48 } | 48 } |
49 if (properties.windowId != null) { | 49 if (properties.windowId != null) { |
50 windowId = properties.windowId; | 50 windowId = properties.windowId; |
51 } | 51 } |
52 } | 52 } |
53 return GetExtensionViews(windowId, type) || null; | 53 return GetExtensionViews(windowId, type) || null; |
54 }); | 54 }, false); |
55 | 55 |
56 apiFunctions.setHandleRequest('getBackgroundPage', function() { | 56 apiFunctions.setHandleRequest('getBackgroundPage', function() { |
57 return GetExtensionViews(-1, 'BACKGROUND')[0] || null; | 57 return GetExtensionViews(-1, 'BACKGROUND')[0] || null; |
58 }); | 58 }, false); |
59 | 59 |
60 apiFunctions.setHandleRequest('getExtensionTabs', function(windowId) { | 60 apiFunctions.setHandleRequest('getExtensionTabs', function(windowId) { |
61 if (windowId == null) | 61 if (windowId == null) |
62 windowId = WINDOW_ID_NONE; | 62 windowId = WINDOW_ID_NONE; |
63 return GetExtensionViews(windowId, 'TAB'); | 63 return GetExtensionViews(windowId, 'TAB'); |
64 }); | 64 }, false); |
65 | 65 |
66 apiFunctions.setHandleRequest('getURL', function(path) { | 66 apiFunctions.setHandleRequest('getURL', function(path) { |
67 path = String(path); | 67 path = String(path); |
68 if (!path.length || path[0] != '/') | 68 if (!path.length || path[0] != '/') |
69 path = '/' + path; | 69 path = '/' + path; |
70 return 'chrome-extension://' + extensionId + path; | 70 return 'chrome-extension://' + extensionId + path; |
71 }); | 71 }, false); |
72 | 72 |
73 // Alias several messaging deprecated APIs to their runtime counterparts. | 73 // Alias several messaging deprecated APIs to their runtime counterparts. |
74 var mayNeedAlias = [ | 74 var mayNeedAlias = [ |
75 // Types | 75 // Types |
76 'Port', | 76 'Port', |
77 // Functions | 77 // Functions |
78 'connect', 'sendMessage', 'connectNative', 'sendNativeMessage', | 78 'connect', 'sendMessage', 'connectNative', 'sendNativeMessage', |
79 // Events | 79 // Events |
80 'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal' | 80 'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal' |
81 ]; | 81 ]; |
82 forEach(mayNeedAlias, function(i, alias) { | 82 forEach(mayNeedAlias, function(i, alias) { |
83 // Checking existence isn't enough since some functions are disabled via | 83 // Checking existence isn't enough since some functions are disabled via |
84 // getters that throw exceptions. Assume that any getter is such a function. | 84 // getters that throw exceptions. Assume that any getter is such a function. |
85 if (chrome.runtime.hasOwnProperty(alias) && | 85 if (chrome.runtime.hasOwnProperty(alias) && |
86 chrome.runtime.__lookupGetter__(alias) === undefined) { | 86 chrome.runtime.__lookupGetter__(alias) === undefined) { |
87 extension[alias] = chrome.runtime[alias]; | 87 extension[alias] = chrome.runtime[alias]; |
88 } | 88 } |
89 }); | 89 }); |
90 | 90 |
91 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', | 91 apiFunctions.setUpdateArgumentsPreValidate('sendRequest', |
92 sendMessageUpdateArguments.bind(null, 'sendRequest')); | 92 sendMessageUpdateArguments.bind(null, 'sendRequest')); |
93 | 93 |
94 apiFunctions.setHandleRequest('sendRequest', | 94 apiFunctions.setHandleRequest('sendRequest', |
95 function(targetId, request, responseCallback) { | 95 function(targetId, request, responseCallback) { |
96 if (sendRequestIsDisabled) | 96 if (sendRequestIsDisabled) |
97 throw new Error(sendRequestIsDisabled); | 97 throw new Error(sendRequestIsDisabled); |
98 var port = chrome.runtime.connect(targetId || extensionId, | 98 var port = chrome.runtime.connect(targetId || extensionId, |
99 {name: chromeHidden.kRequestChannel}); | 99 {name: chromeHidden.kRequestChannel}); |
100 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); | 100 chromeHidden.Port.sendMessageImpl(port, request, responseCallback); |
101 }); | 101 }, false); |
Matt Perry
2013/03/15 17:51:07
This one is the messaging API - do you plan on log
felt
2013/03/15 23:26:15
FYI I have a separate CL pertaining to messaging t
| |
102 | 102 |
103 if (sendRequestIsDisabled) { | 103 if (sendRequestIsDisabled) { |
104 extension.onRequest.addListener = function() { | 104 extension.onRequest.addListener = function() { |
105 throw new Error(sendRequestIsDisabled); | 105 throw new Error(sendRequestIsDisabled); |
106 }; | 106 }; |
107 if (contextType == 'BLESSED_EXTENSION') { | 107 if (contextType == 'BLESSED_EXTENSION') { |
108 extension.onRequestExternal.addListener = function() { | 108 extension.onRequestExternal.addListener = function() { |
109 throw new Error(sendRequestIsDisabled); | 109 throw new Error(sendRequestIsDisabled); |
110 }; | 110 }; |
111 } | 111 } |
112 } | 112 } |
113 }); | 113 }); |
114 | 114 |
115 exports.binding = binding.generate(); | 115 exports.binding = binding.generate(); |
OLD | NEW |