// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** * @fileoverview CFInstall.js provides a set of utilities for managing * the Chrome Frame detection and installation process. * @author slightlyoff@google.com (Alex Russell) */ (function(scope) { // bail if we'd be over-writing an existing CFInstall object if (scope['CFInstall']) { return; } /** * returns an item based on DOM ID. Optionally a document may be provided to * specify the scope to search in. If a node is passed, it's returned as-is. * @param {string|Node} id The ID of the node to be located or a node * @param {Node} doc Optional A document to search for id. * @return {Node} */ var byId = function(id, doc) { return (typeof id == 'string') ? (doc || document).getElementById(id) : id; }; ///////////////////////////////////////////////////////////////////////////// // Plugin Detection ///////////////////////////////////////////////////////////////////////////// /** * Checks to find out if ChromeFrame is available as a plugin * @return {Boolean} */ var isAvailable = function() { // For testing purposes. if (scope.CFInstall._force) { return scope.CFInstall._forceValue; } // Look for CF in the User Agent before trying more expensive checks var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf("chromeframe") >= 0) { return true; } if (typeof window['ActiveXObject'] != 'undefined') { try { var obj = new ActiveXObject('ChromeTab.ChromeFrame'); if (obj) { return true; } } catch(e) { // squelch } } return false; }; /** * Creates a style sheet in the document containing the passed rules. */ var injectStyleSheet = function(rules) { try { var ss = document.createElement('style'); ss.setAttribute('type', 'text/css'); if (ss.styleSheet) { ss.styleSheet.cssText = rules; } else { ss.appendChild(document.createTextNode(rules)); } var h = document.getElementsByTagName('head')[0]; var firstChild = h.firstChild; h.insertBefore(ss, firstChild); } catch (e) { // squelch } }; /** @type {boolean} */ var cfStyleTagInjected = false; /** @type {boolean} */ var cfHiddenInjected = false; /** * Injects style rules into the document to handle formatting of Chrome Frame * prompt. Multiple calls have no effect. */ var injectCFStyleTag = function() { if (cfStyleTagInjected) { // Once and only once return; } var rules = '.chromeFrameInstallDefaultStyle {' + 'width: 800px;' + 'height: 600px;' + 'position: absolute;' + 'left: 50%;' + 'top: 50%;' + 'margin-left: -400px;' + 'margin-top: -300px;' + '}' + '.chromeFrameOverlayContent {' + 'position: absolute;' + 'margin-left: -400px;' + 'margin-top: -300px;' + 'left: 50%;' + 'top: 50%;' + 'border: 1px solid #93B4D9;' + 'background-color: white;' + 'z-index: 2001;' + '}' + '.chromeFrameOverlayContent iframe {' + 'width: 800px;' + 'height: 600px;' + 'border: none;' + '}' + '.chromeFrameOverlayCloseBar {' + 'height: 1em;' + 'text-align: right;' + 'background-color: #CADEF4;' + '}' + '.chromeFrameOverlayUnderlay {' + 'position: absolute;' + 'width: 100%;' + 'height: 100%;' + 'background-color: white;' + 'opacity: 0.5;' + '-moz-opacity: 0.5;' + '-webkit-opacity: 0.5;' + '-ms-filter: ' + '"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";' + 'filter: alpha(opacity=50);' + 'z-index: 2000;' + '}'; injectStyleSheet(rules); cfStyleTagInjected = true; }; /** * Injects style rules to hide the overlay version of the GCF prompt. * Multiple calls have no effect. */ var closeOverlay = function() { // IE has a limit to the # of