Skip to content

Commit 2773cf1

Browse files
author
Daniel Herzog
committed
Review fixes
1 parent 4991bff commit 2773cf1

File tree

5 files changed

+78
-71
lines changed

5 files changed

+78
-71
lines changed

src/build-application/build_resource_manager_1_0.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
window.app.builders.ResourceManager["1.0"] = function(service)
44
{
5-
var logger_service = new cls.NetworkLoggerService();
5+
var network_logger = new cls.NetworkLogger();
66
new cls.ResourceManagerAllView("resource_all", ui_strings.M_VIEW_LABEL_ALL_RESOURCES, "scroll resource-manager", "", "");
77
//new cls.ResourceManagerFontView('resource_fonts', "Fonts", 'scroll', '', '');
88
//new cls.ResourceManagerImageView('resource_images', "Images", 'scroll', '', '');
@@ -11,13 +11,13 @@ window.app.builders.ResourceManager["1.0"] = function(service)
1111
"scroll network_logger",
1212
null,
1313
"network-logger",
14-
logger_service);
14+
network_logger);
1515
new cls.RequestCraftingView("request_crafter",
1616
ui_strings.M_VIEW_LABEL_REQUEST_CRAFTER,
1717
"scroll",
1818
"",
1919
"",
20-
logger_service);
20+
network_logger);
2121
new cls.NetworkOptionsView("network_options",
2222
ui_strings.M_VIEW_LABEL_NETWORK_OPTIONS,
2323
"scroll network-options-container", "", "");

src/network/network_request_crafting_view.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* @constructor
55
* @extends ViewBase
66
*/
7-
cls.RequestCraftingView = function(id, name, container_class, html, default_handler, service)
7+
cls.RequestCraftingView = function(id, name, container_class, html, default_handler, network_logger)
88
{
9-
this._service = service;
9+
this._network_logger = network_logger;
1010
this._input = null;
1111
this._output = null;
1212
this._urlfield = null;
@@ -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_logger_context();
49+
var ctx = this._network_logger.get_crafter_context();
5050
var entries = [];
5151
if (ctx)
5252
entries = ctx.get_entries();
@@ -142,14 +142,14 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
142142
this._handle_send_request_bound = function()
143143
{
144144
// todo: the old context will probably be kept for comparing previous requests.
145-
this._service.remove_crafter_request_context();
145+
this._network_logger.remove_crafter_request_context();
146146

147147
this._prev_url = this._urlfield.get_value();
148148
this._prev_request = this._input.get_value();
149149
var parsed_request = this._parse_request(this._prev_request);
150150
if (parsed_request)
151151
{
152-
var ctx = this._service.get_logger_context(true);
152+
var ctx = this._network_logger.get_crafter_context(true);
153153
this._error_message = null;
154154
var crafter_request_id = ctx.send_request(this._prev_url, parsed_request);
155155
this._requests.push(crafter_request_id);
@@ -177,7 +177,7 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
177177

178178
this._on_context_added_bound = function(message)
179179
{
180-
if (message.context_type === this._service.CONTEXT_TYPE_CRAFTER)
180+
if (message.context_type === cls.NetworkLogger.CONTEXT_TYPE_CRAFTER)
181181
message.context.addListener("resource-update", this.update.bind(this));
182182
}.bind(this);
183183

@@ -186,7 +186,7 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
186186
eh.change["request-crafter-url-change"] = this._handle_url_change_bound;
187187
eh.keyup["request-crafter-url-change"] = this._handle_url_change_bound;
188188

189-
this._service.addListener("context-added", this._on_context_added_bound);
189+
this._network_logger.addListener("context-added", this._on_context_added_bound);
190190

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

src/network/network_service.js

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
"use strict";
22

3-
cls.NetworkLoggerService = function()
3+
cls.NetworkLogger = function()
44
{
5-
this.CONTEXT_TYPE_LOGGER = this.CONTEXT_TYPE_MAIN = 1;
6-
this.CONTEXT_TYPE_CRAFTER = 2;
7-
85
this._get_matching_context = function(res_id)
96
{
10-
var crafter_context = this._contexts[this.CONTEXT_TYPE_CRAFTER];
7+
var crafter_context = this._contexts[cls.NetworkLogger.CONTEXT_TYPE_CRAFTER];
118
if (crafter_context && res_id in crafter_context.allocated_res_ids)
129
return crafter_context;
1310

14-
var logger_context = this._contexts[this.CONTEXT_TYPE_LOGGER];
11+
var logger_context = this._contexts[cls.NetworkLogger.CONTEXT_TYPE_LOGGER];
1512
return logger_context;
1613
};
1714

@@ -20,7 +17,7 @@ cls.NetworkLoggerService = function()
2017
var ctx = this._contexts[type];
2118
if (!ctx && force)
2219
{
23-
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
20+
var is_main_context = type === cls.NetworkLogger.CONTEXT_TYPE_MAIN;
2421
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
2522
this.post("context-added", {"context_type": type, "context": ctx});
2623
}
@@ -29,42 +26,42 @@ cls.NetworkLoggerService = function()
2926

3027
this.get_logger_context = function()
3128
{
32-
return this._get_request_context(this.CONTEXT_TYPE_LOGGER);
29+
return this._get_request_context(cls.NetworkLogger.CONTEXT_TYPE_LOGGER);
3330
};
3431

35-
this.get_logger_context = function(force)
32+
this.get_crafter_context = function(force)
3633
{
37-
return this._get_request_context(this.CONTEXT_TYPE_CRAFTER, force);
34+
return this._get_request_context(cls.NetworkLogger.CONTEXT_TYPE_CRAFTER, force);
3835
};
3936

4037
this._remove_request_context = function(type)
4138
{
42-
type = type || this.CONTEXT_TYPE_MAIN;
39+
type = type || cls.NetworkLogger.CONTEXT_TYPE_MAIN;
4340
this._contexts[type] = null;
4441
this.post("context-removed", {"context_type": type});
4542
};
4643

4744
this.remove_logger_request_context = function()
4845
{
49-
return this._remove_request_context(this.CONTEXT_TYPE_LOGGER);
46+
return this._remove_request_context(cls.NetworkLogger.CONTEXT_TYPE_LOGGER);
5047
};
5148

5249
this.remove_crafter_request_context = function()
5350
{
54-
return this._remove_request_context(this.CONTEXT_TYPE_CRAFTER);
51+
return this._remove_request_context(cls.NetworkLogger.CONTEXT_TYPE_CRAFTER);
5552
};
5653

57-
// get_window_contexts means "of the main context" here (on the service). That's in line
54+
// get_window_contexts means "of the main context" here (on the logger). That's in line
5855
// with messages of the main context firing here instead of on the context.
5956
this.get_window_contexts = function(type)
6057
{
61-
var ctx = this._get_request_context(this.CONTEXT_TYPE_MAIN);
58+
var ctx = this._get_request_context(cls.NetworkLogger.CONTEXT_TYPE_MAIN);
6259
return ctx && ctx.get_window_contexts();
6360
};
6461

6562
this._queue_message = function(listener, msg)
6663
{
67-
var crafter = this._contexts[this.CONTEXT_TYPE_CRAFTER];
64+
var crafter = this._contexts[cls.NetworkLogger.CONTEXT_TYPE_CRAFTER];
6865
if (crafter && crafter.is_waiting_for_create_request)
6966
{
7067
// Store in a queue. Before we know what resourceID create_request
@@ -97,7 +94,7 @@ cls.NetworkLoggerService = function()
9794

9895
// For this event, the context is always of type CONTEXT_TYPE_LOGGER.
9996
// That needs to be static here, because a new context will be created if it doesn't exist.
100-
var ctx = this._get_request_context(this.CONTEXT_TYPE_LOGGER, true);
97+
var ctx = this._get_request_context(cls.NetworkLogger.CONTEXT_TYPE_LOGGER, true);
10198

10299
// Without a parentDocumentID, this event means "unload" for the old content of this windowID.
103100
if (!data.parentDocumentID)
@@ -119,8 +116,8 @@ cls.NetworkLoggerService = function()
119116
var ctx = this._get_matching_context(data.resourceID);
120117
if (!ctx)
121118
{
122-
var type = this.CONTEXT_TYPE_LOGGER;
123-
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
119+
var type = cls.NetworkLogger.CONTEXT_TYPE_LOGGER;
120+
var is_main_context = type === cls.NetworkLogger.CONTEXT_TYPE_MAIN;
124121
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
125122
this.post("context-added", {"context_type": type, "context": ctx});
126123
}
@@ -394,7 +391,7 @@ cls.NetworkLoggerService = function()
394391

395392
this._handle_get_resource = function(status, data, resource_id)
396393
{
397-
var ctx = this._get_request_context(this.CONTEXT_TYPE_LOGGER);
394+
var ctx = this._get_request_context(cls.NetworkLogger.CONTEXT_TYPE_LOGGER);
398395
if (status)
399396
{
400397
// the object passed to _current_context represents empty event_data. will set no_used_mimetype.
@@ -407,24 +404,27 @@ cls.NetworkLoggerService = function()
407404
}
408405
// Post update message from here. This is only needed when the generic updating per event is paused.
409406
if (this.is_paused)
410-
ctx.post_on_context_or_service("resource-update", {id: event.resourceID});
407+
ctx.post_on_context_or_logger("resource-update", {id: event.resourceID});
411408

412409
};
413410

414411
this.init();
415412
};
413+
cls.NetworkLogger.CONTEXT_TYPE_LOGGER = 1;
414+
cls.NetworkLogger.CONTEXT_TYPE_CRAFTER = 2;
415+
cls.NetworkLogger.CONTEXT_TYPE_MAIN = cls.NetworkLogger.CONTEXT_TYPE_LOGGER;
416416

417-
cls.NetworkLoggerService.WindowContext = function(window_id, service, context)
417+
cls.NetworkLogger.WindowContext = function(window_id, logger, context)
418418
{
419-
this._service = service;
419+
this._logger = logger;
420420
this._context = context;
421421
this.id = window_id;
422422
this.saw_main_document = false;
423423
this.incomplete_warn_discarded = false;
424424
this.entry_ids = [];
425425
};
426426

427-
cls.NetworkLoggerService.WindowContextPrototype = function()
427+
cls.NetworkLogger.WindowContextPrototype = function()
428428
{
429429
this._filter_entries = function(resource_ids, entry, index, entries)
430430
{
@@ -448,9 +448,9 @@ cls.NetworkLoggerService.WindowContextPrototype = function()
448448
};
449449
};
450450

451-
cls.NetworkLoggerService.WindowContext.prototype = new cls.NetworkLoggerService.WindowContextPrototype();
451+
cls.NetworkLogger.WindowContext.prototype = new cls.NetworkLogger.WindowContextPrototype();
452452

453-
cls.RequestContext = function(service, is_main_context)
453+
cls.RequestContext = function(logger, is_main_context)
454454
{
455455
this.FILTER_ALLOW_ALL = {
456456
type_list: [],
@@ -462,7 +462,7 @@ cls.RequestContext = function(service, is_main_context)
462462
this._logger_entries = [];
463463
this._filters = [this.FILTER_ALLOW_ALL];
464464
this._is_main_context = is_main_context;
465-
this._service = service;
465+
this._logger = logger;
466466
this._window_contexts = [];
467467
this._init();
468468
};
@@ -659,15 +659,15 @@ cls.RequestContextPrototype = function()
659659

660660
if (!this.is_paused)
661661
{
662-
this.post_on_context_or_service("resource-update", {id: event.resourceID});
662+
this.post_on_context_or_logger("resource-update", {id: event.resourceID});
663663
}
664664
};
665665

666-
this.post_on_context_or_service = function(name, body)
666+
this.post_on_context_or_logger = function(name, body)
667667
{
668668
// Find out where to post the update message.
669-
// Messages of main_contexts are posted on the service, not the context.
670-
var posting_object = this._is_main_context ? this._service : this;
669+
// Messages of main_contexts are posted on the logger, not the context.
670+
var posting_object = this._is_main_context ? this._logger : this;
671671
posting_object.post(name, body);
672672
};
673673

@@ -682,9 +682,9 @@ cls.RequestContextPrototype = function()
682682
var window_context = this._window_contexts.filter(helpers.eq("id", window_id))[0];
683683
if (!window_context && force)
684684
{
685-
window_context = new cls.NetworkLoggerService.WindowContext(window_id, this._service, this);
685+
window_context = new cls.NetworkLogger.WindowContext(window_id, this._logger, this);
686686
this._window_contexts.push(window_context);
687-
this.post_on_context_or_service("window-context-added", {"window-context": window_context});
687+
this.post_on_context_or_logger("window-context-added", {"window-context": window_context});
688688
}
689689
return window_context;
690690
};
@@ -708,7 +708,7 @@ cls.RequestContextPrototype = function()
708708
return window_id != context.id;
709709
}
710710
);
711-
this.post_on_context_or_service("window-context-removed", {"window-id": window_id});
711+
this.post_on_context_or_logger("window-context-removed", {"window-id": window_id});
712712
};
713713

714714
this.get_entry_from_filtered = function(id)
@@ -733,16 +733,22 @@ cls.RequestContextPrototype = function()
733733
this.send_request = function(url, requestdata)
734734
{
735735
var windowid = window.window_manager_data.get_debug_context();
736+
var PAYLOAD = null;
737+
var HEADER_POLICY_OVERWRITE = 2;
738+
var HEADER_POLICY_REPLACE = 3;
739+
var RELOAD_POLICY_NO_CACHE = 2;
740+
var REQUEST_CONTENT_MODE = null;
741+
var RESPONSE_CONTENT_MODE_STRING_DECODE = [1, 1];
736742
var request = [
737743
windowid,
738744
url,
739745
requestdata.method,
740746
requestdata.headers,
741-
null, // payload
742-
3, // header policy. 2 == overwrite, 3 == replace
743-
2, // reload policy. 2 == no cache, always reload from network
744-
null, // request content mode
745-
[1, 1] // response content mode 1 == string, 1 == decode
747+
PAYLOAD,
748+
HEADER_POLICY_REPLACE,
749+
RELOAD_POLICY_NO_CACHE,
750+
REQUEST_CONTENT_MODE,
751+
RESPONSE_CONTENT_MODE_STRING_DECODE
746752
];
747753
this.is_waiting_for_create_request = true;
748754
var id = this._get_uid();
@@ -1181,7 +1187,7 @@ cls.NetworkLoggerEntryPrototype = function()
11811187
this.events.push(evt);
11821188
};
11831189

1184-
this.check_to_request_body = function(service)
1190+
this.check_to_request_body = function(logger)
11851191
{
11861192
// Decide if body should be fetched, for when content-tracking is off or it's a cached request.
11871193
if (
@@ -1193,7 +1199,7 @@ cls.NetworkLoggerEntryPrototype = function()
11931199
(!this._current_response || this._current_response.saw_responsefinished)
11941200
)
11951201
{
1196-
service.get_body(this);
1202+
logger.get_body(this);
11971203
}
11981204
};
11991205

@@ -1221,7 +1227,7 @@ cls.NetworkLoggerEntryPrototype = function()
12211227
this.__defineGetter__("current_response", function()
12221228
{
12231229
// In 99% of the cases, _current_response is used. It's only
1224-
// exposed for getting the ResourceInfo from the service directly.
1230+
// exposed for getting the ResourceInfo from the logger directly.
12251231
return this._current_response;
12261232
});
12271233
this.__defineSetter__("current_response", function(){});

0 commit comments

Comments
 (0)