Skip to content

Commit 4991bff

Browse files
author
Daniel Herzog
committed
More review fixes
1 parent ca782d2 commit 4991bff

File tree

3 files changed

+63
-43
lines changed

3 files changed

+63
-43
lines changed

src/network/network_request_crafting_view.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
4646

4747
this._render_main_view = function(container)
4848
{
49-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_CRAFTER);
49+
var ctx = this._service.get_logger_context();
5050
var entries = [];
5151
if (ctx)
5252
entries = ctx.get_entries();
@@ -141,16 +141,15 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
141141

142142
this._handle_send_request_bound = function()
143143
{
144-
var CONTEXT_TYPE_CRAFTER = this._service.CONTEXT_TYPE_CRAFTER;
145-
// todo: the old contexts will probably be kept for comparing previous requests.
146-
this._service.remove_request_context(CONTEXT_TYPE_CRAFTER);
144+
// todo: the old context will probably be kept for comparing previous requests.
145+
this._service.remove_crafter_request_context();
147146

148147
this._prev_url = this._urlfield.get_value();
149148
this._prev_request = this._input.get_value();
150149
var parsed_request = this._parse_request(this._prev_request);
151150
if (parsed_request)
152151
{
153-
var ctx = this._service.get_request_context(CONTEXT_TYPE_CRAFTER, true);
152+
var ctx = this._service.get_logger_context(true);
154153
this._error_message = null;
155154
var crafter_request_id = ctx.send_request(this._prev_url, parsed_request);
156155
this._requests.push(crafter_request_id);
@@ -176,21 +175,18 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
176175
this._input.set_value(current);
177176
};
178177

179-
this._on_context_established_bound = function(message)
178+
this._on_context_added_bound = function(message)
180179
{
181180
if (message.context_type === this._service.CONTEXT_TYPE_CRAFTER)
182-
{
183-
var ctx = this._service.get_request_context(message.context_type);
184-
ctx.addListener("resource-update", this.update.bind(this));
185-
}
181+
message.context.addListener("resource-update", this.update.bind(this));
186182
}.bind(this);
187183

188184
var eh = window.eventHandlers;
189185
eh.click["request-crafter-send"] = this._handle_send_request_bound;
190186
eh.change["request-crafter-url-change"] = this._handle_url_change_bound;
191187
eh.keyup["request-crafter-url-change"] = this._handle_url_change_bound;
192188

193-
this._service.addListener("context-added", this._on_context_established_bound);
189+
this._service.addListener("context-added", this._on_context_added_bound);
194190

195191
// for onchange and buffermanager eh.click["request-crafter-send"] = this._handle_send_request_bound;
196192

src/network/network_service.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
cls.NetworkLoggerService = function()
44
{
5-
this.CONTEXT_TYPE_LOGGER = this.CONTEXT_TYPE_MAIN = "network-logger";
6-
this.CONTEXT_TYPE_CRAFTER = "request-crafter";
5+
this.CONTEXT_TYPE_LOGGER = this.CONTEXT_TYPE_MAIN = 1;
6+
this.CONTEXT_TYPE_CRAFTER = 2;
77

88
this._get_matching_context = function(res_id)
99
{
@@ -15,30 +15,50 @@ cls.NetworkLoggerService = function()
1515
return logger_context;
1616
};
1717

18-
this.get_request_context = function(type, force)
18+
this._get_request_context = function(type, force)
1919
{
2020
var ctx = this._contexts[type];
2121
if (!ctx && force)
2222
{
2323
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
2424
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
25-
this.post("context-added", {"context_type": type});
25+
this.post("context-added", {"context_type": type, "context": ctx});
2626
}
2727
return ctx;
2828
};
2929

30-
this.remove_request_context = function(type)
30+
this.get_logger_context = function()
31+
{
32+
return this._get_request_context(this.CONTEXT_TYPE_LOGGER);
33+
};
34+
35+
this.get_logger_context = function(force)
36+
{
37+
return this._get_request_context(this.CONTEXT_TYPE_CRAFTER, force);
38+
};
39+
40+
this._remove_request_context = function(type)
3141
{
3242
type = type || this.CONTEXT_TYPE_MAIN;
3343
this._contexts[type] = null;
3444
this.post("context-removed", {"context_type": type});
3545
};
3646

47+
this.remove_logger_request_context = function()
48+
{
49+
return this._remove_request_context(this.CONTEXT_TYPE_LOGGER);
50+
};
51+
52+
this.remove_crafter_request_context = function()
53+
{
54+
return this._remove_request_context(this.CONTEXT_TYPE_CRAFTER);
55+
};
56+
3757
// get_window_contexts means "of the main context" here (on the service). That's in line
3858
// with messages of the main context firing here instead of on the context.
3959
this.get_window_contexts = function(type)
4060
{
41-
var ctx = this.get_request_context(this.CONTEXT_TYPE_MAIN);
61+
var ctx = this._get_request_context(this.CONTEXT_TYPE_MAIN);
4262
return ctx && ctx.get_window_contexts();
4363
};
4464

@@ -77,7 +97,7 @@ cls.NetworkLoggerService = function()
7797

7898
// For this event, the context is always of type CONTEXT_TYPE_LOGGER.
7999
// That needs to be static here, because a new context will be created if it doesn't exist.
80-
var ctx = this.get_request_context(this.CONTEXT_TYPE_LOGGER, true);
100+
var ctx = this._get_request_context(this.CONTEXT_TYPE_LOGGER, true);
81101

82102
// Without a parentDocumentID, this event means "unload" for the old content of this windowID.
83103
if (!data.parentDocumentID)
@@ -102,7 +122,7 @@ cls.NetworkLoggerService = function()
102122
var type = this.CONTEXT_TYPE_LOGGER;
103123
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
104124
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
105-
this.post("context-added", {"context_type": type});
125+
this.post("context-added", {"context_type": type, "context": ctx});
106126
}
107127
ctx.update("urlload", data);
108128
};
@@ -118,7 +138,7 @@ cls.NetworkLoggerService = function()
118138
if (!ctx)
119139
return;
120140

121-
// Allocate the resource_id we redirect to to the same context.
141+
// Allocate the resource_id we redirect to, to the same context.
122142
if (data.fromResourceID in ctx.allocated_res_ids)
123143
ctx.allocated_res_ids[data.toResourceID] = ctx.allocated_res_ids[data.fromResourceID];
124144

@@ -319,7 +339,7 @@ cls.NetworkLoggerService = function()
319339
this._doc_service = window.services["document-manager"];
320340
this._doc_service.addListener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
321341

322-
messages.addListener("debug-context-selected", this.remove_request_context.bind(this, null));
342+
messages.addListener("debug-context-selected", this._remove_request_context.bind(this, null));
323343
messages.addListener("setting-changed", this._on_setting_changed_bound);
324344

325345
this._message_queue = [];
@@ -374,7 +394,7 @@ cls.NetworkLoggerService = function()
374394

375395
this._handle_get_resource = function(status, data, resource_id)
376396
{
377-
var ctx = this.get_request_context(this.CONTEXT_TYPE_LOGGER);
397+
var ctx = this._get_request_context(this.CONTEXT_TYPE_LOGGER);
378398
if (status)
379399
{
380400
// the object passed to _current_context represents empty event_data. will set no_used_mimetype.
@@ -726,15 +746,16 @@ cls.RequestContextPrototype = function()
726746
];
727747
this.is_waiting_for_create_request = true;
728748
var id = this._get_uid();
729-
var tag = window.tag_manager.set_callback(null, this._handle_create_request.bind(this), [id]);
749+
var tag = window.tag_manager.set_callback(this, this._handle_create_request, [id]);
730750
window.services["resource-manager"].requestCreateRequest(tag, request);
731751
return id;
732752
};
733753

734754
this._handle_create_request = function(status, msg, id)
735755
{
736756
this.is_waiting_for_create_request = false;
737-
if (status == 0)
757+
var SUCCESS = 0;
758+
if (status == SUCCESS)
738759
{
739760
var data = new cls.ResourceManager["1.3"].ResourceID(msg);
740761
this.allocated_res_ids[data.resourceID] = id;

src/network/network_view.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
5858
else
5959
this.text_search.set_query_selector("[handler='select-network-request']");
6060

61-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
61+
var ctx = this._service.get_logger_context();
6262
if (ctx)
6363
{
6464
if (this._type_filters)
@@ -120,7 +120,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
120120
this._render_main_view = function(container)
121121
{
122122
var selected_viewmode = settings.network_logger.get("selected-viewmode");
123-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
123+
var ctx = this._service.get_logger_context();
124124
var entries = ctx.get_entries_filtered();
125125
var table_template;
126126
if (selected_viewmode === "data")
@@ -149,7 +149,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
149149
{
150150
var table_template = after_render_object && after_render_object.template;
151151
var is_data_mode = Boolean(table_template);
152-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
152+
var ctx = this._service.get_logger_context();
153153

154154
// In is_data_mode, the entries have to be retrieved from the table
155155
// to be in the correct order.
@@ -369,7 +369,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
369369
this._resize_detail_evt = null;
370370
}.bind(this);
371371

372-
var _make_selection_func = function(accessor)
372+
this._move_selection = function(accessor)
373373
{
374374
if (this._selected)
375375
{
@@ -454,7 +454,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
454454

455455
this._on_graph_tooltip_bound = function(evt, target)
456456
{
457-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
457+
var ctx = this._service.get_logger_context();
458458
this._graph_tooltip_id = target.get_attr("parent-node-chain", "data-object-id");
459459
var entry = ctx.get_entry(this._graph_tooltip_id);
460460
if (!this.mono_lineheight)
@@ -489,7 +489,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
489489

490490
this._on_url_tooltip_bound = function(evt, target)
491491
{
492-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
492+
var ctx = this._service.get_logger_context();
493493
if (ctx)
494494
{
495495
var entry_id = target.get_attr("parent-node-chain", "data-object-id");
@@ -517,13 +517,13 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
517517

518518
this._on_clear_log_bound = function(evt, target)
519519
{
520-
this._service.remove_request_context();
520+
this._service.remove_logger_request_context();
521521
this.needs_instant_update = true;
522522
}.bind(this);
523523

524524
this._on_close_incomplete_warning_bound = function(evt, target)
525525
{
526-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
526+
var ctx = this._service.get_logger_context();
527527
var window_id = Number(target.get_attr("parent-node-chain", "data-reload-window-id"));
528528
var window_context = ctx.get_window_context(window_id);
529529
if (window_context)
@@ -545,13 +545,16 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
545545
{
546546
if (message.key === "pause")
547547
{
548-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_LOGGER);
549-
var is_paused = ctx.is_paused;
550-
var pause = settings.network_logger.get(message.key);
551-
if (is_paused && !pause)
552-
ctx.unpause();
553-
else if (!is_paused && pause)
554-
ctx.pause();
548+
var ctx = this._service.get_logger_context();
549+
if (ctx)
550+
{
551+
var is_paused = ctx.is_paused;
552+
var pause = settings.network_logger.get(message.key);
553+
if (is_paused && !pause)
554+
ctx.unpause();
555+
else if (!is_paused && pause)
556+
ctx.pause();
557+
}
555558
}
556559
else if (message.key === "network-profiler-mode")
557560
{
@@ -656,7 +659,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
656659
{
657660
if (message.context_type === this._service.CONTEXT_TYPE_LOGGER)
658661
{
659-
var ctx = this._service.get_request_context(message.context_type);
662+
var ctx = this._service.get_logger_context();
660663
if (this._type_filters)
661664
ctx.set_filters(this._type_filters);
662665

@@ -702,10 +705,9 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
702705
this._service.addListener("context-removed", this._on_context_removed_bound);
703706
this._service.addListener("resource-update", this.update.bind(this));
704707

705-
ActionHandlerInterface.apply(this);
706708
this._handlers = {
707-
"select-next-entry": _make_selection_func.bind(this, "nextElementSibling"),
708-
"select-previous-entry": _make_selection_func.bind(this, "previousElementSibling"),
709+
"select-next-entry": this._move_selection.bind(this, "nextElementSibling"),
710+
"select-previous-entry": this._move_selection.bind(this, "previousElementSibling"),
709711
"close-details": this._on_clicked_close_bound
710712
};
711713
ActionBroker.get_instance().register_handler(this);
@@ -720,6 +722,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
720722
this.init(id, name, container_class, html, default_handler);
721723
};
722724

725+
ActionHandlerInterface.apply(this);
723726
this._init(id, name, container_class, html, default_handler);
724727
};
725728
cls.NetworkLogView.prototype = ViewBase;

0 commit comments

Comments
 (0)