=== modified file 'data/Makefile.am' --- data/Makefile.am 2010-03-22 10:07:24 +0000 +++ data/Makefile.am 2010-03-24 23:55:36 +0000 @@ -4,6 +4,8 @@ u1-preview.js \ u1-songs-clickable.js \ load_error.html \ + outside_domain.html \ + trying_sso.html \ connecting.html \ in_development.html \ screen.css \ === added file 'data/outside_domain.html' --- data/outside_domain.html 1970-01-01 00:00:00 +0000 +++ data/outside_domain.html 2010-03-24 23:55:36 +0000 @@ -0,0 +1,56 @@ + + + +Loading error + + + + + + + +
+
+
+

Sorry!

+

The link you clicked is currently unsupported. +Please try exploring a different part of the music store.

+ +

+
+
+ +
+ + + + === added file 'data/trying_sso.html' --- data/trying_sso.html 1970-01-01 00:00:00 +0000 +++ data/trying_sso.html 2010-03-24 23:55:36 +0000 @@ -0,0 +1,58 @@ + + + +Loading error + + + + + + + +
+
+
+

Sorry!

+

An error has occurred. Please ensure that your +computer is connected to Ubuntu One.

+

+
+
+ +
+ + + + === modified file 'libubuntuone/u1-music-store.c' --- libubuntuone/u1-music-store.c 2010-03-23 12:19:23 +0000 +++ libubuntuone/u1-music-store.c 2010-03-24 23:55:36 +0000 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "oauth.h" #include "u1-music-store.h" @@ -39,6 +40,8 @@ #define U1_NOT_REGISTERED_URL "https://one.ubuntu.com/music/notregistered?returnUrl=" #define U1_DEFAULT_ERROR_PAGE "load_error.html" +#define U1_OUTSIDE_DOMAIN_ERROR_PAGE "outside_domain.html" +#define U1_TRYING_SSO_ERROR_PAGE "trying_sso.html" #define U1_IN_DEVELOPMENT_PAGE "in_development.html" #define U1_CONNECTING_PAGE "connecting.html" #define U1_INITIAL_PAGE "Loading Ubuntu One music store" @@ -241,6 +244,63 @@ gchar *not_registered_url; } NotRegisteredReplacementData; +static gchar * +get_url_to_use (U1MusicStore *music_store) +{ + gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url; + const gchar *url_to_use; + + /* If U1MUSICSTOREURL is defined, use that instead of the real URL */ + if (! (url_to_use = g_getenv ("U1MUSICSTOREURL"))) + url_to_use = "https://one.ubuntu.com"; + + if (music_store->priv->base_url != NULL) + g_free (music_store->priv->base_url); + + music_store->priv->base_url = g_strdup (url_to_use); + + /* OAUth sign the URL */ + if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) { + const gchar *oauthfile; + + oauthfile = g_getenv ("OAUTHKEYFILE"); + if (oauthfile != NULL) { + gchar *oauthstring; + gsize len; + + if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) { + parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret); + g_free (oauthstring); + } + } else { + webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), + "Fail! If you specify U1MUSICSTOREURL you must " + "also specify OAUTHKEYFILE as a file with OAuth keys in it", + "text/html", "utf-8", "file:///"); + return NULL; + } + } else + get_credentials_from_keyring (&oauth_token, &oauth_token_secret); + + if (oauth_token == NULL || oauth_token_secret == NULL) + real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL); + else { + gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL); + + real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET", + "ubuntuone", "hammertime", + oauth_token, oauth_token_secret); + g_free (s); + } + + g_free (oauth_token); + g_free (oauth_token_secret); + + return real_url; +} + + + static void got_new_dbus_credentials_cb (DBusGProxy *proxy, const gchar *realm, const gchar *consumer_key, gpointer user_data) { @@ -329,6 +389,64 @@ gpointer user_data) { U1MusicStore *music_store = U1_MUSIC_STORE (user_data); + SoupURI *parsed_uri; + + parsed_uri = soup_uri_new (webkit_network_request_get_uri (request)); + if (parsed_uri != NULL) { + if (!g_strcmp0 ((const gchar *) parsed_uri->host, "www.7digital.com")) { + /* host is 7digital.com. It must be in our store. */ + if (!g_str_has_prefix (parsed_uri->path, "/stores/")) { + /* a 7digital URL not in our store. Die */ + gchar *to_and_from_error_uris; + g_debug("Hitting the unbranded store, so throwing an error"); + to_and_from_error_uris = g_strdup_printf ("%s:::%s", + webkit_web_view_get_uri (web_view), + webkit_network_request_get_uri (request)); + load_internal_html_page (web_view, U1_OUTSIDE_DOMAIN_ERROR_PAGE, to_and_from_error_uris); + g_free (to_and_from_error_uris); + } + } + if (!g_strcmp0 ((const gchar *) parsed_uri->host, "one.ubuntu.com")) { + /* host is one.ubuntu.com. It must not be the login page */ + if (g_str_has_prefix (parsed_uri->path, "/auth/")) { + /* trying to log the user into o.u.c inside the webview. Die. */ + gchar *real_url; + gchar *to_and_from_error_uris; + real_url = get_url_to_use (music_store); + to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s", + webkit_web_view_get_uri (web_view), + webkit_network_request_get_uri (request), + real_url); + g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error"); + if (real_url != NULL) { + load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris); + g_free (real_url); + } else { + load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL); + } + g_free (to_and_from_error_uris); + } + } + if (!g_strcmp0 ((const gchar *) parsed_uri->host, "login.ubuntu.com")) { + /* host is SSO. Die. */ + gchar *real_url; + gchar *to_and_from_error_uris; + real_url = get_url_to_use (music_store); + to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s", + webkit_web_view_get_uri (web_view), + webkit_network_request_get_uri (request), + real_url); + g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error"); + if (real_url != NULL) { + load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris); + g_free (real_url); + } else { + load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL); + } + g_free (to_and_from_error_uris); + } + + } /* Remove watching callback for the page */ if (music_store->priv->watch_id != 0) { @@ -681,61 +799,6 @@ return TRUE; } -static gchar * -get_url_to_use (U1MusicStore *music_store) -{ - gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url; - const gchar *url_to_use; - - /* If U1MUSICSTOREURL is defined, use that instead of the real URL */ - if (! (url_to_use = g_getenv ("U1MUSICSTOREURL"))) - url_to_use = "https://one.ubuntu.com"; - - if (music_store->priv->base_url != NULL) - g_free (music_store->priv->base_url); - - music_store->priv->base_url = g_strdup (url_to_use); - - /* OAUth sign the URL */ - if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) { - const gchar *oauthfile; - - oauthfile = g_getenv ("OAUTHKEYFILE"); - if (oauthfile != NULL) { - gchar *oauthstring; - gsize len; - - if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) { - parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret); - g_free (oauthstring); - } - } else { - webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), - "Fail! If you specify U1MUSICSTOREURL you must " - "also specify OAUTHKEYFILE as a file with OAuth keys in it", - "text/html", "utf-8", "file:///"); - return NULL; - } - } else - get_credentials_from_keyring (&oauth_token, &oauth_token_secret); - - if (oauth_token == NULL || oauth_token_secret == NULL) - real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL); - else { - gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL); - - real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET", - "ubuntuone", "hammertime", - oauth_token, oauth_token_secret); - g_free (s); - } - - g_free (oauth_token); - g_free (oauth_token_secret); - - return real_url; -} - static gboolean load_real_store_cb (gpointer user_data) {