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 * This view displays information on Winsock layered service providers and 7 * namespace providers. 8 * 9 * For each layered service provider, shows the name, dll, and type 10 * information. For each namespace provider, shows the name and 11 * whether or not it's active. 12 * 13 * @constructor 14 */ 15function ServiceProvidersView(tabId, 16 mainBoxId, 17 serviceProvidersTbodyId, 18 namespaceProvidersTbodyId) { 19 DivView.call(this, mainBoxId); 20 21 var tab = document.getElementById(tabId); 22 setNodeDisplay(tab, true); 23 24 this.serviceProvidersTbody_ = 25 document.getElementById(serviceProvidersTbodyId); 26 this.namespaceProvidersTbody_ = 27 document.getElementById(namespaceProvidersTbodyId); 28 29 g_browser.addServiceProvidersObserver(this); 30} 31 32inherits(ServiceProvidersView, DivView); 33 34ServiceProvidersView.prototype.onServiceProvidersChanged = 35function(serviceProviders) { 36 this.updateServiceProviders_(serviceProviders['service_providers']); 37 this.updateNamespaceProviders_(serviceProviders['namespace_providers']); 38}; 39 40/** 41 * Returns type of a layered service provider. 42 */ 43ServiceProvidersView.getLayeredServiceProviderType = 44function(serviceProvider) { 45 if (serviceProvider.chain_length == 0) 46 return 'Layer'; 47 if (serviceProvider.chain_length == 1) 48 return 'Base'; 49 return 'Chain'; 50}; 51 52ServiceProvidersView.namespaceProviderType_ = { 53 '12': 'NS_DNS', 54 '15': 'NS_NLA', 55 '16': 'NS_BTH', 56 '32': 'NS_NTDS', 57 '37': 'NS_EMAIL', 58 '38': 'NS_PNRPNAME', 59 '39': 'NS_PNRPCLOUD' 60}; 61 62/** 63 * Returns the type of a namespace provider as a string. 64 */ 65ServiceProvidersView.getNamespaceProviderType = function(namespaceProvider) { 66 return tryGetValueWithKey(ServiceProvidersView.namespaceProviderType_, 67 namespaceProvider.type); 68}; 69 70ServiceProvidersView.socketType_ = { 71 '1': 'SOCK_STREAM', 72 '2': 'SOCK_DGRAM', 73 '3': 'SOCK_RAW', 74 '4': 'SOCK_RDM', 75 '5': 'SOCK_SEQPACKET' 76}; 77 78/** 79 * Returns socket type of a layered service provider as a string. 80 */ 81ServiceProvidersView.getSocketType = function(layeredServiceProvider) { 82 return tryGetValueWithKey(ServiceProvidersView.socketType_, 83 layeredServiceProvider.socket_type); 84}; 85 86ServiceProvidersView.protocolType_ = { 87 '1': 'IPPROTO_ICMP', 88 '6': 'IPPROTO_TCP', 89 '17': 'IPPROTO_UDP', 90 '58': 'IPPROTO_ICMPV6' 91}; 92 93/** 94 * Returns protocol type of a layered service provider as a string. 95 */ 96ServiceProvidersView.getProtocolType = function(layeredServiceProvider) { 97 return tryGetValueWithKey(ServiceProvidersView.protocolType_, 98 layeredServiceProvider.socket_protocol); 99}; 100 101 /** 102 * Updates the table of layered service providers. 103 */ 104ServiceProvidersView.prototype.updateServiceProviders_ = 105function(serviceProviders) { 106 this.serviceProvidersTbody_.innerHTML = ''; 107 108 // Add a table row for each service provider. 109 for (var i = 0; i < serviceProviders.length; ++i) { 110 var tr = addNode(this.serviceProvidersTbody_, 'tr'); 111 var entry = serviceProviders[i]; 112 113 addNodeWithText(tr, 'td', entry.name); 114 addNodeWithText(tr, 'td', entry.version); 115 addNodeWithText(tr, 'td', 116 ServiceProvidersView.getLayeredServiceProviderType(entry)); 117 addNodeWithText(tr, 'td', ServiceProvidersView.getSocketType(entry)); 118 addNodeWithText(tr, 'td', ServiceProvidersView.getProtocolType(entry)); 119 addNodeWithText(tr, 'td', entry.path); 120 } 121}; 122 123/** 124 * Updates the lable of namespace providers. 125 */ 126ServiceProvidersView.prototype.updateNamespaceProviders_ = 127function(namespaceProviders) { 128 this.namespaceProvidersTbody_.innerHTML = ''; 129 130 // Add a table row for each namespace provider. 131 for (var i = 0; i < namespaceProviders.length; ++i) { 132 var tr = addNode(this.namespaceProvidersTbody_, 'tr'); 133 var entry = namespaceProviders[i]; 134 addNodeWithText(tr, 'td', entry.name); 135 addNodeWithText(tr, 'td', entry.version); 136 addNodeWithText(tr, 'td', 137 ServiceProvidersView.getNamespaceProviderType(entry)); 138 addNodeWithText(tr, 'td', entry.active); 139 } 140}; 141 142