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

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

Issue 797183005: Add a mimeHandler extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@streams-lifetime
Patch Set: Created 5 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
(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('mimeHandler');
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';
raymes 2015/01/12 05:26:04 nit: should we add full stops to these messages?
Sam McNally 2015/01/12 07:13:35 Done.
14
15 var servicePromise = Promise.all([
16 requireAsync('content/public/renderer/service_provider'),
17 requireAsync('extensions/common/api/mime_handler.mojom'),
18 requireAsync('mojo/public/js/router'),
19 ]).then(function(modules) {
20 var serviceProvider = modules[0];
21 var mojom = modules[1];
22 var routerModule = modules[2];
23 return new mojom.MimeHandlerService.proxyClass(new routerModule.Router(
24 serviceProvider.connectToService(mojom.MimeHandlerService.name)));
25 });
26
27 var streamInfoPromise;
raymes 2015/01/13 00:05:11 Do we really need to store this promise? Would it
Sam McNally 2015/01/13 05:30:08 Added a comment on what this caches and why.
28
29 function populateStreamInfo() {
raymes 2015/01/13 00:05:10 Can this be called createStreamInfoPromise?
Sam McNally 2015/01/13 05:30:08 Done.
30 streamInfoPromise = servicePromise.then(function(service) {
31 return service.getStreamInfo();
32 }).then(function(result) {
33 if (!result.stream_info)
34 throw new Error(STREAM_ABORTED_ERROR);
35 return result.stream_info;
36 }, function(error) {
37 throw new Error(NO_STREAM_ERROR);
38 });
raymes 2015/01/13 00:05:11 Can we pull this apart a bit? Like serviecPromise
Sam McNally 2015/01/13 05:30:08 Done for the error case. I think the normal case i
39 }
40
41 binding.registerCustomHook(function(bindingsAPI) {
42 var apiFunctions = bindingsAPI.apiFunctions;
43 apiFunctions.setHandleRequestWithPromise('getStreamInfo', function() {
44 if (!streamInfoPromise)
45 populateStreamInfo();
raymes 2015/01/13 00:05:10 If you returned the promise in the function you co
Sam McNally 2015/01/13 05:30:08 Done.
46 return streamInfoPromise.then(function(streamInfo) {
47 var headers = {};
48 for (var header of streamInfo.response_headers) {
49 headers[header[0]] = header[1];
50 }
51 return {
52 mimeType: streamInfo.mime_type,
53 originalUrl: streamInfo.original_url,
54 streamUrl: streamInfo.stream_url,
55 tabId: streamInfo.tab_id,
56 expectedContentSize: streamInfo.expected_content_size,
57 embedded: !!streamInfo.embedded,
58 responseHeaders: headers,
59 };
60 });
61 });
62
63 apiFunctions.setHandleRequestWithPromise('abortStream', function() {
64 return servicePromise.then(function(service) {
65 return service.abortStream().then(function() {}, function() {
66 throw new Error(NO_STREAM_ERROR);
67 });
68 });
69 });
70 });
71
72 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698