Merge lp:~rodrigo-moya/libubuntuone/avoid-webkit-races into lp:libubuntuone

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: 84
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/libubuntuone/avoid-webkit-races
Merge into: lp:libubuntuone
Diff against target: 233 lines (+94/-49)
1 file modified
libubuntuone/u1-music-store.c (+94/-49)
To merge this branch: bzr merge lp:~rodrigo-moya/libubuntuone/avoid-webkit-races
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Tim Cole (community) Approve
Review via email: mp+23043@code.launchpad.net

Commit message

Don't load pages on the navigation_requested callback, do it in an idle callback to avoid WebKit races

Description of the change

Use WebKitNetworkRequest object to redirect navigation

To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) wrote :

Looks sensible.

review: Approve
83. By Rodrigo Moya

Do the redirection in an idle callback

84. By Rodrigo Moya

Move library overriding to the if...else...block

Revision history for this message
Elliot Murphy (statik) wrote :

This fixes my crashing bug.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntuone/u1-music-store.c'
2--- libubuntuone/u1-music-store.c 2010-04-08 15:05:16 +0000
3+++ libubuntuone/u1-music-store.c 2010-04-08 18:18:23 +0000
4@@ -161,9 +161,8 @@
5 object_class->finalize = u1_music_store_finalize;
6 }
7
8-
9-static void
10-load_internal_html_page (WebKitWebView *web_view, const gchar *file_name, const gchar *reload_url)
11+static gchar *
12+get_internal_html_page_url (WebKitWebView *web_view, const gchar *file_name, const gchar *reload_url)
13 {
14 gchar *calculated_file_path, *calculated_file_url, *calculated_file_url_noreload;
15
16@@ -177,9 +176,20 @@
17 reload_url);
18 g_free (calculated_file_url_noreload);
19 }
20+
21+ g_free (calculated_file_path);
22+
23+ return calculated_file_url;
24+}
25+
26+static void
27+load_internal_html_page (WebKitWebView *web_view, const gchar *file_name, const gchar *reload_url)
28+{
29+ gchar *calculated_file_url;
30+
31+ calculated_file_url = get_internal_html_page_url (web_view, file_name, reload_url);
32 webkit_web_view_open (web_view, calculated_file_url);
33 g_free (calculated_file_url);
34- g_free (calculated_file_path);
35 }
36
37 static void
38@@ -381,18 +391,54 @@
39 g_free (nrrd);
40 }
41
42-static void
43-fire_authentication (U1MusicStore *music_store, const gchar *uri)
44+typedef struct {
45+ WebKitWebView *web_view;
46+ char *uri;
47+} DelayedLoadData;
48+
49+static gboolean
50+html_delayed_load_cb (gpointer user_data)
51+{
52+ DelayedLoadData *delayed_data = (DelayedLoadData *) user_data;
53+
54+ webkit_web_view_open (delayed_data->web_view, delayed_data->uri);
55+
56+ g_object_unref (G_OBJECT (delayed_data->web_view));
57+ g_free (delayed_data->uri);
58+ g_free (delayed_data);
59+
60+ return FALSE;
61+}
62+
63+static void
64+load_delayed_page (WebKitWebView *web_view, const char *uri, WebKitWebPolicyDecision *policy_decision)
65+{
66+ DelayedLoadData *delayed_data;
67+
68+ delayed_data = g_new0 (DelayedLoadData, 1);
69+ delayed_data->web_view = g_object_ref (web_view);
70+ delayed_data->uri = g_strdup (uri);
71+
72+ g_idle_add ((GSourceFunc) html_delayed_load_cb, delayed_data);
73+
74+ webkit_web_policy_decision_ignore (policy_decision);
75+}
76+
77+static void
78+fire_authentication (U1MusicStore *music_store, WebKitNetworkRequest *request, WebKitWebPolicyDecision *policy_decision)
79 {
80 NotRegisteredReplacementData *nrrd;
81+ gchar *internal_uri;
82
83 g_debug ("firing authentication");
84
85- load_internal_html_page (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), U1_CONNECTING_PAGE, NULL);
86+ internal_uri = get_internal_html_page_url (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), U1_CONNECTING_PAGE, NULL);
87+ load_delayed_page (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), internal_uri, policy_decision);
88+ g_free (internal_uri);
89
90 nrrd = g_new0 (NotRegisteredReplacementData, 1);
91 nrrd->music_store = music_store;
92- nrrd->not_registered_url = g_strdup (uri);
93+ nrrd->not_registered_url = g_strdup (webkit_network_request_get_uri (request));
94
95 authentication_set_callbacks (G_CALLBACK (authorization_denied_cb),
96 G_CALLBACK (authorization_denied_cb),
97@@ -412,7 +458,7 @@
98 {
99 U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
100 SoupURI *parsed_uri;
101- gboolean return_value = FALSE;
102+ gchar *internal_uri;
103
104 g_debug ("navigation requested to %s", webkit_network_request_get_uri (request));
105
106@@ -433,19 +479,28 @@
107 return FALSE;
108
109 if (g_str_has_prefix (webkit_network_request_get_uri (request), U1_NOT_REGISTERED_URL)) {
110- fire_authentication (music_store, webkit_network_request_get_uri (request));
111-
112- return_value = TRUE;
113+ fire_authentication (music_store, request, policy_decision);
114 } else if (g_str_has_prefix (parsed_uri->path, "/auth/login") &&
115 g_strrstr (parsed_uri->query, "next=") != NULL) {
116- fire_authentication (music_store, webkit_network_request_get_uri (request));
117-
118- return_value = TRUE;
119+ fire_authentication (music_store, request, policy_decision);
120 } else if (g_str_has_prefix (parsed_uri->path, U1_TOKEN_INVALID_URL)) {
121 authentication_clear_tokens ();
122- fire_authentication (music_store, webkit_network_request_get_uri (request));
123-
124- return_value = TRUE;
125+ fire_authentication (music_store, request, policy_decision);
126+ } else if (g_strrstr (parsed_uri->path, "library.aspx") != NULL ||
127+ g_str_has_prefix (parsed_uri->path, "/music/store/library")) {
128+ //g_str_has_prefix (webkit_network_request_get_uri (request), "https://one.ubuntu.com/music/store/library")) {
129+ const gchar *library_override;
130+
131+ /* If the URL being loaded is the 7d library page, and we have a library
132+ override set, load ours instead. */
133+ library_override = g_getenv ("U1MUSICLIBRARYURL");
134+ if (library_override != NULL &&
135+ g_strcmp0 (library_override, webkit_network_request_get_uri (request)) != 0) {
136+ g_debug ("overriding the library page to ours");
137+ load_delayed_page (web_view, library_override, policy_decision);
138+
139+ return TRUE;
140+ }
141 } else if (!g_strcmp0 ((const gchar *) parsed_uri->host, "www.7digital.com")) {
142 /* host is 7digital.com. It must be in our store. */
143 if (!g_str_has_prefix (parsed_uri->path, "/stores/")) {
144@@ -456,10 +511,14 @@
145 to_and_from_error_uris = g_strdup_printf ("%s:::%s",
146 webkit_web_view_get_uri (web_view),
147 webkit_network_request_get_uri (request));
148- load_internal_html_page (web_view, U1_OUTSIDE_DOMAIN_ERROR_PAGE, to_and_from_error_uris);
149+
150+ internal_uri = get_internal_html_page_url (web_view, U1_OUTSIDE_DOMAIN_ERROR_PAGE, to_and_from_error_uris);
151+ load_delayed_page (web_view, internal_uri, policy_decision);
152+
153+ g_free (internal_uri);
154 g_free (to_and_from_error_uris);
155
156- return_value = TRUE;
157+ return TRUE;
158 }
159 } else if (!g_strcmp0 ((const gchar *) parsed_uri->host, "one.ubuntu.com")) {
160 /* host is one.ubuntu.com. It must not be the login page */
161@@ -475,14 +534,18 @@
162 real_url);
163 g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
164 if (real_url != NULL) {
165- load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
166+ internal_uri = get_internal_html_page_url (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
167 g_free (real_url);
168 } else {
169- load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
170+ internal_uri = get_internal_html_page_url (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
171 }
172+
173+ load_delayed_page (web_view, internal_uri, policy_decision);
174+
175+ g_free (internal_uri);
176 g_free (to_and_from_error_uris);
177
178- return_value = TRUE;
179+ return TRUE;
180 }
181 } else if (!g_strcmp0 ((const gchar *) parsed_uri->host, "login.ubuntu.com")) {
182 gchar *real_url;
183@@ -496,42 +559,24 @@
184 real_url);
185 g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
186 if (real_url != NULL) {
187- load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
188+ internal_uri = get_internal_html_page_url (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
189 g_free (real_url);
190 } else {
191- load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
192+ internal_uri = get_internal_html_page_url (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
193 }
194+
195+ load_delayed_page (web_view, internal_uri, policy_decision);
196+
197+ g_free (internal_uri);
198 g_free (to_and_from_error_uris);
199
200- return_value = TRUE;
201- } else if (g_strrstr (webkit_network_request_get_uri (request), "library.aspx") != NULL ||
202- g_str_has_prefix (parsed_uri->path, "/music/store/library")) {
203- //g_str_has_prefix (webkit_network_request_get_uri (request), "https://one.ubuntu.com/music/store/library")) {
204- const gchar *library_override;
205-
206- /* If the URL being loaded is the 7d library page, and we have a library
207- override set, load ours instead. */
208- library_override = g_getenv ("U1MUSICLIBRARYURL");
209- if (library_override != NULL &&
210- g_strcmp0 (library_override, webkit_network_request_get_uri (request)) != 0) {
211- g_debug ("overriding the library page to ours");
212- webkit_web_view_open (web_view, library_override);
213- }
214-
215- return_value = TRUE;
216- }
217-
218- if (return_value) {
219- webkit_web_policy_decision_ignore (policy_decision);
220- } else {
221- /* Inform webkit to continue with the loading */
222- webkit_web_policy_decision_use (policy_decision);
223+ return TRUE;
224 }
225
226 /* Free memory */
227 soup_uri_free (parsed_uri);
228
229- return return_value;
230+ return FALSE;
231 }
232
233 static void

Subscribers

People subscribed via source and target branches