Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

Issue 1311973002: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.loadState_ = LoadState.LOADING; 96 this.loadState_ = LoadState.LOADING;
97 this.parentWindow_ = null; 97 this.parentWindow_ = null;
98 this.parentOrigin_ = null;
98 99
99 this.delayedScriptingMessages_ = []; 100 this.delayedScriptingMessages_ = [];
100 101
101 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( 102 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf(
102 'chrome://print') == 0; 103 'chrome://print') == 0;
103 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; 104 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html';
104 105
105 // The sizer element is placed behind the plugin element to cause scrollbars 106 // The sizer element is placed behind the plugin element to cause scrollbars
106 // to be displayed in the window. It is sized according to the document size 107 // to be displayed in the window. It is sized according to the document size
107 // of the pdf and zoom level. 108 // of the pdf and zoom level.
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 714
714 /** 715 /**
715 * Handle a scripting message from outside the extension (typically sent by 716 * Handle a scripting message from outside the extension (typically sent by
716 * PDFScriptingAPI in a page containing the extension) to interact with the 717 * PDFScriptingAPI in a page containing the extension) to interact with the
717 * plugin. 718 * plugin.
718 * @param {MessageObject} message the message to handle. 719 * @param {MessageObject} message the message to handle.
719 */ 720 */
720 handleScriptingMessage: function(message) { 721 handleScriptingMessage: function(message) {
721 if (this.parentWindow_ != message.source) { 722 if (this.parentWindow_ != message.source) {
722 this.parentWindow_ = message.source; 723 this.parentWindow_ = message.source;
724 this.parentOrigin_ = message.origin;
723 // Ensure that we notify the embedder if the document is loaded. 725 // Ensure that we notify the embedder if the document is loaded.
724 if (this.loadState_ != LoadState.LOADING) 726 if (this.loadState_ != LoadState.LOADING)
725 this.sendDocumentLoadedMessage_(); 727 this.sendDocumentLoadedMessage_();
726 } 728 }
727 729
728 if (this.handlePrintPreviewScriptingMessage_(message)) 730 if (this.handlePrintPreviewScriptingMessage_(message))
729 return; 731 return;
730 732
731 // Delay scripting messages from users of the scripting API until the 733 // Delay scripting messages from users of the scripting API until the
732 // document is loaded. This simplifies use of the APIs. 734 // document is loaded. This simplifies use of the APIs.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 return false; 801 return false;
800 }, 802 },
801 803
802 /** 804 /**
803 * @private 805 * @private
804 * Send a scripting message outside the extension (typically to 806 * Send a scripting message outside the extension (typically to
805 * PDFScriptingAPI in a page containing the extension). 807 * PDFScriptingAPI in a page containing the extension).
806 * @param {Object} message the message to send. 808 * @param {Object} message the message to send.
807 */ 809 */
808 sendScriptingMessage_: function(message) { 810 sendScriptingMessage_: function(message) {
809 if (this.parentWindow_) 811 if (this.parentWindow_ && this.parentOrigin_) {
810 this.parentWindow_.postMessage(message, '*'); 812 var targetOrigin;
813 // Only send data back to the embedder if it is from the same origin,
814 // unless we're sending it to ourselves (which could happen in the case
815 // of tests). We also allow documentLoaded messages through as this won't
816 // leak important information.
817 if (this.parentOrigin_ == window.location.origin)
818 targetOrigin = this.parentOrigin_;
819 else if (message.type == 'documentLoaded')
820 targetOrigin = '*';
821 else
822 targetOrigin = this.browserApi_.getStreamInfo().originalUrl;
823 this.parentWindow_.postMessage(message, targetOrigin);
824
825 // Dispatch an event which can be hooked into for testing.
826 window.dispatchEvent(new CustomEvent('scripting-message-sent',
Sam McNally 2015/08/25 03:11:20 Could you add an extra listener on the plugin obje
raymes 2015/08/25 04:02:23 Done.
827 { 'detail': { 'target': this.parentWindow_, 'message': message } }));
828 }
811 }, 829 },
812 830
813
814 /** 831 /**
815 * @type {Viewport} the viewport of the PDF viewer. 832 * @type {Viewport} the viewport of the PDF viewer.
816 */ 833 */
817 get viewport() { 834 get viewport() {
818 return this.viewport_; 835 return this.viewport_;
819 }, 836 },
820 837
821 /** 838 /**
822 * Each bookmark is an Object containing a: 839 * Each bookmark is an Object containing a:
823 * - title 840 * - title
824 * - page (optional) 841 * - page (optional)
825 * - array of children (themselves bookmarks) 842 * - array of children (themselves bookmarks)
826 * @type {Array} the top-level bookmarks of the PDF. 843 * @type {Array} the top-level bookmarks of the PDF.
827 */ 844 */
828 get bookmarks() { 845 get bookmarks() {
829 return this.bookmarks_; 846 return this.bookmarks_;
830 } 847 }
831 }; 848 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698