Author: jbevain
Date: 2007-11-20 06:10:52 -0500 (Tue, 20 Nov 2007)
New Revision: 89969
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin-class.h
trunk/moon/plugin/plugin.cpp
Log:
2007-11-20 Jb Evain <[EMAIL PROTECTED]>
* plugin-class.h (html_get_element_text): add a function
to get the `innerText` of an html element from its id.
* plugin-class.cpp (html_get_element_text): implement it.
* plugin.cpp (PluginInstance::UpdateSourceByReference):
use html_get_element_text to get the inline xaml.
Fixes #342349.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-11-20 11:06:01 UTC (rev 89968)
+++ trunk/moon/plugin/ChangeLog 2007-11-20 11:10:52 UTC (rev 89969)
@@ -1,3 +1,12 @@
+2007-11-20 Jb Evain <[EMAIL PROTECTED]>
+
+ * plugin-class.h (html_get_element_text): add a function
+ to get the `innerText` of an html element from its id.
+ * plugin-class.cpp (html_get_element_text): implement it.
+ * plugin.cpp (PluginInstance::UpdateSourceByReference):
+ use html_get_element_text to get the inline xaml.
+ Fixes #342349.
+
2007-11-16 Chris Toshok <[EMAIL PROTECTED]>
* plugin-class.cpp, plugin-class.h: switch
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2007-11-20 11:06:01 UTC (rev 89968)
+++ trunk/moon/plugin/plugin-class.cpp 2007-11-20 11:10:52 UTC (rev 89969)
@@ -24,11 +24,14 @@
#include <nsCOMPtr.h>
#include <nsIDOMElement.h>
+#include <nsIDOMRange.h>
+#include <nsIDOMDocumentRange.h>
#include <nsIDOMDocument.h>
#include <nsIDOMWindow.h>
#include <nsStringAPI.h>
#include <nsIDOMHTMLDocument.h>
#include <nsIDOMNodeList.h>
+#include <nsIDOMHTMLElement.h>
// Events
#include <nsIDOMEvent.h>
@@ -3369,6 +3372,42 @@
return dom_document;
}
+const char *
+html_get_element_text (PluginInstance *plugin, const char *element_id)
+{
+ nsresult rv = NS_OK;
+ NPP npp = plugin->getInstance ();
+
+ nsCOMPtr<nsIDOMDocument> document;
+ document = get_dom_document (npp);
+ if (!document)
+ return NULL;
+
+ nsString ns_id = NS_ConvertUTF8toUTF16 (element_id, strlen
(element_id));
+ nsCOMPtr<nsIDOMElement> element;
+ rv = document->GetElementById (ns_id, getter_AddRefs (element));
+ if (NS_FAILED (rv))
+ return NULL;
+
+ nsCOMPtr<nsIDOMDocument> owner;
+ element->GetOwnerDocument (getter_AddRefs (owner));
+
+ nsCOMPtr<nsIDOMDocumentRange> doc_range = do_QueryInterface (owner);
+ if (!doc_range)
+ return NULL;
+
+ nsCOMPtr<nsIDOMRange> range;
+ doc_range->CreateRange (getter_AddRefs (range));
+ if (!range)
+ return NULL;
+
+ range->SelectNodeContents (element);
+
+ nsString text;
+ range->ToString (text);
+ return g_strdup (NS_ConvertUTF16toUTF8 (text).get ());
+}
+
gpointer
html_object_attach_event (PluginInstance *plugin, NPObject *npobj, char *name,
callback_dom_event *cb)
{
Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h 2007-11-20 11:06:01 UTC (rev 89968)
+++ trunk/moon/plugin/plugin-class.h 2007-11-20 11:10:52 UTC (rev 89969)
@@ -682,6 +682,9 @@
gboolean ctrl_key, gboolean shift_key, int mouse_button);
extern "C" {
+
+ const char *html_get_element_text (PluginInstance *plugin, const char
*element_id);
+
// These are meant to be called by System.Silverlight.dll
void html_object_get_property (PluginInstance *plugin, NPObject *npobj,
char *name, Value *result);
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2007-11-20 11:06:01 UTC (rev 89968)
+++ trunk/moon/plugin/plugin.cpp 2007-11-20 11:10:52 UTC (rev 89969)
@@ -443,35 +443,19 @@
void
PluginInstance::UpdateSourceByReference (const char *value)
{
- NPObject *object = NULL;
- NPString reference;
- NPVariant result;
+ const char *xaml;
- if (NPERR_NO_ERROR != NPN_GetValue(this->instance, NPNVWindowNPObject,
&object)) {
- DEBUGMSG ("*** Failed to get window object");
+ xaml = html_get_element_text (this, value);
+ if (!xaml)
return;
- }
- char jscript[strlen (value) + strlen (".text") + 1];
+ if (xaml_loader)
+ delete xaml_loader;
- g_strlcpy (jscript, value, sizeof(jscript));
- g_strlcat (jscript, ".text", sizeof(jscript));
+ xaml_loader = PluginXamlLoader::FromStr (xaml, this, this->surface);
+ TryLoad ();
- reference.utf8characters = jscript;
- reference.utf8length = strlen (jscript);
-
- if (NPN_Evaluate(this->instance, object, &reference, &result)) {
- if (NPVARIANT_IS_STRING (result)) {
- if (xaml_loader)
- delete xaml_loader;
- xaml_loader = PluginXamlLoader::FromStr
(NPVARIANT_TO_STRING (result).utf8characters, this, this->surface);
- TryLoad ();
- }
-
- NPN_ReleaseVariantValue (&result);
- }
-
- NPN_ReleaseObject (object);
+ g_free ((gpointer) xaml);
}
bool
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches