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 eaf96ac6559e17fa4f494b4e89bda07c2d7ff9cf..028eabf44825ece705de52b11781e565b3685643 100644 |
| --- a/chrome/browser/resources/pdf/pdf.js |
| +++ b/chrome/browser/resources/pdf/pdf.js |
| @@ -31,14 +31,6 @@ function getFilenameFromURL(url) { |
| } |
| /** |
| - * Called when navigation happens in the current tab. |
| - * @param {string} url The url to be opened in the current tab. |
| - */ |
| -function onNavigateInCurrentTab(url) { |
| - window.location.href = url; |
| -} |
| - |
| -/** |
| * Called when navigation happens in the new tab. |
| * @param {string} url The url to be opened in the new tab. |
| */ |
| @@ -187,9 +179,9 @@ function PDFViewer(streamDetails) { |
| // Parse open pdf parameters. |
| this.paramsParser_ = new OpenPDFParamsParser(); |
| - this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
| - this.viewport_, this.paramsParser_, onNavigateInCurrentTab, |
| - onNavigateInNewTab); |
| + this.navigator_ = new Navigator( |
| + this.streamDetails_.originalUrl, this.viewport_, this.paramsParser_, |
| + this.onNavigateInCurrentTab_.bind(this), onNavigateInNewTab); |
|
raymes
2015/02/12 22:19:05
This shouldn't change
|
| } |
| PDFViewer.prototype = { |
| @@ -344,33 +336,53 @@ 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() { |
| + save_: function() { this.plugin_.postMessage({type: 'save'}); }, |
|
raymes
2015/02/12 22:19:05
nit: don't change these
|
| + |
| + /** |
| + * @private |
| + * Callback to fetch namedDestination from plugin. |
| + */ |
| + namedDestCallback_: function(namedDestination, url) { |
|
raymes
2015/02/12 22:19:05
This should be called getNamedDestination(name)
|
| this.plugin_.postMessage({ |
| - type: 'save' |
| + type: 'getNamedDestination', |
| + namedDestination: namedDestination, |
| + navigationUrl: url |
| }); |
| }, |
| /** |
| + * Called when navigation happens in the current tab. |
| + * @param {string} url The url to be opened in the current tab. |
| + */ |
| + onNavigateInCurrentTab_: function(url) { |
| + var pageNumber = |
| + this.paramsParser_.getViewportFromUrlParams( |
| + url, this.namedDestCallback_.bind(this), true) |
| + .page; |
| + if (pageNumber != undefined && pageNumber != -1) |
| + this.viewport_.goToPage(pageNumber); |
| + else |
| + window.location.href = url; |
| + }, |
|
raymes
2015/02/12 22:19:05
This shouldn't be here
|
| + |
| + |
| + /** |
| * @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() { |
| - var urlParams = |
| - this.paramsParser_.getViewportFromUrlParams( |
| - this.streamDetails_.originalUrl); |
| - if (urlParams.page) |
| + var urlParams = this.paramsParser_.getViewportFromUrlParams( |
| + this.streamDetails_.originalUrl, this.namedDestCallback_.bind(this), |
| + false); |
|
raymes
2015/02/12 22:19:05
This should look like
this.parmsParser_.getViewpo
|
| + if (urlParams.page && urlParams.page != -1) |
| this.viewport_.goToPage(urlParams.page); |
| if (urlParams.position) { |
| // Make sure we don't cancel effect of page parameter. |
| @@ -454,7 +466,6 @@ PDFViewer.prototype = { |
| } else { |
| this.pageIndicator_.initialFadeIn(); |
| } |
| - |
| this.toolbar_.initialFadeIn(); |
| break; |
| case 'email': |
| @@ -490,9 +501,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) |
| @@ -518,6 +526,12 @@ PDFViewer.prototype = { |
| if (this.isMaterial_) |
| this.bookmarksPane_.bookmarks = message.data.bookmarks; |
| break; |
| + case 'getNamedDestinationReply': |
|
raymes
2015/02/12 22:19:05
this should just call: this.paramsParser_.onNamedD
|
| + if (message.data.namedDestinationPageNumber != undefined) |
| + this.viewport_.goToPage(message.data.namedDestinationPageNumber); |
| + else if (message.data.navigationUrl) |
| + window.location.href = message.data.navigationUrl; |
| + break; |
| } |
| }, |