Skip to content

Commit 556d467

Browse files
author
Daniel Herzog
committed
Fix for DFL-2523: Network view doesn't handle multiple top-runtimes
1 parent fdc7d72 commit 556d467

File tree

5 files changed

+103
-22
lines changed

5 files changed

+103
-22
lines changed

src/ecma-debugger/runtimes.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,14 +1331,15 @@ cls.EcmascriptDebugger["6.0"].Runtimes = function(service_version)
13311331
return __scripts[scriptId] && __scripts[scriptId].runtime_id || null;
13321332
}
13331333

1334-
this.reloadWindow = function()
1334+
this.reloadWindow = function(passed_window)
13351335
{
1336-
if (__selected_window)
1336+
var sel_window = passed_window || __selected_window;
1337+
if (sel_window)
13371338
{
1338-
if (!__windows_reloaded[__selected_window])
1339-
__windows_reloaded[__selected_window] = 1;
1339+
if (!__windows_reloaded[sel_window])
1340+
__windows_reloaded[sel_window] = 1;
13401341

1341-
var rt_id = this.getRuntimeIdsFromWindow(__selected_window)[0];
1342+
var rt_id = this.getRuntimeIdsFromWindow(sel_window)[0];
13421343
if (window.services['ecmascript-debugger'] &&
13431344
window.services['ecmascript-debugger'].is_enabled &&
13441345
// For background processes we can not use the exec service.

src/ecma-debugger/views.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ cls.MainView .create_ui_widgets = function()
477477

478478
eventHandlers.click['reload-window'] = function(event, target)
479479
{
480-
runtimes.reloadWindow();
480+
var window_id = target.get_attr("parent-node-chain", "data-reload-window-id");
481+
runtimes.reloadWindow(window_id);
481482
}
482483
}

src/network/network_service.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ cls.NetworkLoggerService = function(view)
88
this._on_abouttoloaddocument_bound = function(msg)
99
{
1010
var data = new cls.DocumentManager["1.0"].AboutToLoadDocument(msg);
11-
// if not a top resource, don't reset the context. This usually means it's an iframe or a redirect.
12-
// todo: handle multiple top-runtimes
13-
if (data.parentDocumentID)
14-
return;
1511

16-
this._current_context = new cls.RequestContext();
17-
this._current_context.saw_main_document_abouttoloaddocument = true;
12+
if (!this._current_context)
13+
this._current_context = new cls.RequestContext();
14+
15+
if (!data.parentDocumentID)
16+
{
17+
// This basically means "unload" for that windowID, potentially
18+
// existing data for that windowID needs to be cleared now.
19+
this._current_context.remove_window_context(data.windowID);
20+
}
21+
22+
var window_context = this._current_context.get_window_context(data.windowID);
23+
if (!window_context)
24+
{
25+
var window_context = new cls.NetworkLoggerService.WindowContext(data.windowID);
26+
this._current_context.window_contexts.push(window_context);
27+
}
28+
window_context.saw_main_document_abouttoloaddocument = true;
1829
}.bind(this);
1930

2031
this._on_urlload_bound = function(msg)
@@ -274,11 +285,18 @@ cls.NetworkLoggerService = function(view)
274285
this.init();
275286
};
276287

288+
cls.NetworkLoggerService.WindowContext = function(window_id)
289+
{
290+
this.id = window_id;
291+
this.saw_main_document_abouttoloaddocument = false;
292+
}
277293

278294
cls.RequestContext = function()
279295
{
280296
this._logger_entries = [];
281297
this._filters = [];
298+
this.window_contexts = [];
299+
this._entry_to_window_id_map = {}; // todo: this should just be an array on a WindowContext ob
282300

283301
this._init();
284302
};
@@ -410,6 +428,15 @@ cls.RequestContextPrototype = function()
410428

411429
this.update = function(eventname, event)
412430
{
431+
if (event.windowID)
432+
{
433+
var matching_window_context = this.get_window_context(event.windowID);
434+
if (!matching_window_context)
435+
{
436+
this.window_contexts.push(new cls.NetworkLoggerService.WindowContext(event.windowID));
437+
}
438+
}
439+
413440
var logger_entries = this.get_entries_with_res_id(event.resourceID);
414441
if (!logger_entries.length && eventname !== "urlload")
415442
{
@@ -453,6 +480,12 @@ cls.RequestContextPrototype = function()
453480
var id = this._get_uid();
454481
logger_entry = new cls.NetworkLoggerEntry(id, event.resourceID, event.documentID, this.get_starttime());
455482
this._logger_entries.push(logger_entry);
483+
// Store the id in the list of entries per window_id
484+
var map = this._entry_to_window_id_map;
485+
if (!map[event.windowID])
486+
map[event.windowID] = [];
487+
488+
map[event.windowID].push(id);
456489
}
457490
logger_entry.last_requestID = event.requestID;
458491
logger_entry.update(eventname, event);
@@ -463,6 +496,25 @@ cls.RequestContextPrototype = function()
463496

464497
};
465498

499+
this.remove_window_context = function(window_id)
500+
{
501+
var ids_to_remove = this._entry_to_window_id_map[window_id];
502+
if (ids_to_remove && ids_to_remove.length)
503+
{
504+
this._logger_entries = this._logger_entries.filter(function(entry){
505+
return !ids_to_remove.contains(entry.id);
506+
});
507+
}
508+
this._entry_to_window_id_map[event.windowID] = [];
509+
// Remove the window_context itself
510+
this.window_contexts = this.window_contexts.filter(
511+
function(win_context)
512+
{
513+
return win_context.id != window_id;
514+
}
515+
);
516+
};
517+
466518
this.get_entry_from_filtered = function(id)
467519
{
468520
return this.get_entries_filtered().filter(function(e) { return e.id == id; })[0];
@@ -481,6 +533,20 @@ cls.RequestContextPrototype = function()
481533
return "uid-" + count++;
482534
}
483535
})();
536+
537+
this.discard_incomplete_warning = function(window_id)
538+
{
539+
for (var i = 0, window_context; window_context = this.window_contexts[i]; i++)
540+
if (window_context.id === window_id)
541+
window_context.incomplete_warn_discarded = true;
542+
543+
};
544+
545+
this.get_window_context = function(window_id)
546+
{
547+
return this.window_contexts.filter(helpers.eq("id", window_id))[0];
548+
};
549+
484550
};
485551

486552
cls.RequestContext.prototype = new cls.RequestContextPrototype();
@@ -1020,6 +1086,7 @@ cls.NetworkLoggerResponsePrototype = function()
10201086
{
10211087
if (!event.mimeType) { this.body_unavailable = true; }
10221088
this.responsebody = event;
1089+
// todo: check how to distinguish body_unavailable and empty body.
10231090
};
10241091

10251092
this._update_event_urlunload = function(event)

src/network/network_templates.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,22 @@ templates.request_crafter_main = function(url, loading, request, response)
9797
];
9898
};
9999

100-
templates.incomplete_warning = function()
100+
templates.incomplete_warning = function(context, index, all_contexts)
101101
{
102+
if (context.incomplete_warn_discarded ||
103+
context.saw_main_document_abouttoloaddocument)
104+
{
105+
return [];
106+
}
107+
108+
// Only add the title if there's more than one context in total
109+
var title = "";
110+
if (all_contexts.length > 1)
111+
{
112+
var win = window.window_manager_data.get_window(context.id);
113+
title = win && (" - " + win.title);
114+
}
115+
102116
return ["div",
103117
["div",
104118
["span",
@@ -108,23 +122,21 @@ templates.incomplete_warning = function()
108122
]
109123
],
110124
["p",
111-
ui_strings.S_HTTP_INCOMPLETE_LOADING_GRAPH
125+
ui_strings.S_HTTP_INCOMPLETE_LOADING_GRAPH + title
112126
],
113127
["span",
114128
" ",
115129
"class", "close_incomplete_warning",
116130
"handler", "close-incomplete-warning",
117131
"tabindex", "1"
118132
],
119-
"class", "info-box network_incomplete_warning"
133+
"class", "info-box network_incomplete_warning",
134+
"data-reload-window-id", String(context.id)
120135
];
121136
};
122137

123138
templates.main = function(ctx, entries, selected, detail_width, table_template)
124139
{
125-
var show_incomplete_warning = !ctx.saw_main_document_abouttoloaddocument &&
126-
!ctx.incomplete_warn_discarded;
127-
128140
return [
129141
[
130142
"div", templates.url_list(ctx, entries, selected),
@@ -142,8 +154,7 @@ templates.main = function(ctx, entries, selected, detail_width, table_template)
142154
[
143155
"div", templates.summary(entries), "class", "network-summary"
144156
],
145-
show_incomplete_warning ?
146-
templates.incomplete_warning() : []
157+
ctx.window_contexts.map(templates.incomplete_warning)
147158
];
148159
};
149160

src/network/network_view.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,9 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler)
527527
this._on_close_incomplete_warning_bound = function(evt, target)
528528
{
529529
var ctx = this._service.get_request_context();
530-
if (ctx)
531-
ctx.incomplete_warn_discarded = true;
530+
var window_id = Number(target.get_attr("parent-node-chain", "data-reload-window-id"));
531+
if (ctx && window_id)
532+
ctx.discard_incomplete_warning(window_id);
532533

533534
this.needs_instant_update = true;
534535
this.update();

0 commit comments

Comments
 (0)