Skip to content

Commit

Permalink
OOP PDF: Use the stream's tab ID when interacting with chrome.tabs.
Browse files Browse the repository at this point in the history
Previously, chrome.tabs API calls were not passed the tab ID and
chrome.tabs event listeners did not filter by tab ID. This caused zooms
from other tabs of the same domain to affect PDF zoom and the active tab
at the time of PDF load to be switched to manual zoom and zoomed to the
initial zoom for the PDF. This CL changes those calls and event handlers
to only affect and be affected by the tab containing the PDF.

BUG=418818
TEST=Run with --out-of-process-pdf.
Open a PDF and another page from the same domain. Zooming the other page
should not affect the PDF's zoom.
Reload the PDF and focus the other page before the PDF load completes.
The other page should not be zoomed when the PDF load completes and
zooming the other page should function normally.

Review URL: https://codereview.chromium.org/727623003

Cr-Commit-Position: refs/heads/master@{#304377}
  • Loading branch information
sammc authored and Commit bot committed Nov 17, 2014
1 parent fd30294 commit 8665956
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions chrome/browser/resources/pdf/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ function PDFViewer(streamDetails) {

// Set up the zoom API.
if (chrome.tabs) {
chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'},
chrome.tabs.setZoomSettings(this.streamDetails.tabId,
{mode: 'manual', scope: 'per-tab'},
this.afterZoom_.bind(this));
chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
if (zoomChangeInfo.tabId != this.streamDetails.tabId)
return;
// If the zoom level is close enough to the current zoom level, don't
// change it. This avoids us getting into an infinite loop of zoom changes
// due to floating point error.
Expand Down Expand Up @@ -421,7 +424,8 @@ PDFViewer.prototype = {
var zoom = this.viewport_.zoom;
if (chrome.tabs && !this.setZoomInProgress_) {
this.setZoomInProgress_ = true;
chrome.tabs.setZoom(zoom, this.setZoomComplete_.bind(this, zoom));
chrome.tabs.setZoom(this.streamDetails.tabId, zoom,
this.setZoomComplete_.bind(this, zoom));
}
this.plugin_.postMessage({
type: 'viewport',
Expand All @@ -441,10 +445,12 @@ PDFViewer.prototype = {
*/
setZoomComplete_: function(lastZoom) {
var zoom = this.viewport_.zoom;
if (zoom != lastZoom)
chrome.tabs.setZoom(zoom, this.setZoomComplete_.bind(this, zoom));
else
if (zoom != lastZoom) {
chrome.tabs.setZoom(this.streamDetails.tabId, zoom,
this.setZoomComplete_.bind(this, zoom));
} else {
this.setZoomInProgress_ = false;
}
},

/**
Expand Down

0 comments on commit 8665956

Please sign in to comment.