| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return Promise.all(promises).then( | 171 return Promise.all(promises).then( |
| 172 function() { return BrowserApi.create(streamInfo, manageZoom); }); | 172 function() { return BrowserApi.create(streamInfo, manageZoom); }); |
| 173 }); | 173 }); |
| 174 } | 174 } |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Creates a BrowserApi instance for an extension not running as a mime handler. | 177 * Creates a BrowserApi instance for an extension not running as a mime handler. |
| 178 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed | 178 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed |
| 179 * from the URL. | 179 * from the URL. |
| 180 */ | 180 */ |
| 181 function createBrowserApiForStandaloneExtension() { | 181 function createBrowserApiForPrintPreview() { |
| 182 let url = window.location.search.substring(1); | 182 let url = window.location.search.substring(1); |
| 183 let streamInfo = { | 183 let streamInfo = { |
| 184 streamUrl: url, | 184 streamUrl: url, |
| 185 originalUrl: url, | 185 originalUrl: url, |
| 186 responseHeaders: {}, | 186 responseHeaders: {}, |
| 187 embedded: window.parent != window, | 187 embedded: window.parent != window, |
| 188 tabId: -1, | 188 tabId: -1, |
| 189 }; | 189 }; |
| 190 return new Promise(function(resolve, reject) { | 190 return new Promise(function(resolve, reject) { |
| 191 if (!chrome.tabs) { | 191 if (!chrome.tabs) { |
| 192 resolve(); | 192 resolve(); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 chrome.tabs.getCurrent(function(tab) { | 195 chrome.tabs.getCurrent(function(tab) { |
| 196 streamInfo.tabId = tab.id; | 196 streamInfo.tabId = tab.id; |
| 197 streamInfo.tabUrl = tab.url; | 197 streamInfo.tabUrl = tab.url; |
| 198 resolve(); | 198 resolve(); |
| 199 }); | 199 }); |
| 200 }).then(function() { return BrowserApi.create(streamInfo, false); }); | 200 }).then(function() { return BrowserApi.create(streamInfo, false); }); |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * Returns a promise that will resolve to a BrowserApi instance. | 204 * Returns a promise that will resolve to a BrowserApi instance. |
| 205 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the | 205 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the |
| 206 * current environment. | 206 * current environment. |
| 207 */ | 207 */ |
| 208 function createBrowserApi() { | 208 function createBrowserApi() { |
| 209 if (window.location.search) | 209 if (location.origin === 'chrome://print') { |
| 210 return createBrowserApiForStandaloneExtension(); | 210 return createBrowserApiForPrintPreview(); |
| 211 } |
| 211 | 212 |
| 212 return createBrowserApiForMimeHandlerView(); | 213 return createBrowserApiForMimeHandlerView(); |
| 213 } | 214 } |
| OLD | NEW |