OLD | NEW |
1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 /** | 15 /** |
16 * Polyfill for Chrome Apps' runtime API. | 16 * Polyfill for the Chrome Apps runtime API. |
17 */ | 17 */ |
18 | 18 |
19 'use strict'; | 19 'use strict'; |
20 | 20 |
| 21 (function() { |
| 22 |
21 // Add namespaces for the polyfill if they don't already exist. | 23 // Add namespaces for the polyfill if they don't already exist. |
22 if (!chrome.runtime) | 24 if (!chrome.runtime) |
23 chrome.runtime = {}; | 25 chrome.runtime = {}; |
24 | 26 |
25 (function() { | 27 /** |
| 28 * Not implemented. |
| 29 */ |
| 30 chrome.runtime.Port = class { |
| 31 constructor() { |
| 32 throw new Error('Port not implemented.'); |
| 33 } |
| 34 }; |
| 35 |
| 36 /** |
| 37 * Not implemented. |
| 38 */ |
| 39 chrome.runtime.MessageSender = class { |
| 40 constructor() { |
| 41 throw new Error('MessageSender not implemented.'); |
| 42 } |
| 43 }; |
26 | 44 |
27 /** | 45 /** |
28 * The operating system the browser is running on. | 46 * The operating system the browser is running on. |
29 */ | 47 */ |
30 chrome.runtime.PlatformOs = { | 48 chrome.runtime.PlatformOs = { |
31 ANDROID: 'android', | 49 ANDROID: 'android', |
32 CROS: 'cros', | 50 CROS: 'cros', |
33 LINUX: 'linux', | 51 LINUX: 'linux', |
34 MAC: 'mac', | 52 MAC: 'mac', |
35 OPENBSD: 'openbsd', | 53 OPENBSD: 'openbsd', |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 chrome.runtime.getBackgroundPage = function(callback) { | 134 chrome.runtime.getBackgroundPage = function(callback) { |
117 caterpillar_.setError('No background page for progressive web apps.'); | 135 caterpillar_.setError('No background page for progressive web apps.'); |
118 callback(); | 136 callback(); |
119 }; | 137 }; |
120 | 138 |
121 /** | 139 /** |
122 * Opens an extension's options page, if possible. | 140 * Opens an extension's options page, if possible. |
123 * | 141 * |
124 * Always sets an error in lastError since this isn't an extension. | 142 * Always sets an error in lastError since this isn't an extension. |
125 * | 143 * |
126 * @param {function} opt_callback Callback function on success or error. | 144 * @param {function=} opt_callback Callback function on success or error. |
127 */ | 145 */ |
128 chrome.runtime.openOptionsPage = function(opt_callback) { | 146 chrome.runtime.openOptionsPage = function(opt_callback) { |
129 caterpillar_.setError('Could not create an options page.'); | 147 caterpillar_.setError('Could not create an options page.'); |
130 if (opt_callback) | 148 if (opt_callback) |
131 opt_callback(); | 149 opt_callback(); |
132 }; | 150 }; |
133 | 151 |
134 /** | 152 /** |
135 * Returns details about the app or extension from the manifest. The object | 153 * Returns details about the app or extension from the manifest. The object |
136 * returned is a serialization of the full manifest file. | 154 * returned is a serialization of the full manifest file. |
137 * | 155 * |
138 * Note that this returns the *original* Chrome App manifest, not the | 156 * Note that this returns the *original* Chrome App manifest, not the |
139 * progressive web app manifest. | 157 * progressive web app manifest. |
140 * | 158 * |
141 * @returns {object} Copy of the Chrome App manifest. | 159 * @returns {object} Copy of the Chrome App manifest. |
142 */ | 160 */ |
143 chrome.runtime.getManifest = function() { | 161 chrome.runtime.getManifest = function() { |
144 return JSON.parse(JSON.stringify(caterpillar_.manifest)); | 162 return JSON.parse(JSON.stringify(caterpillar_.manifest)); |
145 }; | 163 }; |
146 | 164 |
147 /** | 165 /** |
| 166 * Not implemented. |
| 167 */ |
| 168 chrome.runtime.getURL = function() { |
| 169 throw new Error('getURL not implemented.'); |
| 170 }; |
| 171 |
| 172 /** |
148 * Sets the URL to be visited upon uninstallation. | 173 * Sets the URL to be visited upon uninstallation. |
149 * | 174 * |
150 * Does nothing but call the callback, since there is no uninstallation event | 175 * Does nothing but call the callback, since there is no uninstallation event |
151 * for a progressive web app. | 176 * for a progressive web app. |
152 * | 177 * |
153 * @param {string} url URL to visit upon uninstallation. | 178 * @param {string} url URL to visit upon uninstallation. |
154 * @param {function} opt_callback Callback function on success or error. | 179 * @param {function=} opt_callback Callback function on success or error. |
155 */ | 180 */ |
156 chrome.runtime.setUninstallURL = function(url, opt_callback) { | 181 chrome.runtime.setUninstallURL = function(url, opt_callback) { |
157 if (opt_callback) | 182 if (opt_callback) |
158 opt_callback(); | 183 opt_callback(); |
159 }; | 184 }; |
160 | 185 |
161 /** | 186 /** |
162 * Reloads the app. | 187 * Reloads the app. |
163 * | 188 * |
164 * In this polyfill, this function just refreshes the page. | 189 * In this polyfill, this function just refreshes the page. |
(...skipping 28 matching lines...) Expand all Loading... |
193 }; | 218 }; |
194 | 219 |
195 /** | 220 /** |
196 * Not implemented. | 221 * Not implemented. |
197 */ | 222 */ |
198 chrome.runtime.connectNative = function() { | 223 chrome.runtime.connectNative = function() { |
199 throw new Error('connectNative not implemented.'); | 224 throw new Error('connectNative not implemented.'); |
200 }; | 225 }; |
201 | 226 |
202 /** | 227 /** |
| 228 * Not implemented. |
| 229 */ |
| 230 chrome.runtime.sendMessage = function() { |
| 231 throw new Error('sendMessage not implemented.'); |
| 232 }; |
| 233 |
| 234 /** |
| 235 * Not implemented. |
| 236 */ |
| 237 chrome.runtime.sendNativeMessage = function() { |
| 238 throw new Error('sendNativeMessage not implemented.'); |
| 239 }; |
| 240 |
| 241 /** |
203 * Gets information about the current operating system. | 242 * Gets information about the current operating system. |
204 * | 243 * |
205 * @param {function} callback Function taking PlatformInfo. | 244 * @param {function} callback Function taking PlatformInfo. |
206 */ | 245 */ |
207 chrome.runtime.getPlatformInfo = function(callback) { | 246 chrome.runtime.getPlatformInfo = function(callback) { |
208 // Here, we use platform.js to guess a reasonable value for the platform | 247 // Here, we use platform.js to guess a reasonable value for the platform |
209 // information expected by Chrome Apps. This is pretty hard since we can't | 248 // information expected by Chrome Apps. This is pretty hard since we can't |
210 // make the same guarantees a Chrome App can about the open web, so this is | 249 // make the same guarantees a Chrome App can about the open web, so this is a |
211 // a "best guess". | 250 // "best guess". |
212 | 251 |
213 // We need to guess: android, cros, linux, mac, openbsd, win | 252 // We need to guess: android, cros, linux, mac, openbsd, win |
214 // We also need to guess: x86-64, x86-32, arm | 253 // We also need to guess: x86-64, x86-32, arm |
215 var os = platform.os.family.toLowerCase(); | 254 var os = platform.os.family.toLowerCase(); |
216 if (os.indexOf('win') !== -1) { | 255 if (os.indexOf('win') !== -1) { |
217 os = 'win'; | 256 os = 'win'; |
218 } else if (os.indexOf('android') !== -1) { | 257 } else if (os.indexOf('android') !== -1) { |
219 os = 'android'; | 258 os = 'android'; |
220 } else if (os.indexOf('linux') !== -1) { | 259 } else if (os.indexOf('linux') !== -1) { |
221 os = 'linux'; | 260 os = 'linux'; |
(...skipping 12 matching lines...) Expand all Loading... |
234 callback(info); | 273 callback(info); |
235 }; | 274 }; |
236 | 275 |
237 /** | 276 /** |
238 * Not implemented. | 277 * Not implemented. |
239 */ | 278 */ |
240 chrome.runtime.getPackageDirectoryEntry = function() { | 279 chrome.runtime.getPackageDirectoryEntry = function() { |
241 throw new Error('getPackageDirectoryEntry not implemented.'); | 280 throw new Error('getPackageDirectoryEntry not implemented.'); |
242 }; | 281 }; |
243 | 282 |
244 // TODO(alger): Implement or stub Port. | 283 /** |
245 // TODO(alger): Implement or stub MessageSender. | 284 * Not implemented events. All addListener methods for not implemented events |
246 // TODO(alger): Implement or stub sendMessage. | 285 * have been stubbed in this polyfill. |
247 // TODO(alger): Implement or stub getURL. | 286 */ |
248 // TODO(alger): Implement or stub sendMessage. | 287 |
249 // TODO(alger): Implement or stub sendNativeMessage. | 288 chrome.runtime.onStartup = { |
250 // TODO(alger): Implement or stub onStartup. | 289 addListener: function() { |
251 // TODO(alger): Implement or stub onInstalled. | 290 throw new Error('onStartup not implemented.'); |
252 // TODO(alger): Implement or stub onSuspend. | 291 } |
253 // TODO(alger): Implement or stub onSuspendCanceled. | 292 }; |
254 // TODO(alger): Implement or stub onUpdateAvailable. | 293 |
255 // TODO(alger): Implement or stub onBrowserUpdateAvailable. | 294 chrome.runtime.onInstalled = { |
256 // TODO(alger): Implement or stub onConnect. | 295 addListener: function() { |
257 // TODO(alger): Implement or stub onConnectExternal. | 296 throw new Error('onInstalled not implemented.'); |
258 // TODO(alger): Implement or stub onMessage. | 297 } |
259 // TODO(alger): Implement or stub onMessageExternal. | 298 }; |
260 // TODO(alger): Implement or stub onRestartRequired. | 299 |
| 300 chrome.runtime.onSuspend = { |
| 301 addListener: function() { |
| 302 throw new Error('onSuspend not implemented.'); |
| 303 } |
| 304 }; |
| 305 |
| 306 chrome.runtime.onSuspendCanceled = { |
| 307 addListener: function() { |
| 308 throw new Error('onSuspendCanceled not implemented.'); |
| 309 } |
| 310 }; |
| 311 |
| 312 chrome.runtime.onUpdateAvailable = { |
| 313 addListener: function() { |
| 314 throw new Error('onUpdateAvailable not implemented.'); |
| 315 } |
| 316 }; |
| 317 |
| 318 chrome.runtime.onBrowserUpdateAvailable = { |
| 319 addListener: function() { |
| 320 throw new Error('onBrowserUpdateAvailable not implemented.'); |
| 321 } |
| 322 }; |
| 323 |
| 324 chrome.runtime.onConnect = { |
| 325 addListener: function() { |
| 326 throw new Error('onConnect not implemented.'); |
| 327 } |
| 328 }; |
| 329 |
| 330 chrome.runtime.onConnectExternal = { |
| 331 addListener: function() { |
| 332 throw new Error('onConnectExternal not implemented.'); |
| 333 } |
| 334 }; |
| 335 |
| 336 chrome.runtime.onMessage = { |
| 337 addListener: function() { |
| 338 throw new Error('onMessage not implemented.'); |
| 339 } |
| 340 }; |
| 341 |
| 342 chrome.runtime.onMessageExternal = { |
| 343 addListener: function() { |
| 344 throw new Error('onMessageExternal not implemented.'); |
| 345 } |
| 346 }; |
| 347 |
| 348 chrome.runtime.onRestartRequired = { |
| 349 addListener: function() { |
| 350 throw new Error('onRestartRequired not implemented.'); |
| 351 } |
| 352 }; |
261 | 353 |
262 }).call(this); | 354 }).call(this); |
OLD | NEW |