Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/resources/net_internals/requestsview.js

Issue 1088007: Add an initial implementation of net-internals inspector in javascript.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: more build file Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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 * RequestsView is the class which glues together the different components to
7 * form the primary UI:
8 *
9 * - The search filter
10 * - The requests table
11 * - The details panel
12 * - The action bar
13 *
14 * @constructor
15 */
16 function RequestsView(tableBodyId, filterInputId, filterCountId,
17 deleteSelectedId, selectAllId, detailsView) {
18 this.sourceIdToEntryMap_ = {};
19 this.currentSelectedSources_ = [];
20
21 LogDataProvider.addObserver(this);
22
23 this.tableBody_ = document.getElementById(tableBodyId);
24 this.detailsView_ = detailsView;
25
26 this.filterInput_ = document.getElementById(filterInputId);
27 this.filterCount_ = document.getElementById(filterCountId);
28
29 this.filterInput_.addEventListener("search",
30 this.onFilterTextChanged_.bind(this), true);
31
32 document.getElementById(deleteSelectedId).onclick =
33 this.deleteSelected_.bind(this);
34
35 document.getElementById(selectAllId).addEventListener(
36 'click', this.selectAll_.bind(this), true);
37
38 this.currentFilter_ = '';
39 this.numPrefilter_ = 0;
40 this.numPostfilter_ = 0;
41
42 this.invalidateFilterCounter_();
43 this.invalidateDetailsView_();
44 }
45
46 // How soon after updating the filter list the counter should be updated.
47 RequestsView.REPAINT_FILTER_COUNTER_TIMEOUT_MS = 0;
48
49 RequestsView.prototype.onFilterTextChanged_ = function() {
50 this.setFilter_(this.filterInput_.value);
51 };
52
53 RequestsView.prototype.setFilter_ = function(filterText) {
54 this.currentFilter_ = filterText;
55
56 // Iterate through all of the rows and see if they match the filter.
57 for (var id in this.sourceIdToEntryMap_) {
58 var entry = this.sourceIdToEntryMap_[id];
59 entry.setIsMatchedByFilter(entry.matchesFilter(this.currentFilter_));
60 }
61 };
62
63 RequestsView.prototype.onLogEntryAdded = function(logEntry) {
64 // Lookup the source.
65 var sourceEntry = this.sourceIdToEntryMap_[logEntry.source.id];
66
67 if (!sourceEntry) {
68 sourceEntry = new SourceEntry(this);
69 this.sourceIdToEntryMap_[logEntry.source.id] = sourceEntry;
70 this.incrementPrefilterCount(1);
71 }
72
73 sourceEntry.update(logEntry);
74
75 if (sourceEntry.isSelected())
76 this.invalidateDetailsView_();
77 };
78
79 RequestsView.prototype.incrementPrefilterCount = function(offset) {
80 this.numPrefilter_ += offset;
81 this.invalidateFilterCounter_();
82 };
83
84 RequestsView.prototype.incrementPostfilterCount = function(offset) {
85 this.numPostfilter_ += offset;
86 this.invalidateFilterCounter_();
87 };
88
89 RequestsView.prototype.onSelectionChanged = function() {
90 this.invalidateDetailsView_();
91 };
92
93 RequestsView.prototype.clearSelection = function() {
94 var prevSelection = this.currentSelectedSources_;
95 this.currentSelectedSources_ = [];
96
97 // Unselect everything that is currently selected.
98 for (var i = 0; i < prevSelection.length; ++i) {
99 prevSelection[i].setSelected(false);
100 }
101
102 this.onSelectionChanged();
103 };
104
105 RequestsView.prototype.deleteSelected_ = function() {
106 var prevSelection = this.currentSelectedSources_;
107 this.currentSelectedSources_ = [];
108
109 for (var i = 0; i < prevSelection.length; ++i) {
110 var entry = prevSelection[i];
111 entry.remove();
112 delete this.sourceIdToEntryMap_[entry.getSourceId()];
113 this.incrementPrefilterCount(-1);
114 }
115 };
116
117 RequestsView.prototype.selectAll_ = function(event) {
118 for (var id in this.sourceIdToEntryMap_) {
119 var entry = this.sourceIdToEntryMap_[id];
120 if (entry.isMatchedByFilter()) {
121 entry.setSelected(true);
122 }
123 }
124 event.preventDefault();
125 };
126
127 RequestsView.prototype.modifySelectionArray = function(
128 sourceEntry, addToSelection) {
129 // Find the index for |sourceEntry| in the current selection list.
130 var index = -1;
131 for (var i = 0; i < this.currentSelectedSources_.length; ++i) {
132 if (this.currentSelectedSources_[i] == sourceEntry) {
133 index = i;
134 break;
135 }
136 }
137
138 if (index != -1 && !addToSelection) {
139 // Remove from the selection.
140 this.currentSelectedSources_.splice(index, 1);
141 }
142
143 if (index == -1 && addToSelection) {
144 this.currentSelectedSources_.push(sourceEntry);
145 }
146 }
147
148 RequestsView.prototype.invalidateDetailsView_ = function() {
149 this.detailsView_.setData(this.currentSelectedSources_);
150 };
151
152 RequestsView.prototype.invalidateFilterCounter_ = function() {
153 if (!this.outstandingRepaintFilterCounter_) {
154 this.outstandingRepaintFilterCounter_ = true;
155 window.setTimeout(this.repaintFilterCounter_.bind(this),
156 RequestsView.REPAINT_FILTER_COUNTER_TIMEOUT_MS);
157 }
158 };
159
160 RequestsView.prototype.repaintFilterCounter_ = function() {
161 this.outstandingRepaintFilterCounter_ = false;
162 this.filterCount_.innerHTML = '';
163 addTextNode(this.filterCount_,
164 this.numPostfilter_ + " of " + this.numPrefilter_);
165 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/main.js ('k') | chrome/browser/resources/net_internals/sourceentry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698