From 5818437129222cb7a348f8a948e6b82a6bc5dc1d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 13 Dec 2007 11:52:47 +0000 Subject: Add support to evaluate scripts. --- (limited to 'src') 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 #include #include +#include +#include #include #include @@ -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 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 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 contentWindow; + rv = web_view->browser->GetContentDOMWindow(getter_AddRefs(contentWindow)); + NS_ENSURE_SUCCESS(rv,); + + nsCOMPtr 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 -- cgit v0.9.1