Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/resources/pdf/open_pdf_params_parser.js

Issue 830433002: Navigation to relative fragments does not work correctly for OOP pdf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters 8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters
9 * passed in the url to set initial viewport settings for opening the pdf. 9 * passed in the url to set initial viewport settings for opening the pdf.
10 * @param {string} url to be parsed. 10 * @param {string} url to be parsed.
11 */ 11 */
12 function OpenPDFParamsParser(url) { 12 function OpenPDFParamsParser(url) {
13 this.url_ = url;
14 this.urlParams = {}; 13 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.
15 this.parseOpenPDFParams_(); 14 // A dictionary of all the named destinations in the PDF.
15 this.namedDestinations = {};
16 } 16 }
17 17
18 OpenPDFParamsParser.prototype = { 18 OpenPDFParamsParser.prototype = {
19 /** 19 /**
20 * @private 20 * @private
21 * Parse zoom parameter of open PDF parameters. If this 21 * Parse zoom parameter of open PDF parameters. If this
22 * parameter is passed while opening PDF then PDF should be opened 22 * parameter is passed while opening PDF then PDF should be opened
23 * at the specified zoom level. 23 * at the specified zoom level.
24 * @param {number} zoom value. 24 * @param {number} zoom value.
25 */ 25 */
26 parseZoomParam_: function(paramValue) { 26 parseZoomParam_: function(paramValue) {
raymes 2015/01/15 23:07:42 This function can take the urlParams as an argumen
Deepak 2015/01/16 04:39:21 On 2015/01/15 23:07:42, raymes wrote: Done.
27 var paramValueSplit = paramValue.split(','); 27 var paramValueSplit = paramValue.split(',');
28 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) 28 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3))
29 return; 29 return;
30 30
31 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. 31 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0.
32 var zoomFactor = parseFloat(paramValueSplit[0]) / 100; 32 var zoomFactor = parseFloat(paramValueSplit[0]) / 100;
33 if (isNaN(zoomFactor)) 33 if (isNaN(zoomFactor))
34 return; 34 return;
35 35
36 // Handle #zoom=scale. 36 // Handle #zoom=scale.
37 if (paramValueSplit.length == 1) { 37 if (paramValueSplit.length == 1) {
38 this.urlParams['zoom'] = zoomFactor; 38 this.urlParams['zoom'] = zoomFactor;
39 return; 39 return;
40 } 40 }
41 41
42 // Handle #zoom=scale,left,top. 42 // Handle #zoom=scale,left,top.
43 var position = {x: parseFloat(paramValueSplit[1]), 43 var position = {x: parseFloat(paramValueSplit[1]),
44 y: parseFloat(paramValueSplit[2])}; 44 y: parseFloat(paramValueSplit[2])};
45 this.urlParams['position'] = position; 45 this.urlParams['position'] = position;
46 this.urlParams['zoom'] = zoomFactor; 46 this.urlParams['zoom'] = zoomFactor;
47 }, 47 },
48 48
49 /** 49 /**
50 * @private 50 * @private
51 * Parse open PDF parameters. These parameters are mentioned in the url 51 * Parse PDF url parameters. These parameters are mentioned in the url
52 * and specify actions to be performed when opening pdf files. 52 * and specify actions to be performed when opening pdf files.
53 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/ 53 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/
54 * pdfs/pdf_open_parameters.pdf for details. 54 * pdfs/pdf_open_parameters.pdf for details.
55 * @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.
56 * @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.
55 */ 57 */
56 parseOpenPDFParams_: function() { 58 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.
57 var originalUrl = this.url_; 59 // Resetting urlParams.
60 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.
61 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.
58 var paramIndex = originalUrl.search('#'); 62 var paramIndex = originalUrl.search('#');
59 if (paramIndex == -1) 63 if (paramIndex == -1)
60 return; 64 return this.urlParams;
61 65
62 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); 66 var paramTokens = originalUrl.substring(paramIndex + 1).split('&');
67 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.
68 this.urlParams['page'] = this.namedDestinations[paramTokens[0]];
69 return this.urlParams;
70 }
71
63 var paramsDictionary = {}; 72 var paramsDictionary = {};
64 for (var i = 0; i < paramTokens.length; ++i) { 73 for (var i = 0; i < paramTokens.length; ++i) {
65 var keyValueSplit = paramTokens[i].split('='); 74 var keyValueSplit = paramTokens[i].split('=');
66 if (keyValueSplit.length != 2) 75 if (keyValueSplit.length != 2)
67 continue; 76 continue;
68 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; 77 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
69 } 78 }
70 79
80 if ('nameddest' in paramsDictionary) {
81 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.
82 if (!isNaN(pageNumber) && pageNumber >= 0)
83 this.urlParams['page'] = pageNumber;
84 }
85
71 if ('page' in paramsDictionary) { 86 if ('page' in paramsDictionary) {
72 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. 87 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
73 var pageNumber = parseInt(paramsDictionary['page']); 88 var pageNumber = parseInt(paramsDictionary['page']);
74 if (!isNaN(pageNumber)) 89 if (!isNaN(pageNumber) && pageNumber > 0)
75 this.urlParams['page'] = pageNumber - 1; 90 this.urlParams['page'] = pageNumber - 1;
76 } 91 }
77 92
78 if ('zoom' in paramsDictionary) 93 if ('zoom' in paramsDictionary)
79 this.parseZoomParam_(paramsDictionary['zoom']); 94 this.parseZoomParam_(paramsDictionary['zoom']);
95
96 return this.urlParams;
80 } 97 }
81 }; 98 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698