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(); |
raymes
2015/01/15 04:51:11
Let's keep this named paramsParser_. An underscore
Deepak
2015/01/15 06:30:05
Done.
| |
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.getURLPDFParams(this.streamDetails_.originalUrl); |
289 if (this.urlParams_.position) { | 288 if (urlParams.page) |
289 this.viewport_.goToPage(urlParams.page); | |
290 if (urlParams.nameddest) | |
291 this.viewport_.goToPage(urlParams.nameddest); | |
raymes
2015/01/15 04:51:11
If we merge nameddest and page we can remove this
Deepak
2015/01/15 06:30:05
Done.
| |
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 navigate to given URL. This might involve navigating | |
348 * within the PDF page or opening a new url (in the same tab or a new tab) | |
349 * @param {string} message data that have the url for navigation. | |
350 * @param {boolean} message data that have info regarding navigation happen | |
351 * within the PDF page or in the newTab. | |
352 */ | |
353 navigate_: function(urlFragment, isNewTab) { | |
raymes
2015/01/15 04:51:11
I'd like to start reducing this size of this class
Deepak
2015/01/15 06:30:05
I understand, I will do refactoring in a separate
| |
354 var namedFragment; | |
355 if (urlFragment.length != 0) { | |
356 // If |urlFragment| starts with '#', then it's for the same URL with a | |
357 // different URL fragment. | |
358 if (urlFragment.charAt(0) == '#') { | |
359 // if '#' is already present in |originalUrl| then remove old fragment | |
360 // and add new url fragment. | |
361 namedFragment = urlFragment.substring(1); | |
362 var originalUrl = this.streamDetails_.originalUrl; | |
363 var hashIndex = originalUrl.search('#'); | |
364 if (hashIndex != -1) | |
365 urlFragment = originalUrl.substring(0, hashIndex) + urlFragment; | |
366 else | |
367 urlFragment = originalUrl + urlFragment; | |
368 } | |
369 } | |
370 var inputURL = urlFragment; | |
371 // If there's no scheme, add http. | |
372 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) { | |
373 inputURL = 'http://' + inputURL; | |
374 } | |
375 // Make sure inputURL starts with a valid scheme. | |
376 if (inputURL.indexOf('http://') != 0 && | |
377 inputURL.indexOf('https://') != 0 && | |
378 inputURL.indexOf('ftp://') != 0 && | |
379 inputURL.indexOf('file://') != 0 && | |
380 inputURL.indexOf('mailto:') != 0) { | |
381 return; | |
382 } | |
383 // Make sure inputURL is not only a scheme. | |
384 if (inputURL == 'http://' || | |
385 inputURL == 'https://' || | |
386 inputURL == 'ftp://' || | |
387 inputURL == 'file://' || | |
388 inputURL == 'mailto:') { | |
389 return; | |
390 } | |
391 | |
392 if (isNewTab) { | |
393 chrome.tabs.create({ url: inputURL }); | |
raymes
2015/01/15 04:51:11
Cool, thanks for looking into that! Let's leave it
Deepak
2015/01/15 06:30:05
Acknowledged.
| |
394 } else { | |
395 var pageNumber = -1; | |
396 if (namedFragment) | |
397 pageNumber = this.paramsParser.namedDestinations[namedFragment]; | |
398 if (pageNumber >= 0) | |
399 this.viewport_.goToPage(pageNumber); | |
400 else | |
401 window.location.href = inputURL; | |
402 } | |
403 }, | |
raymes
2015/01/15 04:51:11
Here is what I was thinking (there are a few chang
Deepak
2015/01/15 06:30:05
Done.
| |
404 | |
405 /** | |
406 * @private | |
344 * An event handler for handling message events received from the plugin. | 407 * An event handler for handling message events received from the plugin. |
345 * @param {MessageObject} message a message event. | 408 * @param {MessageObject} message a message event. |
346 */ | 409 */ |
347 handlePluginMessage_: function(message) { | 410 handlePluginMessage_: function(message) { |
348 switch (message.data.type.toString()) { | 411 switch (message.data.type.toString()) { |
349 case 'documentDimensions': | 412 case 'documentDimensions': |
350 this.documentDimensions_ = message.data; | 413 this.documentDimensions_ = message.data; |
351 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 414 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
352 // If we received the document dimensions, the password was good so we | 415 // If we received the document dimensions, the password was good so we |
353 // can dismiss the password screen. | 416 // can dismiss the password screen. |
(...skipping 25 matching lines...) Expand all Loading... | |
379 case 'getSelectedTextReply': | 442 case 'getSelectedTextReply': |
380 this.sendScriptingMessage_(message.data); | 443 this.sendScriptingMessage_(message.data); |
381 break; | 444 break; |
382 case 'goToPage': | 445 case 'goToPage': |
383 this.viewport_.goToPage(message.data.page); | 446 this.viewport_.goToPage(message.data.page); |
384 break; | 447 break; |
385 case 'loadProgress': | 448 case 'loadProgress': |
386 this.updateProgress_(message.data.progress); | 449 this.updateProgress_(message.data.progress); |
387 break; | 450 break; |
388 case 'navigate': | 451 case 'navigate': |
389 if (message.data.newTab) | 452 this.navigate_(message.data.url, message.data.newTab); |
390 window.open(message.data.url); | 453 break; |
391 else | 454 case 'setNamedDestinations': |
392 window.location.href = message.data.url; | 455 this.paramsParser.namedDestinations = message.data.namedDestinations; |
393 break; | 456 break; |
394 case 'setScrollPosition': | 457 case 'setScrollPosition': |
395 var position = this.viewport_.position; | 458 var position = this.viewport_.position; |
396 if (message.data.x != undefined) | 459 if (message.data.x != undefined) |
397 position.x = message.data.x; | 460 position.x = message.data.x; |
398 if (message.data.y != undefined) | 461 if (message.data.y != undefined) |
399 position.y = message.data.y; | 462 position.y = message.data.y; |
400 this.viewport_.position = position; | 463 this.viewport_.position = position; |
401 break; | 464 break; |
402 case 'setTranslatedStrings': | 465 case 'setTranslatedStrings': |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 this.streamDetails_.tabId != -1); | 670 this.streamDetails_.tabId != -1); |
608 }, | 671 }, |
609 | 672 |
610 /** | 673 /** |
611 * @type {Viewport} the viewport of the PDF viewer. | 674 * @type {Viewport} the viewport of the PDF viewer. |
612 */ | 675 */ |
613 get viewport() { | 676 get viewport() { |
614 return this.viewport_; | 677 return this.viewport_; |
615 } | 678 } |
616 }; | 679 }; |
OLD | NEW |