OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 runtime API. | 5 // Custom binding for the runtime API. |
6 | 6 |
7 var binding = require('binding').Binding.create('runtime'); | 7 var binding = require('binding').Binding.create('runtime'); |
8 | 8 |
9 var messaging = require('messaging'); | 9 var messaging = require('messaging'); |
10 var runtimeNatives = requireNative('runtime'); | 10 var runtimeNatives = requireNative('runtime'); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 151 } |
152 return [appName]; | 152 return [appName]; |
153 }); | 153 }); |
154 | 154 |
155 apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { | 155 apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { |
156 // Don't let orphaned content scripts communicate with their extension. | 156 // Don't let orphaned content scripts communicate with their extension. |
157 // http://crbug.com/168263 | 157 // http://crbug.com/168263 |
158 if (unloadEvent.wasDispatched) | 158 if (unloadEvent.wasDispatched) |
159 throw new Error('Error connecting to extension ' + targetId); | 159 throw new Error('Error connecting to extension ' + targetId); |
160 | 160 |
161 if (!targetId) | 161 if (!targetId) { |
| 162 // runtime.id is only defined inside extensions. If we're in a webpage, |
| 163 // the best we can do at this point is to fail. |
| 164 if (!runtime.id) { |
| 165 throw new Error('chrome.runtime.connect() called from a webpage must ' + |
| 166 'specify an Extension ID (string) for its first ' + |
| 167 'argument'); |
| 168 } |
162 targetId = runtime.id; | 169 targetId = runtime.id; |
| 170 } |
163 | 171 |
164 var name = ''; | 172 var name = ''; |
165 if (connectInfo && connectInfo.name) | 173 if (connectInfo && connectInfo.name) |
166 name = connectInfo.name; | 174 name = connectInfo.name; |
167 | 175 |
168 var includeTlsChannelId = | 176 var includeTlsChannelId = |
169 !!(connectInfo && connectInfo.includeTlsChannelId); | 177 !!(connectInfo && connectInfo.includeTlsChannelId); |
170 | 178 |
171 var portId = runtimeNatives.OpenChannelToExtension(targetId, name, | 179 var portId = runtimeNatives.OpenChannelToExtension(targetId, name, |
172 includeTlsChannelId); | 180 includeTlsChannelId); |
(...skipping 24 matching lines...) Expand all Loading... |
197 var bg = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; | 205 var bg = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; |
198 callback(bg); | 206 callback(bg); |
199 } | 207 } |
200 }); | 208 }); |
201 | 209 |
202 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); | 210 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); |
203 }); | 211 }); |
204 | 212 |
205 exports.bindDirectoryEntryCallback = bindDirectoryEntryCallback; | 213 exports.bindDirectoryEntryCallback = bindDirectoryEntryCallback; |
206 exports.binding = binding.generate(); | 214 exports.binding = binding.generate(); |
OLD | NEW |