adobereader.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @fileoverview Detects the Adobe Reader PDF browser plugin.
  16. *
  17. * @author chrisn@google.com (Chris Nokleberg)
  18. * @see ../demos/useragent.html
  19. */
  20. /** @suppress {extraProvide} */
  21. goog.provide('goog.userAgent.adobeReader');
  22. goog.require('goog.string');
  23. goog.require('goog.userAgent');
  24. (function() {
  25. var version = '';
  26. if (goog.userAgent.IE) {
  27. var detectOnIe = function(classId) {
  28. try {
  29. new ActiveXObject(classId);
  30. return true;
  31. } catch (ex) {
  32. return false;
  33. }
  34. };
  35. if (detectOnIe('AcroPDF.PDF.1')) {
  36. version = '7';
  37. } else if (detectOnIe('PDF.PdfCtrl.6')) {
  38. version = '6';
  39. }
  40. // TODO(chrisn): Add detection for previous versions if anyone needs them.
  41. } else {
  42. if (navigator.mimeTypes && navigator.mimeTypes.length > 0) {
  43. var mimeType = navigator.mimeTypes['application/pdf'];
  44. if (mimeType && mimeType.enabledPlugin) {
  45. var description = mimeType.enabledPlugin.description;
  46. if (description && description.indexOf('Adobe') != -1) {
  47. // Newer plugins do not include the version in the description, so we
  48. // default to 7.
  49. version = description.indexOf('Version') != -1 ?
  50. description.split('Version')[1] :
  51. '7';
  52. }
  53. }
  54. }
  55. }
  56. /**
  57. * Whether we detect the user has the Adobe Reader browser plugin installed.
  58. * @type {boolean}
  59. */
  60. goog.userAgent.adobeReader.HAS_READER = !!version;
  61. /**
  62. * The version of the installed Adobe Reader plugin. Versions after 7
  63. * will all be reported as '7'.
  64. * @type {string}
  65. */
  66. goog.userAgent.adobeReader.VERSION = version;
  67. /**
  68. * On certain combinations of platform/browser/plugin, a print dialog
  69. * can be shown for PDF files without a download dialog or making the
  70. * PDF visible to the user, by loading the PDF into a hidden iframe.
  71. *
  72. * Currently this variable is true if Adobe Reader version 6 or later
  73. * is detected on Windows.
  74. *
  75. * @type {boolean}
  76. */
  77. goog.userAgent.adobeReader.SILENT_PRINT =
  78. goog.userAgent.WINDOWS && goog.string.compareVersions(version, '6') >= 0;
  79. })();