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 pageNumber = |
| 288 this.viewport_.goToPage(this.urlParams_.page); | 287 this.paramsParser.getInitalPage(this.streamDetails_.originalUrl); |
| 289 if (this.urlParams_.position) { | 288 if (pageNumber >= 0) |
| 289 this.viewport_.goToPage(pageNumber); | |
| 290 var urlParams = | |
| 291 this.paramsParser.getURLPDFParams(this.streamDetails_.originalUrl); | |
| 292 if (urlParams.position) { | |
| 290 // Make sure we don't cancel effect of page parameter. | 293 // Make sure we don't cancel effect of page parameter. |
| 291 this.viewport_.position = { | 294 this.viewport_.position = { |
| 292 x: this.viewport_.position.x + this.urlParams_.position.x, | 295 x: this.viewport_.position.x + urlParams.position.x, |
| 293 y: this.viewport_.position.y + this.urlParams_.position.y | 296 y: this.viewport_.position.y + urlParams.position.y |
| 294 }; | 297 }; |
| 295 } | 298 } |
| 296 if (this.urlParams_.zoom) | 299 if (urlParams.zoom) |
| 297 this.viewport_.setZoom(this.urlParams_.zoom); | 300 this.viewport_.setZoom(urlParams.zoom); |
| 298 }, | 301 }, |
| 299 | 302 |
| 300 /** | 303 /** |
| 301 * @private | 304 * @private |
| 302 * Update the loading progress of the document in response to a progress | 305 * Update the loading progress of the document in response to a progress |
| 303 * message being received from the plugin. | 306 * message being received from the plugin. |
| 304 * @param {number} progress the progress as a percentage. | 307 * @param {number} progress the progress as a percentage. |
| 305 */ | 308 */ |
| 306 updateProgress_: function(progress) { | 309 updateProgress_: function(progress) { |
| 307 this.progressBar_.progress = progress; | 310 this.progressBar_.progress = progress; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 334 */ | 337 */ |
| 335 onPasswordSubmitted_: function(event) { | 338 onPasswordSubmitted_: function(event) { |
| 336 this.plugin_.postMessage({ | 339 this.plugin_.postMessage({ |
| 337 type: 'getPasswordComplete', | 340 type: 'getPasswordComplete', |
| 338 password: event.detail.password | 341 password: event.detail.password |
| 339 }); | 342 }); |
| 340 }, | 343 }, |
| 341 | 344 |
| 342 /** | 345 /** |
| 343 * @private | 346 * @private |
| 347 * Helper function to process url from message and to navigate within the | |
| 348 * PDF page or opening new url in the same tab. | |
|
raymes
2015/01/14 00:19:00
nit: Helper function to navigate to the given URL.
Deepak
2015/01/14 06:29:01
Done.
| |
| 349 * @param {Object} message data that have the url and newTab info. | |
|
raymes
2015/01/14 00:19:00
Please update this with the new params :)
Deepak
2015/01/14 06:29:01
Done.
| |
| 350 */ | |
| 351 navigate_: function(urlFragment, isNewTab) { | |
| 352 if (urlFragment.length != 0) { | |
|
raymes
2015/01/14 00:19:00
nit: everything from here below should be indented
Deepak
2015/01/14 06:29:01
Done.
| |
| 353 // If |urlFragment| starts with '#', then it's for the same URL with a | |
| 354 // different URL fragment. | |
| 355 if (urlFragment.charAt(0) == '#') { | |
| 356 // if '#' is already present in |originalUrl| then remove old fragment and | |
| 357 // add new |url_copy| fragment. | |
| 358 var hashIndex = this.streamDetails_.originalUrl.search('#'); | |
|
raymes
2015/01/14 00:19:00
nit: let's put the original url in a local variabl
Deepak
2015/01/14 06:29:01
Done.
| |
| 359 if (hashIndex != -1) { | |
| 360 urlFragment = this.streamDetails_.originalUrl.substring(0, hashIndex) + | |
| 361 urlFragment; | |
| 362 } | |
| 363 else { | |
| 364 urlFragment = this.streamDetails_.originalUrl + urlFragment; | |
| 365 } | |
| 366 } | |
|
raymes
2015/01/14 00:19:00
the logic from here down differs from Instance::Na
Deepak
2015/01/14 06:29:01
If I scroll here like Instance::NavigateTo() then
raymes
2015/01/15 04:51:10
What I mean is to move the following lines below u
| |
| 367 } | |
| 368 var inputURL = urlFragment; | |
| 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 |url_copy| 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 |url_copy| 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 }); | |
|
raymes
2015/01/14 00:19:00
As I mentioned earlier - we don't need to use the
Deepak
2015/01/14 06:29:01
I remember, you told me to use window.open(url);
B
| |
| 392 } else { | |
| 393 var pageNumber = this.paramsParser.getInitalPage(inputURL); | |
| 394 if (pageNumber >= 0) | |
| 395 this.viewport_.goToPage(pageNumber); | |
| 396 else | |
| 397 window.location.href = inputURL; | |
| 398 } | |
| 399 }, | |
| 400 | |
| 401 /** | |
| 402 * @private | |
| 344 * An event handler for handling message events received from the plugin. | 403 * An event handler for handling message events received from the plugin. |
| 345 * @param {MessageObject} message a message event. | 404 * @param {MessageObject} message a message event. |
| 346 */ | 405 */ |
| 347 handlePluginMessage_: function(message) { | 406 handlePluginMessage_: function(message) { |
| 348 switch (message.data.type.toString()) { | 407 switch (message.data.type.toString()) { |
| 349 case 'documentDimensions': | 408 case 'documentDimensions': |
| 350 this.documentDimensions_ = message.data; | 409 this.documentDimensions_ = message.data; |
| 351 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 410 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
| 352 // If we received the document dimensions, the password was good so we | 411 // If we received the document dimensions, the password was good so we |
| 353 // can dismiss the password screen. | 412 // can dismiss the password screen. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 379 case 'getSelectedTextReply': | 438 case 'getSelectedTextReply': |
| 380 this.sendScriptingMessage_(message.data); | 439 this.sendScriptingMessage_(message.data); |
| 381 break; | 440 break; |
| 382 case 'goToPage': | 441 case 'goToPage': |
| 383 this.viewport_.goToPage(message.data.page); | 442 this.viewport_.goToPage(message.data.page); |
| 384 break; | 443 break; |
| 385 case 'loadProgress': | 444 case 'loadProgress': |
| 386 this.updateProgress_(message.data.progress); | 445 this.updateProgress_(message.data.progress); |
| 387 break; | 446 break; |
| 388 case 'navigate': | 447 case 'navigate': |
| 389 if (message.data.newTab) | 448 this.navigate_(message.data.url, message.data.newTab); |
| 390 window.open(message.data.url); | 449 break; |
| 391 else | 450 case 'setNamedDestinations': |
| 392 window.location.href = message.data.url; | 451 this.paramsParser.namedDestinations = message.data.namedDestinations; |
| 393 break; | 452 break; |
| 394 case 'setScrollPosition': | 453 case 'setScrollPosition': |
| 395 var position = this.viewport_.position; | 454 var position = this.viewport_.position; |
| 396 if (message.data.x != undefined) | 455 if (message.data.x != undefined) |
| 397 position.x = message.data.x; | 456 position.x = message.data.x; |
| 398 if (message.data.y != undefined) | 457 if (message.data.y != undefined) |
| 399 position.y = message.data.y; | 458 position.y = message.data.y; |
| 400 this.viewport_.position = position; | 459 this.viewport_.position = position; |
| 401 break; | 460 break; |
| 402 case 'setTranslatedStrings': | 461 case 'setTranslatedStrings': |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 this.streamDetails_.tabId != -1); | 666 this.streamDetails_.tabId != -1); |
| 608 }, | 667 }, |
| 609 | 668 |
| 610 /** | 669 /** |
| 611 * @type {Viewport} the viewport of the PDF viewer. | 670 * @type {Viewport} the viewport of the PDF viewer. |
| 612 */ | 671 */ |
| 613 get viewport() { | 672 get viewport() { |
| 614 return this.viewport_; | 673 return this.viewport_; |
| 615 } | 674 } |
| 616 }; | 675 }; |
| OLD | NEW |