Path: blob/trunk/third_party/closure/goog/net/xpc/relay.js
1865 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Standalone script to be included in the relay-document16* used by goog.net.xpc.IframeRelayTransport. This script will decode the17* fragment identifier, determine the target window object and deliver18* the data to it.19*20*/2122/** @suppress {extraProvide} */23goog.provide('goog.net.xpc.relay');2425(function() {26// Decode the fragement identifier.27// location.href is expected to be structured as follows:28// <url>#<channel_name>[,<iframe_id>]|<data>2930// Get the fragment identifier.31var raw = window.location.hash;32if (!raw) {33return;34}35if (raw.charAt(0) == '#') {36raw = raw.substring(1);37}38var pos = raw.indexOf('|');39var head = raw.substring(0, pos).split(',');40var channelName = head[0];41var iframeId = head.length == 2 ? head[1] : null;42var frame = raw.substring(pos + 1);4344// Find the window object of the peer.45//46// The general structure of the frames looks like this:47// - peer148// - relay249// - peer250// - relay151//52// We are either relay1 or relay2.5354var win;55if (iframeId) {56// We are relay2 and need to deliver the data to peer2.57win = window.parent.frames[iframeId];58} else {59// We are relay1 and need to deliver the data to peer1.60win = window.parent.parent;61}6263// Deliver the data.64try {65win['xpcRelay'](channelName, frame);66} catch (e) {67// Nothing useful can be done here.68// It would be great to inform the sender the delivery of this message69// failed, but this is not possible because we are already in the receiver's70// domain at this point.71}72})();737475