[epiphany/wip/tingping/extension-page: 7/7] Don't store WebPage in EphyWebExtension
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/tingping/extension-page: 7/7] Don't store WebPage in EphyWebExtension
- Date: Mon, 14 Jan 2019 15:37:04 +0000 (UTC)
commit 4fd5aa7da6c9cd5f93a2fea46a22ee67df4311dc
Author: Patrick Griffis <pgriffis igalia com>
Date: Thu Jan 10 10:29:18 2019 -0500
Don't store WebPage in EphyWebExtension
The caller can provide the needed information and this avoids
a potentially stale pointer.
embed/ephy-embed-shell.c | 24 ++++++++++------
embed/ephy-web-extension-proxy.c | 10 ++++---
embed/ephy-web-extension-proxy.h | 6 ++--
embed/web-extension/ephy-web-extension.c | 47 ++++++++++++++++++--------------
4 files changed, 53 insertions(+), 34 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 9d2a00578..50a821d49 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -349,7 +349,7 @@ typedef struct {
EphyEmbedShell *shell;
char *origin;
gint32 promise_id;
- gint32 page_id;
+ guint64 page_id;
} PasswordManagerData;
static void
@@ -370,7 +370,7 @@ password_manager_query_finished_cb (GList *records,
data->page_id,
data->origin);
if (proxy)
- ephy_web_extension_proxy_password_query_response (proxy, username, password, data->promise_id);
+ ephy_web_extension_proxy_password_query_response (proxy, username, password, data->promise_id,
data->page_id);
g_object_unref (data->shell);
g_free (data->origin);
@@ -395,6 +395,14 @@ property_to_int32 (JSCValue *value,
return jsc_value_to_int32 (prop);
}
+static int
+property_to_uint64 (JSCValue *value,
+ const char *name)
+{
+ g_autoptr(JSCValue) prop = jsc_value_object_get_property (value, name);
+ return (guint64)jsc_value_to_double (prop);
+}
+
static void
web_extension_password_manager_query_received_cb (WebKitUserContentManager *manager,
WebKitJavascriptResult *message,
@@ -408,7 +416,7 @@ web_extension_password_manager_query_received_cb (WebKitUserContentManager *mana
g_autofree char *username_field = property_to_string_or_null (value, "usernameField");
g_autofree char *password_field = property_to_string_or_null (value, "passwordField");
gint32 promise_id = property_to_int32 (value, "promiseID");
- gint32 page_id = property_to_int32 (value, "pageID");
+ guint64 page_id = property_to_uint64 (value, "pageID");
PasswordManagerData *data = g_new (PasswordManagerData, 1);
data->shell = g_object_ref (shell);
@@ -483,7 +491,7 @@ web_extension_password_manager_save_real (EphyEmbedShell *shell,
g_autofree char *password_field = property_to_string_or_null (value, "passwordField");
g_autoptr(JSCValue) is_new_prop = jsc_value_object_get_property (value, "isNew");
gboolean is_new = jsc_value_to_boolean (is_new_prop);
- gint32 page_id = property_to_int32 (value, "pageID");
+ guint64 page_id = property_to_uint64 (value, "pageID");
EphyWebView *view;
/* Both password and password field are required. */
@@ -553,9 +561,9 @@ web_extension_password_manager_cached_users_received_cb (WebKitUserContentManage
EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
JSCValue *value = webkit_javascript_result_get_js_value (message);
- g_autofree char *origin = jsc_value_to_string (jsc_value_object_get_property (value, "origin"));
- gint32 promise_id = jsc_value_to_int32 (jsc_value_object_get_property (value, "promiseID"));
- gint32 page_id = jsc_value_to_int32 (jsc_value_object_get_property (value, "pageID"));
+ g_autofree char *origin = property_to_string_or_null (value, "origin");
+ gint32 promise_id = property_to_int32 (value, "promiseID");
+ guint64 page_id = property_to_uint64 (value, "pageID");
GList *cached_users;
cached_users = ephy_password_manager_get_cached_users (priv->password_manager, origin);
@@ -563,7 +571,7 @@ web_extension_password_manager_cached_users_received_cb (WebKitUserContentManage
EphyWebExtensionProxy *proxy = ephy_embed_shell_get_extension_proxy_for_page_id (
shell, page_id, origin);
if (proxy)
- ephy_web_extension_proxy_password_cached_users_response (proxy, cached_users, promise_id);
+ ephy_web_extension_proxy_password_cached_users_response (proxy, cached_users, promise_id, page_id);
}
static void
diff --git a/embed/ephy-web-extension-proxy.c b/embed/ephy-web-extension-proxy.c
index 45c272fb7..2e60c0365 100644
--- a/embed/ephy-web-extension-proxy.c
+++ b/embed/ephy-web-extension-proxy.c
@@ -298,7 +298,8 @@ ephy_web_extension_proxy_history_clear (EphyWebExtensionProxy *web_extension)
void
ephy_web_extension_proxy_password_cached_users_response (EphyWebExtensionProxy *web_extension,
GList *users,
- gint32 id)
+ gint32 promise_id,
+ guint64 page_id)
{
if (!web_extension->proxy)
return;
@@ -310,7 +311,7 @@ ephy_web_extension_proxy_password_cached_users_response (EphyWebExtensionProxy *
g_dbus_proxy_call (web_extension->proxy,
"PasswordQueryUsernamesResponse",
- g_variant_new ("(asi)", &builder, id),
+ g_variant_new ("(asit)", &builder, promise_id, page_id),
G_DBUS_CALL_FLAGS_NONE,
-1,
web_extension->cancellable,
@@ -321,14 +322,15 @@ void
ephy_web_extension_proxy_password_query_response (EphyWebExtensionProxy *web_extension,
const char *username,
const char *password,
- gint32 id)
+ gint32 promise_id,
+ guint64 page_id)
{
if (!web_extension->proxy)
return;
g_dbus_proxy_call (web_extension->proxy,
"PasswordQueryResponse",
- g_variant_new ("(ssi)", username ?: "", password ?: "", id),
+ g_variant_new ("(ssit)", username ?: "", password ?: "", promise_id, page_id),
G_DBUS_CALL_FLAGS_NONE,
-1,
web_extension->cancellable,
diff --git a/embed/ephy-web-extension-proxy.h b/embed/ephy-web-extension-proxy.h
index 6e3450f7e..c0c5b0202 100644
--- a/embed/ephy-web-extension-proxy.h
+++ b/embed/ephy-web-extension-proxy.h
@@ -44,9 +44,11 @@ void ephy_web_extension_proxy_history_delete_host
void ephy_web_extension_proxy_history_clear
(EphyWebExtensionProxy *web_extension);
void ephy_web_extension_proxy_password_cached_users_response
(EphyWebExtensionProxy *web_extension,
GList
*users,
- gint32
id);
+ gint32
promise_id,
+ guint64
page_id);
void ephy_web_extension_proxy_password_query_response
(EphyWebExtensionProxy *web_extension,
const char
*username,
const char
*password,
- gint32
id);
+ gint32
promise_id,
+ guint64
page_id);
G_END_DECLS
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index b49559309..68b15972a 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -55,7 +55,6 @@ struct _EphyWebExtension {
EphyUriTester *uri_tester;
WebKitScriptWorld *script_world;
- WebKitWebPage *web_page;
gboolean is_private_profile;
};
@@ -87,11 +86,13 @@ static const char introspection_xml[] =
" <method name='PasswordQueryResponse'>"
" <arg type='s' name='username' direction='in'/>"
" <arg type='s' name='password' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
+ " <arg type='i' name='promise_id' direction='in'/>"
+ " <arg type='t' name='page_id' direction='in'/>"
" </method>"
" <method name='PasswordQueryUsernamesResponse'>"
" <arg type='as' name='users' direction='in'/>"
- " <arg type='i' name='id' direction='in'/>"
+ " <arg type='i' name='promise_id' direction='in'/>"
+ " <arg type='t' name='page_id' direction='in'/>"
" </method>"
" </interface>"
"</node>";
@@ -388,7 +389,6 @@ ephy_web_extension_page_created_cb (EphyWebExtension *extension,
g_object_unref (js_context);
page_id = webkit_web_page_get_id (web_page);
- extension->web_page = web_page;
if (extension->dbus_connection)
ephy_web_extension_emit_page_created (extension, page_id);
else
@@ -409,11 +409,12 @@ ephy_web_extension_page_created_cb (EphyWebExtension *extension,
}
static JSCValue *
-get_password_manager (EphyWebExtension *self)
+get_password_manager (EphyWebExtension *self, guint64 page_id)
{
- g_assert (self->web_page);
-
- WebKitFrame *frame = webkit_web_page_get_main_frame (self->web_page);
+ WebKitWebPage *page = webkit_web_extension_get_page (self->extension, page_id);
+ if (page == NULL)
+ return NULL;
+ WebKitFrame *frame = webkit_web_page_get_main_frame (page);
JSCContext *context = webkit_frame_get_js_context_for_script_world (frame,
self->script_world);
g_autoptr(JSCValue) ephy = jsc_context_get_value (context, "Ephy");
@@ -494,26 +495,32 @@ handle_method_call (GDBusConnection *connection,
} else if (g_strcmp0 (method_name, "PasswordQueryUsernamesResponse") == 0) {
g_autofree const char **users;
g_autoptr(JSCValue) ret;
- gint32 id;
+ gint32 promise_id;
+ guint64 page_id;
users = g_variant_get_strv (g_variant_get_child_value (parameters, 0), NULL);
- g_variant_get_child (parameters, 1, "i", &id);
+ g_variant_get_child (parameters, 1, "i", &promise_id);
+ g_variant_get_child (parameters, 2, "t", &page_id);
- g_autoptr(JSCValue) password_manager = get_password_manager (extension);
- ret = jsc_value_object_invoke_method (password_manager, "_onQueryUsernamesResponse",
- G_TYPE_STRV, users, G_TYPE_INT, id, G_TYPE_NONE);
+ g_autoptr(JSCValue) password_manager = get_password_manager (extension, page_id);
+ if (password_manager != NULL)
+ ret = jsc_value_object_invoke_method (password_manager, "_onQueryUsernamesResponse",
+ G_TYPE_STRV, users, G_TYPE_INT, promise_id, G_TYPE_NONE);
} else if (g_strcmp0 (method_name, "PasswordQueryResponse") == 0) {
const char *username;
const char *password;
- gint32 id;
+ gint32 promise_id;
+ guint64 page_id;
g_autoptr(JSCValue) ret;
- g_variant_get (parameters, "(&s&si)", &username, &password, &id);
- g_autoptr(JSCValue) password_manager = get_password_manager (extension);
- ret = jsc_value_object_invoke_method (password_manager, "_onQueryResponse",
- G_TYPE_STRING, username,
- G_TYPE_STRING, password,
- G_TYPE_INT, id, G_TYPE_NONE);
+
+ g_variant_get (parameters, "(&s&sit)", &username, &password, &promise_id, &page_id);
+ g_autoptr(JSCValue) password_manager = get_password_manager (extension, page_id);
+ if (password_manager != NULL)
+ ret = jsc_value_object_invoke_method (password_manager, "_onQueryResponse",
+ G_TYPE_STRING, username,
+ G_TYPE_STRING, password,
+ G_TYPE_INT, promise_id, G_TYPE_NONE);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]