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

Side by Side Diff: extensions/renderer/resources/mime_handler_private_custom_bindings.js

Issue 2409073002: Use mojo from the PDF extension instead of using an extension API.
Patch Set: 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * Custom bindings for the mime handler API.
7 */
8
9 var binding = require('binding').Binding.create('mimeHandlerPrivate');
10
11 var NO_STREAM_ERROR =
12 'Streams are only available from a mime handler view guest.';
13 var STREAM_ABORTED_ERROR = 'Stream has been aborted.';
14
15 var servicePromise = Promise.all([
16 requireAsync('content/public/renderer/frame_interfaces'),
17 requireAsync('extensions/common/api/mime_handler.mojom'),
18 requireAsync('mojo/public/js/router'),
19 ]).then(function(modules) {
20 var frameInterfaces = modules[0];
21 var mojom = modules[1];
22 var routerModule = modules[2];
23 return new mojom.MimeHandlerService.proxyClass(new routerModule.Router(
24 frameInterfaces.getInterface(mojom.MimeHandlerService.name)));
25 });
26
27 // Stores a promise to the GetStreamInfo() result to avoid making additional
28 // calls in response to getStreamInfo() calls.
29 var streamInfoPromise;
30
31 function throwNoStreamError() {
32 throw new Error(NO_STREAM_ERROR);
33 }
34
35 function createStreamInfoPromise() {
36 return servicePromise.then(function(service) {
37 return service.getStreamInfo();
38 }).then(function(result) {
39 if (!result.stream_info)
40 throw new Error(STREAM_ABORTED_ERROR);
41 return result.stream_info;
42 }, throwNoStreamError);
43 }
44
45 function constructStreamInfoDict(streamInfo) {
46 var headers = {};
47 for (var header of streamInfo.response_headers) {
48 headers[header[0]] = header[1];
49 }
50 return {
51 mimeType: streamInfo.mime_type,
52 originalUrl: streamInfo.original_url,
53 streamUrl: streamInfo.stream_url,
54 tabId: streamInfo.tab_id,
55 embedded: !!streamInfo.embedded,
56 responseHeaders: headers,
57 };
58 }
59
60 binding.registerCustomHook(function(bindingsAPI) {
61 var apiFunctions = bindingsAPI.apiFunctions;
62 apiFunctions.setHandleRequestWithPromise('getStreamInfo', function() {
63 if (!streamInfoPromise)
64 streamInfoPromise = createStreamInfoPromise();
65 return streamInfoPromise.then(constructStreamInfoDict);
66 });
67
68 apiFunctions.setHandleRequestWithPromise('abortStream', function() {
69 return servicePromise.then(function(service) {
70 return service.abortStream().then(function() {});
71 }).catch(throwNoStreamError);
72 });
73 });
74
75 exports.$set('binding', binding.generate());
OLDNEW
« no previous file with comments | « extensions/renderer/resources/keep_alive.js ('k') | extensions/test/data/api_test_base_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698