| 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() { |
| 11 var div = document.createElement('div'); | 11 var div = document.createElement('div'); |
| 12 div.style.visibility = 'hidden'; | 12 div.style.visibility = 'hidden'; |
| 13 div.style.overflow = 'scroll'; | 13 div.style.overflow = 'scroll'; |
| 14 div.style.width = '50px'; | 14 div.style.width = '50px'; |
| 15 div.style.height = '50px'; | 15 div.style.height = '50px'; |
| 16 div.style.position = 'absolute'; | 16 div.style.position = 'absolute'; |
| 17 document.body.appendChild(div); | 17 document.body.appendChild(div); |
| 18 var result = div.offsetWidth - div.clientWidth; | 18 var result = div.offsetWidth - div.clientWidth; |
| 19 div.parentNode.removeChild(div); | 19 div.parentNode.removeChild(div); |
| 20 return result; | 20 return result; |
| 21 } | 21 } |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Return the filename component of a URL. |
| 25 * @param {string} url The URL to get the filename from. |
| 26 * @return {string} The filename component. |
| 27 */ |
| 28 function getFilenameFromURL(url) { |
| 29 var components = url.split(/\/|\\/); |
| 30 return components[components.length - 1]; |
| 31 } |
| 32 |
| 33 /** |
| 24 * The minimum number of pixels to offset the toolbar by from the bottom and | 34 * The minimum number of pixels to offset the toolbar by from the bottom and |
| 25 * right side of the screen. | 35 * right side of the screen. |
| 26 */ | 36 */ |
| 27 PDFViewer.MIN_TOOLBAR_OFFSET = 15; | 37 PDFViewer.MIN_TOOLBAR_OFFSET = 15; |
| 28 | 38 |
| 29 /** | 39 /** |
| 30 * 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 |
| 31 * document. | 41 * document. |
| 32 * @param {Object} streamDetails The stream object which points to the data | 42 * @param {Object} streamDetails The stream object which points to the data |
| 33 * contained in the PDF. | 43 * contained in the PDF. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), | 84 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), |
| 75 false); | 85 false); |
| 76 | 86 |
| 77 // Handle scripting messages from outside the extension that wish to interact | 87 // Handle scripting messages from outside the extension that wish to interact |
| 78 // with it. We also send a message indicating that extension has loaded and | 88 // with it. We also send a message indicating that extension has loaded and |
| 79 // is ready to receive messages. | 89 // is ready to receive messages. |
| 80 window.addEventListener('message', this.handleScriptingMessage_.bind(this), | 90 window.addEventListener('message', this.handleScriptingMessage_.bind(this), |
| 81 false); | 91 false); |
| 82 this.sendScriptingMessage_({type: 'readyToReceive'}); | 92 this.sendScriptingMessage_({type: 'readyToReceive'}); |
| 83 | 93 |
| 94 document.title = getFilenameFromURL(this.streamDetails.originalUrl); |
| 84 this.plugin_.setAttribute('src', this.streamDetails.originalUrl); | 95 this.plugin_.setAttribute('src', this.streamDetails.originalUrl); |
| 85 this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); | 96 this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); |
| 86 var headers = ''; | 97 var headers = ''; |
| 87 for (var header in this.streamDetails.responseHeaders) { | 98 for (var header in this.streamDetails.responseHeaders) { |
| 88 headers += header + ': ' + | 99 headers += header + ': ' + |
| 89 this.streamDetails.responseHeaders[header] + '\n'; | 100 this.streamDetails.responseHeaders[header] + '\n'; |
| 90 } | 101 } |
| 91 this.plugin_.setAttribute('headers', headers); | 102 this.plugin_.setAttribute('headers', headers); |
| 92 | 103 |
| 93 if (!this.streamDetails.embedded) | 104 if (!this.streamDetails.embedded) |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 this.streamDetails.tabId != -1); | 602 this.streamDetails.tabId != -1); |
| 592 }, | 603 }, |
| 593 | 604 |
| 594 /** | 605 /** |
| 595 * @type {Viewport} the viewport of the PDF viewer. | 606 * @type {Viewport} the viewport of the PDF viewer. |
| 596 */ | 607 */ |
| 597 get viewport() { | 608 get viewport() { |
| 598 return this.viewport_; | 609 return this.viewport_; |
| 599 } | 610 } |
| 600 }; | 611 }; |
| OLD | NEW |