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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 * @param {boolean} refresh If true, force to refresh 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.fileManagerPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
53 }.bind(this)).then(function(url) { | 53 }.bind(this)).then(function(url) { |
54 if (chrome.runtime.lastError) { | 54 if (chrome.runtime.lastError) { |
55 return Promise.reject( | 55 return Promise.reject( |
56 'Token fetch failed: ' + chrome.runtime.lastError.message); | 56 'Token fetch failed: ' + chrome.runtime.lastError.message); |
57 } | 57 } |
58 if (!url) | 58 if (!url) |
59 return Promise.reject('Token fetch failed.'); | 59 return Promise.reject('Token fetch failed.'); |
60 var token = url.substring(url.indexOf('access_token=') + 13); | 60 var token = url.substring(url.indexOf('access_token=') + 13); |
61 if (token) { | 61 if (token) { |
62 this.cachedToken_ = token; | 62 this.cachedToken_ = token; |
63 return token; | 63 return token; |
64 } else { | 64 } else { |
65 return Promise.reject('Token fetch failed.'); | 65 return Promise.reject('Token fetch failed.'); |
66 } | 66 } |
67 }.bind(this)); | 67 }.bind(this)); |
68 }; | 68 }; |
69 | 69 |
70 /** | 70 /** |
71 * Retrieves the url for cast. | 71 * Retrieves the url for cast. |
72 * | 72 * |
73 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 73 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
74 */ | 74 */ |
75 MediaManager.prototype.getUrl = function() { | 75 MediaManager.prototype.getUrl = function() { |
76 if (this.cachedUrl_) | 76 if (this.cachedUrl_) |
77 return Promise.resolve(this.cachedUrl_); | 77 return Promise.resolve(this.cachedUrl_); |
78 | 78 |
79 return new Promise(function(fulfill, reject) { | 79 return new Promise(function(fulfill, reject) { |
80 // TODO(yoshiki): Creates the method to get a url and use it. | 80 // TODO(yoshiki): Creates the method to get a url and use it. |
81 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); | 81 chrome.fileManagerPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
82 }.bind(this)).then(function(url) { | 82 }.bind(this)).then(function(url) { |
83 if (chrome.runtime.lastError) { | 83 if (chrome.runtime.lastError) { |
84 return Promise.reject( | 84 return Promise.reject( |
85 'URL fetch failed: ' + chrome.runtime.lastError.message); | 85 'URL fetch failed: ' + chrome.runtime.lastError.message); |
86 } | 86 } |
87 if (!url) | 87 if (!url) |
88 return Promise.reject('URL fetch failed.'); | 88 return Promise.reject('URL fetch failed.'); |
89 var access_token_index = url.indexOf('access_token='); | 89 var access_token_index = url.indexOf('access_token='); |
90 if (access_token_index) { | 90 if (access_token_index) { |
91 url = url.substring(0, access_token_index - 1); | 91 url = url.substring(0, access_token_index - 1); |
92 } | 92 } |
93 this.cachedUrl_ = url; | 93 this.cachedUrl_ = url; |
94 return url; | 94 return url; |
95 }.bind(this)); | 95 }.bind(this)); |
96 }; | 96 }; |
97 | 97 |
98 /** | 98 /** |
99 * Retrieves the mime of file. | 99 * Retrieves the mime of file. |
100 * | 100 * |
101 * @return {Promise} Promise which is resolved with the mime. Reject if failed. | 101 * @return {Promise} Promise which is resolved with the mime. Reject if failed. |
102 */ | 102 */ |
103 MediaManager.prototype.getMime = function() { | 103 MediaManager.prototype.getMime = function() { |
104 if (this.cachedDriveProp_) | 104 if (this.cachedDriveProp_) |
105 return Promise.resolve(this.cachedDriveProp_.contentMimeType || ''); | 105 return Promise.resolve(this.cachedDriveProp_.contentMimeType || ''); |
106 | 106 |
107 return new Promise(function(fulfill, reject) { | 107 return new Promise(function(fulfill, reject) { |
108 chrome.fileBrowserPrivate.getEntryProperties( | 108 chrome.fileManagerPrivate.getEntryProperties( |
109 [this.entry_.toURL()], fulfill); | 109 [this.entry_.toURL()], fulfill); |
110 }.bind(this)).then(function(props) { | 110 }.bind(this)).then(function(props) { |
111 if (!props || !props[0]) { | 111 if (!props || !props[0]) { |
112 return Promise.reject('Mime fetch failed.'); | 112 return Promise.reject('Mime fetch failed.'); |
113 } else if (!props[0].contentMimeType) { | 113 } else if (!props[0].contentMimeType) { |
114 // TODO(yoshiki): Adds a logic to guess the mime. | 114 // TODO(yoshiki): Adds a logic to guess the mime. |
115 this.cachedDriveProp_ = props[0]; | 115 this.cachedDriveProp_ = props[0]; |
116 return ''; | 116 return ''; |
117 } else { | 117 } else { |
118 this.cachedDriveProp_ = props[0]; | 118 this.cachedDriveProp_ = props[0]; |
119 return props[0].contentMimeType; | 119 return props[0].contentMimeType; |
120 } | 120 } |
121 }.bind(this)); | 121 }.bind(this)); |
122 }; | 122 }; |
123 | 123 |
124 /** | 124 /** |
125 * Retrieves the thumbnail url of file. | 125 * Retrieves the thumbnail url of file. |
126 * | 126 * |
127 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 127 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
128 */ | 128 */ |
129 MediaManager.prototype.getThumbnail = function() { | 129 MediaManager.prototype.getThumbnail = function() { |
130 if (this.cachedDriveProp_) | 130 if (this.cachedDriveProp_) |
131 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl || ''); | 131 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl || ''); |
132 | 132 |
133 return new Promise(function(fulfill, reject) { | 133 return new Promise(function(fulfill, reject) { |
134 chrome.fileBrowserPrivate.getEntryProperties( | 134 chrome.fileManagerPrivate.getEntryProperties( |
135 [this.entry_.toURL()], fulfill); | 135 [this.entry_.toURL()], fulfill); |
136 }.bind(this)).then(function(props) { | 136 }.bind(this)).then(function(props) { |
137 if (!props || !props[0]) { | 137 if (!props || !props[0]) { |
138 return Promise.reject('Thumbnail fetch failed.'); | 138 return Promise.reject('Thumbnail fetch failed.'); |
139 } else { | 139 } else { |
140 this.cachedDriveProp_ = props[0]; | 140 this.cachedDriveProp_ = props[0]; |
141 return props[0].thumbnailUrl || ''; | 141 return props[0].thumbnailUrl || ''; |
142 } | 142 } |
143 }.bind(this)); | 143 }.bind(this)); |
144 }; | 144 }; |
OLD | NEW |