Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: ios/web/web_state/js/resources/message_dynamic_ui.js

Issue 1132163007: Invoke JS messaging for UIWebView via window.requestAnimationFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Indentation fix Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Scripts for the message handler for use with UIWebView. 5 // Scripts for the message handler for use with UIWebView.
6 6
7 goog.provide('__crWeb.messageDynamic'); 7 goog.provide('__crWeb.messageDynamic');
8 8
9 goog.require('__crWeb.common'); 9 goog.require('__crWeb.common');
10 10
11 /** 11 /**
12 * Namespace for this module. 12 * Namespace for this module.
13 */ 13 */
14 __gCrWeb.message_dynamic = {}; 14 __gCrWeb.message_dynamic = {};
15 15
16 /* Beginning of anonymous object. */ 16 /* Beginning of anonymous object. */
17 new function() { 17 new function() {
18 /** 18 /**
19 * Returns true if sending the message queue should be delayed.
20 */
21 function pageRequiresDelayedSend() {
22 // The Apple mobile password recovery page does not interact well with
23 // iframes, so on pages with the 'iforgot.apple.com' domain, delay sending
24 // the queue.
25 return window.location.origin === "https://iforgot.apple.com";
26 }
27
28 /**
19 * Sends queued commands to the Objective-C side. 29 * Sends queued commands to the Objective-C side.
20 * @param {Object} queueObject Queue object containing messages to send. 30 * @param {Object} queueObject Queue object containing messages to send.
21 */ 31 */
22 __gCrWeb.message_dynamic.sendQueue = function(queueObject) { 32 __gCrWeb.message_dynamic.sendQueue = function(queueObject) {
23 // The technique requires the document to be present. If it is not, the 33 var send = function() {
24 // messages will be sent once the document object is created. 34 // The technique requires the document to be present. If it is not, the
25 if (!document || !document.body) { 35 // messages will be sent once the document object is created.
26 // This happens in rare occasions early in the page cycle. It is 36 if (!document || !document.body) {
27 // possible to create a body element indirectly here, but it has side 37 // This happens in rare occasions early in the page cycle. It is
28 // effects such as blocking page redirection. The safest solution is to 38 // possible to create a body element indirectly here, but it has side
29 // try again in 1/10th of a second. 39 // effects such as blocking page redirection. The safest solution is to
30 window.setTimeout(__gCrWeb.message.invokeQueues, 100); 40 // try again in 1/10th of a second.
31 return; 41 window.setTimeout(__gCrWeb.message.invokeQueues, 100);
42 return;
43 }
44
45 var frame = document.createElement('iframe');
46 frame.style.display = 'none';
47 frame.src = queueObject.scheme + '://' + __gCrWeb.windowId + '#' +
48 encodeURIComponent(__gCrWeb.common.JSONStringify(queueObject.queue));
49 queueObject.reset();
50 document.body.appendChild(frame);
51 document.body.removeChild(frame);
52 };
53
54 // Some pages do not interact well with iframes. On those pages, delay
55 // sending the queue.
56 if (pageRequiresDelayedSend()) {
57 window.requestAnimationFrame(send);
58 } else {
59 send();
32 } 60 }
33
34 var frame = document.createElement('iframe');
35 frame.style.display = 'none';
36 frame.src = queueObject.scheme + '://' + __gCrWeb.windowId + '#' +
37 encodeURIComponent(__gCrWeb.common.JSONStringify(queueObject.queue));
38 queueObject.reset();
39 document.body.appendChild(frame);
40 document.body.removeChild(frame);
41 }; 61 };
42 } 62 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698