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 // This script contains unprivileged javascript APIs related to chrome | 5 // This script contains unprivileged javascript APIs related to chrome |
6 // extensions. It is loaded by any extension-related context, such as content | 6 // extensions. It is loaded by any extension-related context, such as content |
7 // scripts or background pages. | 7 // scripts or background pages. |
8 // See user_script_slave.cc for script that is loaded by content scripts only. | 8 // See user_script_slave.cc for script that is loaded by content scripts only. |
9 | 9 |
10 require('json_schema'); | 10 require('json_schema'); |
11 require('event_bindings'); | 11 require('event_bindings'); |
12 var lastError = require('lastError'); | 12 var lastError = require('lastError'); |
13 var miscNatives = requireNative('miscellaneous_bindings'); | 13 var miscNatives = requireNative('miscellaneous_bindings'); |
14 var CloseChannel = miscNatives.CloseChannel; | 14 var CloseChannel = miscNatives.CloseChannel; |
15 var PortAddRef = miscNatives.PortAddRef; | 15 var PortAddRef = miscNatives.PortAddRef; |
16 var PortRelease = miscNatives.PortRelease; | 16 var PortRelease = miscNatives.PortRelease; |
17 var PostMessage = miscNatives.PostMessage; | 17 var PostMessage = miscNatives.PostMessage; |
18 var BindToGC = miscNatives.BindToGC; | 18 var BindToGC = miscNatives.BindToGC; |
19 | 19 |
20 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 20 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
21 var manifestVersion; | 21 |
22 var extensionId; | 22 var processNatives = requireNative('process'); |
| 23 var manifestVersion = processNatives.GetManifestVersion(); |
| 24 var extensionId = processNatives.GetExtensionId(); |
23 | 25 |
24 // The reserved channel name for the sendRequest/sendMessage APIs. | 26 // The reserved channel name for the sendRequest/sendMessage APIs. |
25 // Note: sendRequest is deprecated. | 27 // Note: sendRequest is deprecated. |
26 chromeHidden.kRequestChannel = "chrome.extension.sendRequest"; | 28 chromeHidden.kRequestChannel = "chrome.extension.sendRequest"; |
27 chromeHidden.kMessageChannel = "chrome.extension.sendMessage"; | 29 chromeHidden.kMessageChannel = "chrome.extension.sendMessage"; |
28 | 30 |
29 // Map of port IDs to port object. | 31 // Map of port IDs to port object. |
30 var ports = {}; | 32 var ports = {}; |
31 | 33 |
32 // Map of port IDs to chromeHidden.onUnload listeners. Keep track of these | 34 // Map of port IDs to chromeHidden.onUnload listeners. Keep track of these |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 }); | 283 }); |
282 port.onMessage.addListener(function(response) { | 284 port.onMessage.addListener(function(response) { |
283 try { | 285 try { |
284 responseCallback(response); | 286 responseCallback(response); |
285 } finally { | 287 } finally { |
286 port.disconnect(); | 288 port.disconnect(); |
287 port = null; | 289 port = null; |
288 } | 290 } |
289 }); | 291 }); |
290 } | 292 } |
291 | |
292 // This function is called on context initialization for both content scripts | |
293 // and extension contexts. | |
294 chromeHidden.onLoad.addListener(function(tempExtensionId, | |
295 isExtensionProcess, | |
296 inIncognitoContext, | |
297 tempManifestVersion) { | |
298 extensionId = tempExtensionId; | |
299 manifestVersion = tempManifestVersion; | |
300 | |
301 chrome.extension = chrome.extension || {}; | |
302 | |
303 if (manifestVersion < 2) { | |
304 chrome.self = chrome.extension; | |
305 chrome.extension.inIncognitoTab = inIncognitoContext; | |
306 } | |
307 | |
308 chrome.extension.inIncognitoContext = inIncognitoContext; | |
309 }); | |
OLD | NEW |