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

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

Issue 2299943002: Record the PDF and top level URL when the PDF plugin crashes. (Closed)
Patch Set: Remove logging Created 4 years, 3 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
156 return new Promise(function(resolve, reject) { 155 return new Promise(function(resolve, reject) {
Sam McNally 2016/09/07 07:53:02 I'd prefer doing both API calls in parallel. Somet
Lei Zhang 2016/09/08 01:10:31 Done. Hope I got it right. A JS presubmit check do
157 if (!manageZoom) { 156 if (streamInfo.tabId == -1) {
158 resolve(); 157 resolve(false);
raymes 2016/09/07 06:10:14 nit: Maybe just resolve() or resolve(null) since t
Lei Zhang 2016/09/08 01:10:31 Done.
159 return; 158 return;
160 } 159 }
161 chrome.tabs.setZoomSettings( 160 chrome.tabs.get(streamInfo.tabId, resolve);
162 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); 161 }).then(function(tab) {
163 }).then(function() { return BrowserApi.create(streamInfo, manageZoom); }); 162 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1;
163 return new Promise(function(resolve, reject) {
164 if (tab)
165 streamInfo.tabUrl = tab.url;
166 if (!manageZoom) {
167 resolve();
168 return;
169 }
170 chrome.tabs.setZoomSettings(
171 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve);
172 }).then(function() { return BrowserApi.create(streamInfo, manageZoom); });
raymes 2016/09/07 06:10:14 This looks good to me, but I'm also not great with
Lei Zhang 2016/09/08 01:10:31 Acknowledged.
173 });
164 }); 174 });
165 } 175 }
166 176
167 /** 177 /**
168 * Creates a BrowserApi instance for an extension not running as a mime handler. 178 * Creates a BrowserApi instance for an extension not running as a mime handler.
169 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed 179 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
170 * from the URL. 180 * from the URL.
171 */ 181 */
172 function createBrowserApiForStandaloneExtension() { 182 function createBrowserApiForStandaloneExtension() {
173 let url = window.location.search.substring(1); 183 let url = window.location.search.substring(1);
174 let streamInfo = { 184 let streamInfo = {
175 streamUrl: url, 185 streamUrl: url,
176 originalUrl: url, 186 originalUrl: url,
177 responseHeaders: {}, 187 responseHeaders: {},
178 embedded: window.parent != window, 188 embedded: window.parent != window,
179 tabId: -1, 189 tabId: -1,
180 }; 190 };
181 return new Promise(function(resolve, reject) { 191 return new Promise(function(resolve, reject) {
182 if (!chrome.tabs) { 192 if (!chrome.tabs) {
183 resolve(); 193 resolve();
184 return; 194 return;
185 } 195 }
186 chrome.tabs.getCurrent(function(tab) { 196 chrome.tabs.getCurrent(function(tab) {
187 streamInfo.tabId = tab.id; 197 streamInfo.tabId = tab.id;
198 streamInfo.tabUrl = tab.url;
188 resolve(); 199 resolve();
189 }); 200 });
190 }).then(function() { return BrowserApi.create(streamInfo, false); }); 201 }).then(function() { return BrowserApi.create(streamInfo, false); });
191 } 202 }
192 203
193 /** 204 /**
194 * Returns a promise that will resolve to a BrowserApi instance. 205 * Returns a promise that will resolve to a BrowserApi instance.
195 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the 206 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the
196 * current environment. 207 * current environment.
197 */ 208 */
198 function createBrowserApi() { 209 function createBrowserApi() {
199 if (window.location.search) 210 if (window.location.search)
200 return createBrowserApiForStandaloneExtension(); 211 return createBrowserApiForStandaloneExtension();
201 212
202 return createBrowserApiForMimeHandlerView(); 213 return createBrowserApiForMimeHandlerView();
203 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698