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 6 function chromeos() { 7 } 8 9 chromeos.connectionManager = function() { 10 }; 11 12 chromeos.connectionManager.device_info_callback_ = null; 13 chromeos.connectionManager.transaction_status_callback_ = null; 14 chromeos.connectionManager.parent_page_url_ = 'chrome://mobilesetup'; 15 16 chromeos.connectionManager.getDeviceInfo = function(callback) { 17 chromeos.connectionManager.device_info_callback_ = callback; 18 chromeos.connectionManager.requestDeviceInfo_(); 19 }; 20 21 chromeos.connectionManager.setTransactionStatus = function(status, callback) { 22 chromeos.connectionManager.transaction_status_callback_ = callback; 23 chromeos.connectionManager.reportTransactionStatus_(status); 24 }; 25 26 chromeos.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 35 chromeos.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 43 window.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