Browse Source

[CSP] removes inlined styles and scripts

Yury Delendik 12 years ago
parent
commit
99c9079f54
  1. 7
      web/ui_utils.js
  2. 4
      web/viewer.html
  3. 26
      web/viewer.js

7
web/ui_utils.js

@ -117,6 +117,13 @@ function scrollIntoView(element, spot) {
parent.scrollTop = offsetY; parent.scrollTop = offsetY;
} }
/**
* Event handler to suppress context menu.
*/
function noContextMenuHandler(e) {
e.preventDefault();
}
/** /**
* Returns the filename or guessed filename from the url (see issue 3455). * Returns the filename or guessed filename from the url (see issue 3455).
* url {String} The original PDF location. * url {String} The original PDF location.

4
web/viewer.html

@ -158,8 +158,6 @@ limitations under the License.
<span id="numPages" class="toolbarLabel"></span> <span id="numPages" class="toolbarLabel"></span>
</div> </div>
<div id="toolbarViewerRight"> <div id="toolbarViewerRight">
<input id="fileInput" class="fileInput" type="file" oncontextmenu="return false;" style="visibility: hidden; position: fixed; right: 0; top: 0" />
<button id="presentationMode" class="toolbarButton presentationMode hiddenSmallView" title="Switch to Presentation Mode" tabindex="12" data-l10n-id="presentation_mode"> <button id="presentationMode" class="toolbarButton presentationMode hiddenSmallView" title="Switch to Presentation Mode" tabindex="12" data-l10n-id="presentation_mode">
<span data-l10n-id="presentation_mode_label">Presentation Mode</span> <span data-l10n-id="presentation_mode_label">Presentation Mode</span>
</button> </button>
@ -190,7 +188,7 @@ limitations under the License.
</button> </button>
</div> </div>
<span id="scaleSelectContainer" class="dropdownToolbarButton"> <span id="scaleSelectContainer" class="dropdownToolbarButton">
<select id="scaleSelect" title="Zoom" oncontextmenu="return false;" tabindex="11" data-l10n-id="zoom"> <select id="scaleSelect" title="Zoom" tabindex="11" data-l10n-id="zoom">
<option id="pageAutoOption" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option> <option id="pageAutoOption" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
<option id="pageActualOption" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option> <option id="pageActualOption" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>
<option id="pageFitOption" value="page-fit" data-l10n-id="page_scale_fit">Fit Page</option> <option id="pageFitOption" value="page-fit" data-l10n-id="page_scale_fit">Fit Page</option>

26
web/viewer.js

@ -17,7 +17,7 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle, /* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager, PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, getOutputScale, scrollIntoView, getPDFFileNameFromURL, getFileName, getOutputScale, scrollIntoView, getPDFFileNameFromURL,
PDFHistory */ PDFHistory, noContextMenuHandler */
'use strict'; 'use strict';
@ -796,11 +796,9 @@ var PDFView = {
moreInfoButton.removeAttribute('hidden'); moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true'); lessInfoButton.setAttribute('hidden', 'true');
}; };
moreInfoButton.oncontextmenu = moreInfoButton.oncontextmenu = noContextMenuHandler;
lessInfoButton.oncontextmenu = lessInfoButton.oncontextmenu = noContextMenuHandler;
closeButton.oncontextmenu = function(e) { closeButton.oncontextmenu = noContextMenuHandler;
e.preventDefault();
};
moreInfoButton.removeAttribute('hidden'); moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true'); lessInfoButton.setAttribute('hidden', 'true');
errorMoreInfo.value = moreInfoText; errorMoreInfo.value = moreInfoText;
@ -2208,7 +2206,16 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
//var file = window.location.href.split('#')[0]; //var file = window.location.href.split('#')[0];
//#endif //#endif
//#if !(FIREFOX || MOZCENTRAL) //#if !(FIREFOX || MOZCENTRAL || CHROME)
var fileInput = document.createElement('input');
fileInput.id = 'fileInput';
fileInput.className = 'fileInput';
fileInput.setAttribute('type', 'file');
fileInput.setAttribute('style',
'visibility: hidden; position: fixed; right: 0; top: 0');
fileInput.oncontextmenu = noContextMenuHandler;
document.body.appendChild(fileInput);
if (!window.File || !window.FileReader || !window.FileList || !window.Blob) { if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
document.getElementById('openFile').setAttribute('hidden', 'true'); document.getElementById('openFile').setAttribute('hidden', 'true');
} else { } else {
@ -2300,6 +2307,9 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
} }
}); });
// Suppress context menus for some controls
document.getElementById('scaleSelect').oncontextmenu = noContextMenuHandler;
var mainContainer = document.getElementById('mainContainer'); var mainContainer = document.getElementById('mainContainer');
var outerContainer = document.getElementById('outerContainer'); var outerContainer = document.getElementById('outerContainer');
mainContainer.addEventListener('transitionend', function(e) { mainContainer.addEventListener('transitionend', function(e) {
@ -2355,10 +2365,12 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
PDFView.presentationMode(); PDFView.presentationMode();
}); });
//#if !(FIREFOX || MOZCENTRAL || CHROME)
document.getElementById('openFile').addEventListener('click', document.getElementById('openFile').addEventListener('click',
function() { function() {
document.getElementById('fileInput').click(); document.getElementById('fileInput').click();
}); });
//#endif
document.getElementById('print').addEventListener('click', document.getElementById('print').addEventListener('click',
function() { function() {

Loading…
Cancel
Save