Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: chrome/renderer/resources/extension_process_bindings.js

Issue 7104002: Does not crash with unexpected function in debug build. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 var callback = function(errorMessage) { 492 var callback = function(errorMessage) {
493 if (errorMessage) 493 if (errorMessage)
494 chrome.experimental.tts.speakCompleted(requestId, errorMessage); 494 chrome.experimental.tts.speakCompleted(requestId, errorMessage);
495 else 495 else
496 chrome.experimental.tts.speakCompleted(requestId); 496 chrome.experimental.tts.speakCompleted(requestId);
497 }; 497 };
498 chrome.Event.prototype.dispatch.apply(this, [text, options, callback]); 498 chrome.Event.prototype.dispatch.apply(this, [text, options, callback]);
499 }; 499 };
500 } 500 }
501 501
502 // Get the platform from navigator.appVersion.
503 function getPlatform() {
504 var platforms = [
505 [/CrOS Touch/, "chromeos touch"],
506 [/CrOS/, "chromeos"],
507 [/Linux/, "linux"],
508 [/Mac/, "mac"],
509 [/Win/, "win"],
510 ];
511
512 for (var i = 0; i < platforms.length; i++) {
513 if (platforms[i][0].test(navigator.appVersion)) {
514 return platforms[i][1];
515 }
516 }
517 return "unknown";
518 }
519
502 chromeHidden.onLoad.addListener(function (extensionId) { 520 chromeHidden.onLoad.addListener(function (extensionId) {
503 if (!extensionId) { 521 if (!extensionId) {
504 return; 522 return;
505 } 523 }
506 chrome.initExtension(extensionId, false, IsIncognitoProcess()); 524 chrome.initExtension(extensionId, false, IsIncognitoProcess());
507 525
508 // Setup the ChromeSetting class so we can use it to construct 526 // Setup the ChromeSetting class so we can use it to construct
509 // ChromeSetting objects from the API definition. 527 // ChromeSetting objects from the API definition.
510 setupChromeSetting(); 528 setupChromeSetting();
511 529
512 // |apiFunctions| is a hash of name -> object that stores the 530 // |apiFunctions| is a hash of name -> object that stores the
513 // name & definition of the apiFunction. Custom handling of api functions 531 // name & definition of the apiFunction. Custom handling of api functions
514 // is implemented by adding a "handleRequest" function to the object. 532 // is implemented by adding a "handleRequest" function to the object.
515 var apiFunctions = {}; 533 var apiFunctions = {};
516 534
517 // Read api definitions and setup api functions in the chrome namespace. 535 // Read api definitions and setup api functions in the chrome namespace.
518 // TODO(rafaelw): Consider defining a json schema for an api definition 536 // TODO(rafaelw): Consider defining a json schema for an api definition
519 // and validating either here, in a unit_test or both. 537 // and validating either here, in a unit_test or both.
520 // TODO(rafaelw): Handle synchronous functions. 538 // TODO(rafaelw): Handle synchronous functions.
521 // TOOD(rafaelw): Consider providing some convenient override points 539 // TOOD(rafaelw): Consider providing some convenient override points
522 // for api functions that wish to insert themselves into the call. 540 // for api functions that wish to insert themselves into the call.
523 var apiDefinitions = chromeHidden.JSON.parse(GetExtensionAPIDefinition()); 541 var apiDefinitions = chromeHidden.JSON.parse(GetExtensionAPIDefinition());
542 var platform = getPlatform();
524 543
525 apiDefinitions.forEach(function(apiDef) { 544 apiDefinitions.forEach(function(apiDef) {
545 // Check platform, if apiDef has platforms key.
546 if (apiDef.platforms && apiDef.platforms.indexOf(platform) == -1) {
547 return;
548 }
549
526 var module = chrome; 550 var module = chrome;
527 var namespaces = apiDef.namespace.split('.'); 551 var namespaces = apiDef.namespace.split('.');
528 for (var index = 0, name; name = namespaces[index]; index++) { 552 for (var index = 0, name; name = namespaces[index]; index++) {
529 module[name] = module[name] || {}; 553 module[name] = module[name] || {};
530 module = module[name]; 554 module = module[name];
531 } 555 }
532 556
533 // Add types to global validationTypes 557 // Add types to global validationTypes
534 if (apiDef.types) { 558 if (apiDef.types) {
535 apiDef.types.forEach(function(t) { 559 apiDef.types.forEach(function(t) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 931
908 if (!chrome.experimental) 932 if (!chrome.experimental)
909 chrome.experimental = {}; 933 chrome.experimental = {};
910 934
911 if (!chrome.experimental.accessibility) 935 if (!chrome.experimental.accessibility)
912 chrome.experimental.accessibility = {}; 936 chrome.experimental.accessibility = {};
913 937
914 if (!chrome.experimental.tts) 938 if (!chrome.experimental.tts)
915 chrome.experimental.tts = {}; 939 chrome.experimental.tts = {};
916 })(); 940 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698