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

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

Issue 477933003: OOP PDF - Add OpenPDFParamsParser class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (update variable name) Created 6 years, 3 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 | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <include src="../../../../ui/webui/resources/js/util.js"> 7 <include src="../../../../ui/webui/resources/js/util.js">
8 <include src="open_pdf_params_parser.js">
8 <include src="pdf_scripting_api.js"> 9 <include src="pdf_scripting_api.js">
9 <include src="viewport.js"> 10 <include src="viewport.js">
10 11
11 /** 12 /**
12 * @return {number} Width of a scrollbar in pixels 13 * @return {number} Width of a scrollbar in pixels
13 */ 14 */
14 function getScrollbarWidth() { 15 function getScrollbarWidth() {
15 var div = document.createElement('div'); 16 var div = document.createElement('div');
16 div.style.visibility = 'hidden'; 17 div.style.visibility = 'hidden';
17 div.style.overflow = 'scroll'; 18 div.style.overflow = 'scroll';
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // If the zoom level is close enough to the current zoom level, don't 144 // If the zoom level is close enough to the current zoom level, don't
144 // change it. This avoids us getting into an infinite loop of zoom changes 145 // change it. This avoids us getting into an infinite loop of zoom changes
145 // due to floating point error. 146 // due to floating point error.
146 var MIN_ZOOM_DELTA = 0.01; 147 var MIN_ZOOM_DELTA = 0.01;
147 var zoomDelta = Math.abs(this.viewport_.zoom - 148 var zoomDelta = Math.abs(this.viewport_.zoom -
148 zoomChangeInfo.newZoomFactor); 149 zoomChangeInfo.newZoomFactor);
149 if (zoomDelta > MIN_ZOOM_DELTA) 150 if (zoomDelta > MIN_ZOOM_DELTA)
150 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 151 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
151 }.bind(this)); 152 }.bind(this));
152 } 153 }
154
155 // Parse open pdf parameters.
156 var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl);
157 this.urlParams_ = paramsParser.urlParams;
153 } 158 }
154 159
155 PDFViewer.prototype = { 160 PDFViewer.prototype = {
156 /** 161 /**
157 * @private 162 * @private
158 * Handle key events. These may come from the user directly or via the 163 * Handle key events. These may come from the user directly or via the
159 * scripting API. 164 * scripting API.
160 * @param {KeyboardEvent} e the event to handle. 165 * @param {KeyboardEvent} e the event to handle.
161 */ 166 */
162 handleKeyEvent_: function(e) { 167 handleKeyEvent_: function(e) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 * Notify the plugin to print. 263 * Notify the plugin to print.
259 */ 264 */
260 print_: function() { 265 print_: function() {
261 this.plugin_.postMessage({ 266 this.plugin_.postMessage({
262 type: 'print', 267 type: 'print',
263 }); 268 });
264 }, 269 },
265 270
266 /** 271 /**
267 * @private 272 * @private
268 * Handle open PDF parameters. These parameters are mentioned in the URL
269 * and specify actions to be performed when opening PDF files.
270 * See http://crbug.com/64309 for details.
271 */
272 handleOpenPDFParams_: function() {
273 var originalUrl = this.streamDetails.originalUrl;
274 var paramIndex = originalUrl.search('#');
275 if (paramIndex == -1)
276 return;
277
278 var paramTokens = originalUrl.substring(paramIndex + 1).split('&');
279 var paramsDictionary = {};
280 for (var i = 0; i < paramTokens.length; ++i) {
281 var keyValueSplit = paramTokens[i].split('=');
282 if (keyValueSplit.length != 2)
283 continue;
284 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
285 }
286
287 // Order is important as later actions can override the effects
288 // of previous actions.
289 if ('page' in paramsDictionary) {
290 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
291 var pageNumber = parseInt(paramsDictionary['page']);
292 if (!isNaN(pageNumber))
293 this.viewport_.goToPage(pageNumber - 1);
294 }
295 },
296
297 /**
298 * @private
299 * Update the loading progress of the document in response to a progress 273 * Update the loading progress of the document in response to a progress
300 * message being received from the plugin. 274 * message being received from the plugin.
301 * @param {number} progress the progress as a percentage. 275 * @param {number} progress the progress as a percentage.
302 */ 276 */
303 updateProgress_: function(progress) { 277 updateProgress_: function(progress) {
304 this.progressBar_.progress = progress; 278 this.progressBar_.progress = progress;
305 if (progress == -1) { 279 if (progress == -1) {
306 // Document load failed. 280 // Document load failed.
307 this.errorScreen_.style.visibility = 'visible'; 281 this.errorScreen_.style.visibility = 'visible';
308 this.sizer_.style.display = 'none'; 282 this.sizer_.style.display = 'none';
309 this.toolbar_.style.visibility = 'hidden'; 283 this.toolbar_.style.visibility = 'hidden';
310 if (this.passwordScreen_.active) { 284 if (this.passwordScreen_.active) {
311 this.passwordScreen_.deny(); 285 this.passwordScreen_.deny();
312 this.passwordScreen_.active = false; 286 this.passwordScreen_.active = false;
313 } 287 }
314 } else if (progress == 100) { 288 } else if (progress == 100) {
315 // Document load complete. 289 // Document load complete.
316 this.handleOpenPDFParams_();
317 this.loaded = true; 290 this.loaded = true;
318 var loadEvent = new Event('pdfload'); 291 var loadEvent = new Event('pdfload');
319 window.dispatchEvent(loadEvent); 292 window.dispatchEvent(loadEvent);
320 this.sendScriptingMessage_({ 293 this.sendScriptingMessage_({
321 type: 'documentLoaded' 294 type: 'documentLoaded'
322 }); 295 });
323 if (this.lastViewportPosition_) 296 if (this.lastViewportPosition_)
324 this.viewport_.position = this.lastViewportPosition_; 297 this.viewport_.position = this.lastViewportPosition_;
298
299 // Handle open pdf params. Order is important as later actions can
300 // override the effects of previous actions.
301 if (this.urlParams_.page)
302 this.viewport_.goToPage(this.urlParams_.page);
325 } 303 }
326 }, 304 },
327 305
328 /** 306 /**
329 * @private 307 * @private
330 * An event handler for handling password-submitted events. These are fired 308 * An event handler for handling password-submitted events. These are fired
331 * when an event is entered into the password screen. 309 * when an event is entered into the password screen.
332 * @param {Object} event a password-submitted event. 310 * @param {Object} event a password-submitted event.
333 */ 311 */
334 onPasswordSubmitted_: function(event) { 312 onPasswordSubmitted_: function(event) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 549
572 /** 550 /**
573 * @type {Viewport} the viewport of the PDF viewer. 551 * @type {Viewport} the viewport of the PDF viewer.
574 */ 552 */
575 get viewport() { 553 get viewport() {
576 return this.viewport_; 554 return this.viewport_;
577 } 555 }
578 }; 556 };
579 557
580 var viewer = new PDFViewer(); 558 var viewer = new PDFViewer();
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698