[gnome-online-accounts] Fake the embedded browser's user-agent when needed
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] Fake the embedded browser's user-agent when needed
- Date: Tue, 15 May 2012 20:41:10 +0000 (UTC)
commit 1fdeed0dda3fd57b3abccf1f4137820fbde9442c
Author: Debarshi Ray <debarshir gnome org>
Date: Tue May 15 22:03:36 2012 +0200
Fake the embedded browser's user-agent when needed
The culprit here is Google. It refuses to show the mobile version of
their page even if btmpl=mobile is passed as mentioned in their
documentation. Moreover, some mobile browser user-agents do not work.
eg., Nokia N9. So we fake a HTC Wildfire, instead.
A new virtual method has been added to GoaOAuthProvider and
GoaOAuth2Provider to allow the providers to specify if they want to
identify themselves as running on a mobile platform. This is required
because faking an Android phone can lead to an Android branded version
of the approval page. eg., with Facebook.
Fixes: https://bugzilla.gnome.org/659435
src/goabackend/goagoogleprovider.c | 7 +++++++
src/goabackend/goaoauth2provider.c | 33 +++++++++++++++++++++++++++++++++
src/goabackend/goaoauth2provider.h | 3 +++
src/goabackend/goaoauthprovider.c | 33 +++++++++++++++++++++++++++++++++
src/goabackend/goaoauthprovider.h | 3 +++
src/goabackend/goawebview.c | 21 +++++++++++++++++++++
src/goabackend/goawebview.h | 1 +
7 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index a4b742d..d9d0eea 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -478,6 +478,12 @@ get_use_external_browser (GoaOAuthProvider *provider)
return FALSE;
}
+static gboolean
+get_use_mobile_browser (GoaOAuthProvider *provider)
+{
+ return TRUE;
+}
+
/* ---------------------------------------------------------------------------------------------------- */
static void
@@ -567,6 +573,7 @@ goa_google_provider_class_init (GoaGoogleProviderClass *klass)
oauth_class->get_authentication_cookie = get_authentication_cookie;
oauth_class->build_authorization_uri = build_authorization_uri;
oauth_class->get_use_external_browser = get_use_external_browser;
+ oauth_class->get_use_mobile_browser = get_use_mobile_browser;
oauth_class->add_account_key_values = add_account_key_values;
oauth_class->parse_request_token_error = parse_request_token_error;
}
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 039ef40..fbed7a3 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -122,6 +122,35 @@ goa_oauth2_provider_get_use_external_browser (GoaOAuth2Provider *provider)
/* ---------------------------------------------------------------------------------------------------- */
+static gboolean
+goa_oauth2_provider_get_use_mobile_browser_default (GoaOAuth2Provider *provider)
+{
+ return FALSE;
+}
+
+/**
+ * goa_oauth_provider_get_use_mobile_browser:
+ * @provider: A #GoaOAuth2Provider.
+ *
+ * Returns whether there is a need for the embedded browser to identify
+ * itself as running on a mobile phone in order to get a more compact
+ * version of the approval page.
+ *
+ * This is a virtual method where the default implementation returns
+ * %FALSE.
+ *
+ * Returns: %TRUE if the embedded browser should identify itself as
+ * running on a mobile platform, %FALSE otherwise.
+ */
+gboolean
+goa_oauth2_provider_get_use_mobile_browser (GoaOAuth2Provider *provider)
+{
+ g_return_val_if_fail (GOA_IS_OAUTH2_PROVIDER (provider), FALSE);
+ return GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->get_use_mobile_browser (provider);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
goa_oauth2_provider_add_account_key_values_default (GoaOAuth2Provider *provider,
GVariantBuilder *builder)
@@ -832,6 +861,9 @@ get_tokens_and_identity (GoaOAuth2Provider *provider,
web_view = goa_web_view_new ();
embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
+ if (goa_oauth2_provider_get_use_mobile_browser (provider))
+ goa_web_view_fake_mobile (GOA_WEB_VIEW (web_view));
+
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (embed), url);
g_signal_connect (embed,
"document-load-finished",
@@ -1556,6 +1588,7 @@ goa_oauth2_provider_class_init (GoaOAuth2ProviderClass *klass)
klass->build_authorization_uri = goa_oauth2_provider_build_authorization_uri_default;
klass->get_token_uri = goa_oauth2_provider_get_token_uri_default;
klass->get_use_external_browser = goa_oauth2_provider_get_use_external_browser_default;
+ klass->get_use_mobile_browser = goa_oauth2_provider_get_use_mobile_browser_default;
klass->add_account_key_values = goa_oauth2_provider_add_account_key_values_default;
}
diff --git a/src/goabackend/goaoauth2provider.h b/src/goabackend/goaoauth2provider.h
index a8882b8..3089476 100644
--- a/src/goabackend/goaoauth2provider.h
+++ b/src/goabackend/goaoauth2provider.h
@@ -68,6 +68,7 @@ struct _GoaOAuth2Provider
* @get_identity_sync: Virtual function for goa_oauth2_provider_get_identity_sync().
* @build_authorization_uri: Virtual function for goa_oauth2_provider_build_authorization_uri().
* @get_use_external_browser: Virtual function for goa_oauth2_provider_get_use_external_browser().
+ * @get_use_mobile_browser: Virtual function for goa_oauth2_provider_get_use_mobile_browser().
* @add_account_key_values: Virtual function for goa_oauth2_provider_add_account_key_values().
*
* Class structure for #GoaOAuth2Provider.
@@ -97,6 +98,7 @@ struct _GoaOAuth2ProviderClass
const gchar *escaped_scope);
const gchar *(*get_token_uri) (GoaOAuth2Provider *provider);
gboolean (*get_use_external_browser) (GoaOAuth2Provider *provider);
+ gboolean (*get_use_mobile_browser) (GoaOAuth2Provider *provider);
void (*add_account_key_values) (GoaOAuth2Provider *provider,
GVariantBuilder *builder);
@@ -130,6 +132,7 @@ gchar *goa_oauth2_provider_build_authorization_uri (GoaOAuth2Provider *p
const gchar *escaped_client_id,
const gchar *escaped_scope);
gboolean goa_oauth2_provider_get_use_external_browser (GoaOAuth2Provider *provider);
+gboolean goa_oauth2_provider_get_use_mobile_browser (GoaOAuth2Provider *provider);
void goa_oauth2_provider_add_account_key_values (GoaOAuth2Provider *provider,
GVariantBuilder *builder);
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index aba5b41..5348a72 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -125,6 +125,35 @@ goa_oauth_provider_get_use_external_browser (GoaOAuthProvider *provider)
/* ---------------------------------------------------------------------------------------------------- */
+static gboolean
+goa_oauth_provider_get_use_mobile_browser_default (GoaOAuthProvider *provider)
+{
+ return FALSE;
+}
+
+/**
+ * goa_oauth_provider_get_use_mobile_browser:
+ * @provider: A #GoaOAuthProvider.
+ *
+ * Returns whether there is a need for the embedded browser to identify
+ * itself as running on a mobile phone in order to get a more compact
+ * version of the approval page.
+ *
+ * This is a virtual method where the default implementation returns
+ * %FALSE.
+ *
+ * Returns: %TRUE if the embedded browser should identify itself as
+ * running on a mobile platform, %FALSE otherwise.
+ */
+gboolean
+goa_oauth_provider_get_use_mobile_browser (GoaOAuthProvider *provider)
+{
+ g_return_val_if_fail (GOA_IS_OAUTH_PROVIDER (provider), FALSE);
+ return GOA_OAUTH_PROVIDER_GET_CLASS (provider)->get_use_mobile_browser (provider);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
goa_oauth_provider_add_account_key_values_default (GoaOAuthProvider *provider,
GVariantBuilder *builder)
@@ -824,6 +853,9 @@ get_tokens_and_identity (GoaOAuthProvider *provider,
web_view = goa_web_view_new ();
embed = goa_web_view_get_view (GOA_WEB_VIEW (web_view));
+ if (goa_oauth_provider_get_use_mobile_browser (provider))
+ goa_web_view_fake_mobile (GOA_WEB_VIEW (web_view));
+
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (embed), url);
g_signal_connect (embed,
"document-load-finished",
@@ -1590,6 +1622,7 @@ goa_oauth_provider_class_init (GoaOAuthProviderClass *klass)
klass->build_authorization_uri = goa_oauth_provider_build_authorization_uri_default;
klass->get_use_external_browser = goa_oauth_provider_get_use_external_browser_default;
+ klass->get_use_mobile_browser = goa_oauth_provider_get_use_mobile_browser_default;
klass->get_request_uri_params = goa_oauth_provider_get_request_uri_params_default;
klass->add_account_key_values = goa_oauth_provider_add_account_key_values_default;
}
diff --git a/src/goabackend/goaoauthprovider.h b/src/goabackend/goaoauthprovider.h
index 3b6519e..c6451cb 100644
--- a/src/goabackend/goaoauthprovider.h
+++ b/src/goabackend/goaoauthprovider.h
@@ -71,6 +71,7 @@ struct _GoaOAuthProvider
* @parse_request_token_error: Virtual function for goa_oauth_provider_parse_request_token_error().
* @build_authorization_uri: Virtual function for goa_oauth_provider_build_authorization_uri().
* @get_use_external_browser: Virtual function for goa_oauth_provider_get_use_external_browser().
+ * @get_use_mobile_browser: Virtual function for goa_oauth_provider_get_use_mobile_browser().
* @get_request_uri_params: Virtual function for goa_oauth_provider_get_request_uri_params().
* @add_account_key_values: Virtual function for goa_oauth_provider_add_account_key_values().
*
@@ -104,6 +105,7 @@ struct _GoaOAuthProviderClass
const gchar *authorization_uri,
const gchar *escaped_oauth_token);
gboolean (*get_use_external_browser) (GoaOAuthProvider *provider);
+ gboolean (*get_use_mobile_browser) (GoaOAuthProvider *provider);
gchar **(*get_request_uri_params) (GoaOAuthProvider *provider);
void (*add_account_key_values) (GoaOAuthProvider *provider,
GVariantBuilder *builder);
@@ -141,6 +143,7 @@ gchar *goa_oauth_provider_build_authorization_uri (GoaOAuthProvider *pro
const gchar *authorization_uri,
const gchar *escaped_oauth_token);
gboolean goa_oauth_provider_get_use_external_browser (GoaOAuthProvider *provider);
+gboolean goa_oauth_provider_get_use_mobile_browser (GoaOAuthProvider *provider);
void goa_oauth_provider_add_account_key_values (GoaOAuthProvider *provider,
GVariantBuilder *builder);
diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
index 7ac4b2c..c4b27b9 100644
--- a/src/goabackend/goawebview.c
+++ b/src/goabackend/goawebview.c
@@ -288,3 +288,24 @@ goa_web_view_get_view (GoaWebView *self)
{
return self->priv->web_view;
}
+
+void
+goa_web_view_fake_mobile (GoaWebView *self)
+{
+ WebKitWebSettings *settings;
+
+ settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (self->priv->web_view));
+
+ /* Fake a HTC Wildfire. Some providers, like Google, refuse
+ * to provide the mobile version of their authentication pages
+ * otherwise. eg., in Google's case, passing btmpl=mobile does
+ * not help.
+ *
+ * Also note that the user agents of some mobile browsers may
+ * not work. eg., Nokia N9.
+ */
+ g_object_set (G_OBJECT (settings),
+ "user-agent", "Mozilla/5.0 (Linux; U; Android 2.2.1; HTC Wildfire Build/FRG83D) "
+ "AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
+ NULL);
+}
diff --git a/src/goabackend/goawebview.h b/src/goabackend/goawebview.h
index 935de73..fe4e21c 100644
--- a/src/goabackend/goawebview.h
+++ b/src/goabackend/goawebview.h
@@ -52,6 +52,7 @@ struct _GoaWebViewClass
GType goa_web_view_get_type (void) G_GNUC_CONST;
GtkWidget *goa_web_view_new (void);
GtkWidget *goa_web_view_get_view (GoaWebView *self);
+void goa_web_view_fake_mobile (GoaWebView *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]