Chromium Code Reviews| Index: chrome/browser/resources/print_preview.js |
| diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js |
| index 5c2bb573d08f23304ed4f05c38cf0c3fcf627f2b..e877410d4cb2de9f6f6da701cf06f65eb5b672ff 100644 |
| --- a/chrome/browser/resources/print_preview.js |
| +++ b/chrome/browser/resources/print_preview.js |
| @@ -4,10 +4,6 @@ |
| var localStrings = new LocalStrings(); |
| -// Whether or not the PDF plugin supports all the capabilities needed for |
| -// print preview. |
| -var hasCompatiblePDFPlugin = true; |
| - |
| // The total page count of the previewed document regardless of which pages the |
| // user has selected. |
| var totalPageCount = -1; |
| @@ -48,10 +44,18 @@ const MANAGE_PRINTERS = 'Manage Printers'; |
| * the printer list. |
| */ |
| function onLoad() { |
| + $('system-dialog-link').addEventListener('click', showSystemDialog); |
| + $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| + $('dummy-viewer').classList.add('hidden'); |
| + |
| + if(!checkCompatiblePluginExists()) { |
|
Lei Zhang
2011/05/11 22:19:51
nit: space after if
dpapad
2011/05/11 23:31:03
Done.
|
| + displayErrorMessage(localStrings.getString('noPlugin')); |
| + return; |
| + } |
| + |
|
vandebo (ex-Chrome)
2011/05/11 22:13:54
Should we remove the dummy-viewer is some way so t
dpapad
2011/05/11 23:31:03
The plugin is removed from the page on line 49. If
|
| $('printer-list').disabled = true; |
| $('print-button').disabled = true; |
| $('print-button').addEventListener('click', printFile); |
| - $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| $('all-pages').addEventListener('click', onPageSelectionMayHaveChanged); |
| $('copies').addEventListener('input', copiesFieldChanged); |
| $('print-pages').addEventListener('click', handleIndividualPagesCheckbox); |
| @@ -68,7 +72,6 @@ function onLoad() { |
| $('bw').addEventListener('click', function() { setColor(false); }); |
| $('printer-list').addEventListener( |
| 'change', updateControlsWithSelectedPrinterCapabilities); |
| - $('system-dialog-link').addEventListener('click', showSystemDialog); |
| $('increment').addEventListener('click', |
| function() { onCopiesButtonsClicked(1); }); |
| $('decrement').addEventListener('click', |
| @@ -323,7 +326,6 @@ function printFile() { |
| function requestPrintPreview() { |
| isPreviewStillLoading = true; |
| setControlsDisabled(true); |
| - $('dancing-dots').classList.remove('hidden'); |
| $('dancing-dots').classList.remove('invisible'); |
| chrome.send('getPreview', [getSettingsJSON()]); |
| } |
| @@ -374,9 +376,6 @@ function addDestinationListOption(optionText, optionValue, is_default) { |
| * @param {boolean} color is true if the PDF plugin should display in color. |
| */ |
| function setColor(color) { |
| - if (!hasCompatiblePDFPlugin) { |
| - return; |
| - } |
| var pdfViewer = $('pdf-viewer'); |
| if (!pdfViewer) { |
| return; |
| @@ -390,6 +389,7 @@ function setColor(color) { |
| */ |
| function displayErrorMessage(errorMessage) { |
| isPreviewStillLoading = false; |
| + $('dancing-dots').classList.remove('invisible'); |
| $('dancing-dots-text').classList.add('hidden'); |
| $('error-text').innerHTML = errorMessage; |
| $('error-text').classList.remove('hidden'); |
| @@ -462,10 +462,6 @@ function updatePrintPreview(pageCount, jobTitle, mimeType) { |
| * Create the PDF plugin or reload the existing one. |
| */ |
| function createPDFPlugin() { |
| - if (!hasCompatiblePDFPlugin) { |
| - return; |
| - } |
| - |
| // Enable the print button. |
| if (!$('printer-list').disabled) { |
| $('print-button').disabled = false; |
| @@ -491,13 +487,6 @@ function createPDFPlugin() { |
| pdfPlugin.setAttribute('src', 'chrome://print/print.pdf'); |
| var mainView = $('mainview'); |
| mainView.appendChild(pdfPlugin); |
| - |
| - // Check to see if the PDF plugin is our PDF plugin. (or compatible) |
| - if (!pdfPlugin.onload) { |
| - hasCompatiblePDFPlugin = false; |
| - displayErrorMessage(localStrings.getString('noPlugin')); |
| - return; |
| - } |
| pdfPlugin.onload('onPDFLoad()'); |
| // Older version of the PDF plugin may not have this method. |
| @@ -510,6 +499,14 @@ function createPDFPlugin() { |
| } |
| /** |
| + * Returns true if a compatible pdf plugin exists, false if it doesn't. |
| + */ |
| +function checkCompatiblePluginExists() { |
| + var dummyPlugin = $('dummy-viewer') |
| + return !!dummyPlugin.onload; |
| +} |
| + |
| +/** |
| * Updates the state of print button depending on the user selection. |
| * The button is enabled only when the following conditions are true. |
| * 1) The selected page ranges are valid. |