| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview Implements the in-line Google Chrome Frame installation flow. | |
| 7 * Displays a dialog containing the download page. Upon completion, registers | |
| 8 * the Google Chrome Frame components in the current browser process. | |
| 9 * | |
| 10 **/ | |
| 11 goog.provide('google.cf.installer.CrossDomainInstall'); | |
| 12 | |
| 13 goog.require('goog.net.xpc.CrossPageChannel'); | |
| 14 goog.require('goog.style'); | |
| 15 goog.require('goog.Uri'); | |
| 16 | |
| 17 goog.require('google.cf.installer.InteractionDelegate'); | |
| 18 goog.require('google.cf.installer.DialogInteractionDelegate'); | |
| 19 | |
| 20 /** | |
| 21 * @type {Object} | |
| 22 **/ | |
| 23 google.cf.installer.CrossDomainInstall = {}; | |
| 24 | |
| 25 /** | |
| 26 * @define {string} Defines the default download page URL. | |
| 27 **/ | |
| 28 google.cf.installer.CrossDomainInstall.DEFAULT_DOWNLOAD_PAGE_URL = | |
| 29 '//www.google.com/chromeframe/eula.html'; | |
| 30 | |
| 31 /** | |
| 32 * Executes the in-line installation flow. | |
| 33 * @param {function()} successHandler Invoked upon installation success. When | |
| 34 * invoked, Google Chrome Frame will be active in the current and all | |
| 35 * future-launched browser processes. | |
| 36 * @param {function()=} opt_failureHandler Invoked upon installation failure or | |
| 37 * cancellation. | |
| 38 * @param {string=} opt_url An alternative URL for the download page. | |
| 39 * @param {google.cf.installer.InteractionDelegate=} opt_interactionDelegate An | |
| 40 * alternative UI implementation for the modal dialog. | |
| 41 * @param {string=} opt_dummyResourceUri A manually-specified dummy resource URI | |
| 42 * that will be used to carry cross-domain responses. | |
| 43 */ | |
| 44 google.cf.installer.CrossDomainInstall.execute = function( | |
| 45 successHandler, opt_failureHandler, opt_url, opt_interactionDelegate, | |
| 46 opt_dummyResourceUri) { | |
| 47 var url = new goog.Uri( | |
| 48 opt_url || | |
| 49 google.cf.installer.CrossDomainInstall.DEFAULT_DOWNLOAD_PAGE_URL); | |
| 50 | |
| 51 if (!url.hasScheme()) | |
| 52 url = new goog.Uri(window.location.href).resolve(url); | |
| 53 | |
| 54 var interactionDelegate = opt_interactionDelegate || | |
| 55 new google.cf.installer.DialogInteractionDelegate(); | |
| 56 | |
| 57 var cfg = {}; | |
| 58 | |
| 59 // TODO(user): Probably need to import some of the link/image url | |
| 60 // detection stuff from XDRPC. | |
| 61 if (opt_dummyResourceUri) { | |
| 62 var dummyUrl = new goog.Uri(opt_dummyResourceUri); | |
| 63 if (!dummyUrl.hasScheme()) | |
| 64 dummyUrl = new goog.Uri(window.location.href).resolve(dummyUrl); | |
| 65 | |
| 66 cfg[goog.net.xpc.CfgFields.LOCAL_POLL_URI] = dummyUrl.toString(); | |
| 67 } | |
| 68 | |
| 69 cfg[goog.net.xpc.CfgFields.PEER_URI] = url.toString(); | |
| 70 | |
| 71 var channel = new goog.net.xpc.CrossPageChannel(cfg); | |
| 72 var iframe = channel.createPeerIframe( | |
| 73 interactionDelegate.getIFrameContainer(), | |
| 74 function(newIFrame) { | |
| 75 newIFrame.setAttribute('frameBorder', '0'); | |
| 76 newIFrame.setAttribute('border', '0'); | |
| 77 interactionDelegate.customizeIFrame(newIFrame); | |
| 78 }); | |
| 79 channel.registerService('dimensions', function(size) { | |
| 80 goog.style.setContentBoxSize(iframe, new goog.math.Size(size['width'], | |
| 81 size['height'])); | |
| 82 interactionDelegate.show(); | |
| 83 }, true); // true => deserialize messages into objects | |
| 84 channel.registerService('result', function(obj) { | |
| 85 channel.close(); | |
| 86 interactionDelegate.reset(); | |
| 87 var result = obj['result']; | |
| 88 if (result) | |
| 89 successHandler(); | |
| 90 else if (opt_failureHandler) | |
| 91 opt_failureHandler(); | |
| 92 }, true); // true => deserialize messages into objects | |
| 93 // TODO(user): Perhaps listen to onload and set a timeout for connect. | |
| 94 channel.connect(); | |
| 95 }; | |
| 96 | |
| 97 // In compiled mode, this binary is wrapped in an anonymous function which | |
| 98 // receives the outer scope as its only parameter. In non-compiled mode, the | |
| 99 // outer scope is window. | |
| 100 // Look in the outer scope for the stub, and pass it the implementation. | |
| 101 try { | |
| 102 if (arguments[0]['CF_google_cf_xd_install_stub']) { | |
| 103 arguments[0]['CF_google_cf_xd_install_stub']( | |
| 104 google.cf.installer.CrossDomainInstall.execute); | |
| 105 } | |
| 106 } catch (e) { | |
| 107 if (window['CF_google_cf_xd_install_stub']) { | |
| 108 window['CF_google_cf_xd_install_stub']( | |
| 109 google.cf.installer.CrossDomainInstall.execute); | |
| 110 } | |
| 111 } | |
| OLD | NEW |