diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2007-12-13 11:52:47 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2007-12-13 11:52:47 (GMT) |
commit | 5818437129222cb7a348f8a948e6b82a6bc5dc1d (patch) | |
tree | ecc684c18b5c5bfd8d4e53e6c6530843fa9c059e | |
parent | 6a193c175811272095ea088981143ad5d36e630d (diff) |
Add support to evaluate scripts.
-rw-r--r-- | python/hulahop.defs | 9 | ||||
-rw-r--r-- | src/hulahop-web-view.cpp | 24 | ||||
-rw-r--r-- | src/hulahop-web-view.h | 4 |
3 files changed, 35 insertions, 2 deletions
diff --git a/python/hulahop.defs b/python/hulahop.defs index 403208c..55c1733 100644 --- a/python/hulahop.defs +++ b/python/hulahop.defs @@ -67,3 +67,12 @@ (return-type "none") ) +(define-method evaluate_script + (of-object "HulahopWebView") + (c-name "hulahop_web_view_evaluate_script") + (parameters + '("gchar*" "script") + ) + (return-type "none") +) + diff --git a/src/hulahop-web-view.cpp b/src/hulahop-web-view.cpp index 286f3cf..00705b9 100644 --- a/src/hulahop-web-view.cpp +++ b/src/hulahop-web-view.cpp @@ -30,6 +30,8 @@ #include <nsIInterfaceRequestorUtils.h> #include <jscntxt.h> #include <nsIJSContextStack.h> +#include <nsIScriptGlobalObject.h> +#include <nsIScriptContext.h> #include <PyXPCOM.h> #include <gtk/gtkfixed.h> @@ -298,7 +300,7 @@ hulahop_web_view_grab_focus(HulahopWebView *web_view) } void -hulahop_web_view_push_js_context (HulahopWebView *web_view) +hulahop_web_view_push_js_context(HulahopWebView *web_view) { nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); nsresult rv = stack->Push(nsnull); @@ -306,10 +308,28 @@ hulahop_web_view_push_js_context (HulahopWebView *web_view) } void -hulahop_web_view_pop_js_context (HulahopWebView *web_view) +hulahop_web_view_pop_js_context(HulahopWebView *web_view) { nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); nsresult rv = stack->Pop(nsnull); g_assert(NS_SUCCEEDED(rv)); } +void +hulahop_web_view_evaluate_script(HulahopWebView *web_view, const char *script) +{ + nsresult rv; + + nsCOMPtr<nsIDOMWindow> contentWindow; + rv = web_view->browser->GetContentDOMWindow(getter_AddRefs(contentWindow)); + NS_ENSURE_SUCCESS(rv,); + + nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(contentWindow); + NS_ENSURE_TRUE(globalObject,); + + nsIScriptContext *context = globalObject->GetContext(); + NS_ENSURE_TRUE(context,); + + context->EvaluateString(NS_ConvertUTF8toUTF16(script), nsnull, nsnull, + nsnull, 0, nsnull, nsnull, nsnull); +} diff --git a/src/hulahop-web-view.h b/src/hulahop-web-view.h index 40ea6e8..f832b7a 100644 --- a/src/hulahop-web-view.h +++ b/src/hulahop-web-view.h @@ -45,6 +45,10 @@ PyObject *hulahop_web_view_get_window_root (HulahopWebView *web_view); void hulahop_web_view_push_js_context (HulahopWebView *web_view); void hulahop_web_view_pop_js_context (HulahopWebView *web_view); +void hulahop_web_view_evaluate_script (HulahopWebView *web_view, + const char *script); + + G_END_DECLS #endif |