| 1 |
// Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Contains the base class for transports. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
goog.provide('goog.net.xpc.Transport'); |
| 22 |
|
| 23 |
goog.require('goog.Disposable'); |
| 24 |
goog.require('goog.dom'); |
| 25 |
goog.require('goog.net.xpc.TransportNames'); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* The base class for transports. |
| 31 |
* @param {goog.dom.DomHelper=} opt_domHelper The dom helper to use for |
| 32 |
* finding the window objects. |
| 33 |
* @constructor |
| 34 |
* @extends {goog.Disposable}; |
| 35 |
*/ |
| 36 |
goog.net.xpc.Transport = function(opt_domHelper) { |
| 37 |
goog.Disposable.call(this); |
| 38 |
|
| 39 |
/** |
| 40 |
* The dom helper to use for finding the window objects to reference. |
| 41 |
* @type {goog.dom.DomHelper} |
| 42 |
* @private |
| 43 |
*/ |
| 44 |
this.domHelper_ = opt_domHelper || goog.dom.getDomHelper(); |
| 45 |
}; |
| 46 |
goog.inherits(goog.net.xpc.Transport, goog.Disposable); |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* The transport type. |
| 51 |
* @type {number} |
| 52 |
* @protected |
| 53 |
*/ |
| 54 |
goog.net.xpc.Transport.prototype.transportType = 0; |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* @return {number} The transport type identifier. |
| 59 |
*/ |
| 60 |
goog.net.xpc.Transport.prototype.getType = function() { |
| 61 |
return this.transportType; |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the window associated with this transport instance. |
| 67 |
* @return {!Window} The window to use. |
| 68 |
*/ |
| 69 |
goog.net.xpc.Transport.prototype.getWindow = function() { |
| 70 |
return this.domHelper_.getWindow(); |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Return the transport name. |
| 76 |
* @return {string} the transport name. |
| 77 |
*/ |
| 78 |
goog.net.xpc.Transport.prototype.getName = function() { |
| 79 |
return goog.net.xpc.TransportNames[String(this.transportType)] || ''; |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Handles transport service messages (internal signalling). |
| 85 |
* @param {string} payload The message content. |
| 86 |
*/ |
| 87 |
goog.net.xpc.Transport.prototype.transportServiceHandler = goog.abstractMethod; |
| 88 |
|
| 89 |
|
| 90 |
/** |
| 91 |
* Connects this transport. |
| 92 |
* The transport implementation is expected to call |
| 93 |
* CrossPageChannel.prototype.notifyConnected when the channel is ready |
| 94 |
* to be used. |
| 95 |
*/ |
| 96 |
goog.net.xpc.Transport.prototype.connect = goog.abstractMethod; |
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* Sends a message. |
| 101 |
* @param {string} service The name off the service the message is to be |
| 102 |
* delivered to. |
| 103 |
* @param {string} payload The message content. |
| 104 |
*/ |
| 105 |
goog.net.xpc.Transport.prototype.send = goog.abstractMethod; |