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

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: Fixing Build error. 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 | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | pdf/out_of_process_instance.cc » ('j') | 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 /** 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 zoomChangeInfo.newZoomFactor); 133 zoomChangeInfo.newZoomFactor);
134 // We should not change zoom level when we are responsible for initiating 134 // We should not change zoom level when we are responsible for initiating
135 // the zoom. onZoomChange() is called before setZoomComplete() callback 135 // the zoom. onZoomChange() is called before setZoomComplete() callback
136 // when we initiate the zoom. 136 // when we initiate the zoom.
137 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) 137 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
138 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 138 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
139 }.bind(this)); 139 }.bind(this));
140 } 140 }
141 141
142 // Parse open pdf parameters. 142 // Parse open pdf parameters.
143 var paramsParser = new OpenPDFParamsParser(this.streamDetails_.originalUrl); 143 this.paramsParser_ = new OpenPDFParamsParser();
144 this.urlParams_ = paramsParser.urlParams;
145 } 144 }
146 145
147 PDFViewer.prototype = { 146 PDFViewer.prototype = {
148 /** 147 /**
149 * @private 148 * @private
150 * Handle key events. These may come from the user directly or via the 149 * Handle key events. These may come from the user directly or via the
151 * scripting API. 150 * scripting API.
152 * @param {KeyboardEvent} e the event to handle. 151 * @param {KeyboardEvent} e the event to handle.
153 */ 152 */
154 handleKeyEvent_: function(e) { 153 handleKeyEvent_: function(e) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 }); 280 });
282 }, 281 },
283 282
284 /** 283 /**
285 * @private 284 * @private
286 * Handle open pdf parameters. This function updates the viewport as per 285 * Handle open pdf parameters. This function updates the viewport as per
287 * the parameters mentioned in the url while opening pdf. The order is 286 * the parameters mentioned in the url while opening pdf. The order is
288 * important as later actions can override the effects of previous actions. 287 * important as later actions can override the effects of previous actions.
289 */ 288 */
290 handleURLParams_: function() { 289 handleURLParams_: function() {
291 if (this.urlParams_.page) 290 var urlParams =
292 this.viewport_.goToPage(this.urlParams_.page); 291 this.paramsParser_.getViewportFromUrlParams(
293 if (this.urlParams_.position) { 292 this.streamDetails_.originalUrl);
293 if (urlParams.page)
294 this.viewport_.goToPage(urlParams.page);
295 if (urlParams.position) {
294 // Make sure we don't cancel effect of page parameter. 296 // Make sure we don't cancel effect of page parameter.
295 this.viewport_.position = { 297 this.viewport_.position = {
296 x: this.viewport_.position.x + this.urlParams_.position.x, 298 x: this.viewport_.position.x + urlParams.position.x,
297 y: this.viewport_.position.y + this.urlParams_.position.y 299 y: this.viewport_.position.y + urlParams.position.y
298 }; 300 };
299 } 301 }
300 if (this.urlParams_.zoom) 302 if (urlParams.zoom)
301 this.viewport_.setZoom(this.urlParams_.zoom); 303 this.viewport_.setZoom(urlParams.zoom);
302 }, 304 },
303 305
304 /** 306 /**
305 * @private 307 * @private
306 * Update the loading progress of the document in response to a progress 308 * Update the loading progress of the document in response to a progress
307 * message being received from the plugin. 309 * message being received from the plugin.
308 * @param {number} progress the progress as a percentage. 310 * @param {number} progress the progress as a percentage.
309 */ 311 */
310 updateProgress_: function(progress) { 312 updateProgress_: function(progress) {
311 this.progressBar_.progress = progress; 313 this.progressBar_.progress = progress;
(...skipping 26 matching lines...) Expand all
338 */ 340 */
339 onPasswordSubmitted_: function(event) { 341 onPasswordSubmitted_: function(event) {
340 this.plugin_.postMessage({ 342 this.plugin_.postMessage({
341 type: 'getPasswordComplete', 343 type: 'getPasswordComplete',
342 password: event.detail.password 344 password: event.detail.password
343 }); 345 });
344 }, 346 },
345 347
346 /** 348 /**
347 * @private 349 * @private
350 * Helper function to navigate to given URL. This might involve navigating
351 * within the PDF page or opening a new url (in the same tab or a new tab).
352 * @param {string} url The URL to navigate to.
353 * @param {boolean} newTab Whether to perform the navigation in a new tab or
354 * in the current tab.
355 */
356 navigate_: function(url, newTab) {
357 if (url.length == 0)
358 return;
359 var originalUrl = this.streamDetails_.originalUrl;
360 // If |urlFragment| starts with '#', then it's for the same URL with a
361 // different URL fragment.
362 if (url.charAt(0) == '#') {
363 // if '#' is already present in |originalUrl| then remove old fragment
364 // and add new url fragment.
365 var hashIndex = originalUrl.search('#');
366 if (hashIndex != -1)
367 url = originalUrl.substring(0, hashIndex) + url;
368 else
369 url = originalUrl + url;
370 }
371
372 var inputURL = url;
373 // If there's no scheme, add http.
374 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1)
375 inputURL = 'http://' + inputURL;
376
377 // Make sure inputURL starts with a valid scheme.
378 if (inputURL.indexOf('http://') != 0 &&
379 inputURL.indexOf('https://') != 0 &&
380 inputURL.indexOf('ftp://') != 0 &&
381 inputURL.indexOf('file://') != 0 &&
382 inputURL.indexOf('mailto:') != 0) {
383 return;
384 }
385 // Make sure inputURL is not only a scheme.
386 if (inputURL == 'http://' ||
387 inputURL == 'https://' ||
388 inputURL == 'ftp://' ||
389 inputURL == 'file://' ||
390 inputURL == 'mailto:') {
391 return;
392 }
393
394 if (newTab) {
395 chrome.tabs.create({ url: inputURL });
396 } else {
397 var pageNumber =
398 this.paramsParser_.getViewportFromUrlParams(inputURL).page;
399 if (pageNumber != undefined)
400 this.viewport_.goToPage(pageNumber);
401 else
402 window.location.href = inputURL;
403 }
404 },
405
406 /**
407 * @private
348 * An event handler for handling message events received from the plugin. 408 * An event handler for handling message events received from the plugin.
349 * @param {MessageObject} message a message event. 409 * @param {MessageObject} message a message event.
350 */ 410 */
351 handlePluginMessage_: function(message) { 411 handlePluginMessage_: function(message) {
352 switch (message.data.type.toString()) { 412 switch (message.data.type.toString()) {
353 case 'documentDimensions': 413 case 'documentDimensions':
354 this.documentDimensions_ = message.data; 414 this.documentDimensions_ = message.data;
355 this.viewport_.setDocumentDimensions(this.documentDimensions_); 415 this.viewport_.setDocumentDimensions(this.documentDimensions_);
356 // If we received the document dimensions, the password was good so we 416 // If we received the document dimensions, the password was good so we
357 // can dismiss the password screen. 417 // can dismiss the password screen.
(...skipping 25 matching lines...) Expand all
383 break; 443 break;
384 case 'goToPage': 444 case 'goToPage':
385 this.viewport_.goToPage(message.data.page); 445 this.viewport_.goToPage(message.data.page);
386 break; 446 break;
387 case 'loadProgress': 447 case 'loadProgress':
388 this.updateProgress_(message.data.progress); 448 this.updateProgress_(message.data.progress);
389 break; 449 break;
390 case 'navigate': 450 case 'navigate':
391 if (this.isPrintPreview_) 451 if (this.isPrintPreview_)
392 break; 452 break;
393 if (message.data.newTab) 453 this.navigate_(message.data.url, message.data.newTab);
394 chrome.tabs.create({ url: message.data.url }); 454 break;
395 else 455 case 'setNamedDestinations':
396 window.location.href = message.data.url; 456 this.paramsParser_.namedDestinations = message.data.namedDestinations;
397 break; 457 break;
398 case 'setScrollPosition': 458 case 'setScrollPosition':
399 var position = this.viewport_.position; 459 var position = this.viewport_.position;
400 if (message.data.x !== undefined) 460 if (message.data.x !== undefined)
401 position.x = message.data.x; 461 position.x = message.data.x;
402 if (message.data.y !== undefined) 462 if (message.data.y !== undefined)
403 position.y = message.data.y; 463 position.y = message.data.y;
404 this.viewport_.position = position; 464 this.viewport_.position = position;
405 break; 465 break;
406 case 'setTranslatedStrings': 466 case 'setTranslatedStrings':
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 this.streamDetails_.tabId != -1); 678 this.streamDetails_.tabId != -1);
619 }, 679 },
620 680
621 /** 681 /**
622 * @type {Viewport} the viewport of the PDF viewer. 682 * @type {Viewport} the viewport of the PDF viewer.
623 */ 683 */
624 get viewport() { 684 get viewport() {
625 return this.viewport_; 685 return this.viewport_;
626 } 686 }
627 }; 687 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698