Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 = |
| 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 Loading... | |
| 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) | |
|
raymes
2015/01/15 23:07:43
nit: '.' at the end of hte sentence
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
| |
| 348 * @param {string} message data that have the url for navigation. | |
|
raymes
2015/01/15 23:07:43
You need to include the name of the param here. e.
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
| |
| 349 * @param {boolean} message data that have info regarding navigation happen | |
| 350 * within the PDF page or in the newTab. | |
| 351 */ | |
| 352 navigate_: function(url, isNewTab) { | |
|
raymes
2015/01/15 23:07:43
nit: isNewTab->newTab
Deepak
2015/01/16 04:39:21
On 2015/01/15 23:07:43, raymes wrote:
Done.
| |
| 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 (isNewTab) { | |
| 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 25 matching lines...) Expand all Loading... | |
| 379 case 'getSelectedTextReply': | 439 case 'getSelectedTextReply': |
| 380 this.sendScriptingMessage_(message.data); | 440 this.sendScriptingMessage_(message.data); |
| 381 break; | 441 break; |
| 382 case 'goToPage': | 442 case 'goToPage': |
| 383 this.viewport_.goToPage(message.data.page); | 443 this.viewport_.goToPage(message.data.page); |
| 384 break; | 444 break; |
| 385 case 'loadProgress': | 445 case 'loadProgress': |
| 386 this.updateProgress_(message.data.progress); | 446 this.updateProgress_(message.data.progress); |
| 387 break; | 447 break; |
| 388 case 'navigate': | 448 case 'navigate': |
| 389 if (message.data.newTab) | 449 this.navigate_(message.data.url, message.data.newTab); |
| 390 window.open(message.data.url); | 450 break; |
| 391 else | 451 case 'setNamedDestinations': |
| 392 window.location.href = message.data.url; | 452 this.paramsParser_.namedDestinations = message.data.namedDestinations; |
| 393 break; | 453 break; |
| 394 case 'setScrollPosition': | 454 case 'setScrollPosition': |
| 395 var position = this.viewport_.position; | 455 var position = this.viewport_.position; |
| 396 if (message.data.x != undefined) | 456 if (message.data.x != undefined) |
| 397 position.x = message.data.x; | 457 position.x = message.data.x; |
| 398 if (message.data.y != undefined) | 458 if (message.data.y != undefined) |
| 399 position.y = message.data.y; | 459 position.y = message.data.y; |
| 400 this.viewport_.position = position; | 460 this.viewport_.position = position; |
| 401 break; | 461 break; |
| 402 case 'setTranslatedStrings': | 462 case 'setTranslatedStrings': |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 this.streamDetails_.tabId != -1); | 667 this.streamDetails_.tabId != -1); |
| 608 }, | 668 }, |
| 609 | 669 |
| 610 /** | 670 /** |
| 611 * @type {Viewport} the viewport of the PDF viewer. | 671 * @type {Viewport} the viewport of the PDF viewer. |
| 612 */ | 672 */ |
| 613 get viewport() { | 673 get viewport() { |
| 614 return this.viewport_; | 674 return this.viewport_; |
| 615 } | 675 } |
| 616 }; | 676 }; |
| OLD | NEW |