OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var Event = require('event_bindings').Event; | 5 var Event = require('event_bindings').Event; |
6 var forEach = require('utils').forEach; | 6 var forEach = require('utils').forEach; |
7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw | 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw |
8 // variables as arguments. | 8 // variables as arguments. |
9 var GetAvailability = requireNative('v8_context').GetAvailability; | 9 var GetAvailability = requireNative('v8_context').GetAvailability; |
10 var exceptionHandler = require('uncaught_exception_handler'); | 10 var exceptionHandler = require('uncaught_exception_handler'); |
11 var lastError = require('lastError'); | 11 var lastError = require('lastError'); |
12 var loadTypeSchema = require('json_schema').loadTypeSchema; | 12 var loadTypeSchema = require('json_schema').loadTypeSchema; |
13 var logActivity = requireNative('activityLogger'); | 13 var logActivity = requireNative('activityLogger'); |
14 var logging = requireNative('logging'); | 14 var logging = requireNative('logging'); |
15 var process = requireNative('process'); | 15 var process = requireNative('process'); |
16 var schemaRegistry = requireNative('schema_registry'); | 16 var schemaRegistry = requireNative('schema_registry'); |
17 var schemaUtils = require('schemaUtils'); | 17 var schemaUtils = require('schemaUtils'); |
18 var sendRequestHandler = require('sendRequest'); | 18 var sendRequestHandler = require('sendRequest'); |
19 | 19 |
20 var contextType = process.GetContextType(); | 20 var contextType = process.GetContextType(); |
21 var extensionId = process.GetExtensionId(); | 21 var extensionId = process.GetExtensionId(); |
22 var manifestVersion = process.GetManifestVersion(); | 22 var manifestVersion = process.GetManifestVersion(); |
23 var platform = process.GetPlatform(); | |
23 var sendRequest = sendRequestHandler.sendRequest; | 24 var sendRequest = sendRequestHandler.sendRequest; |
24 | 25 |
25 // Stores the name and definition of each API function, with methods to | 26 // Stores the name and definition of each API function, with methods to |
26 // modify their behaviour (such as a custom way to handle requests to the | 27 // modify their behaviour (such as a custom way to handle requests to the |
27 // API, a custom callback, etc). | 28 // API, a custom callback, etc). |
28 function APIFunctions(namespace) { | 29 function APIFunctions(namespace) { |
29 this.apiFunctions_ = { __proto__: null }; | 30 this.apiFunctions_ = { __proto__: null }; |
30 this.unavailableApiFunctions_ = { __proto__: null }; | 31 this.unavailableApiFunctions_ = { __proto__: null }; |
31 this.namespace = namespace; | 32 this.namespace = namespace; |
32 } | 33 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 function(apiName, customizedFunction) { | 81 function(apiName, customizedFunction) { |
81 return this.setHook_( | 82 return this.setHook_( |
82 apiName, 'updateArgumentsPreValidate', customizedFunction); | 83 apiName, 'updateArgumentsPreValidate', customizedFunction); |
83 }; | 84 }; |
84 | 85 |
85 APIFunctions.prototype.setCustomCallback = | 86 APIFunctions.prototype.setCustomCallback = |
86 function(apiName, customizedFunction) { | 87 function(apiName, customizedFunction) { |
87 return this.setHook_(apiName, 'customCallback', customizedFunction); | 88 return this.setHook_(apiName, 'customCallback', customizedFunction); |
88 }; | 89 }; |
89 | 90 |
90 // Get the platform from navigator.appVersion. | |
91 function getPlatform() { | |
92 var platforms = [ | |
93 [/CrOS Touch/, "chromeos touch"], | |
lazyboy
2017/07/07 23:09:26
You're also removing "chromeos touch", which is un
Devlin
2017/07/10 18:35:31
Good idea; done.
| |
94 [/CrOS/, "chromeos"], | |
95 [/Linux/, "linux"], | |
96 [/Mac/, "mac"], | |
97 [/Win/, "win"], | |
98 ]; | |
99 | |
100 for (var i = 0; i < platforms.length; i++) { | |
101 if ($RegExp.exec(platforms[i][0], navigator.appVersion)) { | |
102 return platforms[i][1]; | |
103 } | |
104 } | |
105 return "unknown"; | |
106 } | |
107 | |
108 function isPlatformSupported(schemaNode, platform) { | 91 function isPlatformSupported(schemaNode, platform) { |
109 return !schemaNode.platforms || | 92 return !schemaNode.platforms || |
110 $Array.indexOf(schemaNode.platforms, platform) > -1; | 93 $Array.indexOf(schemaNode.platforms, platform) > -1; |
111 } | 94 } |
112 | 95 |
113 function isManifestVersionSupported(schemaNode, manifestVersion) { | 96 function isManifestVersionSupported(schemaNode, manifestVersion) { |
114 return !schemaNode.maximumManifestVersion || | 97 return !schemaNode.maximumManifestVersion || |
115 manifestVersion <= schemaNode.maximumManifestVersion; | 98 manifestVersion <= schemaNode.maximumManifestVersion; |
116 } | 99 } |
117 | 100 |
(...skipping 20 matching lines...) Expand all Loading... | |
138 logging.CHECK($Array.indexOf(whitelistedModules, jsModuleName) !== -1, | 121 logging.CHECK($Array.indexOf(whitelistedModules, jsModuleName) !== -1, |
139 'Module ' + jsModuleName + ' does not define a custom type.'); | 122 'Module ' + jsModuleName + ' does not define a custom type.'); |
140 var jsModule = require(jsModuleName); | 123 var jsModule = require(jsModuleName); |
141 logging.CHECK(jsModule, 'No module ' + jsModuleName + ' found for ' + | 124 logging.CHECK(jsModule, 'No module ' + jsModuleName + ' found for ' + |
142 type.id + '.'); | 125 type.id + '.'); |
143 var customType = jsModule[jsModuleName]; | 126 var customType = jsModule[jsModuleName]; |
144 logging.CHECK(customType, jsModuleName + ' must export itself.'); | 127 logging.CHECK(customType, jsModuleName + ' must export itself.'); |
145 return customType; | 128 return customType; |
146 } | 129 } |
147 | 130 |
148 var platform = getPlatform(); | |
149 | |
150 function Binding(apiName) { | 131 function Binding(apiName) { |
151 this.apiName_ = apiName; | 132 this.apiName_ = apiName; |
152 this.apiFunctions_ = new APIFunctions(apiName); | 133 this.apiFunctions_ = new APIFunctions(apiName); |
153 this.customHooks_ = []; | 134 this.customHooks_ = []; |
154 }; | 135 }; |
155 | 136 |
156 $Object.defineProperty(Binding, 'create', { | 137 $Object.defineProperty(Binding, 'create', { |
157 __proto__: null, | 138 __proto__: null, |
158 configurable: false, | 139 configurable: false, |
159 enumerable: false, | 140 enumerable: false, |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 availability.message); | 521 availability.message); |
541 return; | 522 return; |
542 } | 523 } |
543 | 524 |
544 this.runHooks_(mod, schema); | 525 this.runHooks_(mod, schema); |
545 return mod; | 526 return mod; |
546 } | 527 } |
547 }; | 528 }; |
548 | 529 |
549 exports.$set('Binding', Binding); | 530 exports.$set('Binding', Binding); |
OLD | NEW |