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

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: fix typo 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 promises = [];
155 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1; 156 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1;
156 return new Promise(function(resolve, reject) { 157 if (streamInfo.tabId != -1) {
157 if (!manageZoom) { 158 promises.push(new Promise(function(resolve) {
158 resolve(); 159 chrome.tabs.get(streamInfo.tabId, resolve);
159 return; 160 }).then(function(tab) {
160 } 161 if (tab)
161 chrome.tabs.setZoomSettings( 162 streamInfo.tabUrl = tab.url;
162 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve); 163 }));
163 }).then(function() { return BrowserApi.create(streamInfo, manageZoom); }); 164 }
165 if (manageZoom) {
166 promises.push(new Promise(function(resolve) {
167 chrome.tabs.setZoomSettings(
168 streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve);
169 }));
170 }
171 return Promise.all(promises).then(
172 function() { return BrowserApi.create(streamInfo, manageZoom); });
164 }); 173 });
165 } 174 }
166 175
167 /** 176 /**
168 * 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.
169 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed 178 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
170 * from the URL. 179 * from the URL.
171 */ 180 */
172 function createBrowserApiForStandaloneExtension() { 181 function createBrowserApiForStandaloneExtension() {
173 let url = window.location.search.substring(1); 182 let url = window.location.search.substring(1);
174 let streamInfo = { 183 let streamInfo = {
175 streamUrl: url, 184 streamUrl: url,
176 originalUrl: url, 185 originalUrl: url,
177 responseHeaders: {}, 186 responseHeaders: {},
178 embedded: window.parent != window, 187 embedded: window.parent != window,
179 tabId: -1, 188 tabId: -1,
180 }; 189 };
181 return new Promise(function(resolve, reject) { 190 return new Promise(function(resolve, reject) {
182 if (!chrome.tabs) { 191 if (!chrome.tabs) {
183 resolve(); 192 resolve();
184 return; 193 return;
185 } 194 }
186 chrome.tabs.getCurrent(function(tab) { 195 chrome.tabs.getCurrent(function(tab) {
187 streamInfo.tabId = tab.id; 196 streamInfo.tabId = tab.id;
197 streamInfo.tabUrl = tab.url;
188 resolve(); 198 resolve();
189 }); 199 });
190 }).then(function() { return BrowserApi.create(streamInfo, false); }); 200 }).then(function() { return BrowserApi.create(streamInfo, false); });
191 } 201 }
192 202
193 /** 203 /**
194 * Returns a promise that will resolve to a BrowserApi instance. 204 * Returns a promise that will resolve to a BrowserApi instance.
195 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the 205 * @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the
196 * current environment. 206 * current environment.
197 */ 207 */
198 function createBrowserApi() { 208 function createBrowserApi() {
199 if (window.location.search) 209 if (window.location.search)
200 return createBrowserApiForStandaloneExtension(); 210 return createBrowserApiForStandaloneExtension();
201 211
202 return createBrowserApiForMimeHandlerView(); 212 return createBrowserApiForMimeHandlerView();
203 } 213 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/streams_private/streams_private_api.cc ('k') | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698