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

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

Issue 1308323007: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2490
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
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 716
716 /** 717 /**
717 * Handle a scripting message from outside the extension (typically sent by 718 * Handle a scripting message from outside the extension (typically sent by
718 * PDFScriptingAPI in a page containing the extension) to interact with the 719 * PDFScriptingAPI in a page containing the extension) to interact with the
719 * plugin. 720 * plugin.
720 * @param {MessageObject} message the message to handle. 721 * @param {MessageObject} message the message to handle.
721 */ 722 */
722 handleScriptingMessage: function(message) { 723 handleScriptingMessage: function(message) {
723 if (this.parentWindow_ != message.source) { 724 if (this.parentWindow_ != message.source) {
724 this.parentWindow_ = message.source; 725 this.parentWindow_ = message.source;
726 this.parentOrigin_ = message.origin;
725 // Ensure that we notify the embedder if the document is loaded. 727 // Ensure that we notify the embedder if the document is loaded.
726 if (this.loadState_ != LoadState.LOADING) 728 if (this.loadState_ != LoadState.LOADING)
727 this.sendDocumentLoadedMessage_(); 729 this.sendDocumentLoadedMessage_();
728 } 730 }
729 731
730 if (this.handlePrintPreviewScriptingMessage_(message)) 732 if (this.handlePrintPreviewScriptingMessage_(message))
731 return; 733 return;
732 734
733 // Delay scripting messages from users of the scripting API until the 735 // Delay scripting messages from users of the scripting API until the
734 // document is loaded. This simplifies use of the APIs. 736 // document is loaded. This simplifies use of the APIs.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return false; 803 return false;
802 }, 804 },
803 805
804 /** 806 /**
805 * @private 807 * @private
806 * Send a scripting message outside the extension (typically to 808 * Send a scripting message outside the extension (typically to
807 * PDFScriptingAPI in a page containing the extension). 809 * PDFScriptingAPI in a page containing the extension).
808 * @param {Object} message the message to send. 810 * @param {Object} message the message to send.
809 */ 811 */
810 sendScriptingMessage_: function(message) { 812 sendScriptingMessage_: function(message) {
811 if (this.parentWindow_) 813 if (this.parentWindow_ && this.parentOrigin_) {
812 this.parentWindow_.postMessage(message, '*'); 814 var targetOrigin;
815 // Only send data back to the embedder if it is from the same origin,
816 // unless we're sending it to ourselves (which could happen in the case
817 // of tests). We also allow documentLoaded messages through as this won't
818 // leak important information.
819 if (this.parentOrigin_ == window.location.origin)
820 targetOrigin = this.parentOrigin_;
821 else if (message.type == 'documentLoaded')
822 targetOrigin = '*';
823 else
824 targetOrigin = this.browserApi_.getStreamInfo().originalUrl;
825 this.parentWindow_.postMessage(message, targetOrigin);
826 }
813 }, 827 },
814 828
815
816 /** 829 /**
817 * @type {Viewport} the viewport of the PDF viewer. 830 * @type {Viewport} the viewport of the PDF viewer.
818 */ 831 */
819 get viewport() { 832 get viewport() {
820 return this.viewport_; 833 return this.viewport_;
821 }, 834 },
822 835
823 /** 836 /**
824 * Each bookmark is an Object containing a: 837 * Each bookmark is an Object containing a:
825 * - title 838 * - title
826 * - page (optional) 839 * - page (optional)
827 * - array of children (themselves bookmarks) 840 * - array of children (themselves bookmarks)
828 * @type {Array} the top-level bookmarks of the PDF. 841 * @type {Array} the top-level bookmarks of the PDF.
829 */ 842 */
830 get bookmarks() { 843 get bookmarks() {
831 return this.bookmarks_; 844 return this.bookmarks_;
832 } 845 }
833 }; 846 };
OLDNEW
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698