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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this.onPasswordSubmitted_.bind(this)); | 48 this.onPasswordSubmitted_.bind(this)); |
49 this.errorScreen_ = $('error-screen'); | 49 this.errorScreen_ = $('error-screen'); |
50 | 50 |
51 // Create the viewport. | 51 // Create the viewport. |
52 this.viewport_ = new Viewport(window, | 52 this.viewport_ = new Viewport(window, |
53 this.sizer_, | 53 this.sizer_, |
54 this.viewportChanged_.bind(this), | 54 this.viewportChanged_.bind(this), |
55 this.beforeZoom_.bind(this), | 55 this.beforeZoom_.bind(this), |
56 this.afterZoom_.bind(this), | 56 this.afterZoom_.bind(this), |
57 getScrollbarWidth()); | 57 getScrollbarWidth()); |
58 | 58 var isPrintPreview = |
| 59 this.streamDetails.originalUrl.indexOf('chrome://print') == 0; |
59 // Create the plugin object dynamically so we can set its src. The plugin | 60 // Create the plugin object dynamically so we can set its src. The plugin |
60 // element is sized to fill the entire window and is set to be fixed | 61 // element is sized to fill the entire window and is set to be fixed |
61 // positioning, acting as a viewport. The plugin renders into this viewport | 62 // positioning, acting as a viewport. The plugin renders into this viewport |
62 // according to the scroll position of the window. | 63 // according to the scroll position of the window. |
63 this.plugin_ = document.createElement('embed'); | 64 // |
| 65 // TODO(sammc): Remove special casing for print preview. This is currently |
| 66 // necessary because setting the src for an embed element triggers origin |
| 67 // checking and the PDF extension is not allowed to embed URLs with a scheme |
| 68 // of "chrome", which is used by print preview. |
| 69 this.plugin_ = document.createElement(isPrintPreview ? 'object' : 'embed'); |
64 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 70 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
65 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 71 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
66 this.plugin_.id = 'plugin'; | 72 this.plugin_.id = 'plugin'; |
67 this.plugin_.type = 'application/x-google-chrome-pdf'; | 73 this.plugin_.type = 'application/x-google-chrome-pdf'; |
68 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), | 74 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), |
69 false); | 75 false); |
70 | 76 |
71 // Handle scripting messages from outside the extension that wish to interact | 77 // Handle scripting messages from outside the extension that wish to interact |
72 // with it. We also send a message indicating that extension has loaded and | 78 // with it. We also send a message indicating that extension has loaded and |
73 // is ready to receive messages. | 79 // is ready to receive messages. |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 this.streamDetails.tabId != -1); | 591 this.streamDetails.tabId != -1); |
586 }, | 592 }, |
587 | 593 |
588 /** | 594 /** |
589 * @type {Viewport} the viewport of the PDF viewer. | 595 * @type {Viewport} the viewport of the PDF viewer. |
590 */ | 596 */ |
591 get viewport() { | 597 get viewport() { |
592 return this.viewport_; | 598 return this.viewport_; |
593 } | 599 } |
594 }; | 600 }; |
OLD | NEW |