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

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

Issue 2892623002: Type check PDF plugin JS code, down to 53 errors. (Closed)
Patch Set: Revert compiled_resources2.gyp for now. Created 3 years, 7 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 * @param {Object} getNamedDestinationsFunction The function called to fetch 10 * @param {Object} getNamedDestinationsFunction The function called to fetch
11 * the page number for a named destination. 11 * the page number for a named destination.
12 * @constructor
12 */ 13 */
13 function OpenPDFParamsParser(getNamedDestinationsFunction) { 14 function OpenPDFParamsParser(getNamedDestinationsFunction) {
14 this.outstandingRequests_ = []; 15 this.outstandingRequests_ = [];
15 this.getNamedDestinationsFunction_ = getNamedDestinationsFunction; 16 this.getNamedDestinationsFunction_ = getNamedDestinationsFunction;
16 } 17 }
17 18
18 OpenPDFParamsParser.prototype = { 19 OpenPDFParamsParser.prototype = {
19 /** 20 /**
20 * @private 21 * @private
21 * Parse zoom parameter of open PDF parameters. If this 22 * Parse zoom parameter of open PDF parameters. If this
22 * parameter is passed while opening PDF then PDF should be opened 23 * parameter is passed while opening PDF then PDF should be opened
23 * at the specified zoom level. 24 * at the specified zoom level.
24 * @param {number} zoom value. 25 * @param {string} paramValue zoom value.
25 * @param {Object} viewportPosition to store zoom and position value. 26 * @param {Object} viewportPosition to store zoom and position value.
26 */ 27 */
27 parseZoomParam_: function(paramValue, viewportPosition) { 28 parseZoomParam_: function(paramValue, viewportPosition) {
28 var paramValueSplit = paramValue.split(','); 29 var paramValueSplit = paramValue.split(',');
29 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) 30 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3))
30 return; 31 return;
31 32
32 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. 33 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0.
33 var zoomFactor = parseFloat(paramValueSplit[0]) / 100; 34 var zoomFactor = parseFloat(paramValueSplit[0]) / 100;
34 if (isNaN(zoomFactor)) 35 if (isNaN(zoomFactor))
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * @param {Function} callback function to be called with viewport info. 106 * @param {Function} callback function to be called with viewport info.
106 */ 107 */
107 getViewportFromUrlParams: function(url, callback) { 108 getViewportFromUrlParams: function(url, callback) {
108 var viewportPosition = {}; 109 var viewportPosition = {};
109 viewportPosition['url'] = url; 110 viewportPosition['url'] = url;
110 111
111 var paramsDictionary = this.parseUrlParams_(url); 112 var paramsDictionary = this.parseUrlParams_(url);
112 113
113 if ('page' in paramsDictionary) { 114 if ('page' in paramsDictionary) {
114 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. 115 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
115 var pageNumber = parseInt(paramsDictionary['page']); 116 var pageNumber = parseInt(paramsDictionary['page'], 10);
116 if (!isNaN(pageNumber) && pageNumber > 0) 117 if (!isNaN(pageNumber) && pageNumber > 0)
117 viewportPosition['page'] = pageNumber - 1; 118 viewportPosition['page'] = pageNumber - 1;
118 } 119 }
119 120
120 if ('zoom' in paramsDictionary) 121 if ('zoom' in paramsDictionary)
121 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); 122 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition);
122 123
123 if (viewportPosition.page === undefined && 124 if (viewportPosition.page === undefined &&
124 'nameddest' in paramsDictionary) { 125 'nameddest' in paramsDictionary) {
125 this.outstandingRequests_.push({ 126 this.outstandingRequests_.push({
(...skipping 12 matching lines...) Expand all
138 * @param {number} pageNumber The page corresponding to the named destination 139 * @param {number} pageNumber The page corresponding to the named destination
139 * requested. 140 * requested.
140 */ 141 */
141 onNamedDestinationReceived: function(pageNumber) { 142 onNamedDestinationReceived: function(pageNumber) {
142 var outstandingRequest = this.outstandingRequests_.shift(); 143 var outstandingRequest = this.outstandingRequests_.shift();
143 if (pageNumber != -1) 144 if (pageNumber != -1)
144 outstandingRequest.viewportPosition.page = pageNumber; 145 outstandingRequest.viewportPosition.page = pageNumber;
145 outstandingRequest.callback(outstandingRequest.viewportPosition); 146 outstandingRequest.callback(outstandingRequest.viewportPosition);
146 }, 147 },
147 }; 148 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/navigator.js ('k') | chrome/browser/resources/pdf/toolbar_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698