From 86659565cc45d0e77171616d88ebc0cc48f500d8 Mon Sep 17 00:00:00 2001 From: sammc Date: Sun, 16 Nov 2014 17:11:40 -0800 Subject: [PATCH] OOP PDF: Use the stream's tab ID when interacting with chrome.tabs. 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} --- chrome/browser/resources/pdf/pdf.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js index d60526c76165..0ca054f9059e 100644 --- a/chrome/browser/resources/pdf/pdf.js +++ b/chrome/browser/resources/pdf/pdf.js @@ -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. @@ -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', @@ -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; + } }, /**