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

Side by Side Diff: chrome/browser/resources/pdf/pdf.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
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 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 zoomChangeInfo.newZoomFactor); 129 zoomChangeInfo.newZoomFactor);
130 // We should not change zoom level when we are responsible for initiating 130 // We should not change zoom level when we are responsible for initiating
131 // the zoom. onZoomChange() is called before setZoomComplete() callback 131 // the zoom. onZoomChange() is called before setZoomComplete() callback
132 // when we initiate the zoom. 132 // when we initiate the zoom.
133 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) 133 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
134 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 134 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
135 }.bind(this)); 135 }.bind(this));
136 } 136 }
137 137
138 // Parse open pdf parameters. 138 // Parse open pdf parameters.
139 var paramsParser = new OpenPDFParamsParser(this.streamDetails_.originalUrl); 139 this.paramsParser_ = new OpenPDFParamsParser();
140 this.urlParams_ = paramsParser.urlParams;
141 } 140 }
142 141
143 PDFViewer.prototype = { 142 PDFViewer.prototype = {
144 /** 143 /**
145 * @private 144 * @private
146 * Handle key events. These may come from the user directly or via the 145 * Handle key events. These may come from the user directly or via the
147 * scripting API. 146 * scripting API.
148 * @param {KeyboardEvent} e the event to handle. 147 * @param {KeyboardEvent} e the event to handle.
149 */ 148 */
150 handleKeyEvent_: function(e) { 149 handleKeyEvent_: function(e) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 }); 276 });
278 }, 277 },
279 278
280 /** 279 /**
281 * @private 280 * @private
282 * Handle open pdf parameters. This function updates the viewport as per 281 * Handle open pdf parameters. This function updates the viewport as per
283 * the parameters mentioned in the url while opening pdf. The order is 282 * the parameters mentioned in the url while opening pdf. The order is
284 * important as later actions can override the effects of previous actions. 283 * important as later actions can override the effects of previous actions.
285 */ 284 */
286 handleURLParams_: function() { 285 handleURLParams_: function() {
287 if (this.urlParams_.page) 286 var urlParams =
raymes 2015/01/18 22:01:39 nit: let's rename this viewportPosition
288 this.viewport_.goToPage(this.urlParams_.page); 287 this.paramsParser_.getViewportFromUrlParams(
289 if (this.urlParams_.position) { 288 this.streamDetails_.originalUrl);
289 if (urlParams.page)
290 this.viewport_.goToPage(urlParams.page);
291 if (urlParams.position) {
290 // Make sure we don't cancel effect of page parameter. 292 // Make sure we don't cancel effect of page parameter.
291 this.viewport_.position = { 293 this.viewport_.position = {
292 x: this.viewport_.position.x + this.urlParams_.position.x, 294 x: this.viewport_.position.x + urlParams.position.x,
293 y: this.viewport_.position.y + this.urlParams_.position.y 295 y: this.viewport_.position.y + urlParams.position.y
294 }; 296 };
295 } 297 }
296 if (this.urlParams_.zoom) 298 if (urlParams.zoom)
297 this.viewport_.setZoom(this.urlParams_.zoom); 299 this.viewport_.setZoom(urlParams.zoom);
298 }, 300 },
299 301
300 /** 302 /**
301 * @private 303 * @private
302 * Update the loading progress of the document in response to a progress 304 * Update the loading progress of the document in response to a progress
303 * message being received from the plugin. 305 * message being received from the plugin.
304 * @param {number} progress the progress as a percentage. 306 * @param {number} progress the progress as a percentage.
305 */ 307 */
306 updateProgress_: function(progress) { 308 updateProgress_: function(progress) {
307 this.progressBar_.progress = progress; 309 this.progressBar_.progress = progress;
(...skipping 26 matching lines...) Expand all
334 */ 336 */
335 onPasswordSubmitted_: function(event) { 337 onPasswordSubmitted_: function(event) {
336 this.plugin_.postMessage({ 338 this.plugin_.postMessage({
337 type: 'getPasswordComplete', 339 type: 'getPasswordComplete',
338 password: event.detail.password 340 password: event.detail.password
339 }); 341 });
340 }, 342 },
341 343
342 /** 344 /**
343 * @private 345 * @private
346 * Helper function to navigate to given URL. This might involve navigating
347 * within the PDF page or opening a new url (in the same tab or a new tab).
348 * @param {string} url The URL to navigate to.
349 * @param {boolean} newTab Whether to perform the navigation in a new tab or
350 * in the current tab.
351 */
352 navigate_: function(url, newTab) {
353 if (url.length == 0)
354 return;
355 var originalUrl = this.streamDetails_.originalUrl;
356 // If |urlFragment| starts with '#', then it's for the same URL with a
357 // different URL fragment.
358 if (url.charAt(0) == '#') {
359 // if '#' is already present in |originalUrl| then remove old fragment
360 // and add new url fragment.
361 var hashIndex = originalUrl.search('#');
362 if (hashIndex != -1)
363 url = originalUrl.substring(0, hashIndex) + url;
364 else
365 url = originalUrl + url;
366 }
367
368 var inputURL = url;
369 // If there's no scheme, add http.
370 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1)
371 inputURL = 'http://' + inputURL;
372
373 // Make sure inputURL starts with a valid scheme.
374 if (inputURL.indexOf('http://') != 0 &&
375 inputURL.indexOf('https://') != 0 &&
376 inputURL.indexOf('ftp://') != 0 &&
377 inputURL.indexOf('file://') != 0 &&
378 inputURL.indexOf('mailto:') != 0) {
379 return;
380 }
381 // Make sure inputURL is not only a scheme.
382 if (inputURL == 'http://' ||
383 inputURL == 'https://' ||
384 inputURL == 'ftp://' ||
385 inputURL == 'file://' ||
386 inputURL == 'mailto:') {
387 return;
388 }
389
390 if (newTab) {
391 chrome.tabs.create({ url: inputURL });
392 } else {
393 var pageNumber =
394 this.paramsParser_.getViewportFromUrlParams(inputURL).page;
395 if (pageNumber != undefined)
396 this.viewport_.goToPage(pageNumber);
397 else
398 window.location.href = inputURL;
399 }
400 },
401
402 /**
403 * @private
344 * An event handler for handling message events received from the plugin. 404 * An event handler for handling message events received from the plugin.
345 * @param {MessageObject} message a message event. 405 * @param {MessageObject} message a message event.
346 */ 406 */
347 handlePluginMessage_: function(message) { 407 handlePluginMessage_: function(message) {
348 switch (message.data.type.toString()) { 408 switch (message.data.type.toString()) {
349 case 'documentDimensions': 409 case 'documentDimensions':
350 this.documentDimensions_ = message.data; 410 this.documentDimensions_ = message.data;
351 this.viewport_.setDocumentDimensions(this.documentDimensions_); 411 this.viewport_.setDocumentDimensions(this.documentDimensions_);
352 // If we received the document dimensions, the password was good so we 412 // If we received the document dimensions, the password was good so we
353 // can dismiss the password screen. 413 // can dismiss the password screen.
(...skipping 23 matching lines...) Expand all
377 case 'getSelectedTextReply': 437 case 'getSelectedTextReply':
378 this.sendScriptingMessage_(message.data); 438 this.sendScriptingMessage_(message.data);
379 break; 439 break;
380 case 'goToPage': 440 case 'goToPage':
381 this.viewport_.goToPage(message.data.page); 441 this.viewport_.goToPage(message.data.page);
382 break; 442 break;
383 case 'loadProgress': 443 case 'loadProgress':
384 this.updateProgress_(message.data.progress); 444 this.updateProgress_(message.data.progress);
385 break; 445 break;
386 case 'navigate': 446 case 'navigate':
387 if (message.data.newTab) 447 this.navigate_(message.data.url, message.data.newTab);
388 chrome.tabs.create({ url: message.data.url }); 448 break;
389 else 449 case 'setNamedDestinations':
390 window.location.href = message.data.url; 450 this.paramsParser_.namedDestinations = message.data.namedDestinations;
391 break; 451 break;
392 case 'setScrollPosition': 452 case 'setScrollPosition':
393 var position = this.viewport_.position; 453 var position = this.viewport_.position;
394 if (message.data.x != undefined) 454 if (message.data.x != undefined)
395 position.x = message.data.x; 455 position.x = message.data.x;
396 if (message.data.y != undefined) 456 if (message.data.y != undefined)
397 position.y = message.data.y; 457 position.y = message.data.y;
398 this.viewport_.position = position; 458 this.viewport_.position = position;
399 break; 459 break;
400 case 'setTranslatedStrings': 460 case 'setTranslatedStrings':
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 this.streamDetails_.tabId != -1); 665 this.streamDetails_.tabId != -1);
606 }, 666 },
607 667
608 /** 668 /**
609 * @type {Viewport} the viewport of the PDF viewer. 669 * @type {Viewport} the viewport of the PDF viewer.
610 */ 670 */
611 get viewport() { 671 get viewport() {
612 return this.viewport_; 672 return this.viewport_;
613 } 673 }
614 }; 674 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698