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/** 6 * This view displays information on installed Chrome extensions / apps as well 7 * as Winsock layered service providers and 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 */ 13var ModulesView = (function() { 14 'use strict'; 15 16 // We inherit from DivView. 17 var superClass = DivView; 18 19 /** 20 * @constructor 21 */ 22 function ModulesView() { 23 assertFirstConstructorCall(ModulesView); 24 25 // Call superclass's constructor. 26 superClass.call(this, ModulesView.MAIN_BOX_ID); 27 28 this.serviceProvidersTbody_ = 29 $(ModulesView.SERVICE_PROVIDERS_TBODY_ID); 30 this.namespaceProvidersTbody_ = 31 $(ModulesView.NAMESPACE_PROVIDERS_TBODY_ID); 32 33 g_browser.addServiceProvidersObserver(this, false); 34 g_browser.addExtensionInfoObserver(this, true); 35 } 36 37 ModulesView.TAB_ID = 'tab-handle-modules'; 38 ModulesView.TAB_NAME = 'Modules'; 39 ModulesView.TAB_HASH = '#modules'; 40 41 // IDs for special HTML elements in modules_view.html. 42 ModulesView.MAIN_BOX_ID = 'modules-view-tab-content'; 43 ModulesView.EXTENSION_INFO_ID = 'modules-view-extension-info'; 44 ModulesView.WINDOWS_SERVICE_PROVIDERS_ID = 45 'modules-view-windows-service-providers'; 46 47 cr.addSingletonGetter(ModulesView); 48 49 ModulesView.prototype = { 50 // Inherit the superclass's methods. 51 __proto__: superClass.prototype, 52 53 onLoadLogFinish: function(data) { 54 // Show the tab if there are either service providers or extension info. 55 var hasExtensionInfo = this.onExtensionInfoChanged(data.extensionInfo); 56 var hasSpiInfo = this.onServiceProvidersChanged(data.serviceProviders); 57 return hasExtensionInfo || hasSpiInfo; 58 }, 59 60 onExtensionInfoChanged: function(extensionInfo) { 61 var input = new JsEvalContext({extensionInfo: extensionInfo}); 62 jstProcess(input, $(ModulesView.EXTENSION_INFO_ID)); 63 return !!extensionInfo; 64 }, 65 66 onServiceProvidersChanged: function(serviceProviders) { 67 var input = new JsEvalContext(serviceProviders); 68 jstProcess(input, $(ModulesView.WINDOWS_SERVICE_PROVIDERS_ID)); 69 return !!serviceProviders; 70 }, 71 }; 72 73 /** 74 * Returns type of a layered service provider. 75 */ 76 ModulesView.getLayeredServiceProviderType = function(serviceProvider) { 77 if (serviceProvider.chain_length == 0) 78 return 'Layer'; 79 if (serviceProvider.chain_length == 1) 80 return 'Base'; 81 return 'Chain'; 82 }; 83 84 var SOCKET_TYPE = { 85 '1': 'SOCK_STREAM', 86 '2': 'SOCK_DGRAM', 87 '3': 'SOCK_RAW', 88 '4': 'SOCK_RDM', 89 '5': 'SOCK_SEQPACKET' 90 }; 91 92 /** 93 * Returns socket type of a layered service provider as a string. 94 */ 95 ModulesView.getLayeredServiceProviderSocketType = function(serviceProvider) { 96 return tryGetValueWithKey(SOCKET_TYPE, serviceProvider.socket_type); 97 }; 98 99 var PROTOCOL_TYPE = { 100 '1': 'IPPROTO_ICMP', 101 '6': 'IPPROTO_TCP', 102 '17': 'IPPROTO_UDP', 103 '58': 'IPPROTO_ICMPV6' 104 }; 105 106 /** 107 * Returns protocol type of a layered service provider as a string. 108 */ 109 ModulesView.getLayeredServiceProviderProtocolType = 110 function(serviceProvider) { 111 return tryGetValueWithKey(PROTOCOL_TYPE, serviceProvider.socket_protocol); 112 } 113 114 var NAMESPACE_PROVIDER_PTYPE = { 115 '12': 'NS_DNS', 116 '15': 'NS_NLA', 117 '16': 'NS_BTH', 118 '32': 'NS_NTDS', 119 '37': 'NS_EMAIL', 120 '38': 'NS_PNRPNAME', 121 '39': 'NS_PNRPCLOUD' 122 }; 123 124 /** 125 * Returns the type of a namespace provider as a string. 126 */ 127 ModulesView.getNamespaceProviderType = function(namespaceProvider) { 128 return tryGetValueWithKey(NAMESPACE_PROVIDER_PTYPE, 129 namespaceProvider.type); 130 }; 131 132 return ModulesView; 133})(); 134