| 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 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 extensionNatives = requireNative('extension'); | 9 var extensionNatives = requireNative('extension'); |
| 10 var miscBindings = require('miscellaneous_bindings'); | 10 var miscBindings = require('miscellaneous_bindings'); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 apiFunctions.setUpdateArgumentsPreValidate('connectNative', | 76 apiFunctions.setUpdateArgumentsPreValidate('connectNative', |
| 77 function(appName) { | 77 function(appName) { |
| 78 if (typeof(appName) !== 'string') { | 78 if (typeof(appName) !== 'string') { |
| 79 throw new Error('Invalid arguments to connectNative.'); | 79 throw new Error('Invalid arguments to connectNative.'); |
| 80 } | 80 } |
| 81 return [appName]; | 81 return [appName]; |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { | 84 apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { |
| 85 // Don't let orphaned content scripts communicate with their extension. |
| 86 // http://crbug.com/168263 |
| 87 if (unloadEvent.wasDispatched) |
| 88 throw new Error('Error connecting to extension ' + targetId); |
| 89 |
| 85 if (!targetId) | 90 if (!targetId) |
| 86 targetId = runtime.id; | 91 targetId = runtime.id; |
| 92 |
| 87 var name = ''; | 93 var name = ''; |
| 88 if (connectInfo && connectInfo.name) | 94 if (connectInfo && connectInfo.name) |
| 89 name = connectInfo.name; | 95 name = connectInfo.name; |
| 90 | 96 |
| 91 // Don't let orphaned content scripts communicate with their extension. | 97 var portId = runtimeNatives.OpenChannelToExtension(targetId, name); |
| 92 // http://crbug.com/168263 | 98 if (portId >= 0) |
| 93 if (!unloadEvent.wasDispatched) { | 99 return miscBindings.createPort(portId, name); |
| 94 var portId = runtimeNatives.OpenChannelToExtension(runtime.id, | |
| 95 targetId, | |
| 96 name); | |
| 97 if (portId >= 0) | |
| 98 return miscBindings.createPort(portId, name); | |
| 99 } | |
| 100 throw new Error('Error connecting to extension ' + targetId); | |
| 101 }); | 100 }); |
| 102 | 101 |
| 103 // | 102 // |
| 104 // Privileged APIs. | 103 // Privileged APIs. |
| 105 // | 104 // |
| 106 if (contextType != 'BLESSED_EXTENSION') | 105 if (contextType != 'BLESSED_EXTENSION') |
| 107 return; | 106 return; |
| 108 | 107 |
| 109 apiFunctions.setHandleRequest('connectNative', | 108 apiFunctions.setHandleRequest('connectNative', |
| 110 function(nativeAppName) { | 109 function(nativeAppName) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 if (request.callback) { | 121 if (request.callback) { |
| 123 var bg = extensionNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; | 122 var bg = extensionNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; |
| 124 request.callback(bg); | 123 request.callback(bg); |
| 125 } | 124 } |
| 126 request.callback = null; | 125 request.callback = null; |
| 127 }); | 126 }); |
| 128 | 127 |
| 129 }); | 128 }); |
| 130 | 129 |
| 131 exports.binding = binding.generate(); | 130 exports.binding = binding.generate(); |
| OLD | NEW |