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 Logic for interrogating / manipulating the local Chrome Frame 7 * installation. 8 * 9 **/ 10 goog.provide('google.cf.ChromeFrame'); 11 12 /** 13 * Constructs an object for interacting with Chrome Frame through the provided 14 * Window instance. 15 * @constructor 16 * @param {Window=} opt_windowInstance The browser window through which to 17 * interact with Chrome Frame. Defaults to the global window object. 18 **/ 19 google.cf.ChromeFrame = function(opt_windowInstance) { 20 /** 21 * @private 22 * @const 23 * @type {!Window} 24 **/ 25 this.window_ = opt_windowInstance || window; 26 }; 27 28 /** 29 * The name of the Chrome Frame ActiveX control. 30 * @const 31 * @type {string} 32 **/ 33 google.cf.ChromeFrame.CONTROL_NAME = 'ChromeTab.ChromeFrame'; 34 35 /** 36 * Determines whether ChromeFrame is supported on the current platform. 37 * @return {boolean} Whether Chrome Frame is supported on the current platform. 38 */ 39 google.cf.ChromeFrame.prototype.isPlatformSupported = function() { 40 var ua = this.window_.navigator.userAgent; 41 var ieRe = /MSIE (\S+); Windows NT/; 42 43 if (!ieRe.test(ua)) 44 return false; 45 46 // We also only support Win2003/XPSP2 or better. See: 47 // http://msdn.microsoft.com/en-us/library/ms537503%28VS.85%29.aspx . 48 // 'SV1' indicates SP2, only bail if not SP2 or Win2K3 49 if (parseFloat(ieRe.exec(ua)[1]) < 6 && ua.indexOf('SV1') < 0) 50 return false; 51 52 return true; 53 }; 54 55 /** 56 * Determines whether Chrome Frame is the currently active renderer. 57 * @return {boolean} Whether Chrome Frame is rendering the current page. 58 */ 59 google.cf.ChromeFrame.prototype.isActiveRenderer = function () { 60 return this.window_.externalHost ? true : false; 61 }; 62 63 /** 64 * Determines if Google Chrome Frame is activated or locally available for 65 * activation in the current browser instance. In the latter case, will trigger 66 * its activation. 67 * @return {boolean} True if Google Chrome Frame already was active or was 68 * locally available (and now active). False otherwise. 69 */ 70 google.cf.ChromeFrame.prototype.activate = function() { 71 // Look for CF in the User Agent before trying more expensive checks 72 var ua = this.window_.navigator.userAgent.toLowerCase(); 73 if (ua.indexOf('chromeframe') >= 0) 74 return true; 75 76 if (typeof this.window_['ActiveXObject'] != 'undefined') { 77 try { 78 var chromeFrame = /** @type {ChromeTab.ChromeFrame} */( 79 new this.window_.ActiveXObject(google.cf.ChromeFrame.CONTROL_NAME)); 80 if (chromeFrame) { 81 // Register the BHO if it hasn't happened already. 82 chromeFrame.registerBhoIfNeeded(); 83 return true; 84 } 85 } catch (e) { 86 // Squelch 87 } 88 } 89 return false; 90 }; 91