Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 * @param {Object} streamDetails The stream object which points to the data | 43 * @param {Object} streamDetails The stream object which points to the data |
| 44 * contained in the PDF. | 44 * contained in the PDF. |
| 45 */ | 45 */ |
| 46 function PDFViewer(streamDetails) { | 46 function PDFViewer(streamDetails) { |
| 47 this.streamDetails_ = streamDetails; | 47 this.streamDetails_ = streamDetails; |
| 48 this.loaded_ = false; | 48 this.loaded_ = false; |
| 49 this.parentWindow_ = null; | 49 this.parentWindow_ = null; |
| 50 | 50 |
| 51 this.isPrintPreview_ = | 51 this.isPrintPreview_ = |
| 52 this.streamDetails_.originalUrl.indexOf('chrome://print') == 0; | 52 this.streamDetails_.originalUrl.indexOf('chrome://print') == 0; |
| 53 this.isMaterial_ = location.pathname.substring(1) == 'index-material.html'; | |
| 53 | 54 |
| 54 // The sizer element is placed behind the plugin element to cause scrollbars | 55 // The sizer element is placed behind the plugin element to cause scrollbars |
| 55 // to be displayed in the window. It is sized according to the document size | 56 // to be displayed in the window. It is sized according to the document size |
| 56 // of the pdf and zoom level. | 57 // of the pdf and zoom level. |
| 57 this.sizer_ = $('sizer'); | 58 this.sizer_ = $('sizer'); |
| 58 this.toolbar_ = $('toolbar'); | 59 this.toolbar_ = $('toolbar'); |
| 59 this.pageIndicator_ = $('page-indicator'); | 60 this.pageIndicator_ = $('page-indicator'); |
| 60 this.progressBar_ = $('progress-bar'); | 61 this.progressBar_ = $('progress-bar'); |
| 61 this.passwordScreen_ = $('password-screen'); | 62 this.passwordScreen_ = $('password-screen'); |
| 62 this.passwordScreen_.addEventListener('password-submitted', | 63 this.passwordScreen_.addEventListener('password-submitted', |
| 63 this.onPasswordSubmitted_.bind(this)); | 64 this.onPasswordSubmitted_.bind(this)); |
| 64 this.errorScreen_ = $('error-screen'); | 65 this.errorScreen_ = $('error-screen'); |
| 66 this.toolbarHeight_ = this.isMaterial_ ? $('pdf-toolbar').clientHeight : 0; | |
| 65 | 67 |
| 66 // Create the viewport. | 68 // Create the viewport. |
| 67 this.viewport_ = new Viewport(window, | 69 this.viewport_ = new Viewport(window, |
| 68 this.sizer_, | 70 this.sizer_, |
| 69 this.viewportChanged_.bind(this), | 71 this.viewportChanged_.bind(this), |
| 70 this.beforeZoom_.bind(this), | 72 this.beforeZoom_.bind(this), |
| 71 this.afterZoom_.bind(this), | 73 this.afterZoom_.bind(this), |
| 72 getScrollbarWidth()); | 74 getScrollbarWidth(), |
| 75 this.toolbarHeight_); | |
| 73 // Create the plugin object dynamically so we can set its src. The plugin | 76 // Create the plugin object dynamically so we can set its src. The plugin |
| 74 // element is sized to fill the entire window and is set to be fixed | 77 // element is sized to fill the entire window and is set to be fixed |
| 75 // positioning, acting as a viewport. The plugin renders into this viewport | 78 // positioning, acting as a viewport. The plugin renders into this viewport |
| 76 // according to the scroll position of the window. | 79 // according to the scroll position of the window. |
| 77 this.plugin_ = document.createElement('embed'); | 80 this.plugin_ = document.createElement('embed'); |
| 78 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 81 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
| 79 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 82 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
| 80 this.plugin_.id = 'plugin'; | 83 this.plugin_.id = 'plugin'; |
| 81 this.plugin_.type = 'application/x-google-chrome-pdf'; | 84 this.plugin_.type = 'application/x-google-chrome-pdf'; |
| 82 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), | 85 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), |
| 83 false); | 86 false); |
| 87 if (this.isMaterial_) { | |
| 88 this.plugin_.style.height = | |
| 89 (window.innerHeight - this.toolbarHeight_) + 'px'; | |
|
raymes
2015/01/20 23:00:10
Let's add back the width setting here.
Alexandre Carlton
2015/01/20 23:19:17
Done.
| |
| 90 } | |
| 84 | 91 |
| 85 // Handle scripting messages from outside the extension that wish to interact | 92 // Handle scripting messages from outside the extension that wish to interact |
| 86 // with it. We also send a message indicating that extension has loaded and | 93 // with it. We also send a message indicating that extension has loaded and |
| 87 // is ready to receive messages. | 94 // is ready to receive messages. |
| 88 window.addEventListener('message', this.handleScriptingMessage.bind(this), | 95 window.addEventListener('message', this.handleScriptingMessage.bind(this), |
| 89 false); | 96 false); |
| 90 | 97 |
| 91 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); | 98 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); |
| 99 if (this.isMaterial_) | |
| 100 $('title').textContent = document.title; | |
| 92 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); | 101 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); |
| 93 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); | 102 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); |
| 94 var headers = ''; | 103 var headers = ''; |
| 95 for (var header in this.streamDetails_.responseHeaders) { | 104 for (var header in this.streamDetails_.responseHeaders) { |
| 96 headers += header + ': ' + | 105 headers += header + ': ' + |
| 97 this.streamDetails_.responseHeaders[header] + '\n'; | 106 this.streamDetails_.responseHeaders[header] + '\n'; |
| 98 } | 107 } |
| 99 this.plugin_.setAttribute('headers', headers); | 108 this.plugin_.setAttribute('headers', headers); |
| 100 | 109 |
| 101 if (!this.streamDetails_.embedded) | 110 if (!this.streamDetails_.embedded) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 this.viewport_.setZoom(urlParams.zoom); | 312 this.viewport_.setZoom(urlParams.zoom); |
| 304 }, | 313 }, |
| 305 | 314 |
| 306 /** | 315 /** |
| 307 * @private | 316 * @private |
| 308 * Update the loading progress of the document in response to a progress | 317 * Update the loading progress of the document in response to a progress |
| 309 * message being received from the plugin. | 318 * message being received from the plugin. |
| 310 * @param {number} progress the progress as a percentage. | 319 * @param {number} progress the progress as a percentage. |
| 311 */ | 320 */ |
| 312 updateProgress_: function(progress) { | 321 updateProgress_: function(progress) { |
| 313 this.progressBar_.progress = progress; | 322 if (this.isMaterial_) |
| 323 this.progressBar_.value = progress; | |
| 324 else | |
| 325 this.progressBar_.progress = progress; | |
| 326 | |
| 314 if (progress == -1) { | 327 if (progress == -1) { |
| 315 // Document load failed. | 328 // Document load failed. |
| 316 this.errorScreen_.style.visibility = 'visible'; | 329 this.errorScreen_.style.visibility = 'visible'; |
| 317 this.sizer_.style.display = 'none'; | 330 this.sizer_.style.display = 'none'; |
| 318 this.toolbar_.style.visibility = 'hidden'; | 331 this.toolbar_.style.visibility = 'hidden'; |
| 319 if (this.passwordScreen_.active) { | 332 if (this.passwordScreen_.active) { |
| 320 this.passwordScreen_.deny(); | 333 this.passwordScreen_.deny(); |
| 321 this.passwordScreen_.active = false; | 334 this.passwordScreen_.active = false; |
| 322 } | 335 } |
| 323 } else if (progress == 100) { | 336 } else if (progress == 100) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 }, | 549 }, |
| 537 | 550 |
| 538 /** | 551 /** |
| 539 * @private | 552 * @private |
| 540 * A callback that's called after the viewport changes. | 553 * A callback that's called after the viewport changes. |
| 541 */ | 554 */ |
| 542 viewportChanged_: function() { | 555 viewportChanged_: function() { |
| 543 if (!this.documentDimensions_) | 556 if (!this.documentDimensions_) |
| 544 return; | 557 return; |
| 545 | 558 |
| 559 if (this.isMaterial_) { | |
| 560 this.plugin_.style.height = | |
| 561 (window.innerHeight - this.toolbarHeight_) + 'px'; | |
|
raymes
2015/01/20 23:00:10
Let's add back the width setting here.
Alexandre Carlton
2015/01/20 23:19:17
Done.
| |
| 562 } | |
| 563 | |
| 546 // Update the buttons selected. | 564 // Update the buttons selected. |
| 547 $('fit-to-page-button').classList.remove('polymer-selected'); | 565 $('fit-to-page-button').classList.remove('polymer-selected'); |
| 548 $('fit-to-width-button').classList.remove('polymer-selected'); | 566 $('fit-to-width-button').classList.remove('polymer-selected'); |
| 549 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 567 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
| 550 $('fit-to-page-button').classList.add('polymer-selected'); | 568 $('fit-to-page-button').classList.add('polymer-selected'); |
| 551 } else if (this.viewport_.fittingType == | 569 } else if (this.viewport_.fittingType == |
| 552 Viewport.FittingType.FIT_TO_WIDTH) { | 570 Viewport.FittingType.FIT_TO_WIDTH) { |
| 553 $('fit-to-width-button').classList.add('polymer-selected'); | 571 $('fit-to-width-button').classList.add('polymer-selected'); |
| 554 } | 572 } |
| 555 | 573 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 this.streamDetails_.tabId != -1); | 702 this.streamDetails_.tabId != -1); |
| 685 }, | 703 }, |
| 686 | 704 |
| 687 /** | 705 /** |
| 688 * @type {Viewport} the viewport of the PDF viewer. | 706 * @type {Viewport} the viewport of the PDF viewer. |
| 689 */ | 707 */ |
| 690 get viewport() { | 708 get viewport() { |
| 691 return this.viewport_; | 709 return this.viewport_; |
| 692 } | 710 } |
| 693 }; | 711 }; |
| OLD | NEW |