| Index: chrome/browser/resources/pdf/pdf.js
|
| diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
|
| index 0aa437aef03c7e1747929fe50925367d29164878..a96ab101dfbb219797feba193391b61ce369b1d7 100644
|
| --- a/chrome/browser/resources/pdf/pdf.js
|
| +++ b/chrome/browser/resources/pdf/pdf.js
|
| @@ -35,7 +35,8 @@ PDFViewer.MIN_TOOLBAR_OFFSET = 15;
|
| * Creates a new PDFViewer. There should only be one of these objects per
|
| * document.
|
| */
|
| -function PDFViewer() {
|
| +function PDFViewer(streamDetails) {
|
| + this.streamDetails = streamDetails;
|
| this.loaded = false;
|
|
|
| // The sizer element is placed behind the plugin element to cause scrollbars
|
| @@ -77,28 +78,6 @@ function PDFViewer() {
|
| false);
|
| this.sendScriptingMessage_({type: 'readyToReceive'});
|
|
|
| - // If the viewer is started from a MIME type request, there will be a
|
| - // background page and stream details object with the details of the request.
|
| - // Otherwise, we take the query string of the URL to indicate the URL of the
|
| - // PDF to load. This is used for print preview in particular.
|
| - if (chrome.extension.getBackgroundPage &&
|
| - chrome.extension.getBackgroundPage()) {
|
| - this.streamDetails =
|
| - chrome.extension.getBackgroundPage().popStreamDetails();
|
| - }
|
| -
|
| - if (!this.streamDetails) {
|
| - // The URL of this page will be of the form
|
| - // "chrome-extension://<extension id>?<pdf url>". We pull out the <pdf url>
|
| - // part here.
|
| - var url = window.location.search.substring(1);
|
| - this.streamDetails = {
|
| - streamUrl: url,
|
| - originalUrl: url,
|
| - responseHeaders: ''
|
| - };
|
| - }
|
| -
|
| this.plugin_.setAttribute('src', this.streamDetails.originalUrl);
|
| this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl);
|
| var headers = '';
|
| @@ -130,7 +109,7 @@ function PDFViewer() {
|
| this.viewport_.zoomIn.bind(this.viewport_));
|
| $('zoom-out-button').addEventListener('click',
|
| this.viewport_.zoomOut.bind(this.viewport_));
|
| - $('save-button-link').href = this.streamDetails.originalUrl;
|
| + $('save-button-link').addEventListener('click', this.save_.bind(this));
|
| $('print-button').addEventListener('click', this.print_.bind(this));
|
|
|
| // Setup the keyboard event listener.
|
| @@ -180,9 +159,9 @@ PDFViewer.prototype = {
|
| e.preventDefault();
|
| } else if (fromScriptingAPI) {
|
| position.y -= this.viewport.size.height;
|
| - this.viewport.position = position;
|
| + this.viewport_.position = position;
|
| }
|
| - };
|
| + }.bind(this);
|
| var pageDownHandler = function() {
|
| // Go to the next page if we are fit-to-page.
|
| if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
|
| @@ -191,9 +170,9 @@ PDFViewer.prototype = {
|
| e.preventDefault();
|
| } else if (fromScriptingAPI) {
|
| position.y += this.viewport.size.height;
|
| - this.viewport.position = position;
|
| + this.viewport_.position = position;
|
| }
|
| - };
|
| + }.bind(this);
|
|
|
| switch (e.keyCode) {
|
| case 32: // Space key.
|
| @@ -242,15 +221,6 @@ PDFViewer.prototype = {
|
| this.viewport.position = position;
|
| }
|
| return;
|
| - case 83: // s key.
|
| - if (e.ctrlKey || e.metaKey) {
|
| - // Simulate a click on the button so that the <a download ...>
|
| - // attribute is used.
|
| - $('save-button-link').click();
|
| - // Since we do the saving of the page.
|
| - e.preventDefault();
|
| - }
|
| - return;
|
| case 80: // p key.
|
| if (e.ctrlKey || e.metaKey) {
|
| this.print_();
|
| @@ -273,6 +243,17 @@ PDFViewer.prototype = {
|
|
|
| /**
|
| * @private
|
| + * Notify the plugin to save.
|
| + */
|
| + save_: function() {
|
| + this.plugin_.postMessage({
|
| + type: 'save'
|
| + });
|
| + },
|
| +
|
| +
|
| + /**
|
| + * @private
|
| * Handle open pdf parameters. This function updates the viewport as per
|
| * the parameters mentioned in the url while opening pdf. The order is
|
| * important as later actions can override the effects of previous actions.
|
| @@ -574,4 +555,51 @@ PDFViewer.prototype = {
|
| }
|
| };
|
|
|
| -var viewer = new PDFViewer();
|
| +var viewer;
|
| +function initPlugin(streamDetails) {
|
| + viewer = new PDFViewer(streamDetails);
|
| +}
|
| +
|
| +function initUrl() {
|
| + // If the viewer is started from the browser plugin, the plugin ID will be
|
| + // passed in.
|
| + var params = window.location.search.substring(1).split('=');
|
| + var viewId = '';
|
| + if (params.length == 2 && params[0] == 'id')
|
| + viewId = params[1];
|
| +
|
| + if (viewId) {
|
| + chrome.runtime.sendMessage('mhjfbmdgcfjbbpaeojofohoefgiehjai',
|
| + {viewId: viewId},
|
| + initPlugin);
|
| + return;
|
| + }
|
| +
|
| + // The viewer may be started via a background page from the extension.
|
| + var streamDetails;
|
| + if (chrome.extension &&
|
| + chrome.extension.getBackgroundPage &&
|
| + chrome.extension.getBackgroundPage()) {
|
| + streamDetails =
|
| + chrome.extension.getBackgroundPage().popStreamDetails();
|
| + if (streamDetails) {
|
| + initPlugin(streamDetails);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + // The viewer may be started directly by passing in the URL of the PDF to load
|
| + // as the query string. This is used for print preview in particular. The URL
|
| + // of this page will be of the form
|
| + // "chrome-extension://<extension id>?<pdf url>". We pull out the <pdf url>
|
| + // part here.
|
| + var url = window.location.search.substring(1);
|
| + streamDetails = {
|
| + streamUrl: url,
|
| + originalUrl: url,
|
| + responseHeaders: ''
|
| + };
|
| + initPlugin(streamDetails);
|
| +}
|
| +
|
| +initUrl();
|
|
|