Author: jbevain
Date: 2007-10-21 13:52:54 -0400 (Sun, 21 Oct 2007)
New Revision: 87871
Added:
trunk/moon/plugin/browser-http.cpp
trunk/moon/plugin/browser-http.h
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/Makefile.am
Log:
2007-10-21 Jb Evain <[EMAIL PROTECTED]>
* browser-http.cpp|h: add the files where the unmanaged
implementation of BrowserHttpRequest will live.
* Makefile.am: add them to the build.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-10-21 17:28:14 UTC (rev 87870)
+++ trunk/moon/plugin/ChangeLog 2007-10-21 17:52:54 UTC (rev 87871)
@@ -1,3 +1,10 @@
+2007-10-21 Jb Evain <[EMAIL PROTECTED]>
+
+ * browser-http.cpp|h: add the files where the unmanaged
+ implementation of BrowserHttpRequest will live.
+
+ * Makefile.am: add them to the build.
+
2007-10-18 Chris Toshok <[EMAIL PROTECTED]>
* plugin-class.cpp (moonlight_dependency_object_invoke): make the
Modified: trunk/moon/plugin/Makefile.am
===================================================================
--- trunk/moon/plugin/Makefile.am 2007-10-21 17:28:14 UTC (rev 87870)
+++ trunk/moon/plugin/Makefile.am 2007-10-21 17:52:54 UTC (rev 87871)
@@ -41,6 +41,8 @@
plugin-glue.cpp \
plugin-class.cpp \
plugin-class.h \
+ browser-http.h \
+ browser-http.cpp \
downloader.cpp
novell_moonlight_xpi_CONTENTS = $(srcdir)/install.js .libs/libmoonloader.so
.libs/libmoonplugin.so
Added: trunk/moon/plugin/browser-http.cpp
===================================================================
--- trunk/moon/plugin/browser-http.cpp 2007-10-21 17:28:14 UTC (rev 87870)
+++ trunk/moon/plugin/browser-http.cpp 2007-10-21 17:52:54 UTC (rev 87871)
@@ -0,0 +1,138 @@
+/*
+ * browser-http.cpp: Moonlight plugin routines for http requests/responses.
+ *
+ * Author:
+ * Jb Evain ([EMAIL PROTECTED])
+ *
+ * Copyright 2007 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#include "browser-http.h"
+
+// SyncBrowserHttpResponse
+
+char *
+SyncBrowserHttpResponse::Read ()
+{
+ if (data != NULL)
+ return data;
+
+ PRUint32 available, length;
+ response_stream->Available (&available);
+
+ data = new char [available];
+ response_stream->Read (data, available, &length);
+ return data;
+}
+
+// BrowserHttpRequest
+
+void
+BrowserHttpRequest::CreateChannel ()
+{
+ nsresult rv = NS_OK;
+ nsCOMPtr<nsIServiceManager> mgr;
+ rv = NS_GetServiceManager (getter_AddRefs (mgr));
+ if (NS_FAILED (rv)) {
+ printf ("failed to ge a ServiceManager \n");
+ }
+
+ nsCOMPtr<nsIIOService> ioservice;
+ rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1",
+ NS_GET_IID (nsIIOService), getter_AddRefs (ioservice));
+
+ if (NS_FAILED (rv)) {
+ printf ("failed to get a IOService \n");
+ }
+
+ nsEmbedCString url;
+ url = this->uri;
+
+ nsCOMPtr<nsIURI> uri;
+ rv = ioservice->NewURI (url, nsnull, nsnull, getter_AddRefs (uri));
+
+ ioservice->NewChannelFromURI (uri, getter_AddRefs (this->channel));
+
+ nsCOMPtr<nsIHttpChannel> httpchannel = do_QueryInterface (channel);
+ if (!httpchannel)
+ return;
+
+ nsEmbedCString meth;
+ meth = this->method;
+ httpchannel->SetRequestMethod (meth);
+}
+
+SyncBrowserHttpResponse *
+BrowserHttpRequest::GetResponse ()
+{
+ nsresult rs = NS_OK;
+ nsCOMPtr<nsIInputStream> input;
+ rs = channel->Open (getter_AddRefs (input));
+ if (NS_FAILED (rs))
+ return NULL;
+
+ return new SyncBrowserHttpResponse (channel, input);
+}
+
+AsyncBrowserHttpResponse *
+BrowserHttpRequest::GetAsyncResponse ()
+{
+ printf ("GetAsyncResponse is not implemented \n");
+ AsyncBrowserHttpResponse *response = new AsyncBrowserHttpResponse
(channel);
+ // TODO: make AsyncBrowserHttpResponse implement nsIStreamListener
+ return response;
+}
+
+void
+BrowserHttpRequest::SetHttpHeader (const char *name, const char *value)
+{
+ nsCOMPtr<nsIHttpChannel> httpchannel = do_QueryInterface (channel);
+ if (!httpchannel)
+ return;
+
+ nsEmbedCString nsname, nsvalue;
+ nsname = name;
+ nsvalue = value;
+
+ httpchannel->SetRequestHeader (nsname, nsvalue, false);
+}
+
+BrowserHttpRequest *
+browser_http_request_new (const char *method, const char *uri)
+{
+ return new BrowserHttpRequest (method, uri);
+}
+
+void
+browser_http_request_set_header (BrowserHttpRequest *request, const char
*name, const char *value)
+{
+ request->SetHttpHeader (name, value);
+}
+
+void
+browser_http_request_destroy (BrowserHttpRequest *request)
+{
+ delete request;
+}
+
+SyncBrowserHttpResponse *
+browser_http_request_get_response (BrowserHttpRequest *request)
+{
+ return request->GetResponse ();
+}
+
+void
+browser_http_test ()
+{
+ printf ("test \n");
+ BrowserHttpRequest *req = new BrowserHttpRequest ("GET",
"http://evain.net/gdb.txt");
+ SyncBrowserHttpResponse *response = req->GetResponse ();
+
+ printf (response->Read ());
+
+ delete response;
+ delete req;
+}
Added: trunk/moon/plugin/browser-http.h
===================================================================
--- trunk/moon/plugin/browser-http.h 2007-10-21 17:28:14 UTC (rev 87870)
+++ trunk/moon/plugin/browser-http.h 2007-10-21 17:52:54 UTC (rev 87871)
@@ -0,0 +1,106 @@
+/*
+ * browser-http.h: Moonlight plugin routines for http requests/responses.
+ *
+ * Author:
+ * Jb Evain ([EMAIL PROTECTED])
+ *
+ * Copyright 2007 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#include "moonlight.h"
+#include "runtime.h"
+
+#include <nsCOMPtr.h>
+#include <nsXPCOM.h>
+#include <nsIURI.h>
+#include <nsIServiceManager.h>
+#include <nsIComponentManager.h>
+#include <nsIIOService.h>
+#include <nsStringAPI.h>
+#include <nsIInputStream.h>
+#include <nsEmbedString.h>
+#include <nsIChannel.h>
+#include <nsIHttpChannel.h>
+#include <nsEmbedString.h>
+
+class BrowserHttpResponse {
+private:
+ nsCOMPtr<nsIChannel> channel;
+
+public:
+ BrowserHttpResponse (nsCOMPtr<nsIChannel> channel)
+ {
+ this->channel = channel;
+ }
+
+ virtual ~BrowserHttpResponse ()
+ {
+ }
+};
+
+class SyncBrowserHttpResponse : public BrowserHttpResponse {
+private:
+ char *data;
+ nsCOMPtr<nsIInputStream> response_stream;
+
+public:
+ SyncBrowserHttpResponse (nsCOMPtr<nsIChannel> channel,
nsCOMPtr<nsIInputStream> response) : BrowserHttpResponse (channel), data (NULL)
+ {
+ this->response_stream = response;
+ }
+
+ virtual ~SyncBrowserHttpResponse ()
+ {
+ delete [] data;
+ }
+
+ char *Read ();
+};
+
+class AsyncBrowserHttpResponse : public BrowserHttpResponse {
+public:
+ AsyncBrowserHttpResponse (nsCOMPtr<nsIChannel> channel) :
BrowserHttpResponse (channel)
+ {
+ }
+};
+
+class BrowserHttpRequest {
+private:
+ const char *uri;
+ const char *method;
+
+ nsCOMPtr<nsIChannel> channel;
+
+ void CreateChannel ();
+public:
+
+ BrowserHttpRequest (const char *method, const char *uri)
+ {
+ this->method = g_strdup (method);
+ this->uri = g_strdup (uri);
+
+ CreateChannel ();
+ }
+
+ ~BrowserHttpRequest ()
+ {
+ }
+
+ SyncBrowserHttpResponse *GetResponse ();
+ AsyncBrowserHttpResponse *GetAsyncResponse ();
+ void SetHttpHeader (const char *name, const char *value);
+};
+
+G_BEGIN_DECLS
+
+BrowserHttpRequest *browser_http_request_new (const char *method, const char
*uri);
+void browser_http_request_destroy (BrowserHttpRequest *request);
+void browser_http_request_set_header (BrowserHttpRequest *request, const char
*name, const char *value);
+SyncBrowserHttpResponse *browser_http_request_get_response (BrowserHttpRequest
*request);
+
+void browser_http_test ();
+
+G_END_DECLS
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches