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

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

Issue 1316803003: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 /** 77 /**
78 * Creates a new PDFViewer. There should only be one of these objects per 78 * Creates a new PDFViewer. There should only be one of these objects per
79 * document. 79 * document.
80 * @constructor 80 * @constructor
81 * @param {!BrowserApi} browserApi An object providing an API to the browser. 81 * @param {!BrowserApi} browserApi An object providing an API to the browser.
82 */ 82 */
83 function PDFViewer(browserApi) { 83 function PDFViewer(browserApi) {
84 this.browserApi_ = browserApi; 84 this.browserApi_ = browserApi;
85 this.loadState_ = LoadState.LOADING; 85 this.loadState_ = LoadState.LOADING;
86 this.parentWindow_ = null; 86 this.parentWindow_ = null;
87 this.parentOrigin_ = null;
87 88
88 this.delayedScriptingMessages_ = []; 89 this.delayedScriptingMessages_ = [];
89 90
90 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( 91 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf(
91 'chrome://print') == 0; 92 'chrome://print') == 0;
92 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; 93 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html';
93 94
94 // The sizer element is placed behind the plugin element to cause scrollbars 95 // The sizer element is placed behind the plugin element to cause scrollbars
95 // to be displayed in the window. It is sized according to the document size 96 // to be displayed in the window. It is sized according to the document size
96 // of the pdf and zoom level. 97 // of the pdf and zoom level.
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 668
668 /** 669 /**
669 * Handle a scripting message from outside the extension (typically sent by 670 * Handle a scripting message from outside the extension (typically sent by
670 * PDFScriptingAPI in a page containing the extension) to interact with the 671 * PDFScriptingAPI in a page containing the extension) to interact with the
671 * plugin. 672 * plugin.
672 * @param {MessageObject} message the message to handle. 673 * @param {MessageObject} message the message to handle.
673 */ 674 */
674 handleScriptingMessage: function(message) { 675 handleScriptingMessage: function(message) {
675 if (this.parentWindow_ != message.source) { 676 if (this.parentWindow_ != message.source) {
676 this.parentWindow_ = message.source; 677 this.parentWindow_ = message.source;
678 this.parentOrigin_ = message.origin;
677 // Ensure that we notify the embedder if the document is loaded. 679 // Ensure that we notify the embedder if the document is loaded.
678 if (this.loadState_ != LoadState.LOADING) 680 if (this.loadState_ != LoadState.LOADING)
679 this.sendDocumentLoadedMessage_(); 681 this.sendDocumentLoadedMessage_();
680 } 682 }
681 683
682 if (this.handlePrintPreviewScriptingMessage_(message)) 684 if (this.handlePrintPreviewScriptingMessage_(message))
683 return; 685 return;
684 686
685 // Delay scripting messages from users of the scripting API until the 687 // Delay scripting messages from users of the scripting API until the
686 // document is loaded. This simplifies use of the APIs. 688 // document is loaded. This simplifies use of the APIs.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 return false; 755 return false;
754 }, 756 },
755 757
756 /** 758 /**
757 * @private 759 * @private
758 * Send a scripting message outside the extension (typically to 760 * Send a scripting message outside the extension (typically to
759 * PDFScriptingAPI in a page containing the extension). 761 * PDFScriptingAPI in a page containing the extension).
760 * @param {Object} message the message to send. 762 * @param {Object} message the message to send.
761 */ 763 */
762 sendScriptingMessage_: function(message) { 764 sendScriptingMessage_: function(message) {
763 if (this.parentWindow_) 765 if (this.parentWindow_ && this.parentOrigin_) {
764 this.parentWindow_.postMessage(message, '*'); 766 var targetOrigin;
767 // Only send data back to the embedder if it is from the same origin,
768 // unless we're sending it to ourselves (which could happen in the case
769 // of tests). We also allow documentLoaded messages through as this won't
770 // leak important information.
771 if (this.parentOrigin_ == window.location.origin)
772 targetOrigin = this.parentOrigin_;
773 else if (message.type == 'documentLoaded')
774 targetOrigin = '*';
775 else
776 targetOrigin = this.browserApi_.getStreamInfo().originalUrl;
777 this.parentWindow_.postMessage(message, targetOrigin);
778 }
765 }, 779 },
766 780
767
768 /** 781 /**
769 * @type {Viewport} the viewport of the PDF viewer. 782 * @type {Viewport} the viewport of the PDF viewer.
770 */ 783 */
771 get viewport() { 784 get viewport() {
772 return this.viewport_; 785 return this.viewport_;
773 }, 786 },
774 787
775 /** 788 /**
776 * Each bookmark is an Object containing a: 789 * Each bookmark is an Object containing a:
777 * - title 790 * - title
778 * - page (optional) 791 * - page (optional)
779 * - array of children (themselves bookmarks) 792 * - array of children (themselves bookmarks)
780 * @type {Array} the top-level bookmarks of the PDF. 793 * @type {Array} the top-level bookmarks of the PDF.
781 */ 794 */
782 get bookmarks() { 795 get bookmarks() {
783 return this.bookmarks_; 796 return this.bookmarks_;
784 } 797 }
785 }; 798 };
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