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

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

Issue 918953002: Fix for PDFs with lots of named destinations take a long time to load. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 */ 10 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 viewportPosition['zoom'] = zoomFactor; 45 viewportPosition['zoom'] = zoomFactor;
46 }, 46 },
47 47
48 /** 48 /**
49 * @private 49 * @private
50 * Parse PDF url parameters. These parameters are mentioned in the url 50 * Parse PDF url parameters. These parameters are mentioned in the url
51 * and specify actions to be performed when opening pdf files. 51 * and specify actions to be performed when opening pdf files.
52 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/ 52 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/
53 * pdfs/pdf_open_parameters.pdf for details. 53 * pdfs/pdf_open_parameters.pdf for details.
54 * @param {string} url that needs to be parsed. 54 * @param {string} url that needs to be parsed.
55 * @param {Object} namedDestCallback Callback to be called to fetch page
56 * number for namedDestination.
57 * @param {boolean} isNavigate Tells weather this call happen for navigation
58 * as we need url for navigation case when we don't have page number for
59 * namedDestionation.
55 * @return {Object} A dictionary containing the viewport which should be 60 * @return {Object} A dictionary containing the viewport which should be
56 * displayed based on the URL. 61 * displayed based on the URL.
57 */ 62 */
58 getViewportFromUrlParams: function(url) { 63 getViewportFromUrlParams: function(url, namedDestCallback, isNavigate) {
raymes 2015/02/12 22:19:05 -None of the isNavigate stuff should be here, see
59 var viewportPosition = {}; 64 var viewportPosition = {};
60 var paramIndex = url.search('#'); 65 var paramIndex = url.search('#');
61 if (paramIndex == -1) 66 if (paramIndex == -1)
62 return viewportPosition; 67 return viewportPosition;
raymes 2015/02/12 22:19:05 callback(viewportPosition) return;
63 68
64 var paramTokens = url.substring(paramIndex + 1).split('&'); 69 var paramTokens = url.substring(paramIndex + 1).split('&');
65 if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) { 70 if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) {
66 // Handle the case of http://foo.com/bar#NAMEDDEST. This is not 71 // Handle the case of http://foo.com/bar#NAMEDDEST. This is not
67 // explicitlymentioned except by example in the Adobe 72 // explicitlymentioned except by example in the Adobe
68 // "PDF Open Parameters" document. 73 // "PDF Open Parameters" document.
69 viewportPosition['page'] = this.namedDestinations[paramTokens[0]]; 74 viewportPosition['page'] = this.namedDestinations[paramTokens[0]];
raymes 2015/02/12 22:19:05 This is where we need to call into the plugin. We
75 if (viewportPosition['page'] == undefined) {
76 // -1 value indicates that we are going to get page number from plugin.
77 viewportPosition['page'] = -1;
78 if (isNavigate)
79 namedDestCallback(paramTokens[0], url);
80 else
81 namedDestCallback(paramTokens[0]);
82 }
70 return viewportPosition; 83 return viewportPosition;
raymes 2015/02/12 22:19:05 callback(viewportPosition) return;
71 } 84 }
72 85
73 var paramsDictionary = {}; 86 var paramsDictionary = {};
74 for (var i = 0; i < paramTokens.length; ++i) { 87 for (var i = 0; i < paramTokens.length; ++i) {
75 var keyValueSplit = paramTokens[i].split('='); 88 var keyValueSplit = paramTokens[i].split('=');
76 if (keyValueSplit.length != 2) 89 if (keyValueSplit.length != 2)
77 continue; 90 continue;
78 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; 91 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
79 } 92 }
80 93
81 if ('nameddest' in paramsDictionary) { 94 if ('nameddest' in paramsDictionary) {
82 var page = this.namedDestinations[paramsDictionary['nameddest']]; 95 var page = this.namedDestinations[paramsDictionary['nameddest']];
83 if (page != undefined) 96 if (page == undefined) {
97 // -1 value indicates that we are going to get page number from plugin.
98 viewportPosition['page'] = -1;
99 if (isNavigate)
100 namedDestCallback(paramsDictionary['nameddest'], url);
101 else
102 namedDestCallback(paramsDictionary['nameddest']);
103 } else {
raymes 2015/02/12 22:19:05 The same thing here. We should shift this code thi
84 viewportPosition['page'] = page; 104 viewportPosition['page'] = page;
105 }
85 } 106 }
86 107
87 if ('page' in paramsDictionary) { 108 if ('page' in paramsDictionary) {
88 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. 109 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
89 var pageNumber = parseInt(paramsDictionary['page']); 110 var pageNumber = parseInt(paramsDictionary['page']);
90 if (!isNaN(pageNumber) && pageNumber > 0) 111 if (!isNaN(pageNumber) && pageNumber > 0)
91 viewportPosition['page'] = pageNumber - 1; 112 viewportPosition['page'] = pageNumber - 1;
92 } 113 }
93 114
94 if ('zoom' in paramsDictionary) 115 if ('zoom' in paramsDictionary)
95 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); 116 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition);
96 117
97 return viewportPosition; 118 return viewportPosition;
raymes 2015/02/12 22:19:05 callback(viewportPosition) return;
98 } 119 }
99 }; 120 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698