Chromium Code Reviews| Index: chrome/browser/resources/pdf/open_pdf_params_parser.js |
| diff --git a/chrome/browser/resources/pdf/open_pdf_params_parser.js b/chrome/browser/resources/pdf/open_pdf_params_parser.js |
| index f4fe8e7354a1617a6c5929c23e72379af59b9465..913accac4737fd81099908c28704a1d953428f3f 100644 |
| --- a/chrome/browser/resources/pdf/open_pdf_params_parser.js |
| +++ b/chrome/browser/resources/pdf/open_pdf_params_parser.js |
| @@ -10,9 +10,9 @@ |
| * @param {string} url to be parsed. |
| */ |
| function OpenPDFParamsParser(url) { |
| - this.url_ = url; |
| this.urlParams = {}; |
| - this.parseOpenPDFParams_(); |
| + // A dictionary of all the named destinations in the PDF. |
| + this.namedDestinations = {}; |
| } |
| OpenPDFParamsParser.prototype = { |
| @@ -48,18 +48,25 @@ OpenPDFParamsParser.prototype = { |
| /** |
| * @private |
| - * Parse open PDF parameters. These parameters are mentioned in the url |
| + * Parse PDF url parameters. These parameters are mentioned in the url |
| * and specify actions to be performed when opening pdf files. |
| * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/ |
| * pdfs/pdf_open_parameters.pdf for details. |
| + * @param {string} inputUrl that need to be parsed. |
| + * @return {Object} urlParams data that have the PDF url parameter info. |
| */ |
| - parseOpenPDFParams_: function() { |
| - var originalUrl = this.url_; |
| + getURLPDFParams: function(inputUrl) { |
|
raymes
2015/01/15 04:51:11
nit: let's change the name because I think it is d
Deepak
2015/01/15 06:30:05
Done.
|
| + var originalUrl = inputUrl; |
| var paramIndex = originalUrl.search('#'); |
| if (paramIndex == -1) |
| return; |
| - |
| var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); |
| + |
| + if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) { |
| + this.urlParams['page'] = this.namedDestinations[paramTokens[0]]; |
| + return this.urlParams; |
| + } |
|
raymes
2015/01/15 04:51:11
I don't think we need this whole if-block
Deepak
2015/01/15 06:30:05
Then how we will handle
http://XXX.pdf#Chapter5 c
|
| + |
| var paramsDictionary = {}; |
| for (var i = 0; i < paramTokens.length; ++i) { |
| var keyValueSplit = paramTokens[i].split('='); |
| @@ -68,14 +75,22 @@ OpenPDFParamsParser.prototype = { |
| paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
| } |
| + if ('nameddest' in paramsDictionary) { |
| + var pageNumber = parseInt(paramsDictionary['nameddest']); |
| + if (!isNaN(pageNumber) && pageNumber >= 0) |
| + this.urlParams['nameddest'] = pageNumber; |
|
raymes
2015/01/15 04:51:11
Can we just store this in the 'page' param as well
Deepak
2015/01/15 06:30:05
Done.
|
| + } |
| + |
| if ('page' in paramsDictionary) { |
| // |pageNumber| is 1-based, but goToPage() take a zero-based page number. |
| var pageNumber = parseInt(paramsDictionary['page']); |
| - if (!isNaN(pageNumber)) |
| + if (!isNaN(pageNumber) && pageNumber > 0) |
|
raymes
2015/01/15 04:51:11
good catch! thanks :)
Deepak
2015/01/15 06:30:05
Acknowledged.
|
| this.urlParams['page'] = pageNumber - 1; |
| } |
| if ('zoom' in paramsDictionary) |
| this.parseZoomParam_(paramsDictionary['zoom']); |
| + |
| + return this.urlParams; |
| } |
| }; |