Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * Sends queued commands to the Objective-C side. | 19 * Sends queued commands to the Objective-C side. |
| 20 * @param {Object} queueObject Queue object containing messages to send. | 20 * @param {Object} queueObject Queue object containing messages to send. |
| 21 */ | 21 */ |
| 22 __gCrWeb.message_dynamic.sendQueue = function(queueObject) { | 22 __gCrWeb.message_dynamic.sendQueue = function(queueObject) { |
| 23 // The technique requires the document to be present. If it is not, the | 23 var send = function() { |
| 24 // messages will be sent once the document object is created. | 24 // The technique requires the document to be present. If it is not, the |
| 25 if (!document || !document.body) { | 25 // messages will be sent once the document object is created. |
| 26 // This happens in rare occasions early in the page cycle. It is | 26 if (!document || !document.body) { |
| 27 // possible to create a body element indirectly here, but it has side | 27 // This happens in rare occasions early in the page cycle. It is |
| 28 // effects such as blocking page redirection. The safest solution is to | 28 // possible to create a body element indirectly here, but it has side |
| 29 // try again in 1/10th of a second. | 29 // effects such as blocking page redirection. The safest solution is to |
| 30 window.setTimeout(__gCrWeb.message.invokeQueues, 100); | 30 // try again in 1/10th of a second. |
| 31 return; | 31 window.setTimeout(__gCrWeb.message.invokeQueues, 100); |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 var frame = document.createElement('iframe'); | |
| 36 frame.style.display = 'none'; | |
| 37 frame.src = queueObject.scheme + '://' + __gCrWeb.windowId + '#' + | |
| 38 encodeURIComponent(__gCrWeb.common.JSONStringify(queueObject.queue)); | |
| 39 queueObject.reset(); | |
| 40 document.body.appendChild(frame); | |
| 41 document.body.removeChild(frame); | |
| 42 }; | |
| 43 | |
| 44 // The Apple mobile password recovery page does not interact well with | |
| 45 // iframes, so on pages with the 'iforgot.apple.com' domain, delay sending | |
| 46 // the queue. | |
| 47 if (window.location.origin === "https://iforgot.apple.com") { | |
|
stuartmorgan
2015/05/18 19:57:08
Let's do a bit of combination self-documentation a
Jackie Quinn
2015/05/18 20:36:42
Done.
| |
| 48 window.setTimeout(send, 150); | |
| 49 } else { | |
| 50 send(); | |
| 32 } | 51 } |
| 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 }; | 52 }; |
| 42 } | 53 } |
| OLD | NEW |