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 309886fde637a343d583d44f3d367064a374c317..5c41ea7f984b20785980095a3930f7afc46803c1 100644 |
| --- a/chrome/browser/resources/pdf/pdf.js |
| +++ b/chrome/browser/resources/pdf/pdf.js |
| @@ -190,10 +190,11 @@ function PDFViewer(streamDetails) { |
| } |
| // Parse open pdf parameters. |
| - this.paramsParser_ = new OpenPDFParamsParser(); |
| + this.paramsParser_ = |
| + new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); |
|
raymes
2015/02/16 02:02:31
There is some refactoring that would be really nic
Deepak
2015/02/16 06:45:38
I agree with you, will do it in-separate CL.
Thank
|
| this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
| - this.viewport_, this.paramsParser_, onNavigateInCurrentTab, |
| - onNavigateInNewTab); |
| + this.viewport_, this.paramsParser_, |
| + onNavigateInCurrentTab, onNavigateInNewTab); |
| this.viewportScroller_ = |
| new ViewportScroller(this.viewport_, this.plugin_, window); |
| } |
| @@ -350,13 +351,32 @@ PDFViewer.prototype = { |
| * @private |
| * Notify the plugin to print. |
| */ |
| - print_: function() { this.plugin_.postMessage({type: 'print'}); }, |
| + print_: function() { |
| + this.plugin_.postMessage({ |
| + type: 'print' |
| + }); |
| + }, |
| /** |
| * @private |
| * Notify the plugin to save. |
| */ |
| - save_: function() { this.plugin_.postMessage({type: 'save'}); }, |
| + save_: function() { |
| + this.plugin_.postMessage({ |
| + type: 'save' |
| + }); |
| + }, |
| + |
| + /** |
| + * Callback to fetch namedDestination from plugin. |
|
raymes
2015/02/16 02:02:31
nit: Fetches the page number corresponding to the
Deepak
2015/02/16 06:45:38
Done.
|
| + * @param {string} name The namedDestination to fetch page number from plugin. |
| + */ |
| + getNamedDestination_: function(name) { |
| + this.plugin_.postMessage({ |
| + type: 'getNamedDestination', |
| + namedDestination: name |
| + }); |
| + }, |
| /** |
| * @private |
| @@ -365,20 +385,20 @@ PDFViewer.prototype = { |
| * important as later actions can override the effects of previous actions. |
| */ |
| handleURLParams_: function() { |
| - var urlParams = |
| - this.paramsParser_.getViewportFromUrlParams( |
| - this.streamDetails_.originalUrl); |
| - if (urlParams.page) |
| - this.viewport_.goToPage(urlParams.page); |
| - if (urlParams.position) { |
| - // Make sure we don't cancel effect of page parameter. |
| - this.viewport_.position = { |
| - x: this.viewport_.position.x + urlParams.position.x, |
| - y: this.viewport_.position.y + urlParams.position.y |
| - }; |
| - } |
| - if (urlParams.zoom) |
| - this.viewport_.setZoom(urlParams.zoom); |
| + this.paramsParser_.getViewportFromUrlParams( |
| + this.streamDetails_.originalUrl, function(initialViewport) { |
|
raymes
2015/02/16 02:02:31
nit: viewportPosition
Deepak
2015/02/16 06:45:38
Done.
|
| + if (initialViewport.page != undefined) |
| + this.viewport_.goToPage(initialViewport.page); |
| + if (initialViewport.position) { |
| + // Make sure we don't cancel effect of page parameter. |
| + this.viewport_.position = { |
| + x: this.viewport_.position.x + initialViewport.position.x, |
| + y: this.viewport_.position.y + initialViewport.position.y |
| + }; |
| + } |
| + if (initialViewport.zoom) |
| + this.viewport_.setZoom(initialViewport.zoom); |
| + }.bind(this)); |
| }, |
| /** |
| @@ -486,9 +506,6 @@ PDFViewer.prototype = { |
| else |
| this.navigator_.navigate(message.data.url, message.data.newTab); |
| break; |
| - case 'setNamedDestinations': |
| - this.paramsParser_.namedDestinations = message.data.namedDestinations; |
| - break; |
| case 'setScrollPosition': |
| var position = this.viewport_.position; |
| if (message.data.x !== undefined) |
| @@ -519,6 +536,10 @@ PDFViewer.prototype = { |
| case 'setIsSelecting': |
| this.viewportScroller_.setEnableScrolling(message.data.isSelecting); |
| break; |
| + case 'getNamedDestinationReply': |
| + this.paramsParser_.onNamedDestinationReceived( |
| + message.data.namedDestinationPageNumber); |
| + break; |
| } |
| }, |