Chromium Code Reviews| Index: chrome/browser/resources/pdf/pdf.js |
| diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
| index c5920f877dc10c80a416c95c23b8fb7ab4ebc105..3cb7f81ed467000060946bd3509df35aaecf7789 100644 |
| --- a/chrome/browser/resources/pdf/pdf.js |
| +++ b/chrome/browser/resources/pdf/pdf.js |
| @@ -5,6 +5,7 @@ |
| 'use strict'; |
| <include src="../../../../ui/webui/resources/js/util.js"> |
| +<include src="open_pdf_params_parser.js"> |
| <include src="pdf_scripting_api.js"> |
| <include src="viewport.js"> |
| @@ -150,6 +151,10 @@ function PDFViewer() { |
| this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
| }.bind(this)); |
| } |
| + |
| + // Parse open pdf parameters. |
| + var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl); |
| + this.openParams_ = paramsParser.viewportSettings; |
|
raymes
2014/08/28 01:50:32
maybe we can call this this.urlParams_ (a bit more
Nikhil
2014/08/28 05:07:37
Done.
|
| } |
| PDFViewer.prototype = { |
| @@ -265,37 +270,6 @@ PDFViewer.prototype = { |
| /** |
| * @private |
| - * Handle open PDF parameters. These parameters are mentioned in the URL |
| - * and specify actions to be performed when opening PDF files. |
| - * See http://crbug.com/64309 for details. |
| - */ |
| - handleOpenPDFParams_: function() { |
| - var originalUrl = this.streamDetails.originalUrl; |
| - var paramIndex = originalUrl.search('#'); |
| - if (paramIndex == -1) |
| - return; |
| - |
| - var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); |
| - var paramsDictionary = {}; |
| - for (var i = 0; i < paramTokens.length; ++i) { |
| - var keyValueSplit = paramTokens[i].split('='); |
| - if (keyValueSplit.length != 2) |
| - continue; |
| - paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
| - } |
| - |
| - // Order is important as later actions can override the effects |
| - // of previous actions. |
| - if ('page' in paramsDictionary) { |
| - // |pageNumber| is 1-based, but goToPage() take a zero-based page number. |
| - var pageNumber = parseInt(paramsDictionary['page']); |
| - if (!isNaN(pageNumber)) |
| - this.viewport_.goToPage(pageNumber - 1); |
| - } |
| - }, |
| - |
| - /** |
| - * @private |
| * Update the loading progress of the document in response to a progress |
| * message being received from the plugin. |
| * @param {number} progress the progress as a percentage. |
| @@ -313,7 +287,6 @@ PDFViewer.prototype = { |
| } |
| } else if (progress == 100) { |
| // Document load complete. |
| - this.handleOpenPDFParams_(); |
| this.loaded = true; |
| var loadEvent = new Event('pdfload'); |
| window.dispatchEvent(loadEvent); |
| @@ -322,6 +295,11 @@ PDFViewer.prototype = { |
| }); |
| if (this.lastViewportPosition_) |
| this.viewport_.position = this.lastViewportPosition_; |
| + |
| + // Handle open pdf params. Order is important as later actions can |
| + // override the effects of previous actions. |
| + if (this.openParams_.page) |
| + this.viewport_.goToPage(this.openParams_.page); |
| } |
| }, |