Skip to content

Commit 67fcf75

Browse files
author
Daniel Herzog
committed
Added get_window_contexts method to network-logger service; Slight cleanup and fixes
1 parent d93d4d0 commit 67fcf75

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/network/network_service.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ cls.NetworkLoggerService = function()
77

88
this._get_matching_context = function(res_id)
99
{
10-
var crafter_context = this.contexts[this.CONTEXT_TYPE_CRAFTER];
10+
var crafter_context = this._contexts[this.CONTEXT_TYPE_CRAFTER];
1111
if (crafter_context && res_id in crafter_context.allocated_res_ids)
1212
return crafter_context;
1313

14-
var logger_context = this.contexts[this.CONTEXT_TYPE_LOGGER];
14+
var logger_context = this._contexts[this.CONTEXT_TYPE_LOGGER];
1515
return logger_context;
1616
};
1717

1818
this.get_request_context = function(type, force)
1919
{
20-
var ctx = this.contexts[type];
20+
var ctx = this._contexts[type];
2121
if (!ctx && force)
2222
{
2323
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
24-
ctx = this.contexts[type] = new cls.RequestContext(this, is_main_context);
24+
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
2525
this.post("context-added", {"context_type": type});
2626
}
2727
return ctx;
@@ -30,13 +30,20 @@ cls.NetworkLoggerService = function()
3030
this.remove_request_context = function(type)
3131
{
3232
type = (type || this.CONTEXT_TYPE_MAIN);
33-
this.contexts[type] = null;
33+
this._contexts[type] = null;
3434
this.post("context-removed", {"context_type": type});
3535
};
3636

37+
this.get_window_contexts = function(type)
38+
{
39+
type = (type || this.CONTEXT_TYPE_MAIN);
40+
var ctx = this.get_request_context(type);
41+
return ctx && ctx.window_contexts;
42+
};
43+
3744
this._queue_message = function(listener, msg)
3845
{
39-
var crafter = this.contexts[this.CONTEXT_TYPE_CRAFTER];
46+
var crafter = this._contexts[this.CONTEXT_TYPE_CRAFTER];
4047
if (crafter)
4148
{
4249
if (crafter.is_waiting_for_create_request)
@@ -83,15 +90,13 @@ cls.NetworkLoggerService = function()
8390
var window_context = ctx.get_window_context(data.windowID);
8491
if (!window_context)
8592
{
86-
var window_context = (
87-
new cls.NetworkLoggerService.WindowContext(data.windowID, this._service, ctx)
88-
);
93+
var window_context = new cls.NetworkLoggerService.WindowContext(data.windowID, this, ctx);
8994
ctx.window_contexts.push(window_context);
9095
if (!data.parentDocumentID)
9196
{
9297
window_context.saw_main_document = true;
9398
}
94-
ctx.post_("window-context-added", {"window-context": window_context});
99+
ctx.post_on_context_or_service("window-context-added", {"window-context": window_context});
95100
}
96101
};
97102
this._on_abouttoloaddocument_bound = this._on_abouttoloaddocument.bind(this, this._on_abouttoloaddocument_bound);
@@ -107,7 +112,7 @@ cls.NetworkLoggerService = function()
107112
{
108113
var type = this.CONTEXT_TYPE_LOGGER;
109114
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
110-
ctx = this.contexts[type] = new cls.RequestContext(this, is_main_context);
115+
ctx = this._contexts[type] = new cls.RequestContext(this, is_main_context);
111116
this.post("context-added", {"context_type": type});
112117
}
113118
ctx.update("urlload", data);
@@ -313,7 +318,7 @@ cls.NetworkLoggerService = function()
313318
messages.addListener("setting-changed", this._on_setting_changed_bound);
314319

315320
this._message_queue = [];
316-
this.contexts = {};
321+
this._contexts = {};
317322
window.cls.MessageMixin.apply(this);
318323
};
319324

@@ -364,7 +369,7 @@ cls.NetworkLoggerService = function()
364369

365370
this._handle_get_resource = function(status, data, resource_id)
366371
{
367-
var ctx = this.contexts[this.CONTEXT_TYPE_LOGGER];
372+
var ctx = this._contexts[this.CONTEXT_TYPE_LOGGER];
368373
if (status)
369374
{
370375
// the object passed to _current_context represents empty event_data. will set no_used_mimetype.
@@ -378,7 +383,7 @@ cls.NetworkLoggerService = function()
378383
// Post update message from here. This is only needed when the generic updating per event is paused.
379384
if (this.is_paused)
380385
{
381-
ctx.post_("resource-update", {id: event.resourceID});
386+
ctx.post_on_context_or_service("resource-update", {id: event.resourceID});
382387
}
383388
};
384389

@@ -580,7 +585,7 @@ cls.RequestContextPrototype = function()
580585
{
581586
var window_context = new cls.NetworkLoggerService.WindowContext(event.windowID, this._service, this);
582587
this.window_contexts.push(window_context);
583-
this.post_("window-context-added", {"window-context": window_context});
588+
this.post_on_context_or_service("window-context-added", {"window-context": window_context});
584589
}
585590
}
586591

@@ -643,11 +648,11 @@ cls.RequestContextPrototype = function()
643648

644649
if (!this.is_paused)
645650
{
646-
this.post_("resource-update", {id: event.resourceID});
651+
this.post_on_context_or_service("resource-update", {id: event.resourceID});
647652
}
648653
};
649654

650-
this.post_ = function(name, body) // post_on_context_or_service?
655+
this.post_on_context_or_service = function(name, body)
651656
{
652657
// Find out where to post the update message.
653658
// Messages of main_contexts are posted on the service, not the context.
@@ -677,7 +682,7 @@ cls.RequestContextPrototype = function()
677682
return window_id != context.id;
678683
}
679684
);
680-
this.post_("window-context-removed", {"window-id": window_id});
685+
this.post_on_context_or_service("window-context-removed", {"window-id": window_id});
681686
};
682687

683688
this.get_entry_from_filtered = function(id)

0 commit comments

Comments
 (0)