Index: chrome/browser/resources/chromeos/backloader/web/cros_validator.js |
diff --git a/chrome/browser/resources/chromeos/backloader/web/cros_validator.js b/chrome/browser/resources/chromeos/backloader/web/cros_validator.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2ed0c7a906f2f8cc7a4912aedab17296b768ab29 |
--- /dev/null |
+++ b/chrome/browser/resources/chromeos/backloader/web/cros_validator.js |
@@ -0,0 +1,52 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+function ChromeOSValidator() { |
+} |
+ |
+ChromeOSValidator.getInstance = function() { |
+ if (!ChromeOSValidator.instance_) { |
+ ChromeOSValidator.instance_ = new ChromeOSValidator(); |
+ } |
+ return ChromeOSValidator.instance_; |
+}; |
+ |
+ChromeOSValidator.prototype = { |
+ LOADER_ORIGIN: 'chrome-extension://nbicjcbcmclhihdkigkjgkgafckdfcom', |
+ LOADER_PAGE: '/background.html', |
+ callback_: null, |
xiyuan
2012/08/16 16:55:38
nit: prefer to use undefined
zel
2012/08/16 17:17:22
Done.
|
+ |
+ validate: function(callback) { |
+ this.callback_ = callback; |
+ var msg = { method: 'validate' }; |
+ window.parent.postMessage(msg, |
+ this.LOADER_ORIGIN + this.LOADER_PAGE); |
+ }, |
+ |
+ initialize: function() { |
+ document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); |
xiyuan
2012/08/16 16:55:38
This really depends on how ChromeOSValidator is in
zel
2012/08/16 17:17:22
Done.
|
+ }, |
+ |
+ isValidMessage_: function(msg) { |
+ return msg.origin == this.LOADER_ORIGIN; |
+ }, |
+ |
+ onPageLoad: function(e) { |
+ window.addEventListener('message', this.onMessage.bind(this), false); |
+ }, |
+ |
+ onMessage: function(e) { |
+ var msg = e.data; |
+ if (msg.method == 'validationResults' && this.isValidMessage_(e)) { |
+ if (this.callback_) |
+ this.callback_(msg.os == 'ChromeOS'); |
+ } else { |
+ console.log('#### ChromeOSValidator.onMessage: unknown message'); |
+ if (this.callback_) |
+ this.callback_(false); |
+ } |
+ } |
+}; |
+ |
+ChromeOSValidator.getInstance().initialize(); |