diff options
author | Virgil Dupras <hsoft@hardcoded.net> | 2018-07-27 11:41:45 -0400 |
---|---|---|
committer | Virgil Dupras <hsoft@hardcoded.net> | 2018-07-31 13:31:45 -0400 |
commit | 7b887666b79577b234115695ca30cb90a2011076 (patch) | |
tree | 3fc526e5fb3ca5265ef786e16007822e79d53029 /src/webextension | |
parent | ad8923266ebb1f78feff15878345a03a53368add (diff) |
Convert focus_element_by_id.js to C
Diffstat (limited to 'src/webextension')
-rw-r--r-- | src/webextension/ext-dom.c | 26 | ||||
-rw-r--r-- | src/webextension/ext-dom.h | 2 | ||||
-rw-r--r-- | src/webextension/ext-main.c | 24 |
3 files changed, 50 insertions, 2 deletions
diff --git a/src/webextension/ext-dom.c b/src/webextension/ext-dom.c index 188d0a8..faff17f 100644 --- a/src/webextension/ext-dom.c +++ b/src/webextension/ext-dom.c @@ -33,11 +33,11 @@ gboolean ext_dom_is_editable(WebKitDOMElement *element) { char *type; gboolean result = FALSE; - + if (!element) { return FALSE; } - + /* element is editable if it's a text area or input with no type, text or * password */ if (webkit_dom_html_element_get_is_content_editable(WEBKIT_DOM_HTML_ELEMENT(element)) @@ -170,6 +170,27 @@ char *ext_dom_editable_get_value(WebKitDOMElement *element) return value; } +void ext_dom_lock_input(WebKitDOMDocument *parent, char *element_id) +{ + WebKitDOMElement *elem; + + elem = webkit_dom_document_get_element_by_id(parent, element_id); + if (elem != NULL) { + webkit_dom_element_set_attribute(elem, "disabled", "true", NULL); + } +} + +void ext_dom_unlock_input(WebKitDOMDocument *parent, char *element_id) +{ + WebKitDOMElement *elem; + + elem = webkit_dom_document_get_element_by_id(parent, element_id); + if (elem != NULL) { + webkit_dom_element_remove_attribute(elem, "disabled"); + webkit_dom_element_focus(elem); + } +} + /** * Indicates if the give nelement is visible. */ @@ -177,3 +198,4 @@ static gboolean is_element_visible(WebKitDOMHTMLElement *element) { return TRUE; } + diff --git a/src/webextension/ext-dom.h b/src/webextension/ext-dom.h index fa25f4b..7a0cdda 100644 --- a/src/webextension/ext-dom.h +++ b/src/webextension/ext-dom.h @@ -26,5 +26,7 @@ gboolean ext_dom_is_editable(WebKitDOMElement *element); gboolean ext_dom_focus_input(WebKitDOMDocument *doc); char *ext_dom_editable_get_value(WebKitDOMElement *element); +void ext_dom_lock_input(WebKitDOMDocument *parent, char *element_id); +void ext_dom_unlock_input(WebKitDOMDocument *parent, char *element_id); #endif /* end of include guard: _EXT-DOM_H */ diff --git a/src/webextension/ext-main.c b/src/webextension/ext-main.c index 835921c..ccfe6aa 100644 --- a/src/webextension/ext-main.c +++ b/src/webextension/ext-main.c @@ -84,6 +84,14 @@ static const char introspection_xml[] = " <method name='SetHeaderSetting'>" " <arg type='s' name='headers' direction='in'/>" " </method>" + " <method name='LockInput'>" + " <arg type='t' name='page_id' direction='in'/>" + " <arg type='s' name='elemend_id' direction='in'/>" + " </method>" + " <method name='UnlockInput'>" + " <arg type='t' name='page_id' direction='in'/>" + " <arg type='s' name='elemend_id' direction='in'/>" + " </method>" " </interface>" "</node>"; @@ -419,6 +427,22 @@ static void dbus_handle_method_call(GDBusConnection *conn, const char *sender, } ext.headers = soup_header_parse_param_list(value); g_dbus_method_invocation_return_value(invocation, NULL); + } else if (!g_strcmp0(method, "LockInput")) { + g_variant_get(parameters, "(ts)", &pageid, &value); + page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid); + if (!page) { + return; + } + ext_dom_lock_input(webkit_web_page_get_dom_document(page), value); + g_dbus_method_invocation_return_value(invocation, NULL); + } else if (!g_strcmp0(method, "UnlockInput")) { + g_variant_get(parameters, "(ts)", &pageid, &value); + page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid); + if (!page) { + return; + } + ext_dom_unlock_input(webkit_web_page_get_dom_document(page), value); + g_dbus_method_invocation_return_value(invocation, NULL); } } |