- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / net_internals / modules_view.js
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  */
13 var 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       return this.onExtensionInfoChanged(data.extensionInfo) ||
56           this.onServiceProvidersChanged(data.serviceProviders);
57     },
58
59     onExtensionInfoChanged: function(extensionInfo) {
60       var input = new JsEvalContext({extensionInfo: extensionInfo});
61       jstProcess(input, $(ModulesView.EXTENSION_INFO_ID));
62       return !!extensionInfo;
63     },
64
65     onServiceProvidersChanged: function(serviceProviders) {
66       var input = new JsEvalContext(serviceProviders);
67       jstProcess(input, $(ModulesView.WINDOWS_SERVICE_PROVIDERS_ID));
68       return !!serviceProviders;
69     },
70   };
71
72   /**
73    * Returns type of a layered service provider.
74    */
75   ModulesView.getLayeredServiceProviderType = function(serviceProvider) {
76     if (serviceProvider.chain_length == 0)
77       return 'Layer';
78     if (serviceProvider.chain_length == 1)
79       return 'Base';
80     return 'Chain';
81   };
82
83   var SOCKET_TYPE = {
84     '1': 'SOCK_STREAM',
85     '2': 'SOCK_DGRAM',
86     '3': 'SOCK_RAW',
87     '4': 'SOCK_RDM',
88     '5': 'SOCK_SEQPACKET'
89   };
90
91   /**
92    * Returns socket type of a layered service provider as a string.
93    */
94   ModulesView.getLayeredServiceProviderSocketType = function(serviceProvider) {
95     return tryGetValueWithKey(SOCKET_TYPE, serviceProvider.socket_type);
96   };
97
98   var PROTOCOL_TYPE = {
99     '1': 'IPPROTO_ICMP',
100     '6': 'IPPROTO_TCP',
101     '17': 'IPPROTO_UDP',
102     '58': 'IPPROTO_ICMPV6'
103   };
104
105   /**
106    * Returns protocol type of a layered service provider as a string.
107    */
108   ModulesView.getLayeredServiceProviderProtocolType =
109       function(serviceProvider) {
110     return tryGetValueWithKey(PROTOCOL_TYPE, serviceProvider.socket_protocol);
111   }
112
113   var NAMESPACE_PROVIDER_PTYPE = {
114     '12': 'NS_DNS',
115     '15': 'NS_NLA',
116     '16': 'NS_BTH',
117     '32': 'NS_NTDS',
118     '37': 'NS_EMAIL',
119     '38': 'NS_PNRPNAME',
120     '39': 'NS_PNRPCLOUD'
121   };
122
123   /**
124    * Returns the type of a namespace provider as a string.
125    */
126   ModulesView.getNamespaceProviderType = function(namespaceProvider) {
127     return tryGetValueWithKey(NAMESPACE_PROVIDER_PTYPE,
128                               namespaceProvider.type);
129   };
130
131   return ModulesView;
132 })();