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

Unified Diff: mojo/spy/ui/spy_shell.js

Issue 278703002: Initial mojo spy skeleton based on tvcm (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready to land Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: mojo/spy/ui/spy_shell.js
diff --git a/mojo/spy/ui/spy_shell.js b/mojo/spy/ui/spy_shell.js
new file mode 100644
index 0000000000000000000000000000000000000000..8b75c616bf8b59adb133b298070d5663db44a90a
--- /dev/null
+++ b/mojo/spy/ui/spy_shell.js
@@ -0,0 +1,68 @@
+// Copyright (c) 2014 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.
+
+'use strict';
+
+tvcm.require('ui.spy');
+tvcm.require('tvcm.ui');
+tvcm.require('tvcm.ui.dom_helpers');
+tvcm.requireTemplate('ui.spy_shell');
+
+tvcm.exportTo('ui', function() {
+ /**
+ * @constructor
+ */
+ var SpyShell = tvcm.ui.define('x-spy-shell');
+
+ SpyShell.prototype = {
+ __proto__: HTMLUnknownElement.prototype,
+
+ decorate: function(socketURL) {
+ var node = tvcm.instantiateTemplate('#x-spy-shell-template');
+ this.appendChild(node);
+
+ this.socketURL_ = socketURL;
+ this.conn_ = undefined;
+
+ this.statusEl_ = this.querySelector('#status');
+ this.statusEl_.textContent = 'Not connected';
+
+ this.spy_ = this.querySelector('x-spy');
+ tvcm.ui.decorate(this.spy_, ui.Spy);
+
+ this.openConnection_();
+ },
+
+ get socketURL() {
+ return this.socketURL_;
+ },
+
+ openConnection_: function() {
+ if (!(this.conn_ == undefined ||
+ this.conn_.readyState === undefined ||
+ conn.readyState > 1)) {
+ return;
+ }
+
+ this.conn_ = new WebSocket(this.socketURL_);
+ this.conn_.onopen = function() {
+ this.statusEl_.textContent = 'connected at ' + this.socketURL_;
+ this.spy_.connection = this.conn_;
+ }.bind(this);
+
+ this.conn_.onclose = function(event) {
+ this.statusEl_.textContent = 'connection closed';
+ this.spy_.connection = undefined;
+ }.bind(this);
+ this.conn_.onerror = function(event) {
+ this.statusEl_.innerHTML = 'got error';
+ }.bind(this);
+ }
+
+ };
+
+ return {
+ SpyShell: SpyShell
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698