Chromium Code Reviews| Index: chrome/browser/resources/pdf/browser_api.js |
| diff --git a/chrome/browser/resources/pdf/browser_api.js b/chrome/browser/resources/pdf/browser_api.js |
| index 6b75caff30f654827f468143bf46bed3961bd154..b222024ba303b28267dddca2b4596ab9ece178e6 100644 |
| --- a/chrome/browser/resources/pdf/browser_api.js |
| +++ b/chrome/browser/resources/pdf/browser_api.js |
| @@ -55,28 +55,28 @@ class BrowserApi { |
| * @param {number} defaultZoom The default browser zoom. |
| * @param {number} initialZoom The initial browser zoom |
| * upon starting the plugin. |
| - * @param {boolean} manageZoom Whether to manage zoom. |
| + * @param {BrowserApi.ZoomBehaviour} zoomBehaviour How to manage zoom. |
| */ |
| - constructor(streamInfo, defaultZoom, initialZoom, manageZoom) { |
| + constructor(streamInfo, defaultZoom, initialZoom, zoomBehaviour) { |
| this.streamInfo_ = streamInfo; |
| this.defaultZoom_ = defaultZoom; |
| this.initialZoom_ = initialZoom; |
| - this.manageZoom_ = manageZoom; |
| + this.zoomBehaviour_ = zoomBehaviour; |
| } |
| /** |
| * Returns a promise to a BrowserApi. |
| * @param {!Object} streamInfo The stream object pointing to the data |
| * contained in the PDF. |
| - * @param {boolean} manageZoom Whether to manage zoom. |
| + * @param {BrowserApi.ZoomBehaviour} zoomBehaviour How to manage zoom. |
| */ |
| - static create(streamInfo, manageZoom) { |
| + static create(streamInfo, zoomBehaviour) { |
| return Promise.all([ |
| lookupDefaultZoom(streamInfo), |
| lookupInitialZoom(streamInfo) |
| ]).then(function(zoomFactors) { |
| return new BrowserApi( |
| - streamInfo, zoomFactors[0], zoomFactors[1], manageZoom); |
| + streamInfo, zoomFactors[0], zoomFactors[1], zoomBehaviour); |
| }); |
| } |
| @@ -103,8 +103,8 @@ class BrowserApi { |
| * has been updated. |
| */ |
| setZoom(zoom) { |
| - if (!this.manageZoom_) |
| - return Promise.resolve(); |
| + if (this.zoomBehaviour_ != BrowserApi.ZoomBehaviour.MANAGE) |
| + return Promise.reject(new Error('Viewer does not manage browser zoom.')); |
| return new Promise(function(resolve, reject) { |
| chrome.tabs.setZoom(this.streamInfo_.tabId, zoom, resolve); |
| }.bind(this)); |
| @@ -127,12 +127,21 @@ class BrowserApi { |
| } |
| /** |
| + * Returns how to manage the zoom. |
| + * @return {BrowserApi.ZoomBehaviour} How to manage zoom. |
| + */ |
| + getZoomBehaviour() { |
| + return this.zoomBehaviour_; |
| + } |
| + |
| + /** |
| * Adds an event listener to be notified when the browser zoom changes. |
| * @param {function} listener The listener to be called with the new zoom |
| * factor. |
| */ |
| addZoomEventListener(listener) { |
| - if (!this.manageZoom_) |
| + if (!(this.zoomBehaviour_ == BrowserApi.ZoomBehaviour.MANAGE || |
| + this.zoomBehaviour_ == BrowserApi.ZoomBehaviour.PROPAGATE_PARENT)) |
| return; |
| chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |
| @@ -144,6 +153,16 @@ class BrowserApi { |
| }; |
| /** |
| + * Enumeration of ways to manage zoom changes. |
| + * @enum {number} |
| + */ |
| +BrowserApi.ZoomBehaviour = { |
|
Sam McNally
2016/12/04 23:56:45
I believe we're meant to use US spelling.
Kevin McNee
2016/12/05 22:21:00
Really? In code search, "behaviour" pops up quite
Sam McNally
2016/12/05 23:16:47
Behavior pops up a lot more though and consistency
Kevin McNee
2016/12/06 18:07:16
Sure. I can change it before committing.
Kevin McNee
2016/12/06 18:43:07
Done.
|
| + NONE: 0, |
| + MANAGE: 1, |
| + PROPAGATE_PARENT: 2 |
| +}; |
| + |
| +/** |
| * Creates a BrowserApi for an extension running as a mime handler. |
| * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed |
| * using the mimeHandlerPrivate API. |
| @@ -153,8 +172,11 @@ function createBrowserApiForMimeHandlerView() { |
| chrome.mimeHandlerPrivate.getStreamInfo(resolve); |
| }).then(function(streamInfo) { |
| let promises = []; |
| - let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1; |
| + let zoomBehaviour = BrowserApi.ZoomBehaviour.NONE; |
| if (streamInfo.tabId != -1) { |
| + zoomBehaviour = streamInfo.embedded ? |
| + BrowserApi.ZoomBehaviour.PROPAGATE_PARENT : |
| + BrowserApi.ZoomBehaviour.MANAGE; |
| promises.push(new Promise(function(resolve) { |
| chrome.tabs.get(streamInfo.tabId, resolve); |
| }).then(function(tab) { |
| @@ -162,14 +184,14 @@ function createBrowserApiForMimeHandlerView() { |
| streamInfo.tabUrl = tab.url; |
| })); |
| } |
| - if (manageZoom) { |
| + if (zoomBehaviour == BrowserApi.ZoomBehaviour.MANAGE) { |
| promises.push(new Promise(function(resolve) { |
| chrome.tabs.setZoomSettings( |
| streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); |
| })); |
| } |
| return Promise.all(promises).then( |
| - function() { return BrowserApi.create(streamInfo, manageZoom); }); |
| + function() { return BrowserApi.create(streamInfo, zoomBehaviour); }); |
| }); |
| } |
| @@ -197,7 +219,9 @@ function createBrowserApiForPrintPreview() { |
| streamInfo.tabUrl = tab.url; |
| resolve(); |
| }); |
| - }).then(function() { return BrowserApi.create(streamInfo, false); }); |
| + }).then(function() { |
| + return BrowserApi.create(streamInfo, BrowserApi.ZoomBehaviour.NONE); |
| + }); |
| } |
| /** |