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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 var apiFunctions = {}; | 515 var apiFunctions = {}; |
516 | 516 |
517 // Read api definitions and setup api functions in the chrome namespace. | 517 // Read api definitions and setup api functions in the chrome namespace. |
518 // TODO(rafaelw): Consider defining a json schema for an api definition | 518 // TODO(rafaelw): Consider defining a json schema for an api definition |
519 // and validating either here, in a unit_test or both. | 519 // and validating either here, in a unit_test or both. |
520 // TODO(rafaelw): Handle synchronous functions. | 520 // TODO(rafaelw): Handle synchronous functions. |
521 // TOOD(rafaelw): Consider providing some convenient override points | 521 // TOOD(rafaelw): Consider providing some convenient override points |
522 // for api functions that wish to insert themselves into the call. | 522 // for api functions that wish to insert themselves into the call. |
523 var apiDefinitions = chromeHidden.JSON.parse(GetExtensionAPIDefinition()); | 523 var apiDefinitions = chromeHidden.JSON.parse(GetExtensionAPIDefinition()); |
524 | 524 |
525 // Get the platform from navigator.appVersion. | |
526 var platform = "unknown"; | |
Matt Perry
2011/06/07 00:15:52
nit: can you move this block into a separate getPl
Peng
2011/06/07 19:17:30
Done.
| |
527 var platforms = [ | |
528 [/CrOS Touch/, "chromeos touch"], | |
529 [/CrOS/, "chromeos"], | |
530 [/Linux/, "linux"], | |
531 [/Mac/, "mac"], | |
532 [/Win/, "win"], | |
533 ]; | |
534 | |
535 for (var i = 0; i < platforms.length; i++) { | |
536 if (platforms[i][0].test(navigator.appVersion)) { | |
537 platform = platforms[i][1]; | |
538 break; | |
539 } | |
540 } | |
541 | |
525 apiDefinitions.forEach(function(apiDef) { | 542 apiDefinitions.forEach(function(apiDef) { |
543 // Check platform, if apiDef has platforms key. | |
544 if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) { | |
545 return; | |
546 } | |
547 | |
526 var module = chrome; | 548 var module = chrome; |
527 var namespaces = apiDef.namespace.split('.'); | 549 var namespaces = apiDef.namespace.split('.'); |
528 for (var index = 0, name; name = namespaces[index]; index++) { | 550 for (var index = 0, name; name = namespaces[index]; index++) { |
529 module[name] = module[name] || {}; | 551 module[name] = module[name] || {}; |
530 module = module[name]; | 552 module = module[name]; |
531 } | 553 } |
532 | 554 |
533 // Add types to global validationTypes | 555 // Add types to global validationTypes |
534 if (apiDef.types) { | 556 if (apiDef.types) { |
535 apiDef.types.forEach(function(t) { | 557 apiDef.types.forEach(function(t) { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 | 929 |
908 if (!chrome.experimental) | 930 if (!chrome.experimental) |
909 chrome.experimental = {}; | 931 chrome.experimental = {}; |
910 | 932 |
911 if (!chrome.experimental.accessibility) | 933 if (!chrome.experimental.accessibility) |
912 chrome.experimental.accessibility = {}; | 934 chrome.experimental.accessibility = {}; |
913 | 935 |
914 if (!chrome.experimental.tts) | 936 if (!chrome.experimental.tts) |
915 chrome.experimental.tts = {}; | 937 chrome.experimental.tts = {}; |
916 })(); | 938 })(); |
OLD | NEW |