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