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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 /** | 88 /** |
89 * Creates a new PDFViewer. There should only be one of these objects per | 89 * Creates a new PDFViewer. There should only be one of these objects per |
90 * document. | 90 * document. |
91 * @constructor | 91 * @constructor |
92 * @param {!BrowserApi} browserApi An object providing an API to the browser. | 92 * @param {!BrowserApi} browserApi An object providing an API to the browser. |
93 */ | 93 */ |
94 function PDFViewer(browserApi) { | 94 function PDFViewer(browserApi) { |
95 this.browserApi_ = browserApi; | 95 this.browserApi_ = browserApi; |
96 this.originalUrl_ = this.browserApi_.getStreamInfo().originalUrl; | 96 this.originalUrl_ = this.browserApi_.getStreamInfo().originalUrl; |
| 97 this.actualUrl_ = null; |
97 this.loadState_ = LoadState.LOADING; | 98 this.loadState_ = LoadState.LOADING; |
98 this.parentWindow_ = null; | 99 this.parentWindow_ = null; |
99 this.parentOrigin_ = null; | 100 this.parentOrigin_ = null; |
100 this.isFormFieldFocused_ = false; | 101 this.isFormFieldFocused_ = false; |
101 | 102 |
102 this.delayedScriptingMessages_ = []; | 103 this.delayedScriptingMessages_ = []; |
103 | 104 |
104 this.isPrintPreview_ = this.originalUrl_.startsWith('chrome://print'); | 105 this.isPrintPreview_ = this.originalUrl_.startsWith('chrome://print'); |
105 | 106 |
106 // Parse open pdf parameters. | 107 // Parse open pdf parameters. |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 this.passwordScreen_.active = true; | 596 this.passwordScreen_.active = true; |
596 else | 597 else |
597 this.passwordScreen_.deny(); | 598 this.passwordScreen_.deny(); |
598 break; | 599 break; |
599 case 'getSelectedTextReply': | 600 case 'getSelectedTextReply': |
600 this.sendScriptingMessage_(message.data); | 601 this.sendScriptingMessage_(message.data); |
601 break; | 602 break; |
602 case 'goToPage': | 603 case 'goToPage': |
603 this.viewport_.goToPage(message.data.page); | 604 this.viewport_.goToPage(message.data.page); |
604 break; | 605 break; |
| 606 case 'gotActualURL': |
| 607 this.actualUrl_ = message.data.actualURL; |
| 608 break; |
605 case 'loadProgress': | 609 case 'loadProgress': |
606 this.updateProgress_(message.data.progress); | 610 this.updateProgress_(message.data.progress); |
607 break; | 611 break; |
608 case 'navigate': | 612 case 'navigate': |
609 // If in print preview, always open a new tab. | 613 // If in print preview, always open a new tab. |
610 if (this.isPrintPreview_) { | 614 if (this.isPrintPreview_) { |
611 this.navigator_.navigate( | 615 this.navigator_.navigate( |
612 message.data.url, | 616 message.data.url, |
613 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB); | 617 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB); |
614 } else { | 618 } else { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 if (this.parentWindow_ && this.parentOrigin_) { | 839 if (this.parentWindow_ && this.parentOrigin_) { |
836 var targetOrigin; | 840 var targetOrigin; |
837 // Only send data back to the embedder if it is from the same origin, | 841 // Only send data back to the embedder if it is from the same origin, |
838 // unless we're sending it to ourselves (which could happen in the case | 842 // unless we're sending it to ourselves (which could happen in the case |
839 // of tests). We also allow documentLoaded messages through as this won't | 843 // of tests). We also allow documentLoaded messages through as this won't |
840 // leak important information. | 844 // leak important information. |
841 if (this.parentOrigin_ == window.location.origin) | 845 if (this.parentOrigin_ == window.location.origin) |
842 targetOrigin = this.parentOrigin_; | 846 targetOrigin = this.parentOrigin_; |
843 else if (message.type == 'documentLoaded') | 847 else if (message.type == 'documentLoaded') |
844 targetOrigin = '*'; | 848 targetOrigin = '*'; |
| 849 else if (this.actualUrl_) |
| 850 targetOrigin = this.actualUrl_; |
845 else | 851 else |
846 targetOrigin = this.originalUrl_; | 852 targetOrigin = this.originalUrl_; |
847 this.parentWindow_.postMessage(message, targetOrigin); | 853 this.parentWindow_.postMessage(message, targetOrigin); |
848 } | 854 } |
849 }, | 855 }, |
850 | 856 |
851 /** | 857 /** |
852 * @type {Viewport} the viewport of the PDF viewer. | 858 * @type {Viewport} the viewport of the PDF viewer. |
853 */ | 859 */ |
854 get viewport() { | 860 get viewport() { |
855 return this.viewport_; | 861 return this.viewport_; |
856 }, | 862 }, |
857 | 863 |
858 /** | 864 /** |
859 * Each bookmark is an Object containing a: | 865 * Each bookmark is an Object containing a: |
860 * - title | 866 * - title |
861 * - page (optional) | 867 * - page (optional) |
862 * - array of children (themselves bookmarks) | 868 * - array of children (themselves bookmarks) |
863 * @type {Array} the top-level bookmarks of the PDF. | 869 * @type {Array} the top-level bookmarks of the PDF. |
864 */ | 870 */ |
865 get bookmarks() { | 871 get bookmarks() { |
866 return this.bookmarks_; | 872 return this.bookmarks_; |
867 } | 873 } |
868 }; | 874 }; |
OLD | NEW |