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 29 matching lines...) Expand all Loading... |
40 * Creates a new PDFViewer. There should only be one of these objects per | 40 * Creates a new PDFViewer. There should only be one of these objects per |
41 * document. | 41 * document. |
42 * @param {Object} streamDetails The stream object which points to the data | 42 * @param {Object} streamDetails The stream object which points to the data |
43 * contained in the PDF. | 43 * contained in the PDF. |
44 */ | 44 */ |
45 function PDFViewer(streamDetails) { | 45 function PDFViewer(streamDetails) { |
46 this.streamDetails_ = streamDetails; | 46 this.streamDetails_ = streamDetails; |
47 this.loaded_ = false; | 47 this.loaded_ = false; |
48 this.parentWindow_ = null; | 48 this.parentWindow_ = null; |
49 | 49 |
| 50 this.isMaterial_ = location.pathname.substring(1) == 'index-material.html'; |
50 // The sizer element is placed behind the plugin element to cause scrollbars | 51 // The sizer element is placed behind the plugin element to cause scrollbars |
51 // to be displayed in the window. It is sized according to the document size | 52 // to be displayed in the window. It is sized according to the document size |
52 // of the pdf and zoom level. | 53 // of the pdf and zoom level. |
53 this.sizer_ = $('sizer'); | 54 this.sizer_ = $('sizer'); |
54 this.toolbar_ = $('toolbar'); | 55 this.toolbar_ = $('toolbar'); |
55 this.pageIndicator_ = $('page-indicator'); | 56 this.pageIndicator_ = $('page-indicator'); |
56 this.progressBar_ = $('progress-bar'); | 57 this.progressBar_ = $('progress-bar'); |
57 this.passwordScreen_ = $('password-screen'); | 58 this.passwordScreen_ = $('password-screen'); |
58 this.passwordScreen_.addEventListener('password-submitted', | 59 this.passwordScreen_.addEventListener('password-submitted', |
59 this.onPasswordSubmitted_.bind(this)); | 60 this.onPasswordSubmitted_.bind(this)); |
60 this.errorScreen_ = $('error-screen'); | 61 this.errorScreen_ = $('error-screen'); |
| 62 this.toolbarHeight_ = (this.isMaterial_) ? $('pdf-toolbar').clientHeight : 0; |
61 | 63 |
62 // Create the viewport. | 64 // Create the viewport. |
63 this.viewport_ = new Viewport(window, | 65 this.viewport_ = new Viewport(window, |
64 this.sizer_, | 66 this.sizer_, |
65 this.viewportChanged_.bind(this), | 67 this.viewportChanged_.bind(this), |
66 this.beforeZoom_.bind(this), | 68 this.beforeZoom_.bind(this), |
67 this.afterZoom_.bind(this), | 69 this.afterZoom_.bind(this), |
68 getScrollbarWidth()); | 70 getScrollbarWidth(), |
| 71 this.toolbarHeight_); |
69 // Create the plugin object dynamically so we can set its src. The plugin | 72 // Create the plugin object dynamically so we can set its src. The plugin |
70 // element is sized to fill the entire window and is set to be fixed | 73 // element is sized to fill the entire window and is set to be fixed |
71 // positioning, acting as a viewport. The plugin renders into this viewport | 74 // positioning, acting as a viewport. The plugin renders into this viewport |
72 // according to the scroll position of the window. | 75 // according to the scroll position of the window. |
73 this.plugin_ = document.createElement('embed'); | 76 this.plugin_ = document.createElement('embed'); |
74 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 77 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
75 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 78 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
76 this.plugin_.id = 'plugin'; | 79 this.plugin_.id = 'plugin'; |
77 this.plugin_.type = 'application/x-google-chrome-pdf'; | 80 this.plugin_.type = 'application/x-google-chrome-pdf'; |
78 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), | 81 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), |
79 false); | 82 false); |
| 83 this.plugin_.style.top = this.toolbarHeight_ + 'px'; |
| 84 this.plugin_.style.height = (window.innerHeight - this.toolbarHeight_) + 'px'; |
| 85 this.plugin_.style.width = window.innerWidth + 'px'; |
| 86 |
80 | 87 |
81 // Handle scripting messages from outside the extension that wish to interact | 88 // Handle scripting messages from outside the extension that wish to interact |
82 // with it. We also send a message indicating that extension has loaded and | 89 // with it. We also send a message indicating that extension has loaded and |
83 // is ready to receive messages. | 90 // is ready to receive messages. |
84 window.addEventListener('message', this.handleScriptingMessage.bind(this), | 91 window.addEventListener('message', this.handleScriptingMessage.bind(this), |
85 false); | 92 false); |
86 | 93 |
87 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); | 94 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); |
| 95 if (this.isMaterial_) |
| 96 $('title').innerHTML = document.title; |
88 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); | 97 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); |
89 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); | 98 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); |
90 var headers = ''; | 99 var headers = ''; |
91 for (var header in this.streamDetails_.responseHeaders) { | 100 for (var header in this.streamDetails_.responseHeaders) { |
92 headers += header + ': ' + | 101 headers += header + ': ' + |
93 this.streamDetails_.responseHeaders[header] + '\n'; | 102 this.streamDetails_.responseHeaders[header] + '\n'; |
94 } | 103 } |
95 this.plugin_.setAttribute('headers', headers); | 104 this.plugin_.setAttribute('headers', headers); |
96 | 105 |
97 if (!this.streamDetails_.embedded) | 106 if (!this.streamDetails_.embedded) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 this.viewport_.setZoom(this.urlParams_.zoom); | 306 this.viewport_.setZoom(this.urlParams_.zoom); |
298 }, | 307 }, |
299 | 308 |
300 /** | 309 /** |
301 * @private | 310 * @private |
302 * Update the loading progress of the document in response to a progress | 311 * Update the loading progress of the document in response to a progress |
303 * message being received from the plugin. | 312 * message being received from the plugin. |
304 * @param {number} progress the progress as a percentage. | 313 * @param {number} progress the progress as a percentage. |
305 */ | 314 */ |
306 updateProgress_: function(progress) { | 315 updateProgress_: function(progress) { |
307 this.progressBar_.progress = progress; | 316 if (this.isMaterial_) |
| 317 this.progressBar_.value = progress; |
| 318 else |
| 319 this.progressBar_.progress = progress; |
| 320 |
308 if (progress == -1) { | 321 if (progress == -1) { |
309 // Document load failed. | 322 // Document load failed. |
310 this.errorScreen_.style.visibility = 'visible'; | 323 this.errorScreen_.style.visibility = 'visible'; |
311 this.sizer_.style.display = 'none'; | 324 this.sizer_.style.display = 'none'; |
312 this.toolbar_.style.visibility = 'hidden'; | 325 this.toolbar_.style.visibility = 'hidden'; |
313 if (this.passwordScreen_.active) { | 326 if (this.passwordScreen_.active) { |
314 this.passwordScreen_.deny(); | 327 this.passwordScreen_.deny(); |
315 this.passwordScreen_.active = false; | 328 this.passwordScreen_.active = false; |
316 } | 329 } |
317 } else if (progress == 100) { | 330 } else if (progress == 100) { |
318 // Document load complete. | 331 // Document load complete. |
| 332 if (this.isMaterial_) |
| 333 this.progressBar_.style.visibility = 'hidden'; |
319 if (this.lastViewportPosition_) | 334 if (this.lastViewportPosition_) |
320 this.viewport_.position = this.lastViewportPosition_; | 335 this.viewport_.position = this.lastViewportPosition_; |
321 this.handleURLParams_(); | 336 this.handleURLParams_(); |
322 this.loaded_ = true; | 337 this.loaded_ = true; |
323 this.sendScriptingMessage_({ | 338 this.sendScriptingMessage_({ |
324 type: 'documentLoaded' | 339 type: 'documentLoaded' |
325 }); | 340 }); |
326 } | 341 } |
327 }, | 342 }, |
328 | 343 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 case 'setScrollPosition': | 406 case 'setScrollPosition': |
392 var position = this.viewport_.position; | 407 var position = this.viewport_.position; |
393 if (message.data.x != undefined) | 408 if (message.data.x != undefined) |
394 position.x = message.data.x; | 409 position.x = message.data.x; |
395 if (message.data.y != undefined) | 410 if (message.data.y != undefined) |
396 position.y = message.data.y; | 411 position.y = message.data.y; |
397 this.viewport_.position = position; | 412 this.viewport_.position = position; |
398 break; | 413 break; |
399 case 'setTranslatedStrings': | 414 case 'setTranslatedStrings': |
400 this.passwordScreen_.text = message.data.getPasswordString; | 415 this.passwordScreen_.text = message.data.getPasswordString; |
401 this.progressBar_.text = message.data.loadingString; | 416 if (!this.isMaterial_) |
| 417 this.progressBar_.text = message.data.loadingString; |
402 this.progressBar_.style.visibility = 'visible'; | 418 this.progressBar_.style.visibility = 'visible'; |
403 this.errorScreen_.text = message.data.loadFailedString; | 419 this.errorScreen_.text = message.data.loadFailedString; |
404 break; | 420 break; |
405 case 'cancelStreamUrl': | 421 case 'cancelStreamUrl': |
406 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); | 422 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); |
407 break; | 423 break; |
408 } | 424 } |
409 }, | 425 }, |
410 | 426 |
411 /** | 427 /** |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 this.streamDetails_.tabId != -1); | 617 this.streamDetails_.tabId != -1); |
602 }, | 618 }, |
603 | 619 |
604 /** | 620 /** |
605 * @type {Viewport} the viewport of the PDF viewer. | 621 * @type {Viewport} the viewport of the PDF viewer. |
606 */ | 622 */ |
607 get viewport() { | 623 get viewport() { |
608 return this.viewport_; | 624 return this.viewport_; |
609 } | 625 } |
610 }; | 626 }; |
OLD | NEW |