1// Copyright (c) 2010 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
6function chromeos() {
7}
8
9chromeos.connectionManager = function() {
10};
11
12chromeos.connectionManager.device_info_callback_ = null;
13chromeos.connectionManager.transaction_status_callback_ = null;
14chromeos.connectionManager.parent_page_url_ = 'chrome://mobilesetup';
15
16chromeos.connectionManager.getDeviceInfo = function(callback) {
17  chromeos.connectionManager.device_info_callback_ = callback;
18  chromeos.connectionManager.requestDeviceInfo_();
19};
20
21chromeos.connectionManager.setTransactionStatus = function(status, callback) {
22  chromeos.connectionManager.transaction_status_callback_ = callback;
23  chromeos.connectionManager.reportTransactionStatus_(status);
24};
25
26chromeos.connectionManager.reportTransactionStatus_ = function(status) {
27  var msg = {
28    'type': 'reportTransactionStatusMsg',
29    'domain': location.href,
30    'status': status
31  };
32  window.parent.postMessage(msg, chromeos.connectionManager.parent_page_url_);
33};
34
35chromeos.connectionManager.requestDeviceInfo_ = function() {
36  var msg = {
37    'type': 'requestDeviceInfoMsg',
38    'domain': location.href,
39  };
40  window.parent.postMessage(msg, chromeos.connectionManager.parent_page_url_);
41}
42
43window.addEventListener('message', function(e) {
44  if (e.data.type == 'deviceInfoMsg') {
45    if (chromeos.connectionManager.device_info_callback_)
46      chromeos.connectionManager.device_info_callback_(e.data.payload);
47  }
48});
49