Index: remoting/webapp/js_proto/chrome_mocks.js |
diff --git a/remoting/webapp/js_proto/chrome_mocks.js b/remoting/webapp/js_proto/chrome_mocks.js |
index e64421db527c5d8ef483d5f633452e66fb928613..8e269426eeb3ff65589faca517778e2cb803d624 100644 |
--- a/remoting/webapp/js_proto/chrome_mocks.js |
+++ b/remoting/webapp/js_proto/chrome_mocks.js |
@@ -62,7 +62,10 @@ chromeMocks.runtime = {}; |
/** @constructor */ |
chromeMocks.runtime.Port = function() { |
+ /** @const */ |
this.onMessage = new chromeMocks.Event(); |
+ |
+ /** @const */ |
this.onDisconnect = new chromeMocks.Event(); |
/** @type {string} */ |
@@ -100,6 +103,24 @@ chromeMocks.runtime.sendMessage = function(extensionId, message, |
}); |
}; |
+/** |
+ * Always returns the same mock port for given application name. |
+ * @param {string} application |
+ * @return {chromeMocks.runtime.Port} |
+ */ |
+chromeMocks.runtime.connectNative = function(application) { |
+ var port = nativePorts[application]; |
+ if (port == null) { |
kelvinp
2015/04/06 17:25:10
use ===
John Williams
2015/04/06 19:14:59
Done.
|
+ port = new chromeMocks.runtime.Port(); |
+ port.name = application; |
+ nativePorts[application] = port; |
+ } |
+ return port; |
+}; |
+ |
+/** @const {Object<string,!chromeMocks.runtime.Port>} */ |
+var nativePorts = null; |
+ |
/** @type {string} */ |
chromeMocks.runtime.id = 'extensionId'; |
@@ -225,6 +246,7 @@ chromeMocks.activate = function(components) { |
throw new Error('chromeMocks.activate() can only be called once.'); |
} |
originals_ = {}; |
+ nativePorts = {}; |
components.forEach(function(component) { |
if (!chromeMocks[component]) { |
throw new Error('No mocks defined for chrome.' + component); |
@@ -242,6 +264,7 @@ chromeMocks.restore = function() { |
chrome[components] = originals_[components]; |
} |
originals_ = null; |
+ nativePorts = null; |
}; |
})(); |