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..e8ef7e26eb74881d2021af14e3091153d7b2cc52 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 = {}; |
raymes
2015/01/15 23:07:42
let's remove this as an instance variable and make
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:42, raymes wrote:
Done.
|
- this.parseOpenPDFParams_(); |
+ // A dictionary of all the named destinations in the PDF. |
+ this.namedDestinations = {}; |
} |
OpenPDFParamsParser.prototype = { |
@@ -48,18 +48,27 @@ 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. |
raymes
2015/01/15 23:07:43
nit: need->needs
nit: inputUrl->url
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
|
+ * @return {Object} urlParams data that have the PDF url parameter info. |
raymes
2015/01/15 23:07:42
nit: @return {Object} A dictionary containing the
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:42, raymes wrote:
Done.
|
*/ |
- parseOpenPDFParams_: function() { |
- var originalUrl = this.url_; |
+ getViewportFromUrlParams: function(inputUrl) { |
raymes
2015/01/15 23:07:43
nit: inputUrl->url
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
|
+ // Resetting urlParams. |
+ this.urlParams = {}; |
raymes
2015/01/15 23:07:43
var urlParams = {};
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
|
+ var originalUrl = inputUrl; |
raymes
2015/01/15 23:07:42
nit this isn't needed, just always use "url"
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:42, raymes wrote:
Done.
|
var paramIndex = originalUrl.search('#'); |
if (paramIndex == -1) |
- return; |
+ return this.urlParams; |
var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); |
+ if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) { |
raymes
2015/01/15 23:08:37
nit: Let's add the same comment here as in instanc
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:08:37, raymes wrote:
Done.
|
+ this.urlParams['page'] = this.namedDestinations[paramTokens[0]]; |
+ return this.urlParams; |
+ } |
+ |
var paramsDictionary = {}; |
for (var i = 0; i < paramTokens.length; ++i) { |
var keyValueSplit = paramTokens[i].split('='); |
@@ -68,14 +77,22 @@ OpenPDFParamsParser.prototype = { |
paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
} |
+ if ('nameddest' in paramsDictionary) { |
+ var pageNumber = parseInt(paramsDictionary['nameddest']); |
raymes
2015/01/15 23:07:42
paramsDictionary['nameddest'] isn't expected to be
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:42, raymes wrote:
Done.
|
+ if (!isNaN(pageNumber) && pageNumber >= 0) |
+ this.urlParams['page'] = pageNumber; |
+ } |
+ |
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) |
this.urlParams['page'] = pageNumber - 1; |
} |
if ('zoom' in paramsDictionary) |
this.parseZoomParam_(paramsDictionary['zoom']); |
+ |
+ return this.urlParams; |
} |
}; |