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 13 matching lines...) Expand all Loading... | |
24 * Return the filename component of a URL. | 24 * Return the filename component of a URL. |
25 * @param {string} url The URL to get the filename from. | 25 * @param {string} url The URL to get the filename from. |
26 * @return {string} The filename component. | 26 * @return {string} The filename component. |
27 */ | 27 */ |
28 function getFilenameFromURL(url) { | 28 function getFilenameFromURL(url) { |
29 var components = url.split(/\/|\\/); | 29 var components = url.split(/\/|\\/); |
30 return components[components.length - 1]; | 30 return components[components.length - 1]; |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
34 * Called when navigation happens in the current tab. | |
35 * @param {string} url The url to be opened in the current tab. | |
36 */ | |
37 function onNavigateInCurrentTab(url) { | |
38 window.location.href = url; | |
39 } | |
40 | |
41 /** | |
42 * Called when navigation happens in the new tab. | 34 * Called when navigation happens in the new tab. |
43 * @param {string} url The url to be opened in the new tab. | 35 * @param {string} url The url to be opened in the new tab. |
44 */ | 36 */ |
45 function onNavigateInNewTab(url) { | 37 function onNavigateInNewTab(url) { |
46 // Prefer the tabs API because it guarantees we can just open a new tab. | 38 // Prefer the tabs API because it guarantees we can just open a new tab. |
47 // window.open doesn't have this guarantee. | 39 // window.open doesn't have this guarantee. |
48 if (chrome.tabs) | 40 if (chrome.tabs) |
49 chrome.tabs.create({ url: url}); | 41 chrome.tabs.create({ url: url}); |
50 else | 42 else |
51 window.open(url); | 43 window.open(url); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 // We should not change zoom level when we are responsible for initiating | 172 // We should not change zoom level when we are responsible for initiating |
181 // the zoom. onZoomChange() is called before setZoomComplete() callback | 173 // the zoom. onZoomChange() is called before setZoomComplete() callback |
182 // when we initiate the zoom. | 174 // when we initiate the zoom. |
183 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 175 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
184 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 176 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
185 }.bind(this)); | 177 }.bind(this)); |
186 } | 178 } |
187 | 179 |
188 // Parse open pdf parameters. | 180 // Parse open pdf parameters. |
189 this.paramsParser_ = new OpenPDFParamsParser(); | 181 this.paramsParser_ = new OpenPDFParamsParser(); |
190 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, | 182 this.navigator_ = new Navigator( |
191 this.viewport_, this.paramsParser_, onNavigateInCurrentTab, | 183 this.streamDetails_.originalUrl, this.viewport_, this.paramsParser_, |
192 onNavigateInNewTab); | 184 this.onNavigateInCurrentTab_.bind(this), onNavigateInNewTab); |
raymes
2015/02/12 22:19:05
This shouldn't change
| |
193 } | 185 } |
194 | 186 |
195 PDFViewer.prototype = { | 187 PDFViewer.prototype = { |
196 /** | 188 /** |
197 * @private | 189 * @private |
198 * Handle key events. These may come from the user directly or via the | 190 * Handle key events. These may come from the user directly or via the |
199 * scripting API. | 191 * scripting API. |
200 * @param {KeyboardEvent} e the event to handle. | 192 * @param {KeyboardEvent} e the event to handle. |
201 */ | 193 */ |
202 handleKeyEvent_: function(e) { | 194 handleKeyEvent_: function(e) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 rotateCounterClockwise_: function() { | 329 rotateCounterClockwise_: function() { |
338 this.plugin_.postMessage({ | 330 this.plugin_.postMessage({ |
339 type: 'rotateCounterclockwise' | 331 type: 'rotateCounterclockwise' |
340 }); | 332 }); |
341 }, | 333 }, |
342 | 334 |
343 /** | 335 /** |
344 * @private | 336 * @private |
345 * Notify the plugin to print. | 337 * Notify the plugin to print. |
346 */ | 338 */ |
347 print_: function() { | 339 print_: function() { this.plugin_.postMessage({type: 'print'}); }, |
348 this.plugin_.postMessage({ | |
349 type: 'print' | |
350 }); | |
351 }, | |
352 | 340 |
353 /** | 341 /** |
354 * @private | 342 * @private |
355 * Notify the plugin to save. | 343 * Notify the plugin to save. |
356 */ | 344 */ |
357 save_: function() { | 345 save_: function() { this.plugin_.postMessage({type: 'save'}); }, |
raymes
2015/02/12 22:19:05
nit: don't change these
| |
346 | |
347 /** | |
348 * @private | |
349 * Callback to fetch namedDestination from plugin. | |
350 */ | |
351 namedDestCallback_: function(namedDestination, url) { | |
raymes
2015/02/12 22:19:05
This should be called getNamedDestination(name)
| |
358 this.plugin_.postMessage({ | 352 this.plugin_.postMessage({ |
359 type: 'save' | 353 type: 'getNamedDestination', |
354 namedDestination: namedDestination, | |
355 navigationUrl: url | |
360 }); | 356 }); |
361 }, | 357 }, |
362 | 358 |
363 /** | 359 /** |
360 * Called when navigation happens in the current tab. | |
361 * @param {string} url The url to be opened in the current tab. | |
362 */ | |
363 onNavigateInCurrentTab_: function(url) { | |
364 var pageNumber = | |
365 this.paramsParser_.getViewportFromUrlParams( | |
366 url, this.namedDestCallback_.bind(this), true) | |
367 .page; | |
368 if (pageNumber != undefined && pageNumber != -1) | |
369 this.viewport_.goToPage(pageNumber); | |
370 else | |
371 window.location.href = url; | |
372 }, | |
raymes
2015/02/12 22:19:05
This shouldn't be here
| |
373 | |
374 | |
375 /** | |
364 * @private | 376 * @private |
365 * Handle open pdf parameters. This function updates the viewport as per | 377 * Handle open pdf parameters. This function updates the viewport as per |
366 * the parameters mentioned in the url while opening pdf. The order is | 378 * the parameters mentioned in the url while opening pdf. The order is |
367 * important as later actions can override the effects of previous actions. | 379 * important as later actions can override the effects of previous actions. |
368 */ | 380 */ |
369 handleURLParams_: function() { | 381 handleURLParams_: function() { |
370 var urlParams = | 382 var urlParams = this.paramsParser_.getViewportFromUrlParams( |
371 this.paramsParser_.getViewportFromUrlParams( | 383 this.streamDetails_.originalUrl, this.namedDestCallback_.bind(this), |
372 this.streamDetails_.originalUrl); | 384 false); |
raymes
2015/02/12 22:19:05
This should look like
this.parmsParser_.getViewpo
| |
373 if (urlParams.page) | 385 if (urlParams.page && urlParams.page != -1) |
374 this.viewport_.goToPage(urlParams.page); | 386 this.viewport_.goToPage(urlParams.page); |
375 if (urlParams.position) { | 387 if (urlParams.position) { |
376 // Make sure we don't cancel effect of page parameter. | 388 // Make sure we don't cancel effect of page parameter. |
377 this.viewport_.position = { | 389 this.viewport_.position = { |
378 x: this.viewport_.position.x + urlParams.position.x, | 390 x: this.viewport_.position.x + urlParams.position.x, |
379 y: this.viewport_.position.y + urlParams.position.y | 391 y: this.viewport_.position.y + urlParams.position.y |
380 }; | 392 }; |
381 } | 393 } |
382 if (urlParams.zoom) | 394 if (urlParams.zoom) |
383 this.viewport_.setZoom(urlParams.zoom); | 395 this.viewport_.setZoom(urlParams.zoom); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 // can dismiss the password screen. | 459 // can dismiss the password screen. |
448 if (this.passwordScreen_.active) | 460 if (this.passwordScreen_.active) |
449 this.passwordScreen_.accept(); | 461 this.passwordScreen_.accept(); |
450 | 462 |
451 if (this.isMaterial_) { | 463 if (this.isMaterial_) { |
452 this.materialToolbar_.docLength = | 464 this.materialToolbar_.docLength = |
453 this.documentDimensions_.pageDimensions.length; | 465 this.documentDimensions_.pageDimensions.length; |
454 } else { | 466 } else { |
455 this.pageIndicator_.initialFadeIn(); | 467 this.pageIndicator_.initialFadeIn(); |
456 } | 468 } |
457 | |
458 this.toolbar_.initialFadeIn(); | 469 this.toolbar_.initialFadeIn(); |
459 break; | 470 break; |
460 case 'email': | 471 case 'email': |
461 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + | 472 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + |
462 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + | 473 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + |
463 '&body=' + message.data.body; | 474 '&body=' + message.data.body; |
464 window.location.href = href; | 475 window.location.href = href; |
465 break; | 476 break; |
466 case 'getAccessibilityJSONReply': | 477 case 'getAccessibilityJSONReply': |
467 this.sendScriptingMessage_(message.data); | 478 this.sendScriptingMessage_(message.data); |
(...skipping 15 matching lines...) Expand all Loading... | |
483 case 'loadProgress': | 494 case 'loadProgress': |
484 this.updateProgress_(message.data.progress); | 495 this.updateProgress_(message.data.progress); |
485 break; | 496 break; |
486 case 'navigate': | 497 case 'navigate': |
487 // If in print preview, always open a new tab. | 498 // If in print preview, always open a new tab. |
488 if (this.isPrintPreview_) | 499 if (this.isPrintPreview_) |
489 this.navigator_.navigate(message.data.url, true); | 500 this.navigator_.navigate(message.data.url, true); |
490 else | 501 else |
491 this.navigator_.navigate(message.data.url, message.data.newTab); | 502 this.navigator_.navigate(message.data.url, message.data.newTab); |
492 break; | 503 break; |
493 case 'setNamedDestinations': | |
494 this.paramsParser_.namedDestinations = message.data.namedDestinations; | |
495 break; | |
496 case 'setScrollPosition': | 504 case 'setScrollPosition': |
497 var position = this.viewport_.position; | 505 var position = this.viewport_.position; |
498 if (message.data.x !== undefined) | 506 if (message.data.x !== undefined) |
499 position.x = message.data.x; | 507 position.x = message.data.x; |
500 if (message.data.y !== undefined) | 508 if (message.data.y !== undefined) |
501 position.y = message.data.y; | 509 position.y = message.data.y; |
502 this.viewport_.position = position; | 510 this.viewport_.position = position; |
503 break; | 511 break; |
504 case 'setTranslatedStrings': | 512 case 'setTranslatedStrings': |
505 this.passwordScreen_.text = message.data.getPasswordString; | 513 this.passwordScreen_.text = message.data.getPasswordString; |
506 if (!this.isMaterial_) { | 514 if (!this.isMaterial_) { |
507 this.progressBar_.text = message.data.loadingString; | 515 this.progressBar_.text = message.data.loadingString; |
508 if (!this.isPrintPreview_) | 516 if (!this.isPrintPreview_) |
509 this.progressBar_.style.visibility = 'visible'; | 517 this.progressBar_.style.visibility = 'visible'; |
510 } | 518 } |
511 this.errorScreen_.text = message.data.loadFailedString; | 519 this.errorScreen_.text = message.data.loadFailedString; |
512 break; | 520 break; |
513 case 'cancelStreamUrl': | 521 case 'cancelStreamUrl': |
514 chrome.mimeHandlerPrivate.abortStream(); | 522 chrome.mimeHandlerPrivate.abortStream(); |
515 break; | 523 break; |
516 case 'bookmarks': | 524 case 'bookmarks': |
517 this.bookmarks_ = message.data.bookmarks; | 525 this.bookmarks_ = message.data.bookmarks; |
518 if (this.isMaterial_) | 526 if (this.isMaterial_) |
519 this.bookmarksPane_.bookmarks = message.data.bookmarks; | 527 this.bookmarksPane_.bookmarks = message.data.bookmarks; |
520 break; | 528 break; |
529 case 'getNamedDestinationReply': | |
raymes
2015/02/12 22:19:05
this should just call: this.paramsParser_.onNamedD
| |
530 if (message.data.namedDestinationPageNumber != undefined) | |
531 this.viewport_.goToPage(message.data.namedDestinationPageNumber); | |
532 else if (message.data.navigationUrl) | |
533 window.location.href = message.data.navigationUrl; | |
534 break; | |
521 } | 535 } |
522 }, | 536 }, |
523 | 537 |
524 /** | 538 /** |
525 * @private | 539 * @private |
526 * A callback that's called before the zoom changes. Notify the plugin to stop | 540 * A callback that's called before the zoom changes. Notify the plugin to stop |
527 * reacting to scroll events while zoom is taking place to avoid flickering. | 541 * reacting to scroll events while zoom is taking place to avoid flickering. |
528 */ | 542 */ |
529 beforeZoom_: function() { | 543 beforeZoom_: function() { |
530 this.plugin_.postMessage({ | 544 this.plugin_.postMessage({ |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 * Each bookmark is an Object containing a: | 773 * Each bookmark is an Object containing a: |
760 * - title | 774 * - title |
761 * - page (optional) | 775 * - page (optional) |
762 * - array of children (themselves bookmarks) | 776 * - array of children (themselves bookmarks) |
763 * @type {Array} the top-level bookmarks of the PDF. | 777 * @type {Array} the top-level bookmarks of the PDF. |
764 */ | 778 */ |
765 get bookmarks() { | 779 get bookmarks() { |
766 return this.bookmarks_; | 780 return this.bookmarks_; |
767 } | 781 } |
768 }; | 782 }; |
OLD | NEW |