| 1 |
<!DOCTYPE html> |
| 2 |
<!-- |
| 3 |
|
| 4 |
This file is responsible for setting up the inner peer half of an XPC |
| 5 |
communication channel. It instantiates a CrossPageChannel and attempts to |
| 6 |
connect to the outer peer. The XPC configuration should match that of the |
| 7 |
outer peer (i.e. same channel name, polling URIs, etc). |
| 8 |
--> |
| 9 |
<html> |
| 10 |
<!-- |
| 11 |
Copyright 2009 The Closure Library Authors. All Rights Reserved. |
| 12 |
|
| 13 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 14 |
See the COPYING file for details. |
| 15 |
--> |
| 16 |
|
| 17 |
<head> |
| 18 |
<title>XPC test inner frame</title> |
| 19 |
<script src="../../../base.js" type="text/javascript"></script> |
| 20 |
<script type="text/javascript"> |
| 21 |
goog.require('goog.debug.Logger'); |
| 22 |
goog.require('goog.dom'); |
| 23 |
goog.require('goog.events'); |
| 24 |
goog.require('goog.events.EventType'); |
| 25 |
goog.require('goog.net.xpc.CrossPageChannel'); |
| 26 |
</script> |
| 27 |
<script type="text/javascript"> |
| 28 |
var channel; |
| 29 |
var queuedMessage; |
| 30 |
|
| 31 |
var OBJECT_RESULT_FROM_SERVICE = {'favorites': 'pie'}; |
| 32 |
|
| 33 |
function clearDebug() { |
| 34 |
document.getElementById('debugDiv').innerHTML = ''; |
| 35 |
} |
| 36 |
|
| 37 |
function instantiateChannel(cfg) { |
| 38 |
if (window.channel) { |
| 39 |
window.channel.dispose(); |
| 40 |
} |
| 41 |
window.channel = new goog.net.xpc.CrossPageChannel(cfg); |
| 42 |
window.channel.registerService('echo', echoHandler); |
| 43 |
window.channel.registerService('response', responseHandler); |
| 44 |
connectChannel( |
| 45 |
parent.driver && parent.driver.innerFrameConnected ? |
| 46 |
goog.bind(parent.driver.innerFrameConnected, parent.driver) : null); |
| 47 |
} |
| 48 |
|
| 49 |
function connectChannel(opt_callback) { |
| 50 |
window.channel.connect(opt_callback || goog.nullFunction); |
| 51 |
} |
| 52 |
|
| 53 |
function sendEcho(payload) { |
| 54 |
window.channel.send('echo', payload); |
| 55 |
} |
| 56 |
|
| 57 |
function echoHandler(payload) { |
| 58 |
window.channel.send('response', payload); |
| 59 |
return OBJECT_RESULT_FROM_SERVICE; |
| 60 |
} |
| 61 |
|
| 62 |
function isConnected() { |
| 63 |
return window.channel && window.channel.isConnected(); |
| 64 |
} |
| 65 |
|
| 66 |
function responseHandler(payload) { |
| 67 |
if (parent.driver && parent.driver.innerFrameGotResponse) { |
| 68 |
parent.driver.innerFrameGotResponse(payload); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
</script> |
| 73 |
</head> |
| 74 |
|
| 75 |
<body> |
| 76 |
|
| 77 |
<div style="position:absolute"> |
| 78 |
Debug [<a href="#" onclick="clearDebug()">clear</a>]: <br> |
| 79 |
<div id=debugDiv style="border: 1px #000000 solid; font-size:xx-small"></div> |
| 80 |
</div> |
| 81 |
|
| 82 |
<script type="text/javascript"> |
| 83 |
var debugDiv = goog.dom.getElement('debugDiv'); |
| 84 |
var logger = goog.debug.Logger.getLogger('goog.net.xpc'); |
| 85 |
logger.setLevel(goog.debug.Logger.Level.ALL); |
| 86 |
logger.addHandler(function(logRecord) { |
| 87 |
var msgElm = goog.dom.createDom('div'); |
| 88 |
msgElm.innerHTML = logRecord.getMessage(); |
| 89 |
goog.dom.appendChild(debugDiv, msgElm); |
| 90 |
}); |
| 91 |
|
| 92 |
if (parent && parent.iframeLoadHandler) { |
| 93 |
parent.iframeLoadHandler(); |
| 94 |
} |
| 95 |
</script> |
| 96 |
|
| 97 |
</body> |
| 98 |
|
| 99 |
</html> |