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..e49261ad89886649d961ec9c9dae2d2f52625252 100644 |
--- a/chrome/browser/resources/pdf/open_pdf_params_parser.js |
+++ b/chrome/browser/resources/pdf/open_pdf_params_parser.js |
@@ -10,9 +10,8 @@ |
* @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 = { |
@@ -22,8 +21,9 @@ OpenPDFParamsParser.prototype = { |
* parameter is passed while opening PDF then PDF should be opened |
* at the specified zoom level. |
* @param {number} zoom value. |
+ * @param {Object} urlParams to store zoom and position value. |
*/ |
- parseZoomParam_: function(paramValue) { |
+ parseZoomParam_: function(paramValue, urlParams) { |
var paramValueSplit = paramValue.split(','); |
if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) |
return; |
@@ -35,31 +35,42 @@ OpenPDFParamsParser.prototype = { |
// Handle #zoom=scale. |
if (paramValueSplit.length == 1) { |
- this.urlParams['zoom'] = zoomFactor; |
+ urlParams['zoom'] = zoomFactor; |
return; |
} |
// Handle #zoom=scale,left,top. |
var position = {x: parseFloat(paramValueSplit[1]), |
y: parseFloat(paramValueSplit[2])}; |
- this.urlParams['position'] = position; |
- this.urlParams['zoom'] = zoomFactor; |
+ urlParams['position'] = position; |
+ urlParams['zoom'] = zoomFactor; |
}, |
/** |
* @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} url that needs to be parsed. |
+ * @return {Object} A dictionary containing the viewport which should be |
+ * displayed based on the URL. |
*/ |
- parseOpenPDFParams_: function() { |
- var originalUrl = this.url_; |
- var paramIndex = originalUrl.search('#'); |
+ getViewportFromUrlParams: function(url) { |
+ var urlParams = {}; |
raymes
2015/01/18 22:01:39
nit: let's rename this viewportPosition
Deepak
2015/01/19 03:54:03
Done.
|
+ var paramIndex = url.search('#'); |
if (paramIndex == -1) |
- return; |
+ return urlParams; |
+ |
+ var paramTokens = url.substring(paramIndex + 1).split('&'); |
+ if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) { |
+ // Handle the case of http://foo.com/bar#NAMEDDEST. This is not |
+ // explicitlymentioned except by example in the Adobe |
+ // "PDF Open Parameters" document. |
+ urlParams['page'] = this.namedDestinations[paramTokens[0]]; |
+ return urlParams; |
+ } |
- var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); |
var paramsDictionary = {}; |
for (var i = 0; i < paramTokens.length; ++i) { |
var keyValueSplit = paramTokens[i].split('='); |
@@ -68,14 +79,22 @@ OpenPDFParamsParser.prototype = { |
paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
} |
+ if ('nameddest' in paramsDictionary) { |
+ var page = paramsDictionary['nameddest']; |
raymes
2015/01/18 22:01:39
Sorry I got this wrong last time. What I meant to
Deepak
2015/01/19 03:54:03
I have checked with
http://examples.itextpdf.com/
|
+ if (page) |
+ urlParams['page'] = page; |
+ } |
+ |
if ('page' in paramsDictionary) { |
// |pageNumber| is 1-based, but goToPage() take a zero-based page number. |
var pageNumber = parseInt(paramsDictionary['page']); |
- if (!isNaN(pageNumber)) |
- this.urlParams['page'] = pageNumber - 1; |
+ if (!isNaN(pageNumber) && pageNumber > 0) |
+ urlParams['page'] = pageNumber - 1; |
} |
if ('zoom' in paramsDictionary) |
- this.parseZoomParam_(paramsDictionary['zoom']); |
+ this.parseZoomParam_(paramsDictionary['zoom'], urlParams); |
+ |
+ return urlParams; |
} |
}; |