Author: andreia
Date: 2007-12-24 19:50:16 -0500 (Mon, 24 Dec 2007)
New Revision: 91869
Modified:
trunk/gluezilla/src/ChangeLog
trunk/gluezilla/src/Widget.cpp
trunk/gluezilla/src/Widget.h
trunk/gluezilla/src/gluezilla.cpp
trunk/gluezilla/src/gluezilla.h
trunk/gluezilla/src/interfaces.h
Log:
* Wrap mozilla dom objects around proxies to allow winforms to call
methods accross threads (from the winforms ui thread to the main
mozilla ui thread).
2007-12-25 Andreia Gaita <[EMAIL PROTECTED]>
Modified: trunk/gluezilla/src/ChangeLog
===================================================================
--- trunk/gluezilla/src/ChangeLog 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/ChangeLog 2007-12-25 00:50:16 UTC (rev 91869)
@@ -1,3 +1,9 @@
+2007-12-25 Andreia Gaita <[EMAIL PROTECTED]>
+
+ * Wrap mozilla dom objects around proxies to allow winforms to call
+ methods accross threads (from the winforms ui thread to the main
+ mozilla ui thread).
+
2007-11-19 Wade Berrier <[EMAIL PROTECTED]>
* Makefile.am: include windows.mak in EXTRA_DIST
Modified: trunk/gluezilla/src/Widget.cpp
===================================================================
--- trunk/gluezilla/src/Widget.cpp 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/Widget.cpp 2007-12-25 00:50:16 UTC (rev 91869)
@@ -296,6 +296,7 @@
#ifdef NS_UNIX
gtk_widget_set_usize(reinterpret_cast<GtkWidget*>(this->hwnd), width,
height);
#endif
+
return NS_ERROR_FAILURE;
}
@@ -363,6 +364,60 @@
return NS_ERROR_FAILURE;
}
+// proxy getters
+
+nsresult
+Widget::GetProxyForDocument ()
+{
+ if (!this->document)
+ {
+ nsCOMPtr<nsIDOMWindow> domWindow;
+ this->browserWindow->webBrowser->GetContentDOMWindow(
getter_AddRefs (domWindow) );
+ nsCOMPtr<nsIDOMDocument> domDoc;
+ domWindow->GetDocument (getter_AddRefs(domDoc));
+ nsCOMPtr<nsIDOMHTMLDocument> htmlDoc (do_QueryInterface( domDoc
));
+
+ nsresult rv;
+ nsIProxyObjectManager * proxyManager = nsnull;
+ rv = CallGetService (NS_XPCOMPROXY_CONTRACTID, &proxyManager);
+ if (NS_FAILED (rv)) return rv;
+
+ rv = proxyManager->GetProxyForObject (nsnull,
+
nsIDOMHTMLDocument::GetIID(),
+
htmlDoc,
+
PROXY_SYNC | PROXY_ALWAYS,
+
getter_AddRefs (this->document));
+ // GetProxyForObject addrefs the document yet again, so let it
go
+ NS_RELEASE (htmlDoc);
+ }
+
+ return NS_OK;
+}
+
+nsresult
+Widget::GetProxyForNavigation ()
+{
+ if (!this->webNav)
+ {
+ nsCOMPtr<nsIWebNavigation> navigation (do_QueryInterface
(this->browserWindow->webBrowser));
+
+ nsresult rv;
+ nsIProxyObjectManager * proxyManager = nsnull;
+ rv = CallGetService (NS_XPCOMPROXY_CONTRACTID, &proxyManager);
+ if (NS_FAILED (rv)) return rv;
+
+ rv = proxyManager->GetProxyForObject (nsnull,
+
nsIWebNavigation::GetIID(),
+
navigation,
+
PROXY_SYNC | PROXY_ALWAYS,
+
getter_AddRefs (this->webNav));
+
+ // GetProxyForObject addrefs the navigation yet again, so let
it go
+ NS_RELEASE (navigation);
+
+ }
+ return NS_OK;
+}
// EVENTS
PRBool
Modified: trunk/gluezilla/src/Widget.h
===================================================================
--- trunk/gluezilla/src/Widget.h 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/Widget.h 2007-12-25 00:50:16 UTC (rev 91869)
@@ -60,6 +60,9 @@
delegates["home"].bind (this, &Widget::Home);
delegates["stop"].bind (this, &Widget::Stop);
delegates["reload"].bind (this, &Widget::Reload);
+
+ delegates["getDocument"].bind (this,
&Widget::GetDocument);
+ delegates["getNavigation"].bind (this,
&Widget::GetNavigation);
}
~Widget() {
int a = 0;
@@ -125,6 +128,17 @@
return this->Reload (params->option);
}
+ nsresult GetDocument (Params * params) {
+ this->GetProxyForDocument ();
+ params->document = this->document;
+ return NS_OK;
+ }
+
+ nsresult GetNavigation (Params * params) {
+ this->GetProxyForNavigation ();
+ params->navigation = this->webNav;
+ return NS_OK;
+ }
// end of generic targets for delegation
// Initialization and Shutdown
@@ -148,9 +162,11 @@
nsresult Home ();
nsresult Stop ();
nsresult Reload (ReloadOption option);
-
-
+
// getters
+ nsresult GetProxyForDocument ();
+ nsresult GetProxyForNavigation ();
+
Handle * getHandle () { return this->hwnd;}
@@ -215,17 +231,13 @@
CallbackBin *events;
BrowserWindow *browserWindow;
- nsIDOMHTMLDocument * document;
- nsIWebNavigation * webNav;
+ nsCOMPtr<nsIDOMHTMLDocument> document;
+ nsCOMPtr<nsIWebNavigation> webNav;
private:
nsresult GRE_Startup ();
- //XRE_InitEmbeddingType XRE_InitEmbedding;
- //XRE_TermEmbeddingType XRE_TermEmbedding;
std::map<const char*, WidgetDelegate> delegates;
-// nsCOMPtr<nsIWebBrowser> gWebBrowser;
-
static PRUint32 widgetCount;
@@ -236,7 +248,5 @@
// the appshell we have created
nsIAppShell *appShell;
-
-
};
#endif
Modified: trunk/gluezilla/src/gluezilla.cpp
===================================================================
--- trunk/gluezilla/src/gluezilla.cpp 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/gluezilla.cpp 2007-12-25 00:50:16 UTC (rev 91869)
@@ -257,26 +257,35 @@
}
-NS_METHOD_(void*)
+NS_METHOD_(nsIDOMHTMLDocument*)
gluezilla_getDomDocument (Handle *instance)
{
Widget *widget = reinterpret_cast<Widget *> (instance);
- nsCOMPtr<nsIDOMWindow> domWindow;
-
- widget->browserWindow->webBrowser->GetContentDOMWindow( getter_AddRefs
(domWindow) );
- nsCOMPtr<nsIDOMDocument> domDoc;
- domWindow->GetDocument (getter_AddRefs(domDoc));
- nsCOMPtr<nsIDOMHTMLDocument> htmlDoc (do_QueryInterface( domDoc ));
- return htmlDoc;
+ Params * p = new Params ();
+ p->name = "getDocument";
+ p->instance = widget;
+
+ nsresult result = widget->BeginInvoke (p);
+ nsIDOMHTMLDocument * ret (p->document);
+ if (p)
+ delete (p);
+ return ret;
}
-NS_METHOD_(void*)
+NS_METHOD_(nsIWebNavigation*)
gluezilla_getWebNavigation (Handle *instance)
{
- Widget *widget = reinterpret_cast<Widget *> (instance);
- nsCOMPtr<nsIWebNavigation> webNav (do_QueryInterface
(widget->browserWindow->webBrowser));
- return webNav;
+ Widget * widget = reinterpret_cast<Widget *> (instance);
+ Params * p = new Params ();
+ p->name = "getNavigation";
+ p->instance = widget;
+
+ nsresult result = widget->BeginInvoke (p);
+ nsIWebNavigation * ret (p->navigation);
+ if (p)
+ delete (p);
+ return ret;
}
NS_METHOD_(void)
@@ -322,6 +331,15 @@
str.Assign (text);
}
+NS_METHOD_(nsIServiceManager*)
+gluezilla_getServiceManager(Handle *instance)
+{
+ nsCOMPtr<nsIServiceManager> servMan;
+ NS_GetServiceManager (getter_AddRefs (servMan));
+ return servMan;
+}
+
+
#ifdef NS_UNIX
void *
gtk_startup (gpointer data)
Modified: trunk/gluezilla/src/gluezilla.h
===================================================================
--- trunk/gluezilla/src/gluezilla.h 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/gluezilla.h 2007-12-25 00:50:16 UTC (rev 91869)
@@ -226,8 +226,8 @@
NS_EXPORT_(int) gluezilla_shutdown (Handle *instance);
// DOM
- NS_EXPORT_(void*) gluezilla_getDomDocument (Handle *instance);
- NS_EXPORT_(void*) gluezilla_getWebNavigation (Handle *instance);
+ NS_EXPORT_(nsIDOMHTMLDocument*) gluezilla_getDomDocument (Handle
*instance);
+ NS_EXPORT_(nsIWebNavigation*) gluezilla_getWebNavigation (Handle
*instance);
// string helper methods
NS_EXPORT_(nsString*) gluezilla_stringInit ();
@@ -235,6 +235,7 @@
NS_EXPORT_(PRUnichar*) gluezilla_stringGet(nsString & str);
NS_EXPORT_(void) gluezilla_stringSet(nsString & str, PRUnichar * text);
+ NS_EXPORT_(nsIServiceManager*) gluezilla_getServiceManager(Handle
*instance);
#ifdef __cplusplus
@@ -266,6 +267,13 @@
struct {
FocusOption focus;
};
+ struct {
+ nsIDOMHTMLDocument * document;
+ };
+ struct {
+ nsIWebNavigation * navigation;
+ };
+
};
};
Modified: trunk/gluezilla/src/interfaces.h
===================================================================
--- trunk/gluezilla/src/interfaces.h 2007-12-24 20:53:50 UTC (rev 91868)
+++ trunk/gluezilla/src/interfaces.h 2007-12-25 00:50:16 UTC (rev 91869)
@@ -78,6 +78,9 @@
#include "nsIDOMDocument.h"
#include <nsIURI.h>
+// proxying objects between threads - another non-frozen interface :/
+#include "xpcom/nsIProxyObjectManager.h"
+
/* XRE API */
//#include "xulapp/nsXULAppAPI.h"
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches