Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Returns a promise that will resolve to the default zoom factor. | 8 * Returns a promise that will resolve to the default zoom factor. |
| 9 * @param {!Object} streamInfo The stream object pointing to the data contained | 9 * @param {!Object} streamInfo The stream object pointing to the data contained |
| 10 * in the PDF. | 10 * in the PDF. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 /** | 146 /** |
| 147 * Creates a BrowserApi for an extension running as a mime handler. | 147 * Creates a BrowserApi for an extension running as a mime handler. |
| 148 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed | 148 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed |
| 149 * using the mimeHandlerPrivate API. | 149 * using the mimeHandlerPrivate API. |
| 150 */ | 150 */ |
| 151 function createBrowserApiForMimeHandlerView() { | 151 function createBrowserApiForMimeHandlerView() { |
| 152 return new Promise(function(resolve, reject) { | 152 return new Promise(function(resolve, reject) { |
| 153 chrome.mimeHandlerPrivate.getStreamInfo(resolve); | 153 chrome.mimeHandlerPrivate.getStreamInfo(resolve); |
| 154 }).then(function(streamInfo) { | 154 }).then(function(streamInfo) { |
| 155 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1; | 155 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1; |
|
raymes
2016/09/05 04:11:47
It does feel a bit weird that we pass in whether t
| |
| 156 return new Promise(function(resolve, reject) { | 156 return new Promise(function(resolve, reject) { |
| 157 if (streamInfo.tabId != -1) { | |
| 158 chrome.tabs.get(streamInfo.tabId, function(tab) { | |
| 159 streamInfo.tabUrl = tab.url; | |
| 160 resolve(); | |
| 161 }); | |
| 162 } | |
|
raymes
2016/09/05 04:11:47
Hmm this doesn't look quite right to me. resolve()
Lei Zhang
2016/09/07 00:12:38
Uhh, no idea what I'm doing exactly. Let's take an
| |
| 157 if (!manageZoom) { | 163 if (!manageZoom) { |
| 158 resolve(); | 164 resolve(); |
| 159 return; | 165 return; |
| 160 } | 166 } |
| 161 chrome.tabs.setZoomSettings( | 167 chrome.tabs.setZoomSettings( |
| 162 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); | 168 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); |
| 163 }).then(function() { return BrowserApi.create(streamInfo, manageZoom); }); | 169 }).then(function() { return BrowserApi.create(streamInfo, manageZoom); }); |
| 164 }); | 170 }); |
| 165 } | 171 } |
| 166 | 172 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 178 embedded: window.parent != window, | 184 embedded: window.parent != window, |
| 179 tabId: -1, | 185 tabId: -1, |
| 180 }; | 186 }; |
| 181 return new Promise(function(resolve, reject) { | 187 return new Promise(function(resolve, reject) { |
| 182 if (!chrome.tabs) { | 188 if (!chrome.tabs) { |
| 183 resolve(); | 189 resolve(); |
| 184 return; | 190 return; |
| 185 } | 191 } |
| 186 chrome.tabs.getCurrent(function(tab) { | 192 chrome.tabs.getCurrent(function(tab) { |
| 187 streamInfo.tabId = tab.id; | 193 streamInfo.tabId = tab.id; |
| 194 streamInfo.tabUrl = tab.url; | |
| 188 resolve(); | 195 resolve(); |
| 189 }); | 196 }); |
| 190 }).then(function() { return BrowserApi.create(streamInfo, false); }); | 197 }).then(function() { return BrowserApi.create(streamInfo, false); }); |
| 191 } | 198 } |
| 192 | 199 |
| 193 /** | 200 /** |
| 194 * Returns a promise that will resolve to a BrowserApi instance. | 201 * Returns a promise that will resolve to a BrowserApi instance. |
| 195 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the | 202 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the |
| 196 * current environment. | 203 * current environment. |
| 197 */ | 204 */ |
| 198 function createBrowserApi() { | 205 function createBrowserApi() { |
| 199 if (window.location.search) | 206 if (window.location.search) |
| 200 return createBrowserApiForStandaloneExtension(); | 207 return createBrowserApiForStandaloneExtension(); |
| 201 | 208 |
| 202 return createBrowserApiForMimeHandlerView(); | 209 return createBrowserApiForMimeHandlerView(); |
| 203 } | 210 } |
| OLD | NEW |