[evolution/wip/mcrha/webkit-jsc-api] GetContent and StyleSheet changes
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] GetContent and StyleSheet changes
- Date: Fri, 27 Sep 2019 12:20:31 +0000 (UTC)
commit 5d0a06c025c38b10c72cc879b13e67c079f1f45c
Author: Milan Crha <mcrha redhat com>
Date: Fri Sep 27 14:20:45 2019 +0200
GetContent and StyleSheet changes
src/e-util/e-web-view-jsc-utils.c | 170 +++++++++++----
src/e-util/e-web-view-jsc-utils.h | 35 +++-
src/e-util/e-web-view.c | 89 ++------
src/e-util/e-web-view.h | 4 -
src/e-util/test-web-view.c | 429 +++++++++++++++++++++++++++++++++++---
src/web-extensions/ext-utils.js | 141 +++++++++++--
6 files changed, 703 insertions(+), 165 deletions(-)
---
diff --git a/src/e-util/e-web-view-jsc-utils.c b/src/e-util/e-web-view-jsc-utils.c
index 2a3e37a713..9930195ead 100644
--- a/src/e-util/e-web-view-jsc-utils.c
+++ b/src/e-util/e-web-view-jsc-utils.c
@@ -157,7 +157,8 @@ e_web_view_jsc_printf_scriptv (const gchar *script_format,
case '%':
g_string_append_c (script, ptr[1]);
break;
- case 'b': {
+ /* Using %x for boolean, because %b is unknown to gcc, thus it claims format warnings
*/
+ case 'x': {
gboolean arg = va_arg (va, gboolean);
g_string_append (script, arg ? "true" : "false");
@@ -336,35 +337,50 @@ e_web_view_jsc_set_element_attribute (WebKitWebView *web_view,
}
void
-e_web_view_jsc_create_css_style_sheet (WebKitWebView *web_view,
- const gchar *iframe_id,
- const gchar *style_sheet_id,
- const gchar *content,
- GCancellable *cancellable)
+e_web_view_jsc_create_style_sheet (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *style_sheet_id,
+ const gchar *content,
+ GCancellable *cancellable)
{
g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
g_return_if_fail (style_sheet_id != NULL);
e_web_view_jsc_run_script (web_view, cancellable,
- "Evo.CreateCSSStyleSheet(%s,%s,%s)",
+ "Evo.CreateStyleSheet(%s,%s,%s)",
iframe_id,
style_sheet_id,
content);
}
void
-e_web_view_jsc_add_css_rule_into_style_sheet (WebKitWebView *web_view,
- const gchar *iframe_id,
- const gchar *style_sheet_id,
- const gchar *selector,
- const gchar *style,
- GCancellable *cancellable)
+e_web_view_jsc_remove_style_sheet (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *style_sheet_id,
+ GCancellable *cancellable)
+{
+ g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+ g_return_if_fail (style_sheet_id != NULL);
+
+ e_web_view_jsc_run_script (web_view, cancellable,
+ "Evo.RemoveStyleSheet(%s,%s)",
+ iframe_id,
+ style_sheet_id);
+}
+
+void
+e_web_view_jsc_add_rule_into_style_sheet (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *style_sheet_id,
+ const gchar *selector,
+ const gchar *style,
+ GCancellable *cancellable)
{
g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
g_return_if_fail (style_sheet_id != NULL);
e_web_view_jsc_run_script (web_view, cancellable,
- "Evo.AddCSSRuleIntoStyleSheet(%s,%s,%s,%s)",
+ "Evo.AddRuleIntoStyleSheet(%s,%s,%s,%s)",
iframe_id,
style_sheet_id,
selector,
@@ -386,29 +402,11 @@ e_web_view_jsc_register_element_clicked (WebKitWebView *web_view,
elem_classes);
}
-void
-e_web_view_jsc_get_selection (WebKitWebView *web_view,
- ETextFormat format,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- gchar *script;
-
- g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
-
- script = e_web_view_jsc_printf_script ("Evo.GetSelection(%d)", format);
-
- webkit_web_view_run_javascript (web_view, script, cancellable, callback, user_data);
-
- g_free (script);
-}
-
-gboolean
-e_web_view_jsc_get_selection_finish (WebKitWebView *web_view,
- GAsyncResult *result,
- GSList **out_texts,
- GError **error)
+static gboolean
+ewv_jsc_get_content_finish (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error)
{
WebKitJavascriptResult *js_result;
GError *local_error = NULL;
@@ -455,3 +453,101 @@ e_web_view_jsc_get_selection_finish (WebKitWebView *web_view,
return TRUE;
}
+
+void
+e_web_view_jsc_get_selection (WebKitWebView *web_view,
+ ETextFormat format,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ gchar *script;
+
+ g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+
+ script = e_web_view_jsc_printf_script ("Evo.GetSelection(%d)", format);
+
+ webkit_web_view_run_javascript (web_view, script, cancellable, callback, user_data);
+
+ g_free (script);
+}
+
+gboolean
+e_web_view_jsc_get_selection_finish (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error)
+{
+ g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), FALSE);
+ g_return_val_if_fail (result != NULL, FALSE);
+ g_return_val_if_fail (out_texts != NULL, FALSE);
+
+ return ewv_jsc_get_content_finish (web_view, result, out_texts, error);
+}
+
+void
+e_web_view_jsc_get_document_content (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ ETextFormat format,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ gchar *script;
+
+ g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+
+ script = e_web_view_jsc_printf_script ("Evo.GetDocumentContent(%s,%d)", iframe_id, format);
+
+ webkit_web_view_run_javascript (web_view, script, cancellable, callback, user_data);
+
+ g_free (script);
+}
+
+gboolean
+e_web_view_jsc_get_document_content_finish (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error)
+{
+ g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), FALSE);
+ g_return_val_if_fail (result != NULL, FALSE);
+ g_return_val_if_fail (out_texts != NULL, FALSE);
+
+ return ewv_jsc_get_content_finish (web_view, result, out_texts, error);
+}
+
+void
+e_web_view_jsc_get_element_content (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *element_id,
+ ETextFormat format,
+ gboolean use_outer_html,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ gchar *script;
+
+ g_return_if_fail (WEBKIT_IS_WEB_VIEW (web_view));
+ g_return_if_fail (element_id != NULL);
+
+ script = e_web_view_jsc_printf_script ("Evo.GetElementContent(%s,%s,%d,%x)", iframe_id, element_id,
format, use_outer_html);
+
+ webkit_web_view_run_javascript (web_view, script, cancellable, callback, user_data);
+
+ g_free (script);
+}
+
+gboolean
+e_web_view_jsc_get_element_content_finish (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error)
+{
+ g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), FALSE);
+ g_return_val_if_fail (result != NULL, FALSE);
+ g_return_val_if_fail (out_texts != NULL, FALSE);
+
+ return ewv_jsc_get_content_finish (web_view, result, out_texts, error);
+}
diff --git a/src/e-util/e-web-view-jsc-utils.h b/src/e-util/e-web-view-jsc-utils.h
index 7351256870..104895dde5 100644
--- a/src/e-util/e-web-view-jsc-utils.h
+++ b/src/e-util/e-web-view-jsc-utils.h
@@ -73,13 +73,18 @@ void e_web_view_jsc_set_element_attribute
const gchar *qualified_name,
const gchar *value,
GCancellable *cancellable);
-void e_web_view_jsc_create_css_style_sheet
+void e_web_view_jsc_create_style_sheet
(WebKitWebView *web_view,
const gchar *iframe_id,
const gchar *style_sheet_id,
const gchar *content,
GCancellable *cancellable);
-void e_web_view_jsc_add_css_rule_into_style_sheet
+void e_web_view_jsc_remove_style_sheet
+ (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *style_sheet_id,
+ GCancellable *cancellable);
+void e_web_view_jsc_add_rule_into_style_sheet
(WebKitWebView *web_view,
const gchar *iframe_id,
const gchar *style_sheet_id,
@@ -108,6 +113,32 @@ gboolean e_web_view_jsc_get_selection_finish
GAsyncResult *result,
GSList **out_texts,
GError **error);
+void e_web_view_jsc_get_document_content
+ (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ ETextFormat format,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean e_web_view_jsc_get_document_content_finish
+ (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error);
+void e_web_view_jsc_get_element_content
+ (WebKitWebView *web_view,
+ const gchar *iframe_id,
+ const gchar *element_id,
+ ETextFormat format,
+ gboolean use_outer_html,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean e_web_view_jsc_get_element_content_finish
+ (WebKitWebView *web_view,
+ GAsyncResult *result,
+ GSList **out_texts,
+ GError **error);
G_END_DECLS
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index 86c2feb702..6863568f7d 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -814,6 +814,7 @@ web_view_load_changed_cb (WebKitWebView *webkit_web_view,
/* Make sure the initialize function is called for the top document when it is loaded. */
e_web_view_jsc_run_script (webkit_web_view, web_view->priv->load_cancellable,
"Evo.InitializeAndPostContentLoaded(null);");
+
style_updated_cb (web_view);
web_view_update_document_highlights (web_view);
@@ -2741,30 +2742,25 @@ get_document_content_html_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- GDBusProxy *web_extension;
GTask *task = user_data;
- GVariant *result_variant;
- gchar *html_content = NULL;
- GError *error = NULL;
+ GSList *texts = NULL;
+ GError *local_error = NULL;
- g_return_if_fail (G_IS_DBUS_PROXY (source_object));
+ g_return_if_fail (E_IS_WEB_VIEW (source_object));
g_return_if_fail (G_IS_TASK (task));
- web_extension = G_DBUS_PROXY (source_object);
+ e_web_view_jsc_get_document_content_finish (WEBKIT_WEB_VIEW (source_object), result, &texts,
&local_error);
- result_variant = g_dbus_proxy_call_finish (web_extension, result, &error);
- if (result_variant)
- g_variant_get (result_variant, "(s)", &html_content);
- g_variant_unref (result_variant);
+ if (local_error) {
+ g_task_return_error (task, local_error);
+ g_warn_if_fail (texts == NULL);
+ } else {
+ g_task_return_pointer (task, texts ? texts->data : NULL, g_free);
+ /* The texts::data is owned by the task now */
+ g_slist_free (texts);
+ }
- g_task_return_pointer (task, html_content, g_free);
g_object_unref (task);
-
- if (error)
- g_dbus_error_strip_remote_error (error);
-
- e_util_claim_dbus_proxy_call_error (web_extension, "GetDocumentContentHTML", error);
- g_clear_error (&error);
}
void
@@ -2773,29 +2769,14 @@ e_web_view_get_content_html (EWebView *web_view,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GDBusProxy *web_extension;
GTask *task;
g_return_if_fail (E_IS_WEB_VIEW (web_view));
task = g_task_new (web_view, cancellable, callback, user_data);
- web_extension = e_web_view_get_web_extension_proxy (web_view);
- if (web_extension) {
- g_dbus_proxy_call (
- web_extension,
- "GetDocumentContentHTML",
- g_variant_new (
- "(t)",
- webkit_web_view_get_page_id (
- WEBKIT_WEB_VIEW (web_view))),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- cancellable,
- get_document_content_html_cb,
- g_object_ref (task));
- } else
- g_task_return_pointer (task, NULL, NULL);
+ e_web_view_jsc_get_document_content (WEBKIT_WEB_VIEW (web_view), "", E_TEXT_FORMAT_HTML,
+ cancellable, get_document_content_html_cb, g_object_ref (task));
}
gchar *
@@ -2809,44 +2790,6 @@ e_web_view_get_content_html_finish (EWebView *web_view,
return g_task_propagate_pointer (G_TASK (result), error);
}
-gchar *
-e_web_view_get_content_html_sync (EWebView *web_view,
- GCancellable *cancellable,
- GError **error)
-{
- GDBusProxy *web_extension;
-
- g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
-
- web_extension = e_web_view_get_web_extension_proxy (web_view);
- if (web_extension) {
- GVariant *result;
-
- result = e_util_invoke_g_dbus_proxy_call_sync_wrapper_full (
- web_extension,
- "GetDocumentContentHTML",
- g_variant_new (
- "(t)",
- webkit_web_view_get_page_id (
- WEBKIT_WEB_VIEW (web_view))),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- cancellable,
- error);
-
- if (result) {
- gchar *html_content = NULL;
-
- g_variant_get (result, "(s)", &html_content);
- g_variant_unref (result);
-
- return html_content;
- }
- }
-
- return NULL;
-}
-
gboolean
e_web_view_get_caret_mode (EWebView *web_view)
{
@@ -4526,7 +4469,7 @@ e_web_view_add_css_rule_into_style_sheet (EWebView *web_view,
g_return_if_fail (selector && *selector);
g_return_if_fail (style && *style);
- e_web_view_jsc_add_css_rule_into_style_sheet (WEBKIT_WEB_VIEW (web_view),
+ e_web_view_jsc_add_rule_into_style_sheet (WEBKIT_WEB_VIEW (web_view),
"", style_sheet_id, selector, style,
web_view->priv->load_cancellable);
}
diff --git a/src/e-util/e-web-view.h b/src/e-util/e-web-view.h
index f98f43fa04..fa5778157c 100644
--- a/src/e-util/e-web-view.h
+++ b/src/e-util/e-web-view.h
@@ -151,10 +151,6 @@ gchar * e_web_view_get_content_html_finish
(EWebView *web_view,
GAsyncResult *result,
GError **error);
-gchar * e_web_view_get_content_html_sync
- (EWebView *web_view,
- GCancellable *cancellable,
- GError **error);
GDBusProxy * e_web_view_get_web_extension_proxy
(EWebView *web_view);
gboolean e_web_view_get_caret_mode (EWebView *web_view);
diff --git a/src/e-util/test-web-view.c b/src/e-util/test-web-view.c
index bbbc78947b..f150c046e7 100644
--- a/src/e-util/test-web-view.c
+++ b/src/e-util/test-web-view.c
@@ -436,6 +436,8 @@ test_utils_load_iframe_content (TestFixture *fixture,
test_utils_wait (fixture);
g_signal_handler_disconnect (fixture->web_view, handler_id);
+
+ test_utils_wait_noop (fixture);
}
static void
@@ -465,6 +467,8 @@ test_utils_load_string (TestFixture *fixture,
test_utils_wait (fixture);
g_signal_handler_disconnect (fixture->web_view, handler_id);
+
+ test_utils_wait_noop (fixture);
}
static void
@@ -744,6 +748,19 @@ test_style_sheets (TestFixture *fixture)
" return
Evo.findIFrameDocument(iframe_id).head.getElementsByTagName(\"style\").length;\n"
"}\n"
"\n"
+ "Test.hasStyle = function(iframe_id, style_sheet_id)\n"
+ "{\n"
+ " var doc = Evo.findIFrameDocument(iframe_id);\n"
+ " var styles = doc.head.getElementsByTagName(\"style\"), ii;\n"
+ "\n"
+ " for (ii = styles.length - 1; ii >= 0; ii--) {\n"
+ " if (styles[ii].id == style_sheet_id) {\n"
+ " return true;\n"
+ " }\n"
+ " }\n"
+ " return false;\n"
+ "}\n"
+ "\n"
"Test.getStyle = function(iframe_id, style_sheet_id, selector, property_name)\n"
"{\n"
" var styles = Evo.findIFrameDocument(iframe_id).head.getElementsByTagName(\"style\"),
ii;\n"
@@ -777,7 +794,7 @@ test_style_sheets (TestFixture *fixture)
g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"\", \"sheet1\", \"body\",
\"color\")", NULL);
- e_web_view_jsc_create_css_style_sheet (fixture->web_view, "", "sheet1", "body { color:green; }",
NULL);
+ e_web_view_jsc_create_style_sheet (fixture->web_view, "", "sheet1", "body { color:green; }", NULL);
test_utils_wait_noop (fixture);
g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
@@ -787,7 +804,7 @@ test_style_sheets (TestFixture *fixture)
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"\", \"sheet1\", \"body\",
\"color\")", "green");
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm1_1\", \"sheet2\", \"body\",
\"background-color\")", NULL);
- e_web_view_jsc_add_css_rule_into_style_sheet (fixture->web_view, "frm1_1", "sheet2", "body",
"background-color:black;", NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "frm1_1", "sheet2", "body",
"background-color:black;", NULL);
test_utils_wait_noop (fixture);
g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
@@ -801,7 +818,7 @@ test_style_sheets (TestFixture *fixture)
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm1_1\", \"sheet3\", \"body\",
\"color\")", NULL);
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm2\", \"sheet3\", \"body\",
\"color\")", NULL);
- e_web_view_jsc_add_css_rule_into_style_sheet (fixture->web_view, "*", "sheet3", "body",
"color:orange;", NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "*", "sheet3", "body", "color:orange;",
NULL);
test_utils_wait_noop (fixture);
g_assert_cmpint (3, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
@@ -814,6 +831,87 @@ test_style_sheets (TestFixture *fixture)
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm1\", \"sheet3\", \"body\",
\"color\")", "orange");
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm1_1\", \"sheet3\", \"body\",
\"color\")", "orange");
test_utils_jsc_call_string_and_verify (fixture, "Test.getStyle(\"frm2\", \"sheet3\", \"body\",
\"color\")", "orange");
+
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"\", \"sheetA\")") ?
1 : 0);
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1_1\",
\"sheetA\")") ? 1 : 0);
+
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "", "sheetA", "body", "color:blue;",
NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "frm1", "sheetA", "body", "color:blue;",
NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "frm1_1", "sheetA", "body",
"color:blue;", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (1, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"\", \"sheetA\")") ?
1 : 0);
+ g_assert_cmpint (1, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (1, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1_1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (4, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (3, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_remove_style_sheet (fixture->web_view, "frm1", "sheetA", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (1, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"\", \"sheetA\")") ?
1 : 0);
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (1, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1_1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (4, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (3, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_remove_style_sheet (fixture->web_view, "*", "sheetA", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"\", \"sheetA\")") ?
1 : 0);
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (0, ==, test_utils_jsc_call_bool_sync (fixture, "Test.hasStyle(\"frm1_1\",
\"sheetA\")") ? 1 : 0);
+ g_assert_cmpint (3, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_remove_style_sheet (fixture->web_view, "frm1_1", "*", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (3, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "", "sheetB", "body", "color:green;",
NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "frm1_1", "sheetB", "body",
"color:green;", NULL);
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "frm1_1", "sheetC", "body",
"color:yellow;", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (4, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_remove_style_sheet (fixture->web_view, "", "*", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_add_rule_into_style_sheet (fixture->web_view, "", "sheetC", "body", "color:yellow;",
NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (2, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (1, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
+
+ e_web_view_jsc_remove_style_sheet (fixture->web_view, "*", "*", NULL);
+ test_utils_wait_noop (fixture);
+
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"\")"));
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1\")"));
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm1_1\")"));
+ g_assert_cmpint (0, ==, test_utils_jsc_call_int32_sync (fixture, "Test.nStyles(\"frm2\")"));
}
typedef struct _ElementClickedData {
@@ -1080,47 +1178,56 @@ test_selection_select_in_iframe (TestFixture *fixture,
test_utils_wait_noop (fixture);
}
-typedef struct _GetSelectionData {
+typedef struct _GetContentData {
TestFixture *fixture;
const gchar *expect_plain;
const gchar *expect_html;
-} GetSelectionData;
+} GetContentData;
+
+static void
+test_verify_get_content_data (GetContentData *gcd,
+ const GSList *texts)
+{
+ g_assert_nonnull (gcd);
+
+ if (gcd->expect_plain && gcd->expect_html) {
+ g_assert_cmpint (g_slist_length ((GSList *) texts), ==, 2);
+ g_assert_cmpstr (texts->data, ==, gcd->expect_plain);
+ g_assert_cmpstr (texts->next->data, ==, gcd->expect_html);
+ } else if (gcd->expect_plain) {
+ g_assert_cmpint (g_slist_length ((GSList *) texts), ==, 1);
+ g_assert_cmpstr (texts->data, ==, gcd->expect_plain);
+ } else if (gcd->expect_html) {
+ g_assert_cmpint (g_slist_length ((GSList *) texts), ==, 1);
+ g_assert_cmpstr (texts->data, ==, gcd->expect_html);
+ } else {
+ g_assert_cmpint (g_slist_length ((GSList *) texts), ==, 0);
+ }
+}
static void
test_selection_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- GetSelectionData *gsd = user_data;
+ GetContentData *gcd = user_data;
GSList *texts = NULL;
gboolean success;
GError *error = NULL;
g_assert (WEBKIT_IS_WEB_VIEW (source_object));
- g_assert_nonnull (gsd);
+ g_assert_nonnull (gcd);
success = e_web_view_jsc_get_selection_finish (WEBKIT_WEB_VIEW (source_object), result, &texts,
&error);
g_assert_no_error (error);
g_assert (success);
- if (gsd->expect_plain && gsd->expect_html) {
- g_assert_cmpint (g_slist_length (texts), ==, 2);
- g_assert_cmpstr (texts->data, ==, gsd->expect_plain);
- g_assert_cmpstr (texts->next->data, ==, gsd->expect_html);
- } else if (gsd->expect_plain) {
- g_assert_cmpint (g_slist_length (texts), ==, 1);
- g_assert_cmpstr (texts->data, ==, gsd->expect_plain);
- } else if (gsd->expect_html) {
- g_assert_cmpint (g_slist_length (texts), ==, 1);
- g_assert_cmpstr (texts->data, ==, gsd->expect_html);
- } else {
- g_assert_cmpint (g_slist_length (texts), ==, 0);
- }
+ test_verify_get_content_data (gcd, texts);
g_slist_free_full (texts, g_free);
- test_flag_set (gsd->fixture->flag);
+ test_flag_set (gcd->fixture->flag);
}
static void
@@ -1129,7 +1236,7 @@ test_selection_verify (TestFixture *fixture,
const gchar *expect_html)
{
ETextFormat format;
- GetSelectionData *gsd;
+ GetContentData gcd;
if (expect_plain && expect_html)
format = E_TEXT_FORMAT_BOTH;
@@ -1138,12 +1245,11 @@ test_selection_verify (TestFixture *fixture,
else
format = E_TEXT_FORMAT_PLAIN;
- gsd = g_new0 (GetSelectionData, 1);
- gsd->fixture = fixture;
- gsd->expect_plain = expect_plain;
- gsd->expect_html = expect_html;
+ gcd.fixture = fixture;
+ gcd.expect_plain = expect_plain;
+ gcd.expect_html = expect_html;
- e_web_view_jsc_get_selection (fixture->web_view, format, NULL, test_selection_ready_cb, gsd);
+ e_web_view_jsc_get_selection (fixture->web_view, format, NULL, test_selection_ready_cb, &gcd);
test_utils_wait (fixture);
}
@@ -1219,6 +1325,274 @@ test_selection (TestFixture *fixture)
test_selection_verify (fixture, NULL, NULL);
}
+static void
+test_get_document_content_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GetContentData *gcd = user_data;
+ GSList *texts = NULL;
+ gboolean success;
+ GError *error = NULL;
+
+ g_assert (WEBKIT_IS_WEB_VIEW (source_object));
+ g_assert_nonnull (gcd);
+
+ success = e_web_view_jsc_get_document_content_finish (WEBKIT_WEB_VIEW (source_object), result,
&texts, &error);
+
+ g_assert_no_error (error);
+ g_assert (success);
+
+ test_verify_get_content_data (gcd, texts);
+
+ g_slist_free_full (texts, g_free);
+
+ test_flag_set (gcd->fixture->flag);
+}
+
+static void
+test_get_document_content_verify (TestFixture *fixture,
+ const gchar *iframe_id,
+ const gchar *expect_plain,
+ const gchar *expect_html)
+{
+ ETextFormat format;
+ GetContentData gcd;
+
+ if (expect_plain && expect_html)
+ format = E_TEXT_FORMAT_BOTH;
+ else if (expect_html)
+ format = E_TEXT_FORMAT_HTML;
+ else
+ format = E_TEXT_FORMAT_PLAIN;
+
+ gcd.fixture = fixture;
+ gcd.expect_plain = expect_plain;
+ gcd.expect_html = expect_html;
+
+ e_web_view_jsc_get_document_content (fixture->web_view, iframe_id, format, NULL,
test_get_document_content_ready_cb, &gcd);
+
+ test_utils_wait (fixture);
+}
+
+static void
+test_get_element_content_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GetContentData *gcd = user_data;
+ GSList *texts = NULL;
+ gboolean success;
+ GError *error = NULL;
+
+ g_assert (WEBKIT_IS_WEB_VIEW (source_object));
+ g_assert_nonnull (gcd);
+
+ success = e_web_view_jsc_get_document_content_finish (WEBKIT_WEB_VIEW (source_object), result,
&texts, &error);
+
+ g_assert_no_error (error);
+ g_assert (success);
+
+ test_verify_get_content_data (gcd, texts);
+
+ g_slist_free_full (texts, g_free);
+
+ test_flag_set (gcd->fixture->flag);
+}
+
+static void
+test_get_element_content_verify (TestFixture *fixture,
+ const gchar *iframe_id,
+ const gchar *element_id,
+ gboolean use_outer_html,
+ const gchar *expect_plain,
+ const gchar *expect_html)
+{
+ ETextFormat format;
+ GetContentData gcd;
+
+ if (expect_plain && expect_html)
+ format = E_TEXT_FORMAT_BOTH;
+ else if (expect_html)
+ format = E_TEXT_FORMAT_HTML;
+ else
+ format = E_TEXT_FORMAT_PLAIN;
+
+ gcd.fixture = fixture;
+ gcd.expect_plain = expect_plain;
+ gcd.expect_html = expect_html;
+
+ e_web_view_jsc_get_element_content (fixture->web_view, iframe_id, element_id, format, use_outer_html,
NULL, test_get_element_content_ready_cb, &gcd);
+
+ test_utils_wait (fixture);
+}
+
+static void
+test_get_content_html_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GetContentData *gcd = user_data;
+ GSList *texts = NULL;
+ gchar *text;
+ GError *error = NULL;
+
+ g_assert (WEBKIT_IS_WEB_VIEW (source_object));
+ g_assert_nonnull (gcd);
+
+ text = e_web_view_get_content_html_finish (E_WEB_VIEW (source_object), result, &error);
+
+ g_assert_no_error (error);
+
+ if (text)
+ texts = g_slist_prepend (texts, text);
+
+ test_verify_get_content_data (gcd, texts);
+
+ g_slist_free_full (texts, g_free);
+
+ test_flag_set (gcd->fixture->flag);
+}
+
+static void
+test_get_content_html_verify (TestFixture *fixture,
+ const gchar *expect_html)
+{
+ GetContentData gcd;
+
+ gcd.fixture = fixture;
+ gcd.expect_plain = NULL;
+ gcd.expect_html = expect_html;
+
+ e_web_view_get_content_html (E_WEB_VIEW (fixture->web_view), NULL, test_get_content_html_ready_cb,
&gcd);
+
+ test_utils_wait (fixture);
+}
+
+static void
+test_get_content (TestFixture *fixture)
+{
+ const gchar *html_main =
+ "<html style=\"\"><head><meta charset=\"utf-8\"></head><body>"
+ "<div id=\"frst\">first div</div>"
+ "<div id=\"scnd\">second div</div>"
+ "<iframe id=\"frm1\" src=\"empty:///\"></iframe>"
+ "</body></html>";
+ const gchar *html_frm1 =
+ "<html style=\"\"><head><meta name=\"keywords\" value=\"test\"></head><body>"
+ "<span id=\"frm1p\">"
+ "<div id=\"frst\">frm1 div</div>"
+ "</span>"
+ "</body></html>";
+ const gchar *expect_html, *expect_plain;
+
+ test_utils_load_string (fixture, html_main);
+ test_utils_load_iframe_content (fixture, "frm1", html_frm1);
+
+ /* Clean up styles added by EWebView */
+ test_utils_jsc_call_sync (fixture, "Evo.SetElementStyleProperty(\"\",\"*html\",\"color\",null);",
NULL);
+ test_utils_jsc_call_sync (fixture,
"Evo.SetElementStyleProperty(\"\",\"*html\",\"background-color\",null);", NULL);
+ test_utils_jsc_call_sync (fixture, "Evo.SetElementAttribute(\"\",\"*body\",\"\",\"class\",null);",
NULL);
+ test_utils_jsc_call_sync (fixture, "Evo.SetElementStyleProperty(\"frm1\",\"*html\",\"color\",null);",
NULL);
+ test_utils_jsc_call_sync (fixture,
"Evo.SetElementStyleProperty(\"frm1\",\"*html\",\"background-color\",null);", NULL);
+ test_utils_jsc_call_sync (fixture,
"Evo.SetElementAttribute(\"frm1\",\"*body\",\"\",\"class\",null);", NULL);
+ test_utils_jsc_call_sync (fixture, "Evo.RemoveStyleSheet(\"*\",\"*\");", NULL);
+
+ expect_plain = "first div\nsecond div\n";
+ expect_html = html_main;
+
+ test_get_document_content_verify (fixture, "", expect_plain, NULL);
+ test_get_document_content_verify (fixture, "", NULL, expect_html);
+ test_get_document_content_verify (fixture, "", expect_plain, expect_html);
+ test_get_content_html_verify (fixture, expect_html);
+
+ expect_plain = "frm1 div";
+ expect_html = html_frm1;
+ test_get_document_content_verify (fixture, "frm1", expect_plain, NULL);
+ test_get_document_content_verify (fixture, "frm1", NULL, expect_html);
+ test_get_document_content_verify (fixture, "frm1", expect_plain, expect_html);
+
+ expect_plain = "";
+ expect_html = "<meta charset=\"utf-8\">";
+ test_get_element_content_verify (fixture, "", "*head", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "*head", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "*head", FALSE, expect_plain, expect_html);
+
+ expect_html = "<head><meta charset=\"utf-8\"></head>";
+ test_get_element_content_verify (fixture, "", "*head", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "*head", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "*head", TRUE, expect_plain, expect_html);
+
+ expect_html = "<meta name=\"keywords\" value=\"test\">";
+ test_get_element_content_verify (fixture, "frm1", "*head", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "*head", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "*head", FALSE, expect_plain, expect_html);
+
+ expect_html = "<head><meta name=\"keywords\" value=\"test\"></head>";
+ test_get_element_content_verify (fixture, "frm1", "*head", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "*head", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "*head", TRUE, expect_plain, expect_html);
+
+ expect_plain = "first div\nsecond div\n";
+ expect_html =
+ "<div id=\"frst\">first div</div>"
+ "<div id=\"scnd\">second div</div>"
+ "<iframe id=\"frm1\" src=\"empty:///\"></iframe>";
+ test_get_element_content_verify (fixture, "", "*body", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "*body", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "*body", FALSE, expect_plain, expect_html);
+
+ expect_html = "<body>"
+ "<div id=\"frst\">first div</div>"
+ "<div id=\"scnd\">second div</div>"
+ "<iframe id=\"frm1\" src=\"empty:///\"></iframe></body>";
+ test_get_element_content_verify (fixture, "", "*body", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "*body", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "*body", TRUE, expect_plain, expect_html);
+
+ expect_plain = "frm1 div";
+ expect_html ="<span id=\"frm1p\"><div id=\"frst\">frm1 div</div></span>";
+ test_get_element_content_verify (fixture, "frm1", "*body", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "*body", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "*body", FALSE, expect_plain, expect_html);
+
+ expect_html = "<body><span id=\"frm1p\"><div id=\"frst\">frm1 div</div></span></body>";
+ test_get_element_content_verify (fixture, "frm1", "*body", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "*body", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "*body", TRUE, expect_plain, expect_html);
+
+ expect_plain = "first div";
+ expect_html = "first div";
+ test_get_element_content_verify (fixture, "", "frst", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "frst", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "frst", FALSE, expect_plain, expect_html);
+
+ expect_html = "<div id=\"frst\">first div</div>";
+ test_get_element_content_verify (fixture, "", "frst", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "", "frst", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "", "frst", TRUE, expect_plain, expect_html);
+
+ expect_plain = "frm1 div";
+ expect_html = "frm1 div";
+ test_get_element_content_verify (fixture, "frm1", "frst", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "frst", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "frst", FALSE, expect_plain, expect_html);
+
+ expect_html = "<div id=\"frst\">frm1 div</div>";
+ test_get_element_content_verify (fixture, "frm1", "frst", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "frst", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "frst", TRUE, expect_plain, expect_html);
+
+ test_get_element_content_verify (fixture, "frm1", "frm1p", FALSE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "frm1p", FALSE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "frm1p", FALSE, expect_plain, expect_html);
+
+ expect_html = "<span id=\"frm1p\"><div id=\"frst\">frm1 div</div></span>";
+ test_get_element_content_verify (fixture, "frm1", "frm1p", TRUE, expect_plain, NULL);
+ test_get_element_content_verify (fixture, "frm1", "frm1p", TRUE, NULL, expect_html);
+ test_get_element_content_verify (fixture, "frm1", "frm1p", TRUE, expect_plain, expect_html);
+}
+
gint
main (gint argc,
gchar *argv[])
@@ -1243,6 +1617,7 @@ main (gint argc,
test_utils_add_test ("/EWebView/ElementClicked", test_element_clicked);
test_utils_add_test ("/EWebView/NeedInputChanged", test_need_input_changed);
test_utils_add_test ("/EWebView/Selection", test_selection);
+ test_utils_add_test ("/EWebView/GetContent", test_get_content);
res = g_test_run ();
diff --git a/src/web-extensions/ext-utils.js b/src/web-extensions/ext-utils.js
index 321b80b518..29fd86eb81 100644
--- a/src/web-extensions/ext-utils.js
+++ b/src/web-extensions/ext-utils.js
@@ -44,6 +44,23 @@ Evo.findIFrameDocument = function(iframe_id)
return document;
}
+Evo.findElementInDocumentById = function(doc, element_id)
+{
+ if (!doc)
+ return null;
+
+ if (element_id == "*html")
+ return doc.documentElement;
+
+ if (element_id == "*head")
+ return doc.head;
+
+ if (element_id == "*body")
+ return doc.body;
+
+ return doc.getElementById(element_id);
+}
+
Evo.findElementInDocument = function(doc, element_id)
{
var elem, iframes, ii;
@@ -51,7 +68,7 @@ Evo.findElementInDocument = function(doc, element_id)
if (!doc)
return null;
- elem = doc.getElementById(element_id);
+ elem = Evo.findElementInDocumentById(doc, element_id);
if (elem)
return elem;
@@ -71,7 +88,7 @@ Evo.findElement = function(iframe_id, element_id)
var iframe;
if (iframe_id == "")
- return document.getElementById(element_id);
+ return Evo.findElementInDocumentById(document, element_id);
if (iframe_id == "*") {
return Evo.findElementInDocument(document, element_id);
@@ -82,7 +99,7 @@ Evo.findElement = function(iframe_id, element_id)
if (!iframe)
return null;
- return iframe.contentDocument.getElementById(element_id);
+ return Evo.findElementInDocumentById(iframe.contentDocument, element_id);
}
Evo.SetElementHidden = function(iframe_id, element_id, value)
@@ -98,7 +115,7 @@ Evo.SetElementStyleProperty = function(iframe_id, element_id, property_name, val
var elem = Evo.findElement(iframe_id, element_id);
if (elem) {
- if (value != "")
+ if (value != null && value != "")
elem.style.setProperty(property_name, value);
else
elem.style.removeProperty(property_name);
@@ -110,7 +127,7 @@ Evo.SetElementAttribute = function(iframe_id, element_id, namespace_uri, qualifi
var elem = Evo.findElement(iframe_id, element_id);
if (elem) {
- if (value != "")
+ if (value != null && value != "")
elem.setAttributeNS(namespace_uri, qualified_name, value);
else
elem.removeAttributeNS(namespace_uri, qualified_name);
@@ -131,7 +148,7 @@ Evo.createStyleSheet = function(doc, style_sheet_id, content)
return node;
}
-Evo.CreateCSSStyleSheet = function(iframe_id, style_sheet_id, content)
+Evo.CreateStyleSheet = function(iframe_id, style_sheet_id, content)
{
var doc = Evo.findIFrameDocument(iframe_id);
var styles = doc.head.getElementsByTagName("style"), ii;
@@ -146,7 +163,46 @@ Evo.CreateCSSStyleSheet = function(iframe_id, style_sheet_id, content)
Evo.createStyleSheet(doc, style_sheet_id, content);
}
-Evo.addCSSRuleIntoStyleSheetDocument = function(doc, style_sheet_id, selector, style)
+Evo.removeStyleSheetInDocument = function(doc, style_sheet_id)
+{
+ if (!doc || !doc.head)
+ return;
+
+ var styles = doc.head.getElementsByTagName("style"), ii;
+
+ for (ii = styles.length - 1; ii >= 0; ii--) {
+ if (style_sheet_id == "*" || styles[ii].id == style_sheet_id) {
+ doc.head.removeChild(styles[ii]);
+ }
+ }
+}
+
+Evo.removeStyleSheetInDocumentRecursive = function(doc, style_sheet_id)
+{
+ if (!doc)
+ return;
+
+ Evo.removeStyleSheetInDocument(doc, style_sheet_id);
+
+ var iframes, ii;
+
+ iframes = doc.getElementsByTagName("iframe");
+
+ for (ii = 0; ii < iframes.length; ii++) {
+ Evo.removeStyleSheetInDocumentRecursive(iframes[ii].contentDocument, style_sheet_id);
+ }
+}
+
+Evo.RemoveStyleSheet = function(iframe_id, style_sheet_id)
+{
+ if (iframe_id == "*") {
+ Evo.removeStyleSheetInDocumentRecursive(document, style_sheet_id);
+ } else {
+ Evo.removeStyleSheetInDocument(Evo.findIFrameDocument(iframe_id), style_sheet_id);
+ }
+}
+
+Evo.addRuleIntoStyleSheetDocument = function(doc, style_sheet_id, selector, style)
{
var styles = doc.head.getElementsByTagName("style"), ii, styleobj = null;
@@ -170,27 +226,27 @@ Evo.addCSSRuleIntoStyleSheetDocument = function(doc, style_sheet_id, selector, s
}
}
-Evo.addCSSRuleIntoStyleSheetDocumentRecursive = function(doc, style_sheet_id, selector, style)
+Evo.addRuleIntoStyleSheetDocumentRecursive = function(doc, style_sheet_id, selector, style)
{
- Evo.addCSSRuleIntoStyleSheetDocument(doc, style_sheet_id, selector, style);
+ Evo.addRuleIntoStyleSheetDocument(doc, style_sheet_id, selector, style);
var iframes, ii;
iframes = doc.getElementsByTagName("iframe");
for (ii = 0; ii < iframes.length; ii++) {
- Evo.addCSSRuleIntoStyleSheetDocumentRecursive(iframes[ii].contentDocument, style_sheet_id,
selector, style);
+ Evo.addRuleIntoStyleSheetDocumentRecursive(iframes[ii].contentDocument, style_sheet_id,
selector, style);
}
}
-Evo.AddCSSRuleIntoStyleSheet = function(iframe_id, style_sheet_id, selector, style)
+Evo.AddRuleIntoStyleSheet = function(iframe_id, style_sheet_id, selector, style)
{
if (iframe_id == "*") {
- Evo.addCSSRuleIntoStyleSheetDocumentRecursive(document, style_sheet_id, selector, style);
+ Evo.addRuleIntoStyleSheetDocumentRecursive(document, style_sheet_id, selector, style);
} else {
var doc = Evo.findIFrameDocument(iframe_id);
- Evo.addCSSRuleIntoStyleSheetDocument(doc, style_sheet_id, selector, style);
+ Evo.addRuleIntoStyleSheetDocument(doc, style_sheet_id, selector, style);
}
}
@@ -341,6 +397,26 @@ Evo.convertHTMLToPlain = function(node)
return node.innerText;
}
+Evo.getElementContent = function(node, format, useOuterHTML)
+{
+ if (!node)
+ return null;
+
+ var data;
+
+ if (format == 1) {
+ data = Evo.convertHTMLToPlain(node);
+ } else if (format == 2) {
+ data = useOuterHTML ? node.outerHTML : node.innerHTML;
+ } else if (format == 3) {
+ data = {};
+ data["plain"] = Evo.convertHTMLToPlain(node);
+ data["html"] = useOuterHTML ? node.outerHTML : node.innerHTML;
+ }
+
+ return data;
+}
+
Evo.checkHasSelectionRecursive = function(doc, content)
{
var has = false, iframes, ii;
@@ -354,14 +430,7 @@ Evo.checkHasSelectionRecursive = function(doc, content)
node = doc.createElement(inpre ? "PRE" : "DIV");
node.appendChild(fragment);
- if (content.format == 1) {
- content.data = Evo.convertHTMLToPlain(node);
- } else if (content.format == 2) {
- content.data = inpre ? node.outerHTML : node.innerHTML;
- } else if (content.format == 3) {
- content.data["plain"] = Evo.convertHTMLToPlain(node);
- content.data["html"] = inpre ? node.outerHTML : node.innerHTML;
- }
+ content.data = Evo.getElementContent(node, content.format, inpre);
}
return true;
@@ -390,7 +459,7 @@ Evo.selectionChanged = function()
Evo.GetSelection = function(format)
{
- var content = { format: 0, data: {} };
+ var content = { format: 0, data: null };
content.format = format;
@@ -400,6 +469,34 @@ Evo.GetSelection = function(format)
return content.data;
}
+Evo.GetDocumentContent = function(iframe_id, format)
+{
+ var doc;
+
+ if (iframe_id == "") {
+ doc = document;
+ } else {
+ var iframe = Evo.findIFrame(iframe_id);
+
+ if (!iframe)
+ return null;
+
+ doc = iframe.contentDocument;
+ }
+
+ return Evo.getElementContent(doc.documentElement, format, true);
+}
+
+Evo.GetElementContent = function(iframe_id, element_id, format, use_outer_html)
+{
+ var elem = Evo.findElement(iframe_id, element_id);
+
+ if (!elem)
+ return null;
+
+ return Evo.getElementContent(elem, format, use_outer_html);
+}
+
Evo.Initialize = function(elem)
{
var doc, elems, ii;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]