| 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 bindings for the extension API. | 5 // Custom bindings for the extension API. |
| 6 | 6 |
| 7 var extensionNatives = requireNative('extension'); | 7 (function() { |
| 8 var GetExtensionViews = extensionNatives.GetExtensionViews; | |
| 9 var OpenChannelToExtension = extensionNatives.OpenChannelToExtension; | |
| 10 | 8 |
| 11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 9 native function GetChromeHidden(); |
| 10 native function GetExtensionViews(); |
| 11 native function OpenChannelToExtension(sourceId, targetId, name); |
| 12 |
| 13 var chromeHidden = GetChromeHidden(); |
| 12 | 14 |
| 13 // This should match chrome.windows.WINDOW_ID_NONE. | 15 // This should match chrome.windows.WINDOW_ID_NONE. |
| 14 // | 16 // |
| 15 // We can't use chrome.windows.WINDOW_ID_NONE directly because the | 17 // We can't use chrome.windows.WINDOW_ID_NONE directly because the |
| 16 // chrome.windows API won't exist unless this extension has permission for it; | 18 // chrome.windows API won't exist unless this extension has permission for it; |
| 17 // which may not be the case. | 19 // which may not be the case. |
| 18 var WINDOW_ID_NONE = -1; | 20 var WINDOW_ID_NONE = -1; |
| 19 | 21 |
| 20 chromeHidden.registerCustomHook('extension', | 22 chromeHidden.registerCustomHook('extension', |
| 21 function(bindingsAPI, extensionId) { | 23 function(bindingsAPI, extensionId) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 var name = ''; | 137 var name = ''; |
| 136 if (connectInfo && connectInfo.name) | 138 if (connectInfo && connectInfo.name) |
| 137 name = connectInfo.name; | 139 name = connectInfo.name; |
| 138 | 140 |
| 139 var portId = OpenChannelToExtension(extensionId, targetId, name); | 141 var portId = OpenChannelToExtension(extensionId, targetId, name); |
| 140 if (portId >= 0) | 142 if (portId >= 0) |
| 141 return chromeHidden.Port.createPort(portId, name); | 143 return chromeHidden.Port.createPort(portId, name); |
| 142 throw new Error('Error connecting to extension ' + targetId); | 144 throw new Error('Error connecting to extension ' + targetId); |
| 143 }); | 145 }); |
| 144 }); | 146 }); |
| 147 |
| 148 })(); |
| OLD | NEW |