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.
6 * @fileoverview Implements CFInstall.check and isAvailable in a way that is
7 * compatible with previous versions. Also supports a more streamlined
12 goog.provide('google.cf.installer.CFInstall');
14 goog.require('google.cf.ChromeFrame');
15 goog.require('google.cf.installer.InlineDelegate');
16 goog.require('google.cf.installer.Installer');
17 goog.require('google.cf.installer.OverlayDelegate');
18 goog.require('google.cf.installer.Prompt');
21 * Instantiates the CFInstall object. Normally there will be only one, at
25 google.cf.installer.CFInstall = function() {
26 this.prompt_ = new google.cf.installer.Prompt();
27 this.chromeFrame_ = new google.cf.ChromeFrame();
28 this.installer_ = new google.cf.installer.Installer(
29 this.prompt_, this.chromeFrame_);
30 this['setDownloadPageUrl'] =
31 goog.bind(this.prompt_.setDownloadPageUrl, this.prompt_);
32 this['setImplementationUrl'] =
33 goog.bind(this.prompt_.setImplementationUrl, this.prompt_);
34 this['setSameDomainResourceUri'] =
35 goog.bind(this.prompt_.setSameDomainResourceUri, this.prompt_);
36 this['setInteractionDelegate'] =
37 goog.bind(this.prompt_.setInteractionDelegate, this.prompt_);
38 this['require'] = goog.bind(this.installer_.require, this.installer_);
40 goog.bind(this.chromeFrame_.activate, this.chromeFrame_);
44 * TODO(user): This cookie is not currently set anywhere.
45 * @return {boolean} Whether the user has previously declined Chrome Frame.
48 google.cf.installer.CFInstall.isDeclined_ = function() {
49 return document.cookie.indexOf("disableGCFCheck=1") >=0;
53 * Checks to see if Chrome Frame is available, if not, prompts the user to
54 * install. Once installation is begun, a background timer starts,
55 * checkinging for a successful install every 2 seconds. Upon detection of
56 * successful installation, the current page is reloaded, or if a
57 * 'destination' parameter is passed, the page navigates there instead.
58 * @param {Object} args A bag of configuration properties. Respected
59 * properties are: 'mode', 'url', 'destination', 'node', 'onmissing',
60 * 'preventPrompt', 'oninstall', 'preventInstallDetection', 'cssText', and
63 google.cf.installer.CFInstall.prototype['check'] = function(args) {
66 if (!this.chromeFrame_.isPlatformSupported())
69 if (this.chromeFrame_.activate())
72 if (args['onmissing'])
75 if (google.cf.installer.CFInstall.isDeclined_() || args['preventPrompt'])
78 // NOTE: @slightlyoff, I'm doing away with the window.open option here. Sites
79 // that were using it will now use the popup.
81 // In the case of legacy installation parameters, supply a compatible
82 // InteractionDelegate.
83 if (args['mode'] == 'inline' || args['node'] || args['id'] ||
84 args['cssText'] || args['className']) {
85 if (!args['mode'] || args['mode'] == 'inline') {
86 this.prompt_.setInteractionDelegate(
87 new google.cf.installer.InlineDelegate(args));
89 this.prompt_.setInteractionDelegate(
90 new google.cf.installer.OverlayDelegate(args));
95 this.prompt_.setDownloadPageUrl(args['src']);
97 var onSuccess = function() {
98 if (this.chromeFrame_.activate() && !args['preventInstallDetection']) {
99 if (args['oninstall'])
101 window.location.assign(args['destination'] || window.location);
105 this.prompt_.open(onSuccess, undefined);
108 // In compiled mode, this binary is wrapped in an anonymous function which
109 // receives the outer scope as its only parameter. In non-compiled mode, the
110 // outer scope is window.
112 // Create a single instance of CFInstall and place it in the outer scope
113 // (presumably the global window object).
115 arguments[0]['CFInstall'] = new google.cf.installer.CFInstall();
117 window['CFInstall'] = new google.cf.installer.CFInstall();