Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/resources/pdf/browser_api.js

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 this.zoomBehavior_ = zoomBehavior; 64 this.zoomBehavior_ = zoomBehavior;
65 } 65 }
66 66
67 /** 67 /**
68 * Returns a promise to a BrowserApi. 68 * Returns a promise to a BrowserApi.
69 * @param {!Object} streamInfo The stream object pointing to the data 69 * @param {!Object} streamInfo The stream object pointing to the data
70 * contained in the PDF. 70 * contained in the PDF.
71 * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom. 71 * @param {BrowserApi.ZoomBehavior} zoomBehavior How to manage zoom.
72 */ 72 */
73 static create(streamInfo, zoomBehavior) { 73 static create(streamInfo, zoomBehavior) {
74 return Promise.all([ 74 return Promise
75 lookupDefaultZoom(streamInfo), 75 .all([lookupDefaultZoom(streamInfo), lookupInitialZoom(streamInfo)])
76 lookupInitialZoom(streamInfo) 76 .then(function(zoomFactors) {
77 ]).then(function(zoomFactors) { 77 return new BrowserApi(
78 return new BrowserApi( 78 streamInfo, zoomFactors[0], zoomFactors[1], zoomBehavior);
79 streamInfo, zoomFactors[0], zoomFactors[1], zoomBehavior); 79 });
80 });
81 } 80 }
82 81
83 /** 82 /**
84 * Returns the stream info pointing to the data contained in the PDF. 83 * Returns the stream info pointing to the data contained in the PDF.
85 * @return {Object} The stream info object. 84 * @return {Object} The stream info object.
86 */ 85 */
87 getStreamInfo() { 86 getStreamInfo() {
88 return this.streamInfo_; 87 return this.streamInfo_;
89 } 88 }
90 89
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 PROPAGATE_PARENT: 2 161 PROPAGATE_PARENT: 2
163 }; 162 };
164 163
165 /** 164 /**
166 * Creates a BrowserApi for an extension running as a mime handler. 165 * Creates a BrowserApi for an extension running as a mime handler.
167 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed 166 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
168 * using the mimeHandlerPrivate API. 167 * using the mimeHandlerPrivate API.
169 */ 168 */
170 function createBrowserApiForMimeHandlerView() { 169 function createBrowserApiForMimeHandlerView() {
171 return new Promise(function(resolve, reject) { 170 return new Promise(function(resolve, reject) {
172 chrome.mimeHandlerPrivate.getStreamInfo(resolve); 171 chrome.mimeHandlerPrivate.getStreamInfo(resolve);
173 }).then(function(streamInfo) { 172 })
174 let promises = []; 173 .then(function(streamInfo) {
175 let zoomBehavior = BrowserApi.ZoomBehavior.NONE; 174 let promises = [];
176 if (streamInfo.tabId != -1) { 175 let zoomBehavior = BrowserApi.ZoomBehavior.NONE;
177 zoomBehavior = streamInfo.embedded ? 176 if (streamInfo.tabId != -1) {
178 BrowserApi.ZoomBehavior.PROPAGATE_PARENT : 177 zoomBehavior = streamInfo.embedded ?
179 BrowserApi.ZoomBehavior.MANAGE; 178 BrowserApi.ZoomBehavior.PROPAGATE_PARENT :
180 promises.push(new Promise(function(resolve) { 179 BrowserApi.ZoomBehavior.MANAGE;
181 chrome.tabs.get(streamInfo.tabId, resolve); 180 promises.push(new Promise(function(resolve) {
182 }).then(function(tab) { 181 chrome.tabs.get(streamInfo.tabId, resolve);
183 if (tab) 182 }).then(function(tab) {
184 streamInfo.tabUrl = tab.url; 183 if (tab)
185 })); 184 streamInfo.tabUrl = tab.url;
186 } 185 }));
187 if (zoomBehavior == BrowserApi.ZoomBehavior.MANAGE) { 186 }
188 promises.push(new Promise(function(resolve) { 187 if (zoomBehavior == BrowserApi.ZoomBehavior.MANAGE) {
189 chrome.tabs.setZoomSettings( 188 promises.push(new Promise(function(resolve) {
190 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); 189 chrome.tabs.setZoomSettings(
191 })); 190 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve);
192 } 191 }));
193 return Promise.all(promises).then( 192 }
194 function() { return BrowserApi.create(streamInfo, zoomBehavior); }); 193 return Promise.all(promises).then(function() {
195 }); 194 return BrowserApi.create(streamInfo, zoomBehavior);
195 });
196 });
196 } 197 }
197 198
198 /** 199 /**
199 * Creates a BrowserApi instance for an extension not running as a mime handler. 200 * Creates a BrowserApi instance for an extension not running as a mime handler.
200 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed 201 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
201 * from the URL. 202 * from the URL.
202 */ 203 */
203 function createBrowserApiForPrintPreview() { 204 function createBrowserApiForPrintPreview() {
204 let url = window.location.search.substring(1); 205 let url = window.location.search.substring(1);
205 let streamInfo = { 206 let streamInfo = {
206 streamUrl: url, 207 streamUrl: url,
207 originalUrl: url, 208 originalUrl: url,
208 responseHeaders: {}, 209 responseHeaders: {},
209 embedded: window.parent != window, 210 embedded: window.parent != window,
210 tabId: -1, 211 tabId: -1,
211 }; 212 };
212 return new Promise(function(resolve, reject) { 213 return new Promise(function(resolve, reject) {
213 if (!chrome.tabs) { 214 if (!chrome.tabs) {
214 resolve(); 215 resolve();
215 return; 216 return;
216 } 217 }
217 chrome.tabs.getCurrent(function(tab) { 218 chrome.tabs.getCurrent(function(tab) {
218 streamInfo.tabId = tab.id; 219 streamInfo.tabId = tab.id;
219 streamInfo.tabUrl = tab.url; 220 streamInfo.tabUrl = tab.url;
220 resolve(); 221 resolve();
221 }); 222 });
222 }).then(function() { 223 })
223 return BrowserApi.create(streamInfo, BrowserApi.ZoomBehavior.NONE); 224 .then(function() {
224 }); 225 return BrowserApi.create(streamInfo, BrowserApi.ZoomBehavior.NONE);
226 });
225 } 227 }
226 228
227 /** 229 /**
228 * Returns a promise that will resolve to a BrowserApi instance. 230 * Returns a promise that will resolve to a BrowserApi instance.
229 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the 231 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the
230 * current environment. 232 * current environment.
231 */ 233 */
232 function createBrowserApi() { 234 function createBrowserApi() {
233 if (location.origin === 'chrome://print') { 235 if (location.origin === 'chrome://print') {
234 return createBrowserApiForPrintPreview(); 236 return createBrowserApiForPrintPreview();
235 } 237 }
236 238
237 return createBrowserApiForMimeHandlerView(); 239 return createBrowserApiForMimeHandlerView();
238 } 240 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/omnibox/omnibox.js ('k') | chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698