| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   77  |   77  | 
|   78   this.plugin_.setAttribute('src', this.streamDetails.originalUrl); |   78   this.plugin_.setAttribute('src', this.streamDetails.originalUrl); | 
|   79   this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); |   79   this.plugin_.setAttribute('stream-url', this.streamDetails.streamUrl); | 
|   80   var headers = ''; |   80   var headers = ''; | 
|   81   for (var header in this.streamDetails.responseHeaders) { |   81   for (var header in this.streamDetails.responseHeaders) { | 
|   82     headers += header + ': ' + |   82     headers += header + ': ' + | 
|   83         this.streamDetails.responseHeaders[header] + '\n'; |   83         this.streamDetails.responseHeaders[header] + '\n'; | 
|   84   } |   84   } | 
|   85   this.plugin_.setAttribute('headers', headers); |   85   this.plugin_.setAttribute('headers', headers); | 
|   86  |   86  | 
|   87   if (window.top == window) |   87   if (!this.streamDetails.embedded) | 
|   88     this.plugin_.setAttribute('full-frame', ''); |   88     this.plugin_.setAttribute('full-frame', ''); | 
|   89   document.body.appendChild(this.plugin_); |   89   document.body.appendChild(this.plugin_); | 
|   90  |   90  | 
|   91   // TODO(raymes): Remove this spurious message once crbug.com/388606 is fixed. |   91   // TODO(raymes): Remove this spurious message once crbug.com/388606 is fixed. | 
|   92   // This is a hack to initialize pepper sync scripting and avoid re-entrancy. |   92   // This is a hack to initialize pepper sync scripting and avoid re-entrancy. | 
|   93   this.plugin_.postMessage({ |   93   this.plugin_.postMessage({ | 
|   94     type: 'viewport', |   94     type: 'viewport', | 
|   95     zoom: 1, |   95     zoom: 1, | 
|   96     xOffset: 0, |   96     xOffset: 0, | 
|   97     yOffset: 0 |   97     yOffset: 0 | 
|   98   }); |   98   }); | 
|   99  |   99  | 
|  100   // Setup the button event listeners. |  100   // Setup the button event listeners. | 
|  101   $('fit-to-width-button').addEventListener('click', |  101   $('fit-to-width-button').addEventListener('click', | 
|  102       this.viewport_.fitToWidth.bind(this.viewport_)); |  102       this.viewport_.fitToWidth.bind(this.viewport_)); | 
|  103   $('fit-to-page-button').addEventListener('click', |  103   $('fit-to-page-button').addEventListener('click', | 
|  104       this.viewport_.fitToPage.bind(this.viewport_)); |  104       this.viewport_.fitToPage.bind(this.viewport_)); | 
|  105   $('zoom-in-button').addEventListener('click', |  105   $('zoom-in-button').addEventListener('click', | 
|  106       this.viewport_.zoomIn.bind(this.viewport_)); |  106       this.viewport_.zoomIn.bind(this.viewport_)); | 
|  107   $('zoom-out-button').addEventListener('click', |  107   $('zoom-out-button').addEventListener('click', | 
|  108       this.viewport_.zoomOut.bind(this.viewport_)); |  108       this.viewport_.zoomOut.bind(this.viewport_)); | 
|  109   $('save-button-link').href = this.streamDetails.originalUrl; |  109   $('save-button-link').href = this.streamDetails.originalUrl; | 
|  110   $('print-button').addEventListener('click', this.print_.bind(this)); |  110   $('print-button').addEventListener('click', this.print_.bind(this)); | 
|  111  |  111  | 
|  112   // Setup the keyboard event listener. |  112   // Setup the keyboard event listener. | 
|  113   document.onkeydown = this.handleKeyEvent_.bind(this); |  113   document.onkeydown = this.handleKeyEvent_.bind(this); | 
|  114  |  114  | 
|  115   // Set up the zoom API. |  115   // Set up the zoom API. | 
|  116   if (chrome.tabs) { |  116   if (this.shouldManageZoom_()) { | 
|  117     chrome.tabs.setZoomSettings(this.streamDetails.tabId, |  117     chrome.tabs.setZoomSettings(this.streamDetails.tabId, | 
|  118                                 {mode: 'manual', scope: 'per-tab'}, |  118                                 {mode: 'manual', scope: 'per-tab'}, | 
|  119                                 this.afterZoom_.bind(this)); |  119                                 this.afterZoom_.bind(this)); | 
|  120     chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |  120     chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | 
|  121       if (zoomChangeInfo.tabId != this.streamDetails.tabId) |  121       if (zoomChangeInfo.tabId != this.streamDetails.tabId) | 
|  122         return; |  122         return; | 
|  123       // If the zoom level is close enough to the current zoom level, don't |  123       // If the zoom level is close enough to the current zoom level, don't | 
|  124       // change it. This avoids us getting into an infinite loop of zoom changes |  124       // change it. This avoids us getting into an infinite loop of zoom changes | 
|  125       // due to floating point error. |  125       // due to floating point error. | 
|  126       var MIN_ZOOM_DELTA = 0.01; |  126       var MIN_ZOOM_DELTA = 0.01; | 
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  415   }, |  415   }, | 
|  416  |  416  | 
|  417   /** |  417   /** | 
|  418    * @private |  418    * @private | 
|  419    * A callback that's called after the zoom changes. Notify the plugin of the |  419    * A callback that's called after the zoom changes. Notify the plugin of the | 
|  420    * zoom change and to continue reacting to scroll events. |  420    * zoom change and to continue reacting to scroll events. | 
|  421    */ |  421    */ | 
|  422   afterZoom_: function() { |  422   afterZoom_: function() { | 
|  423     var position = this.viewport_.position; |  423     var position = this.viewport_.position; | 
|  424     var zoom = this.viewport_.zoom; |  424     var zoom = this.viewport_.zoom; | 
|  425     if (chrome.tabs && !this.setZoomInProgress_) { |  425     if (this.shouldManageZoom_() && !this.setZoomInProgress_) { | 
|  426       this.setZoomInProgress_ = true; |  426       this.setZoomInProgress_ = true; | 
|  427       chrome.tabs.setZoom(this.streamDetails.tabId, zoom, |  427       chrome.tabs.setZoom(this.streamDetails.tabId, zoom, | 
|  428                           this.setZoomComplete_.bind(this, zoom)); |  428                           this.setZoomComplete_.bind(this, zoom)); | 
|  429     } |  429     } | 
|  430     this.plugin_.postMessage({ |  430     this.plugin_.postMessage({ | 
|  431       type: 'viewport', |  431       type: 'viewport', | 
|  432       zoom: zoom, |  432       zoom: zoom, | 
|  433       xOffset: position.x, |  433       xOffset: position.x, | 
|  434       yOffset: position.y |  434       yOffset: position.y | 
|  435     }); |  435     }); | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  567    * @private |  567    * @private | 
|  568    * Send a scripting message outside the extension (typically to |  568    * Send a scripting message outside the extension (typically to | 
|  569    * PDFScriptingAPI in a page containing the extension). |  569    * PDFScriptingAPI in a page containing the extension). | 
|  570    * @param {Object} message the message to send. |  570    * @param {Object} message the message to send. | 
|  571    */ |  571    */ | 
|  572   sendScriptingMessage_: function(message) { |  572   sendScriptingMessage_: function(message) { | 
|  573     window.parent.postMessage(message, '*'); |  573     window.parent.postMessage(message, '*'); | 
|  574   }, |  574   }, | 
|  575  |  575  | 
|  576   /** |  576   /** | 
 |  577    * @private | 
 |  578    * Return whether this PDFViewer should manage zoom for its containing page. | 
 |  579    * @return {boolean} Whether this PDFViewer should manage zoom for its | 
 |  580    *     containing page. | 
 |  581    */ | 
 |  582   shouldManageZoom_: function() { | 
 |  583     return !!(chrome.tabs && !this.streamDetails.embedded && | 
 |  584               this.streamDetails.tabId != -1); | 
 |  585   }, | 
 |  586  | 
 |  587   /** | 
|  577    * @type {Viewport} the viewport of the PDF viewer. |  588    * @type {Viewport} the viewport of the PDF viewer. | 
|  578    */ |  589    */ | 
|  579   get viewport() { |  590   get viewport() { | 
|  580     return this.viewport_; |  591     return this.viewport_; | 
|  581   } |  592   } | 
|  582 }; |  593 }; | 
| OLD | NEW |