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 2bb5511402abe108e48da0d5f28c52449bf086c0..34c36f6cefc85fe2a6c0fb6a19e32ed386af5c91 100644 | 
| --- a/chrome/browser/resources/pdf/pdf.js | 
| +++ b/chrome/browser/resources/pdf/pdf.js | 
| @@ -147,7 +147,10 @@ function PDFViewer() { | 
| var MIN_ZOOM_DELTA = 0.01; | 
| var zoomDelta = Math.abs(this.viewport_.zoom - | 
| zoomChangeInfo.newZoomFactor); | 
| - if (zoomDelta > MIN_ZOOM_DELTA) | 
| + // We should not change zoom level when we are responsible for initiating | 
| + // the zoom. onZoomChange() is called before setZoomComplete() callback | 
| + // when we initiate the zoom. | 
| + if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 
| 
 
Nikhil
2014/08/29 10:31:47
Should this be a part of this CL or a separate one
 
raymes
2014/09/01 01:04:58
It's fine to keep it here.
 
Nikhil
2014/09/01 09:11:44
Acknowledged.
 
 | 
| this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 
| }.bind(this)); | 
| } | 
| @@ -270,6 +273,27 @@ PDFViewer.prototype = { | 
| /** | 
| * @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. | 
| + */ | 
| + handleURLParams_: function() { | 
| + if (this.urlParams_.page) | 
| + this.viewport_.goToPage(this.urlParams_.page); | 
| + if (this.urlParams_.position) { | 
| + // Make sure we don't cancel effect of page parameter. | 
| + var currentPosition = this.viewport_.position; | 
| + var destinationPosition = {}; | 
| + destinationPosition['x'] = currentPosition.x + this.urlParams_.position.x; | 
| + destinationPosition['y'] = currentPosition.y + this.urlParams_.position.y; | 
| 
 
raymes
2014/09/01 01:04:58
Is this the way that adobe reader works (does it a
 
Nikhil
2014/09/01 09:11:44
Please consider the following use case -
example.c
 
raymes
2014/09/02 03:27:36
The way you have written it looks fine. But I thin
 
 | 
| + this.viewport_.position = destinationPosition; | 
| + } | 
| + if (this.urlParams_.zoom) | 
| + this.viewport_.setZoom(this.urlParams_.zoom); | 
| + }, | 
| + | 
| + /** | 
| + * @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. | 
| @@ -287,19 +311,15 @@ PDFViewer.prototype = { | 
| } | 
| } else if (progress == 100) { | 
| // Document load complete. | 
| + if (this.lastViewportPosition_) | 
| + this.viewport_.position = this.lastViewportPosition_; | 
| + this.handleURLParams_(); | 
| this.loaded = true; | 
| var loadEvent = new Event('pdfload'); | 
| window.dispatchEvent(loadEvent); | 
| this.sendScriptingMessage_({ | 
| type: 'documentLoaded' | 
| }); | 
| - 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.urlParams_.page) | 
| - this.viewport_.goToPage(this.urlParams_.page); | 
| } | 
| }, |