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 <include src="../../../../ui/webui/resources/js/util.js"> | 7 <include src="../../../../ui/webui/resources/js/util.js"> |
8 <include src="pdf_scripting_api.js"> | 8 <include src="pdf_scripting_api.js"> |
9 <include src="viewport.js"> | 9 <include src="viewport.js"> |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // with it. We also send a message indicating that extension has loaded and | 63 // with it. We also send a message indicating that extension has loaded and |
64 // is ready to receive messages. | 64 // is ready to receive messages. |
65 window.addEventListener('message', this.handleScriptingMessage_.bind(this), | 65 window.addEventListener('message', this.handleScriptingMessage_.bind(this), |
66 false); | 66 false); |
67 this.sendScriptingMessage_({type: 'readyToReceive'}); | 67 this.sendScriptingMessage_({type: 'readyToReceive'}); |
68 | 68 |
69 // If the viewer is started from a MIME type request, there will be a | 69 // If the viewer is started from a MIME type request, there will be a |
70 // background page and stream details object with the details of the request. | 70 // background page and stream details object with the details of the request. |
71 // Otherwise, we take the query string of the URL to indicate the URL of the | 71 // Otherwise, we take the query string of the URL to indicate the URL of the |
72 // PDF to load. This is used for print preview in particular. | 72 // PDF to load. This is used for print preview in particular. |
73 var streamDetails; | |
74 if (chrome.extension.getBackgroundPage && | 73 if (chrome.extension.getBackgroundPage && |
75 chrome.extension.getBackgroundPage()) { | 74 chrome.extension.getBackgroundPage()) { |
76 streamDetails = chrome.extension.getBackgroundPage().popStreamDetails(); | 75 this.streamDetails = |
76 chrome.extension.getBackgroundPage().popStreamDetails(); | |
77 } | 77 } |
78 | 78 |
79 if (!streamDetails) { | 79 if (!this.streamDetails) { |
80 // The URL of this page will be of the form | 80 // The URL of this page will be of the form |
81 // "chrome-extension://<extension id>?<pdf url>". We pull out the <pdf url> | 81 // "chrome-extension://<extension id>?<pdf url>". We pull out the <pdf url> |
82 // part here. | 82 // part here. |
83 var url = window.location.search.substring(1); | 83 var url = window.location.search.substring(1); |
84 streamDetails = { | 84 this.streamDetails = { |
85 streamUrl: url, | 85 streamUrl: url, |
86 originalUrl: url | 86 originalUrl: url, |
87 responseHeaders: '' | |
87 }; | 88 }; |
88 } | 89 } |
89 | 90 |
90 this.plugin_.setAttribute('src', streamDetails.streamUrl); | 91 this.plugin_.setAttribute('src', this.streamDetails.originalUrl); |
92 this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); | |
93 var headers = ''; | |
94 for (var header in this.streamDetails.responseHeaders) { | |
95 headers += header + ': ' + | |
Lei Zhang
2014/05/22 00:13:20
Are we likely to run into any parsing problems wit
| |
96 this.streamDetails.responseHeaders[header] + '\n'; | |
97 } | |
98 this.plugin_.setAttribute('headers', headers); | |
99 | |
91 if (window.top == window) | 100 if (window.top == window) |
92 this.plugin_.setAttribute('full-frame', ''); | 101 this.plugin_.setAttribute('full-frame', ''); |
93 document.body.appendChild(this.plugin_); | 102 document.body.appendChild(this.plugin_); |
94 | 103 |
95 this.setupEventListeners_(streamDetails); | 104 this.setupEventListeners_(); |
96 } | 105 } |
97 | 106 |
98 PDFViewer.prototype = { | 107 PDFViewer.prototype = { |
99 /** | 108 /** |
100 * @private | 109 * @private |
101 * Sets up event listeners for key shortcuts and also the UI buttons. | 110 * Sets up event listeners for key shortcuts and also the UI buttons. |
102 * @param {Object} streamDetails the details of the original HTTP request for | |
103 * the PDF. | |
104 */ | 111 */ |
105 setupEventListeners_: function(streamDetails) { | 112 setupEventListeners_: function() { |
106 // Setup the button event listeners. | 113 // Setup the button event listeners. |
107 $('fit-to-width-button').addEventListener('click', | 114 $('fit-to-width-button').addEventListener('click', |
108 this.viewport_.fitToWidth.bind(this.viewport_)); | 115 this.viewport_.fitToWidth.bind(this.viewport_)); |
109 $('fit-to-page-button').addEventListener('click', | 116 $('fit-to-page-button').addEventListener('click', |
110 this.viewport_.fitToPage.bind(this.viewport_)); | 117 this.viewport_.fitToPage.bind(this.viewport_)); |
111 $('zoom-in-button').addEventListener('click', | 118 $('zoom-in-button').addEventListener('click', |
112 this.viewport_.zoomIn.bind(this.viewport_)); | 119 this.viewport_.zoomIn.bind(this.viewport_)); |
113 $('zoom-out-button').addEventListener('click', | 120 $('zoom-out-button').addEventListener('click', |
114 this.viewport_.zoomOut.bind(this.viewport_)); | 121 this.viewport_.zoomOut.bind(this.viewport_)); |
115 $('save-button-link').href = streamDetails.originalUrl; | 122 $('save-button-link').href = this.streamDetails.originalUrl; |
116 $('print-button').addEventListener('click', this.print_.bind(this)); | 123 $('print-button').addEventListener('click', this.print_.bind(this)); |
117 | 124 |
118 // Setup keyboard event listeners. | 125 // Setup keyboard event listeners. |
119 document.onkeydown = function(e) { | 126 document.onkeydown = function(e) { |
120 switch (e.keyCode) { | 127 switch (e.keyCode) { |
121 case 37: // Left arrow key. | 128 case 37: // Left arrow key. |
122 // Go to the previous page if there are no horizontal scrollbars. | 129 // Go to the previous page if there are no horizontal scrollbars. |
123 if (!this.viewport_.documentHasScrollbars().x) { | 130 if (!this.viewport_.documentHasScrollbars().x) { |
124 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); | 131 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); |
125 // Since we do the movement of the page. | 132 // Since we do the movement of the page. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 position.x = message.data.x; | 287 position.x = message.data.x; |
281 if (message.data.y != undefined) | 288 if (message.data.y != undefined) |
282 position.y = message.data.y; | 289 position.y = message.data.y; |
283 this.viewport_.position = position; | 290 this.viewport_.position = position; |
284 break; | 291 break; |
285 case 'setTranslatedStrings': | 292 case 'setTranslatedStrings': |
286 this.passwordScreen_.text = message.data.getPasswordString; | 293 this.passwordScreen_.text = message.data.getPasswordString; |
287 this.progressBar_.text = message.data.loadingString; | 294 this.progressBar_.text = message.data.loadingString; |
288 this.errorScreen_.text = message.data.loadFailedString; | 295 this.errorScreen_.text = message.data.loadFailedString; |
289 break; | 296 break; |
297 case 'cancelStreamUrl': | |
298 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); | |
299 break; | |
290 } | 300 } |
291 }, | 301 }, |
292 | 302 |
293 /** | 303 /** |
294 * @private | 304 * @private |
295 * A callback that's called when the viewport changes. | 305 * A callback that's called when the viewport changes. |
296 */ | 306 */ |
297 viewportChangedCallback_: function() { | 307 viewportChangedCallback_: function() { |
298 if (!this.documentDimensions_) | 308 if (!this.documentDimensions_) |
299 return; | 309 return; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 | 417 |
408 /** | 418 /** |
409 * @type {Viewport} the viewport of the PDF viewer. | 419 * @type {Viewport} the viewport of the PDF viewer. |
410 */ | 420 */ |
411 get viewport() { | 421 get viewport() { |
412 return this.viewport_; | 422 return this.viewport_; |
413 } | 423 } |
414 }; | 424 }; |
415 | 425 |
416 var viewer = new PDFViewer(); | 426 var viewer = new PDFViewer(); |
OLD | NEW |