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 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 GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return sendRequest( | 377 return sendRequest( |
378 'contentSettings.getResourceIdentifiers', | 378 'contentSettings.getResourceIdentifiers', |
379 [contentType, callback], | 379 [contentType, callback], |
380 extendSchema(schema)); | 380 extendSchema(schema)); |
381 }; | 381 }; |
382 } | 382 } |
383 ContentSetting.prototype = new CustomBindingsObject(); | 383 ContentSetting.prototype = new CustomBindingsObject(); |
384 customBindings['ContentSetting'] = ContentSetting; | 384 customBindings['ContentSetting'] = ContentSetting; |
385 } | 385 } |
386 | 386 |
| 387 function setupStorageArea() { |
| 388 function StorageArea(namespace, schema) { |
| 389 // Binds an API function for a namespace to its browser-side call, e.g. |
| 390 // experimental.settings.sync.get('foo') -> (binds to) -> |
| 391 // experimental.settings.get('sync', 'foo'). |
| 392 // |
| 393 // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or |
| 394 // even generate) for other APIs that need to do this. |
| 395 function bindApiFunction(functionName) { |
| 396 this[functionName] = function() { |
| 397 var schema = this.parameters[functionName]; |
| 398 chromeHidden.validate(arguments, schema); |
| 399 return sendRequest( |
| 400 'experimental.settings.' + functionName, |
| 401 [namespace].concat(Array.prototype.slice.call(arguments)), |
| 402 extendSchema(schema)); |
| 403 }; |
| 404 } |
| 405 ['get', 'set', 'remove', 'clear'].forEach(bindApiFunction.bind(this)); |
| 406 } |
| 407 StorageArea.prototype = new CustomBindingsObject(); |
| 408 customBindings['StorageArea'] = StorageArea; |
| 409 } |
387 function setupInputEvents() { | 410 function setupInputEvents() { |
388 chrome.experimental.input.ime.onKeyEvent.dispatch = | 411 chrome.experimental.input.ime.onKeyEvent.dispatch = |
389 function(engineID, keyData) { | 412 function(engineID, keyData) { |
390 var args = Array.prototype.slice.call(arguments); | 413 var args = Array.prototype.slice.call(arguments); |
391 if (this.validate_) { | 414 if (this.validate_) { |
392 var validationErrors = this.validate_(args); | 415 var validationErrors = this.validate_(args); |
393 if (validationErrors) { | 416 if (validationErrors) { |
394 chrome.experimental.input.ime.eventHandled(requestId, false); | 417 chrome.experimental.input.ime.eventHandled(requestId, false); |
395 return validationErrors; | 418 return validationErrors; |
396 } | 419 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 } | 596 } |
574 return "unknown"; | 597 return "unknown"; |
575 } | 598 } |
576 | 599 |
577 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, | 600 chromeHidden.onLoad.addListener(function(extensionId, isExtensionProcess, |
578 isIncognitoProcess) { | 601 isIncognitoProcess) { |
579 // Setup the ChromeSetting class so we can use it to construct | 602 // Setup the ChromeSetting class so we can use it to construct |
580 // ChromeSetting objects from the API definition. | 603 // ChromeSetting objects from the API definition. |
581 setupChromeSetting(); | 604 setupChromeSetting(); |
582 | 605 |
583 // Setup the ContentSetting class so we can use it to construct | 606 // Ditto ContentSetting. |
584 // ContentSetting objects from the API definition. | |
585 setupContentSetting(); | 607 setupContentSetting(); |
586 | 608 |
| 609 // Ditto StorageArea. |
| 610 setupStorageArea(); |
| 611 |
587 // |apiFunctions| is a hash of name -> object that stores the | 612 // |apiFunctions| is a hash of name -> object that stores the |
588 // name & definition of the apiFunction. Custom handling of api functions | 613 // name & definition of the apiFunction. Custom handling of api functions |
589 // is implemented by adding a "handleRequest" function to the object. | 614 // is implemented by adding a "handleRequest" function to the object. |
590 var apiFunctions = {}; | 615 var apiFunctions = {}; |
591 | 616 |
592 // Read api definitions and setup api functions in the chrome namespace. | 617 // Read api definitions and setup api functions in the chrome namespace. |
593 // TODO(rafaelw): Consider defining a json schema for an api definition | 618 // TODO(rafaelw): Consider defining a json schema for an api definition |
594 // and validating either here, in a unit_test or both. | 619 // and validating either here, in a unit_test or both. |
595 // TODO(rafaelw): Handle synchronous functions. | 620 // TODO(rafaelw): Handle synchronous functions. |
596 // TOOD(rafaelw): Consider providing some convenient override points | 621 // TODO(rafaelw): Consider providing some convenient override points |
597 // for api functions that wish to insert themselves into the call. | 622 // for api functions that wish to insert themselves into the call. |
598 var apiDefinitions = GetExtensionAPIDefinition(); | 623 var apiDefinitions = GetExtensionAPIDefinition(); |
599 var platform = getPlatform(); | 624 var platform = getPlatform(); |
600 | 625 |
601 apiDefinitions.forEach(function(apiDef) { | 626 apiDefinitions.forEach(function(apiDef) { |
602 // Check platform, if apiDef has platforms key. | 627 // Check platform, if apiDef has platforms key. |
603 if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) { | 628 if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) { |
604 return; | 629 return; |
605 } | 630 } |
606 | 631 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1108 |
1084 if (!chrome.tts) | 1109 if (!chrome.tts) |
1085 chrome.tts = {}; | 1110 chrome.tts = {}; |
1086 | 1111 |
1087 if (!chrome.ttsEngine) | 1112 if (!chrome.ttsEngine) |
1088 chrome.ttsEngine = {}; | 1113 chrome.ttsEngine = {}; |
1089 | 1114 |
1090 if (!chrome.experimental.downloads) | 1115 if (!chrome.experimental.downloads) |
1091 chrome.experimental.downloads = {}; | 1116 chrome.experimental.downloads = {}; |
1092 })(); | 1117 })(); |
OLD | NEW |