OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Media manager class. | 8 * Media manager class. |
9 * This class supports the information for the media file. | 9 * This class supports the information for the media file. |
10 * @param {FileEntry} entry Entry of media file. This must be a external entry. | 10 * @param {FileEntry} entry Entry of media file. This must be a external entry. |
(...skipping 19 matching lines...) Expand all Loading... |
30 */ | 30 */ |
31 MediaManager.prototype.isAvailableForCast = function() { | 31 MediaManager.prototype.isAvailableForCast = function() { |
32 return this.getUrl().then(function(url) { | 32 return this.getUrl().then(function(url) { |
33 return true; | 33 return true; |
34 }, function() { | 34 }, function() { |
35 return false; | 35 return false; |
36 }); | 36 }); |
37 }; | 37 }; |
38 | 38 |
39 /** | 39 /** |
40 * Retrives the token for cast. | 40 * Retrieves the token for cast. |
41 * | 41 * |
42 * @param {boolean} refresh If true, force to refrech a token. If false, use the | 42 * @param {boolean} refresh If true, force to refresh a token. If false, use the |
43 * cached token if available. | 43 * cached token if available. |
44 * @return {Promise} Promise which is resolved with the token. Reject if failed. | 44 * @return {Promise} Promise which is resolved with the token. Reject if failed. |
45 */ | 45 */ |
46 MediaManager.prototype.getToken = function(refresh) { | 46 MediaManager.prototype.getToken = function(refresh) { |
47 if (this.cachedToken_ && !refresh) | 47 if (this.cachedToken_ && !refresh) |
48 return Promise.resolve(this.cachedToken_); | 48 return Promise.resolve(this.cachedToken_); |
49 | 49 |
50 return new Promise(function(fulfill, reject) { | 50 return new Promise(function(fulfill, reject) { |
51 // TODO(yoshiki): Creates the method to get a token and use it. | 51 // TODO(yoshiki): Creates the method to get a token and use it. |
52 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); | 52 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
53 }.bind(this)).then(function(url) { | 53 }.bind(this)).then(function(url) { |
54 if (!url) | 54 if (!url) |
55 return Promise.reject('Token fetch failed.'); | 55 return Promise.reject('Token fetch failed.'); |
56 var token = url.substring(url.indexOf('access_token=') + 13); | 56 var token = url.substring(url.indexOf('access_token=') + 13); |
57 if (token) { | 57 if (token) { |
58 this.cachedToken_ = token; | 58 this.cachedToken_ = token; |
59 return token; | 59 return token; |
60 } else { | 60 } else { |
61 return Promise.reject('Token fetch failed.'); | 61 return Promise.reject('Token fetch failed.'); |
62 } | 62 } |
63 }.bind(this)); | 63 }.bind(this)); |
64 }; | 64 }; |
65 | 65 |
66 /** | 66 /** |
67 * Retrives the url for cast. | 67 * Retrieves the url for cast. |
68 * | 68 * |
69 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 69 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
70 */ | 70 */ |
71 MediaManager.prototype.getUrl = function() { | 71 MediaManager.prototype.getUrl = function() { |
72 if (this.cachedUrl_) | 72 if (this.cachedUrl_) |
73 return Promise.resolve(this.cachedUrl_); | 73 return Promise.resolve(this.cachedUrl_); |
74 | 74 |
75 return new Promise(function(fulfill, reject) { | 75 return new Promise(function(fulfill, reject) { |
76 // TODO(yoshiki): Creates the method to get a url and use it. | 76 // TODO(yoshiki): Creates the method to get a url and use it. |
77 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); | 77 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
78 }.bind(this)).then(function(url) { | 78 }.bind(this)).then(function(url) { |
79 if (!url) | 79 if (!url) |
80 return Promise.reject('URL fetch failed.'); | 80 return Promise.reject('URL fetch failed.'); |
81 var access_token_index = url.indexOf('access_token='); | 81 var access_token_index = url.indexOf('access_token='); |
82 if (access_token_index) { | 82 if (access_token_index) { |
83 url = url.substring(0, access_token_index - 1); | 83 url = url.substring(0, access_token_index - 1); |
84 } | 84 } |
85 this.cachedUrl_ = url; | 85 this.cachedUrl_ = url; |
86 return url; | 86 return url; |
87 }.bind(this)); | 87 }.bind(this)); |
88 }; | 88 }; |
89 | 89 |
90 /** | 90 /** |
91 * Retrives the mime of file. | 91 * Retrieves the mime of file. |
92 * | 92 * |
93 * @return {Promise} Promise which is resolved with the mime. Reject if failed. | 93 * @return {Promise} Promise which is resolved with the mime. Reject if failed. |
94 */ | 94 */ |
95 MediaManager.prototype.getMime = function() { | 95 MediaManager.prototype.getMime = function() { |
96 if (this.cachedDriveProp_) | 96 if (this.cachedDriveProp_) |
97 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); | 97 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); |
98 | 98 |
99 return new Promise(function(fulfill, reject) { | 99 return new Promise(function(fulfill, reject) { |
100 chrome.fileBrowserPrivate.getDriveEntryProperties( | 100 chrome.fileBrowserPrivate.getDriveEntryProperties( |
101 [this.entry_.toURL()], fulfill); | 101 [this.entry_.toURL()], fulfill); |
102 }.bind(this)).then(function(props) { | 102 }.bind(this)).then(function(props) { |
103 if (!props || !props[0] || !props[0].contentMimeType) { | 103 if (!props || !props[0] || !props[0].contentMimeType) { |
104 // TODO(yoshiki): Adds a logic to guess the mime. | 104 // TODO(yoshiki): Adds a logic to guess the mime. |
105 return Promise.reject('Mime fetch failed.'); | 105 return Promise.reject('Mime fetch failed.'); |
106 } else { | 106 } else { |
107 this.cachedDriveProp_ = props[0]; | 107 this.cachedDriveProp_ = props[0]; |
108 return props[0].contentMimeType; | 108 return props[0].contentMimeType; |
109 } | 109 } |
110 }.bind(this)); | 110 }.bind(this)); |
111 }; | 111 }; |
112 | 112 |
113 /** | 113 /** |
114 * Retrives the thumbnail urlof file. | 114 * Retrieves the thumbnail url of file. |
115 * | 115 * |
116 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 116 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
117 */ | 117 */ |
118 MediaManager.prototype.getThumbnail = function() { | 118 MediaManager.prototype.getThumbnail = function() { |
119 if (this.cachedDriveProp_) | 119 if (this.cachedDriveProp_) |
120 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); | 120 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); |
121 | 121 |
122 return new Promise(function(fulfill, reject) { | 122 return new Promise(function(fulfill, reject) { |
123 chrome.fileBrowserPrivate.getDriveEntryProperties( | 123 chrome.fileBrowserPrivate.getDriveEntryProperties( |
124 [this.entry_.toURL()], fulfill); | 124 [this.entry_.toURL()], fulfill); |
125 }.bind(this)).then(function(props) { | 125 }.bind(this)).then(function(props) { |
126 if (!props || !props[0] || !props[0].thumbnailUrl) { | 126 if (!props || !props[0] || !props[0].thumbnailUrl) { |
127 // TODO(yoshiki): Adds a logic to guess the mime. | 127 // TODO(yoshiki): Adds a logic to guess the mime. |
128 return Promise.reject('Thuumbnail fetch failed.'); | 128 return Promise.reject('Thumbnail fetch failed.'); |
129 } else { | 129 } else { |
130 this.cachedDriveProp_ = props[0]; | 130 this.cachedDriveProp_ = props[0]; |
131 return props[0].thumbnailUrl; | 131 return props[0].thumbnailUrl; |
132 } | 132 } |
133 }.bind(this)); | 133 }.bind(this)); |
134 }; | 134 }; |
OLD | NEW |