| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 function ChromeOSValidator() { | |
| 6 } | |
| 7 | |
| 8 ChromeOSValidator.getInstance = function() { | |
| 9 if (!ChromeOSValidator.instance_) { | |
| 10 ChromeOSValidator.instance_ = new ChromeOSValidator(); | |
| 11 } | |
| 12 return ChromeOSValidator.instance_; | |
| 13 }; | |
| 14 | |
| 15 ChromeOSValidator.prototype = { | |
| 16 LOADER_ORIGIN: 'chrome-extension://nbicjcbcmclhihdkigkjgkgafckdfcom', | |
| 17 LOADER_PAGE: '/background.html', | |
| 18 callback_: undefined, | |
| 19 | |
| 20 validate: function(callback) { | |
| 21 this.callback_ = callback; | |
| 22 var msg = { method: 'validate' }; | |
| 23 window.parent.postMessage(msg, | |
| 24 this.LOADER_ORIGIN + this.LOADER_PAGE); | |
| 25 }, | |
| 26 | |
| 27 initialize: function() { | |
| 28 window.addEventListener('message', this.onMessage.bind(this), false); | |
| 29 }, | |
| 30 | |
| 31 isValidMessage_: function(msg) { | |
| 32 return msg.origin == this.LOADER_ORIGIN; | |
| 33 }, | |
| 34 | |
| 35 onMessage: function(e) { | |
| 36 var msg = e.data; | |
| 37 if (msg.method == 'validationResults' && this.isValidMessage_(e)) { | |
| 38 if (this.callback_) | |
| 39 this.callback_(msg.os == 'ChromeOS'); | |
| 40 } else { | |
| 41 console.log('#### ChromeOSValidator.onMessage: unknown message'); | |
| 42 if (this.callback_) | |
| 43 this.callback_(false); | |
| 44 } | |
| 45 } | |
| 46 }; | |
| 47 | |
| 48 ChromeOSValidator.getInstance().initialize(); | |
| OLD | NEW |