From 2d6f7c958eb6b1ce63f9731a42bc2ab92356ba5c Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 31 Oct 2017 02:55:23 -0400 Subject: view-source: Gracefully handle closed origin tab Don't just crash. --- (limited to 'src/view-source.c') diff --git a/src/view-source.c b/src/view-source.c index 271ad5a..de555f8 100644 --- a/src/view-source.c +++ b/src/view-source.c @@ -106,19 +106,26 @@ mq_view_source_request(WebKitURISchemeRequest *request, g_hash_table_unref(query); g_free(path); - /* Look up origin tab. */ origin_tab = mq_application_get_tab(application, origin_tab_id); - origin_web_view = mq_tab_page_get_web_view(origin_tab); - /* Get origin tab's data. */ - data = mq_web_view_get_data(origin_web_view, &length); - if (data) { - respond(request, uri, data, length); + if (origin_tab) { + origin_web_view = mq_tab_page_get_web_view(origin_tab); + + data = mq_web_view_get_data(origin_web_view, &length); + if (data) { + respond(request, uri, data, length); + } else { + data_signal_data = g_new(DataSignalData, 1); + data_signal_data->request = request; + data_signal_data->uri = uri; + data_signal_data->handler_id = g_signal_connect( + origin_web_view, "notify::data", + G_CALLBACK(data_cb), data_signal_data); + } } else { - data_signal_data = g_new(DataSignalData, 1); - data_signal_data->request = request; - data_signal_data->uri = uri; - data_signal_data->handler_id = g_signal_connect(origin_web_view, - "notify::data", G_CALLBACK(data_cb), data_signal_data); + /* TODO: Handling reloads by newly requesting the resource + * should obviate this. */ + respond(request, uri, + (guchar *) g_strdup("Viewed tab no longer open"), -1); } } -- cgit v0.9.1