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 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; | |
|
raymes
2015/01/13 06:24:50
nit: don't need the () around this.isMaterial_
| |
| 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 if (this.isMaterial_) { | |
| 84 this.plugin_.style.top = this.toolbarHeight_ + 'px'; | |
|
Sam McNally
2015/01/13 07:03:56
top and width can be set in the css file.
Alexandre Carlton
2015/01/14 22:42:50
Done for top; does width need to be set at all?
| |
| 85 this.plugin_.style.height = | |
| 86 (window.innerHeight - this.toolbarHeight_) + 'px'; | |
| 87 this.plugin_.style.width = window.innerWidth + 'px'; | |
| 88 } | |
| 89 | |
| 80 | 90 |
| 81 // Handle scripting messages from outside the extension that wish to interact | 91 // 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 | 92 // with it. We also send a message indicating that extension has loaded and |
| 83 // is ready to receive messages. | 93 // is ready to receive messages. |
| 84 window.addEventListener('message', this.handleScriptingMessage.bind(this), | 94 window.addEventListener('message', this.handleScriptingMessage.bind(this), |
| 85 false); | 95 false); |
| 86 | 96 |
| 87 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); | 97 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); |
| 98 if (this.isMaterial_) | |
| 99 $('title').innerHTML = document.title; | |
|
Sam McNally
2015/01/13 07:03:56
$('title').textContent
| |
| 88 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); | 100 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); |
| 89 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); | 101 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); |
| 90 var headers = ''; | 102 var headers = ''; |
| 91 for (var header in this.streamDetails_.responseHeaders) { | 103 for (var header in this.streamDetails_.responseHeaders) { |
| 92 headers += header + ': ' + | 104 headers += header + ': ' + |
| 93 this.streamDetails_.responseHeaders[header] + '\n'; | 105 this.streamDetails_.responseHeaders[header] + '\n'; |
| 94 } | 106 } |
| 95 this.plugin_.setAttribute('headers', headers); | 107 this.plugin_.setAttribute('headers', headers); |
| 96 | 108 |
| 97 if (!this.streamDetails_.embedded) | 109 if (!this.streamDetails_.embedded) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 this.viewport_.setZoom(this.urlParams_.zoom); | 309 this.viewport_.setZoom(this.urlParams_.zoom); |
| 298 }, | 310 }, |
| 299 | 311 |
| 300 /** | 312 /** |
| 301 * @private | 313 * @private |
| 302 * Update the loading progress of the document in response to a progress | 314 * Update the loading progress of the document in response to a progress |
| 303 * message being received from the plugin. | 315 * message being received from the plugin. |
| 304 * @param {number} progress the progress as a percentage. | 316 * @param {number} progress the progress as a percentage. |
| 305 */ | 317 */ |
| 306 updateProgress_: function(progress) { | 318 updateProgress_: function(progress) { |
| 307 this.progressBar_.progress = progress; | 319 if (this.isMaterial_) |
| 320 this.progressBar_.value = progress; | |
| 321 else | |
| 322 this.progressBar_.progress = progress; | |
| 323 | |
| 308 if (progress == -1) { | 324 if (progress == -1) { |
| 309 // Document load failed. | 325 // Document load failed. |
| 310 this.errorScreen_.style.visibility = 'visible'; | 326 this.errorScreen_.style.visibility = 'visible'; |
| 311 this.sizer_.style.display = 'none'; | 327 this.sizer_.style.display = 'none'; |
| 312 this.toolbar_.style.visibility = 'hidden'; | 328 this.toolbar_.style.visibility = 'hidden'; |
| 313 if (this.passwordScreen_.active) { | 329 if (this.passwordScreen_.active) { |
| 314 this.passwordScreen_.deny(); | 330 this.passwordScreen_.deny(); |
| 315 this.passwordScreen_.active = false; | 331 this.passwordScreen_.active = false; |
| 316 } | 332 } |
| 317 } else if (progress == 100) { | 333 } else if (progress == 100) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 case 'setScrollPosition': | 407 case 'setScrollPosition': |
| 392 var position = this.viewport_.position; | 408 var position = this.viewport_.position; |
| 393 if (message.data.x != undefined) | 409 if (message.data.x != undefined) |
| 394 position.x = message.data.x; | 410 position.x = message.data.x; |
| 395 if (message.data.y != undefined) | 411 if (message.data.y != undefined) |
| 396 position.y = message.data.y; | 412 position.y = message.data.y; |
| 397 this.viewport_.position = position; | 413 this.viewport_.position = position; |
| 398 break; | 414 break; |
| 399 case 'setTranslatedStrings': | 415 case 'setTranslatedStrings': |
| 400 this.passwordScreen_.text = message.data.getPasswordString; | 416 this.passwordScreen_.text = message.data.getPasswordString; |
| 401 this.progressBar_.text = message.data.loadingString; | 417 if (!this.isMaterial_) |
| 418 this.progressBar_.text = message.data.loadingString; | |
| 402 this.progressBar_.style.visibility = 'visible'; | 419 this.progressBar_.style.visibility = 'visible'; |
| 403 this.errorScreen_.text = message.data.loadFailedString; | 420 this.errorScreen_.text = message.data.loadFailedString; |
| 404 break; | 421 break; |
| 405 case 'cancelStreamUrl': | 422 case 'cancelStreamUrl': |
| 406 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); | 423 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); |
| 407 break; | 424 break; |
| 408 } | 425 } |
| 409 }, | 426 }, |
| 410 | 427 |
| 411 /** | 428 /** |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 }, | 476 }, |
| 460 | 477 |
| 461 /** | 478 /** |
| 462 * @private | 479 * @private |
| 463 * A callback that's called after the viewport changes. | 480 * A callback that's called after the viewport changes. |
| 464 */ | 481 */ |
| 465 viewportChanged_: function() { | 482 viewportChanged_: function() { |
| 466 if (!this.documentDimensions_) | 483 if (!this.documentDimensions_) |
| 467 return; | 484 return; |
| 468 | 485 |
| 486 if (this.isMaterial_) { | |
| 487 this.plugin_.style.height = | |
| 488 (window.innerHeight - this.toolbarHeight_) + 'px'; | |
| 489 this.plugin_.style.height = window.innerWidth; | |
|
Sam McNally
2015/01/13 07:03:56
this.plugin_.style.width.
I think it's worth skipp
| |
| 490 } | |
| 491 | |
| 469 // Update the buttons selected. | 492 // Update the buttons selected. |
| 470 $('fit-to-page-button').classList.remove('polymer-selected'); | 493 $('fit-to-page-button').classList.remove('polymer-selected'); |
| 471 $('fit-to-width-button').classList.remove('polymer-selected'); | 494 $('fit-to-width-button').classList.remove('polymer-selected'); |
| 472 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 495 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
| 473 $('fit-to-page-button').classList.add('polymer-selected'); | 496 $('fit-to-page-button').classList.add('polymer-selected'); |
| 474 } else if (this.viewport_.fittingType == | 497 } else if (this.viewport_.fittingType == |
| 475 Viewport.FittingType.FIT_TO_WIDTH) { | 498 Viewport.FittingType.FIT_TO_WIDTH) { |
| 476 $('fit-to-width-button').classList.add('polymer-selected'); | 499 $('fit-to-width-button').classList.add('polymer-selected'); |
| 477 } | 500 } |
| 478 | 501 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 this.streamDetails_.tabId != -1); | 624 this.streamDetails_.tabId != -1); |
| 602 }, | 625 }, |
| 603 | 626 |
| 604 /** | 627 /** |
| 605 * @type {Viewport} the viewport of the PDF viewer. | 628 * @type {Viewport} the viewport of the PDF viewer. |
| 606 */ | 629 */ |
| 607 get viewport() { | 630 get viewport() { |
| 608 return this.viewport_; | 631 return this.viewport_; |
| 609 } | 632 } |
| 610 }; | 633 }; |
| OLD | NEW |