1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Scripts for the message handler for use with UIWebView.
8 * Namespace for this module.
10 __gCrWeb.message_dynamic = {};
12 /* Beginning of anonymous object. */
15 * Sends queued commands to the Objective-C side.
16 * @param {Object} queueObject Queue object containing messages to send.
18 __gCrWeb.message_dynamic.sendQueue = function(queueObject) {
19 // The technique requires the document to be present. If it is not, the
20 // messages will be sent once the document object is created.
21 if (!document || !document.body) {
22 // This happens in rare occasions early in the page cycle. It is
23 // possible to create a body element indirectly here, but it has side
24 // effects such as blocking page redirection. The safest solution is to
25 // try again in 1/10th of a second.
26 window.setTimeout(__gCrWeb.message.invokeQueues, 100);
30 var frame = document.createElement('iframe');
31 frame.style.display = 'none';
32 frame.src = queueObject.scheme + '://' + __gCrWeb.windowId + '#' +
33 encodeURIComponent(__gCrWeb.common.JSONStringify(queueObject.queue));
35 document.body.appendChild(frame);
36 document.body.removeChild(frame);