| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 toolstrips. | 7 // scripts or toolstrips. |
| 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 // TODO(mpcomplete): we also load this in regular web pages, but don't need to. | 9 // TODO(mpcomplete): we also load this in regular web pages, but don't need to. |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 PortRelease(portId); | 167 PortRelease(portId); |
| 168 chromeHidden.onUnload.removeListener(portReleasers[portId]); | 168 chromeHidden.onUnload.removeListener(portReleasers[portId]); |
| 169 | 169 |
| 170 delete ports[portId]; | 170 delete ports[portId]; |
| 171 delete portReleasers[portId]; | 171 delete portReleasers[portId]; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // This function is called on context initialization for both content scripts | 174 // This function is called on context initialization for both content scripts |
| 175 // and extension contexts. | 175 // and extension contexts. |
| 176 chrome.initExtension = function(extensionId, warnOnPrivilegedApiAccess, | 176 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, |
| 177 inIncognitoContext) { | 177 inIncognitoContext) { |
| 178 delete chrome.initExtension; | |
| 179 chromeHidden.extensionId = extensionId; | 178 chromeHidden.extensionId = extensionId; |
| 180 | 179 |
| 181 chrome.extension = chrome.extension || {}; | 180 chrome.extension = chrome.extension || {}; |
| 182 chrome.self = chrome.extension; | 181 chrome.self = chrome.extension; |
| 183 | 182 |
| 184 chrome.extension.inIncognitoTab = inIncognitoContext; // deprecated | 183 chrome.extension.inIncognitoTab = inIncognitoContext; // deprecated |
| 185 chrome.extension.inIncognitoContext = inIncognitoContext; | 184 chrome.extension.inIncognitoContext = inIncognitoContext; |
| 186 | 185 |
| 187 // Events for when a message channel is opened to our extension. | 186 // Events for when a message channel is opened to our extension. |
| 188 chrome.extension.onConnect = new chrome.Event(); | 187 chrome.extension.onConnect = new chrome.Event(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (!path.length || path[0] != "/") | 251 if (!path.length || path[0] != "/") |
| 253 path = "/" + path; | 252 path = "/" + path; |
| 254 return "chrome-extension://" + extensionId + path; | 253 return "chrome-extension://" + extensionId + path; |
| 255 }; | 254 }; |
| 256 | 255 |
| 257 chrome.i18n = chrome.i18n || {}; | 256 chrome.i18n = chrome.i18n || {}; |
| 258 chrome.i18n.getMessage = function(message_name, placeholders) { | 257 chrome.i18n.getMessage = function(message_name, placeholders) { |
| 259 return GetL10nMessage(message_name, placeholders, extensionId); | 258 return GetL10nMessage(message_name, placeholders, extensionId); |
| 260 }; | 259 }; |
| 261 | 260 |
| 262 if (warnOnPrivilegedApiAccess) { | 261 if (!isExtensionProcess) |
| 263 setupApiStubs(); | 262 setupApiStubs(); |
| 264 } | 263 }); |
| 265 }; | |
| 266 | 264 |
| 267 var notSupportedSuffix = " is not supported in content scripts. " + | 265 var notSupportedSuffix = " is not supported in content scripts. " + |
| 268 "See the content scripts documentation for more details."; | 266 "See the content scripts documentation for more details."; |
| 269 | 267 |
| 270 // Setup to throw an error message when trying to access |name| on the chrome | 268 // Setup to throw an error message when trying to access |name| on the chrome |
| 271 // object. The |name| can be a dot-separated path. | 269 // object. The |name| can be a dot-separated path. |
| 272 function createStub(name) { | 270 function createStub(name) { |
| 273 var module = chrome; | 271 var module = chrome; |
| 274 var parts = name.split("."); | 272 var parts = name.split("."); |
| 275 for (var i = 0; i < parts.length - 1; i++) { | 273 for (var i = 0; i < parts.length - 1; i++) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 "extension.onRequestExternal", | 351 "extension.onRequestExternal", |
| 354 "extension.setUpdateUrlData", | 352 "extension.setUpdateUrlData", |
| 355 "i18n.getAcceptLanguages" | 353 "i18n.getAcceptLanguages" |
| 356 ]; | 354 ]; |
| 357 for (var i = 0; i < privileged.length; i++) { | 355 for (var i = 0; i < privileged.length; i++) { |
| 358 createStub(privileged[i]); | 356 createStub(privileged[i]); |
| 359 } | 357 } |
| 360 } | 358 } |
| 361 | 359 |
| 362 })(); | 360 })(); |
| OLD | NEW |