OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 * Dictionary of constants (Initialized soon after loading by data from browser, | |
7 * updated on load log). The *Types dictionaries map strings to numeric IDs, | |
8 * while the *TypeNames are the other way around. | |
9 */ | |
10 var EventType = null; | |
11 var EventTypeNames = null; | |
12 var EventPhase = null; | |
13 var EventSourceType = null; | |
14 var EventSourceTypeNames = null; | |
15 var LogLevelType = null; | |
16 var ClientInfo = null; | |
17 var NetError = null; | |
18 var LoadFlag = null; | |
19 var LoadState = null; | |
20 var AddressFamily = null; | |
21 | |
22 /** | |
23 * Dictionary of all constants, used for saving log files. | |
24 */ | |
25 var Constants = null; | |
26 | |
27 /** | |
28 * Object to communicate between the renderer and the browser. | |
29 * @type {!BrowserBridge} | |
30 */ | |
31 var g_browser = null; | |
32 | |
33 /** | |
34 * This class is the root view object of the page. It owns all the other | |
35 * views, and manages switching between them. It is also responsible for | |
36 * initializing the views and the BrowserBridge. | |
37 */ | |
38 var MainView = (function() { | |
39 'use strict'; | |
40 | |
41 // We inherit from HorizontalSplitView | |
42 var superClass = HorizontalSplitView; | |
43 | |
44 /** | |
45 * Main entry point. Called once the page has loaded. | |
46 * @constructor | |
47 */ | |
48 function MainView() { | |
49 assertFirstConstructorCall(MainView); | |
50 | |
51 if (hasTouchScreen()) | |
52 document.body.classList.add('touch'); | |
53 | |
54 // This must be initialized before the tabs, so they can register as | |
55 // observers. | |
56 g_browser = BrowserBridge.getInstance(); | |
57 | |
58 // This must be the first constants observer, so other constants observers | |
59 // can safely use the globals, rather than depending on walking through | |
60 // the constants themselves. | |
61 g_browser.addConstantsObserver(new ConstantsObserver()); | |
62 | |
63 // This view is a left navigation bar. | |
64 this.categoryTabSwitcher_ = new TabSwitcherView(); | |
65 var tabs = this.categoryTabSwitcher_; | |
66 | |
67 // Call superclass's constructor, initializing the view which lets you tab | |
68 // between the different sub-views. | |
69 superClass.call(this, | |
70 new DivView(MainView.CATEGORY_TAB_HANDLES_ID), | |
71 tabs); | |
72 | |
73 // Populate the main tabs. Even tabs that don't contain information for the | |
74 // running OS should be created, so they can load log dumps from other | |
75 // OSes. | |
76 tabs.addTab(MobileView.TAB_HANDLE_ID, MobileView.getInstance(), | |
77 false, true); | |
mmenke
2013/01/04 16:22:09
You're planning on getting rid of these in a later
| |
78 | |
79 // Build a map from the anchor name of each tab handle to its "tab ID". | |
80 // We will consider navigations to the #hash as a switch tab request. | |
81 var anchorMap = {}; | |
82 var tabIds = tabs.getAllTabIds(); | |
83 for (var i = 0; i < tabIds.length; ++i) { | |
84 var aNode = $(tabIds[i]); | |
85 anchorMap[aNode.hash] = tabIds[i]; | |
86 } | |
87 // Default the empty hash to the data tab. | |
88 anchorMap['#'] = anchorMap[''] = MobileView.TAB_HANDLE_ID; | |
89 | |
90 window.onhashchange = onUrlHashChange.bind(null, tabs, anchorMap); | |
91 | |
92 // Cut out a small vertical strip at the top of the window, to display | |
93 // a high level status (i.e. if we are capturing events, or displaying a | |
94 // log file). Below it we will position the main tabs and their content | |
95 // area. | |
96 this.statusView_ = StatusView.getInstance(this); | |
97 var verticalSplitView = new VerticalSplitView(this.statusView_, this); | |
98 this.statusView_.setLayoutParent(verticalSplitView); | |
99 var windowView = new WindowView(verticalSplitView); | |
100 | |
101 // Don't cache events from browser in renderer process. | |
102 var softLimit = 10; | |
103 var hardLimit = 20; | |
104 EventsTracker.getInstance().setLimits(softLimit, hardLimit); | |
105 | |
106 // Trigger initial layout. | |
107 windowView.resetGeometry(); | |
108 | |
109 // Select the initial view based on the current URL. | |
110 window.onhashchange(); | |
111 | |
112 // Tell the browser that we are ready to start receiving log events. | |
113 g_browser.sendReady(); | |
114 } | |
115 | |
116 // IDs for special HTML elements in index.html | |
117 MainView.CATEGORY_TAB_HANDLES_ID = 'category-tab-handles'; | |
118 | |
119 cr.addSingletonGetter(MainView); | |
120 | |
121 // On mobile, disable viewing of a loaded log file. | |
122 var isViewingLoadedLog = false; | |
123 | |
124 MainView.isViewingLoadedLog = function() { | |
125 return isViewingLoadedLog; | |
126 }; | |
127 | |
128 MainView.prototype = { | |
129 // Inherit the superclass's methods. | |
130 __proto__: superClass.prototype, | |
131 | |
132 // This is exposed so that log_util.js can call it. | |
133 categoryTabSwitcher: function() { | |
134 return this.categoryTabSwitcher_; | |
135 }, | |
136 | |
137 /** | |
138 * Disabled loading of log files on Mobile. | |
139 */ | |
140 onLoadLog: function(opt_fileName) { | |
141 }, | |
142 | |
143 switchToViewOnlyMode: function() { | |
144 }, | |
145 | |
146 stopCapturing: function() { | |
147 g_browser.disable(); | |
148 document.styleSheets[0].insertRule( | |
149 '.hide-when-not-capturing { display: none; }'); | |
150 } | |
151 }; | |
152 | |
153 /** | |
154 * Takes the current hash in form of "#tab¶m1=value1¶m2=value2&...". | |
155 * Puts the parameters in an object, and passes the resulting object to | |
156 * |categoryTabSwitcher|. Uses tab and |anchorMap| to find a tab ID, | |
157 * which it also passes to the tab switcher. | |
158 * | |
159 * Parameters and values are decoded with decodeURIComponent(). | |
160 */ | |
161 function onUrlHashChange(categoryTabSwitcher, anchorMap) { | |
162 var parameters = window.location.hash.split('&'); | |
163 | |
164 var tabId = anchorMap[parameters[0]]; | |
165 if (!tabId) | |
166 return; | |
167 | |
168 // Split each string except the first around the '='. | |
169 var paramDict = null; | |
170 for (var i = 1; i < parameters.length; i++) { | |
171 var paramStrings = parameters[i].split('='); | |
172 if (paramStrings.length != 2) | |
173 continue; | |
174 if (paramDict == null) | |
175 paramDict = {}; | |
176 var key = decodeURIComponent(paramStrings[0]); | |
177 var value = decodeURIComponent(paramStrings[1]); | |
178 paramDict[key] = value; | |
179 } | |
180 | |
181 categoryTabSwitcher.switchToTab(tabId, paramDict); | |
182 } | |
183 | |
184 return MainView; | |
185 })(); | |
186 | |
187 function ConstantsObserver() {} | |
mmenke
2013/01/04 16:22:09
Think it's worth moving the constants stuff to a s
| |
188 | |
189 /** | |
190 * Loads all constants from |constants|. On failure, global dictionaries are | |
191 * not modifed. | |
192 * @param {Object} receivedConstants The map of received constants. | |
193 */ | |
194 ConstantsObserver.prototype.onReceivedConstants = function(receivedConstants) { | |
195 if (!areValidConstants(receivedConstants)) | |
196 return; | |
197 | |
198 Constants = receivedConstants; | |
199 | |
200 EventType = Constants.logEventTypes; | |
201 EventTypeNames = makeInverseMap(EventType); | |
202 EventPhase = Constants.logEventPhase; | |
203 EventSourceType = Constants.logSourceType; | |
204 EventSourceTypeNames = makeInverseMap(EventSourceType); | |
205 LogLevelType = Constants.logLevelType; | |
206 ClientInfo = Constants.clientInfo; | |
207 LoadFlag = Constants.loadFlag; | |
208 NetError = Constants.netError; | |
209 AddressFamily = Constants.addressFamily; | |
210 LoadState = Constants.loadState; | |
211 | |
212 timeutil.setTimeTickOffset(Constants.timeTickOffset); | |
213 }; | |
214 | |
215 /** | |
216 * Returns true if it's given a valid-looking constants object. | |
217 * @param {Object} receivedConstants The received map of constants. | |
218 * @return {boolean} True if the |receivedConstants| object appears valid. | |
219 */ | |
220 function areValidConstants(receivedConstants) { | |
221 return typeof(receivedConstants) == 'object' && | |
222 typeof(receivedConstants.logEventTypes) == 'object' && | |
223 typeof(receivedConstants.clientInfo) == 'object' && | |
224 typeof(receivedConstants.logEventPhase) == 'object' && | |
225 typeof(receivedConstants.logSourceType) == 'object' && | |
226 typeof(receivedConstants.logLevelType) == 'object' && | |
227 typeof(receivedConstants.loadFlag) == 'object' && | |
228 typeof(receivedConstants.netError) == 'object' && | |
229 typeof(receivedConstants.addressFamily) == 'object' && | |
230 typeof(receivedConstants.timeTickOffset) == 'string' && | |
231 typeof(receivedConstants.logFormatVersion) == 'number'; | |
232 } | |
OLD | NEW |