| 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 var extensionNatives = requireNative('extension'); |
| 8 var GetExtensionViews = extensionNatives.GetExtensionViews; | 8 var GetExtensionViews = extensionNatives.GetExtensionViews; |
| 9 var OpenChannelToExtension = extensionNatives.OpenChannelToExtension; | 9 var OpenChannelToExtension = extensionNatives.OpenChannelToExtension; |
| 10 | 10 |
| 11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 12 | 12 |
| 13 var inIncognitoContext = requireNative('process').InIncognitoContext(); |
| 14 |
| 15 chrome.extension = chrome.extension || {}; |
| 16 |
| 17 var manifestVersion = requireNative('process').GetManifestVersion(); |
| 18 if (manifestVersion < 2) { |
| 19 chrome.self = chrome.extension; |
| 20 chrome.extension.inIncognitoTab = inIncognitoContext; |
| 21 } |
| 22 |
| 23 chrome.extension.inIncognitoContext = inIncognitoContext; |
| 24 |
| 13 // This should match chrome.windows.WINDOW_ID_NONE. | 25 // This should match chrome.windows.WINDOW_ID_NONE. |
| 14 // | 26 // |
| 15 // We can't use chrome.windows.WINDOW_ID_NONE directly because the | 27 // 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; | 28 // chrome.windows API won't exist unless this extension has permission for it; |
| 17 // which may not be the case. | 29 // which may not be the case. |
| 18 var WINDOW_ID_NONE = -1; | 30 var WINDOW_ID_NONE = -1; |
| 19 | 31 |
| 20 chromeHidden.registerCustomHook('extension', | 32 chromeHidden.registerCustomHook('extension', |
| 21 function(bindingsAPI, extensionId) { | 33 function(bindingsAPI, extensionId) { |
| 22 var apiFunctions = bindingsAPI.apiFunctions; | 34 var apiFunctions = bindingsAPI.apiFunctions; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 var name = ''; | 136 var name = ''; |
| 125 if (connectInfo && connectInfo.name) | 137 if (connectInfo && connectInfo.name) |
| 126 name = connectInfo.name; | 138 name = connectInfo.name; |
| 127 | 139 |
| 128 var portId = OpenChannelToExtension(extensionId, targetId, name); | 140 var portId = OpenChannelToExtension(extensionId, targetId, name); |
| 129 if (portId >= 0) | 141 if (portId >= 0) |
| 130 return chromeHidden.Port.createPort(portId, name); | 142 return chromeHidden.Port.createPort(portId, name); |
| 131 throw new Error('Error connecting to extension ' + targetId); | 143 throw new Error('Error connecting to extension ' + targetId); |
| 132 }); | 144 }); |
| 133 }); | 145 }); |
| OLD | NEW |