Chromium Code Reviews| 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 * Common utilities and types for Caterpillar. | 16 * Common utilities and types for Caterpillar. |
| 17 * | 17 * |
| 18 * Must be included before any Caterpillar polyfills. | 18 * Must be included before any Caterpillar polyfills. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 'use strict'; | 21 'use strict'; |
| 22 | 22 |
| 23 // Set up a namespace if one doesn't already exist. | 23 // Set up a namespace if one doesn't already exist. |
| 24 if (!('chrome' in self)) | 24 if (!('chrome' in self)) |
| 25 self.chrome = {}; | 25 self.chrome = {}; |
| 26 | 26 |
| 27 if (!chrome.caterpillar) | 27 if (!chrome.caterpillar) |
| 28 chrome.caterpillar = {}; | 28 chrome.caterpillar = {}; |
| 29 | 29 |
| 30 // We need the chrome.runtime namespace to store errors in. | |
| 31 if (!chrome.runtime) | |
| 32 chrome.runtime = { lastError: null }; | |
| 33 | |
| 34 // Stub out chrome.app.runtime.onLaunched.addListener, since this always appears | |
| 35 // in Chrome Apps. | |
|
raymes
2016/01/31 23:44:37
I'm not sure what this comment means? Why is it st
Matthew Alger
2016/02/01 00:14:33
chrome.app.runtime.onLaunched.addListener is used
raymes
2016/02/01 00:18:44
Could you make the comment say something like this
Matthew Alger
2016/02/01 00:36:52
Done.
| |
| 36 if (!chrome.app) | |
|
Matthew Alger
2016/01/28 04:51:41
Note that Chrome exports chrome.app, so we can't j
raymes
2016/01/31 23:44:37
Could we just always override onLaunched? (do we r
Matthew Alger
2016/02/01 00:14:33
It's not obvious to me that Chrome doesn't/won't e
raymes
2016/02/01 00:18:44
Why not override it? :) I think we had a similar d
Matthew Alger
2016/02/01 00:36:52
Hmmm, okay. Done.
(Though if a chrome.app.runtime
| |
| 37 chrome.app = {}; | |
| 38 if (!chrome.app.runtime) | |
| 39 chrome.app.runtime = {}; | |
| 40 if (!chrome.app.runtime.onLaunched) { | |
| 41 chrome.app.runtime.onLaunched = { | |
| 42 addListener: function() {}, | |
| 43 }; | |
| 44 } | |
|
raymes
2016/01/31 23:44:37
Why did this code need to be moved?
Matthew Alger
2016/02/01 00:14:33
- It's static, so I think it should go in a static
raymes
2016/02/01 00:18:44
Sounds good - this would be useful context to have
Matthew Alger
2016/02/01 00:36:52
Done.
| |
| 45 | |
| 30 (function() { | 46 (function() { |
| 31 | 47 |
| 32 /** | 48 /** |
| 33 * Sets an error message in lastError if chrome.runtime is loaded. | 49 * Sets an error message in lastError if chrome.runtime is loaded. |
|
raymes
2016/02/01 00:18:44
nit: this is no longer accurate, nor the @throws b
Matthew Alger
2016/02/01 00:36:52
! Done.
| |
| 34 * | 50 * |
| 35 * @param {string} message The error message to set. | 51 * @param {string} message The error message to set. |
| 36 * | 52 * |
| 37 * @throws Error with given message if runtime is not loaded, and a warning that | 53 * @throws Error with given message if runtime is not loaded, and a warning that |
| 38 * runtime isn't loaded. | 54 * runtime isn't loaded. |
| 39 */ | 55 */ |
| 40 chrome.caterpillar.setError = function(message) { | 56 chrome.caterpillar.setError = function(message) { |
| 41 if (!chrome.runtime) { | 57 console.warn('Error set in lastError:', message); |
|
raymes
2016/01/31 23:44:37
Do we need to log warnings every time?
Matthew Alger
2016/02/01 00:14:33
Hmm, I'm not sure. I don't think it really matters
raymes
2016/02/01 00:18:44
I think removing it is ok.
Matthew Alger
2016/02/01 00:36:52
Done.
| |
| 42 console.warn('chrome.runtime not found; runtime errors may not be caught.'); | |
| 43 throw new Error(message); | |
| 44 } | |
| 45 chrome.runtime.lastError = { 'message': message }; | 58 chrome.runtime.lastError = { 'message': message }; |
| 46 }; | 59 }; |
| 47 | 60 |
| 48 }).call(this); | 61 }).call(this); |
| OLD | NEW |