| 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 privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
| 6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
| 7 | 7 |
| 8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
| 9 (function() { | 9 (function() { |
| 10 native function GetChromeHidden(); | 10 native function GetChromeHidden(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 var requestId = GetNextRequestId(); | 177 var requestId = GetNextRequestId(); |
| 178 request.id = requestId; | 178 request.id = requestId; |
| 179 requests[requestId] = request; | 179 requests[requestId] = request; |
| 180 var hasCallback = | 180 var hasCallback = |
| 181 (request.callback || opt_args.customCallback) ? true : false; | 181 (request.callback || opt_args.customCallback) ? true : false; |
| 182 return nativeFunction(functionName, sargs, requestId, hasCallback, | 182 return nativeFunction(functionName, sargs, requestId, hasCallback, |
| 183 opt_args.forIOThread); | 183 opt_args.forIOThread); |
| 184 } | 184 } |
| 185 | 185 |
| 186 chromeHidden.sendRequest = sendRequest; |
| 187 |
| 186 // TODO(kalman): It's a shame to need to define this function here, since it's | 188 // TODO(kalman): It's a shame to need to define this function here, since it's |
| 187 // only used in 2 APIs (browserAction and pageAction). It would be nice to | 189 // only used in 2 APIs (browserAction and pageAction). It would be nice to |
| 188 // only load this if one of those APIs has been loaded. | 190 // only load this if one of those APIs has been loaded. |
| 189 // That said, both of those APIs are always injected into pages anyway (see | 191 // That said, both of those APIs are always injected into pages anyway (see |
| 190 // chrome/common/extensions/extension_permission_set.cc). | 192 // chrome/common/extensions/extension_permission_set.cc). |
| 191 function setIcon(details, name, parameters, actionType) { | 193 function setIcon(details, name, parameters, actionType) { |
| 192 var iconSize = 19; | 194 var iconSize = 19; |
| 193 if ("iconIndex" in details) { | 195 if ("iconIndex" in details) { |
| 194 sendRequest(name, [details], parameters); | 196 sendRequest(name, [details], parameters); |
| 195 } else if ("imageData" in details) { | 197 } else if ("imageData" in details) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 if (platforms[i][0].test(navigator.appVersion)) { | 350 if (platforms[i][0].test(navigator.appVersion)) { |
| 349 return platforms[i][1]; | 351 return platforms[i][1]; |
| 350 } | 352 } |
| 351 } | 353 } |
| 352 return "unknown"; | 354 return "unknown"; |
| 353 } | 355 } |
| 354 | 356 |
| 355 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, | 357 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, |
| 356 isIncognitoProcess) { | 358 isIncognitoProcess) { |
| 357 var apiDefinitions = GetExtensionAPIDefinition(); | 359 var apiDefinitions = GetExtensionAPIDefinition(); |
| 360 chromeHidden.apiDefinitions = apiDefinitions; |
| 358 | 361 |
| 359 // Read api definitions and setup api functions in the chrome namespace. | 362 // Read api definitions and setup api functions in the chrome namespace. |
| 360 // TODO(rafaelw): Consider defining a json schema for an api definition | 363 // TODO(rafaelw): Consider defining a json schema for an api definition |
| 361 // and validating either here, in a unit_test or both. | 364 // and validating either here, in a unit_test or both. |
| 362 // TODO(rafaelw): Handle synchronous functions. | 365 // TODO(rafaelw): Handle synchronous functions. |
| 363 // TODO(rafaelw): Consider providing some convenient override points | 366 // TODO(rafaelw): Consider providing some convenient override points |
| 364 // for api functions that wish to insert themselves into the call. | 367 // for api functions that wish to insert themselves into the call. |
| 365 var platform = getPlatform(); | 368 var platform = getPlatform(); |
| 366 | 369 |
| 367 apiDefinitions.forEach(function(apiDef) { | 370 apiDefinitions.forEach(function(apiDef) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (eventDef.name in module || | 455 if (eventDef.name in module || |
| 453 addUnprivilegedAccessGetter(module, eventDef.name, | 456 addUnprivilegedAccessGetter(module, eventDef.name, |
| 454 eventDef.unprivileged)) { | 457 eventDef.unprivileged)) { |
| 455 return; | 458 return; |
| 456 } | 459 } |
| 457 | 460 |
| 458 var eventName = apiDef.namespace + "." + eventDef.name; | 461 var eventName = apiDef.namespace + "." + eventDef.name; |
| 459 var customEvent = customEvents[apiDef.namespace]; | 462 var customEvent = customEvents[apiDef.namespace]; |
| 460 if (customEvent) { | 463 if (customEvent) { |
| 461 module[eventDef.name] = new customEvent( | 464 module[eventDef.name] = new customEvent( |
| 462 eventName, eventDef.parameters, eventDef.extraParameters); | 465 eventName, eventDef.parameters, eventDef.extraParameters, |
| 466 eventDef.options); |
| 463 } else { | 467 } else { |
| 464 module[eventDef.name] = new chrome.Event( | 468 module[eventDef.name] = new chrome.Event( |
| 465 eventName, eventDef.parameters); | 469 eventName, eventDef.parameters, eventDef.options); |
| 466 } | 470 } |
| 467 }); | 471 }); |
| 468 } | 472 } |
| 469 | 473 |
| 470 function addProperties(m, def) { | 474 function addProperties(m, def) { |
| 471 // Parse any values defined for properties. | 475 // Parse any values defined for properties. |
| 472 if (def.properties) { | 476 if (def.properties) { |
| 473 forEach(def.properties, function(prop, property) { | 477 forEach(def.properties, function(prop, property) { |
| 474 if (prop in m || | 478 if (prop in m || |
| 475 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) { | 479 addUnprivilegedAccessGetter(m, prop, property.unprivileged)) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 // See http://crbug.com/100242 | 550 // See http://crbug.com/100242 |
| 547 if (apiExists("webstorePrivate")) { | 551 if (apiExists("webstorePrivate")) { |
| 548 chrome.webstorePrivate.beginInstallWithManifest2 = | 552 chrome.webstorePrivate.beginInstallWithManifest2 = |
| 549 chrome.webstorePrivate.beginInstallWithManifest3; | 553 chrome.webstorePrivate.beginInstallWithManifest3; |
| 550 } | 554 } |
| 551 | 555 |
| 552 if (apiExists("test")) | 556 if (apiExists("test")) |
| 553 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 557 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
| 554 }); | 558 }); |
| 555 })(); | 559 })(); |
| OLD | NEW |