| <!DOCTYPE html> |
| <!-- |
| Copyright 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/base/extension_registry.html"> |
| <link rel="import" href="/core/scripting_object.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.c', function() { |
| function ScriptingController(brushingStateController) { |
| this.brushingStateController_ = brushingStateController; |
| this.scriptObjectNames_ = []; |
| this.scriptObjectValues_ = []; |
| this.brushingStateController.addEventListener( |
| 'model-changed', this.onModelChanged_.bind(this)); |
| |
| // Register all scripting objects. |
| var typeInfos = ScriptingObjectRegistry.getAllRegisteredTypeInfos(); |
| typeInfos.forEach(function(typeInfo) { |
| this.addScriptObject(typeInfo.metadata.name, typeInfo.constructor); |
| // Also make the object available to the DevTools inspector. |
| global[typeInfo.metadata.name] = typeInfo.constructor; |
| }.bind(this)); |
| } |
| |
| function ScriptingObjectRegistry() { |
| } |
| var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE); |
| tr.b.decorateExtensionRegistry(ScriptingObjectRegistry, options); |
| |
| ScriptingController.prototype = { |
| get brushingStateController() { |
| return this.brushingStateController_; |
| }, |
| |
| onModelChanged_: function() { |
| this.scriptObjectValues_.forEach(function(v) { |
| if (v.onModelChanged) |
| v.onModelChanged(); |
| }); |
| }, |
| |
| addScriptObject: function(name, value) { |
| this.scriptObjectNames_.push(name); |
| this.scriptObjectValues_.push(value); |
| }, |
| |
| executeCommand: function(command) { |
| var f = new Function( |
| this.scriptObjectNames_, 'return eval(' + command + ')'); |
| return f.apply(null, this.scriptObjectValues_); |
| } |
| }; |
| |
| return { |
| ScriptingController: ScriptingController, |
| ScriptingObjectRegistry: ScriptingObjectRegistry |
| }; |
| }); |
| </script> |