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

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

Issue 2407713002: Limit PDF helper extension to print preview only (Closed)
Patch Set: Nits + fix compilation failure on macOS Created 4 years, 2 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 listener(zoomChangeInfo.newZoomFactor); 141 listener(zoomChangeInfo.newZoomFactor);
142 }.bind(this)); 142 }.bind(this));
143 } 143 }
144 }; 144 };
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() {
raymes 2016/10/13 00:43:22 With my suggestion below, we won't throw an except
robwu 2016/10/13 23:29:30 Done.
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 promises = [];
156 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1; 156 let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1;
157 if (streamInfo.tabId != -1) { 157 if (streamInfo.tabId != -1) {
158 promises.push(new Promise(function(resolve) { 158 promises.push(new Promise(function(resolve) {
159 chrome.tabs.get(streamInfo.tabId, resolve); 159 chrome.tabs.get(streamInfo.tabId, resolve);
160 }).then(function(tab) { 160 }).then(function(tab) {
161 if (tab) 161 if (tab)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.search) {
210 if (location.ancestorOrigins[0] !== 'chrome://print') {
raymes 2016/10/12 02:08:52 I think it could be good to rework these 2 checks.
robwu 2016/10/12 11:33:28 Are you sure about the claim that this snippet run
raymes 2016/10/13 00:43:22 Yes I'm fairly sure. PDFCreateOutOfProcessPlugin l
robwu 2016/10/13 23:29:30 Done.
211 throw new Error('Refused to load the standalone extension.');
212 }
210 return createBrowserApiForStandaloneExtension(); 213 return createBrowserApiForStandaloneExtension();
214 }
211 215
212 return createBrowserApiForMimeHandlerView(); 216 return createBrowserApiForMimeHandlerView();
213 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698