| 1 |
// Copyright 2008 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Detects the Adobe Reader PDF browser plugin. |
| 17 |
* |
| 18 |
* @author [email protected] (Chris Nokleberg) |
| 19 |
* @see ../demos/useragent.html |
| 20 |
*/ |
| 21 |
|
| 22 |
/** @suppress {extraProvide} */ |
| 23 |
goog.provide('goog.userAgent.adobeReader'); |
| 24 |
|
| 25 |
goog.require('goog.string'); |
| 26 |
goog.require('goog.userAgent'); |
| 27 |
|
| 28 |
|
| 29 |
(function() { |
| 30 |
var version = ''; |
| 31 |
if (goog.userAgent.IE) { |
| 32 |
var detectOnIe = function(classId) { |
| 33 |
|
| 34 |
try { |
| 35 |
new ActiveXObject(classId); |
| 36 |
return true; |
| 37 |
} catch (ex) { |
| 38 |
return false; |
| 39 |
} |
| 40 |
}; |
| 41 |
if (detectOnIe('AcroPDF.PDF.1')) { |
| 42 |
version = '7'; |
| 43 |
} else if (detectOnIe('PDF.PdfCtrl.6')) { |
| 44 |
version = '6'; |
| 45 |
} |
| 46 |
// TODO(chrisn): Add detection for previous versions if anyone needs them. |
| 47 |
} else { |
| 48 |
if (navigator.mimeTypes && navigator.mimeTypes.length > 0) { |
| 49 |
var mimeType = navigator.mimeTypes['application/pdf']; |
| 50 |
if (mimeType && mimeType.enabledPlugin) { |
| 51 |
var description = mimeType.enabledPlugin.description; |
| 52 |
if (description && description.indexOf('Adobe') != -1) { |
| 53 |
// Newer plugins do not include the version in the description, so we |
| 54 |
// default to 7. |
| 55 |
version = description.indexOf('Version') != -1 ? |
| 56 |
description.split('Version')[1] : |
| 57 |
'7'; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Whether we detect the user has the Adobe Reader browser plugin installed. |
| 65 |
* @type {boolean} |
| 66 |
*/ |
| 67 |
goog.userAgent.adobeReader.HAS_READER = !!version; |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* The version of the installed Adobe Reader plugin. Versions after 7 |
| 72 |
* will all be reported as '7'. |
| 73 |
* @type {string} |
| 74 |
*/ |
| 75 |
goog.userAgent.adobeReader.VERSION = version; |
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* On certain combinations of platform/browser/plugin, a print dialog |
| 80 |
* can be shown for PDF files without a download dialog or making the |
| 81 |
* PDF visible to the user, by loading the PDF into a hidden iframe. |
| 82 |
* |
| 83 |
* Currently this variable is true if Adobe Reader version 6 or later |
| 84 |
* is detected on Windows. |
| 85 |
* |
| 86 |
* @type {boolean} |
| 87 |
*/ |
| 88 |
goog.userAgent.adobeReader.SILENT_PRINT = |
| 89 |
goog.userAgent.WINDOWS && goog.string.compareVersions(version, '6') >= 0; |
| 90 |
|
| 91 |
})(); |