AppRTCDemo: replace the use of query-string parameters for pre-JB devices.

Replaces the use of a query-string parameter with a (once-per-session)
JS-to-Java function call, because query-string parameters on file:// URLs are
busted on ICS and earlier Android releases
(https://code.google.com/p/android/issues/detail?id=17535).

Also added channel.html to the list of inputs to cause edits to it to cause a
rebuild of the .apk.

BUG=1949
R=wu@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1890004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4421 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org
2013-07-29 19:07:33 +00:00
parent 7694562805
commit 147d44a450
3 changed files with 18 additions and 28 deletions

View File

@@ -5,39 +5,19 @@
<!--
Helper HTML that redirects Google AppEngine's Channel API to a JS object named
|androidMessageHandler|, which is expected to be injected into the WebView
rendering this page by an Android app's class such as AppRTCClient
rendering this page by an Android app's class such as AppRTCClient.
-->
<body onbeforeunload="closeSocket()" onload="openSocket()">
<script type="text/javascript">
// QueryString is copy/pasta from
// chromium's chrome/test/data/media/html/utils.js.
var QueryString = function () {
// Allows access to query parameters on the URL; e.g., given a URL like:
// http://<url>/my.html?test=123&bob=123
// parameters can now be accessed via QueryString.test or QueryString.bob.
var params = {};
// RegEx to split out values by &.
var r = /([^&=]+)=?([^&]*)/g;
// Lambda function for decoding extracted match values. Replaces '+' with
// space so decodeURIComponent functions properly.
function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
var match;
while (match = r.exec(window.location.search.substring(1)))
params[d(match[1])] = d(match[2]);
return params;
} ();
var token = androidMessageHandler.getToken();
if (!token)
throw "Missing/malformed token parameter: [" + token + "]";
var channel = null;
var socket = null;
function openSocket() {
if (!QueryString.token || !QueryString.token.match(/^[A-z0-9_-]+$/))
throw "Missing/malformed token parameter: " + QueryString.token;
channel = new goog.appengine.Channel(QueryString.token);
channel = new goog.appengine.Channel(token);
socket = channel.open({
'onopen': function() { androidMessageHandler.onOpen(); },
'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); },

View File

@@ -83,10 +83,11 @@ public class GAEChannelClient {
", desc: " + description);
}
});
proxyingMessageHandler = new ProxyingMessageHandler(activity, handler);
proxyingMessageHandler =
new ProxyingMessageHandler(activity, handler, token);
webView.addJavascriptInterface(
proxyingMessageHandler, "androidMessageHandler");
webView.loadUrl("file:///android_asset/channel.html?token=" + token);
webView.loadUrl("file:///android_asset/channel.html");
}
/** Close the connection to the AppEngine channel. */
@@ -106,10 +107,14 @@ public class GAEChannelClient {
private final Activity activity;
private final MessageHandler handler;
private final boolean[] disconnected = { false };
private final String token;
public ProxyingMessageHandler(Activity activity, MessageHandler handler) {
public
ProxyingMessageHandler(Activity activity, MessageHandler handler,
String token) {
this.activity = activity;
this.handler = handler;
this.token = token;
}
public void disconnect() {
@@ -120,6 +125,10 @@ public class GAEChannelClient {
return disconnected[0];
}
@JavascriptInterface public String getToken() {
return token;
}
@JavascriptInterface public void onOpen() {
activity.runOnUiThread(new Runnable() {
public void run() {