Last Comment Bug 537787 - e10s: Remote WebSockets
: e10s: Remote WebSockets
Status: VERIFIED FIXED
: dev-doc-complete
Product: Core
Classification: Components
Component: Networking: WebSockets (show other bugs)
: Other Branch
: All All
: -- normal with 2 votes (vote)
: mozilla7
Assigned To: Josh Matthews [:jdm]
:
Mentors:
: 581033 601582 (view as bug list)
Depends on: websocket 537782 615745 616733 640003 668950
Blocks: e10s-necko 616348 667853 668126 669819
  Show dependency treegraph
 
Reported: 2010-01-04 12:59 PST by Jason Duell [:jduell] (needinfo me)
Modified: 2011-08-31 07:08 PDT (History)
35 users (show)
mak77: in‑testsuite+
martijn.martijn: in‑litmus+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed
7+


Attachments
WIP (48.42 KB, patch)
2010-11-19 14:35 PST, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
WIP v2 (56.80 KB, patch)
2010-11-23 15:34 PST, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Add cross-process websocket support. (67.75 KB, patch)
2010-11-30 17:11 PST, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Add cross-process websocket support. (69.62 KB, patch)
2010-12-06 14:31 PST, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Make websockets work across processes. (25.78 KB, patch)
2011-05-03 12:39 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Remote websockets. (26.50 KB, patch)
2011-05-03 16:00 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Remote websockets. (31.12 KB, patch)
2011-05-04 06:43 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Pqtch (44.03 KB, patch)
2011-05-04 11:42 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Remote websockets. (37.36 KB, patch)
2011-05-23 16:46 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Use SpecialPowers in tests (1.47 KB, patch)
2011-05-23 16:48 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Remote websockets. (47.72 KB, patch)
2011-05-29 21:18 PDT, Josh Matthews [:jdm]
jduell.mcbugs: review-
Details | Diff | Splinter Review
Update websocket test to use SpecialPowers. (3.02 KB, patch)
2011-05-29 21:21 PDT, Josh Matthews [:jdm]
cmtalbert: review+
Details | Diff | Splinter Review
Remote websockets. (65.38 KB, patch)
2011-06-17 13:00 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Test to make sure websocket callbacks don't reenter. (986 bytes, patch)
2011-06-20 13:31 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Test to make sure websocket callbacks don't reenter. (2.76 KB, patch)
2011-06-20 13:32 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Remote websockets. (68.14 KB, patch)
2011-06-20 15:50 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
Test to make sure websocket callbacks don't reenter. (2.76 KB, patch)
2011-06-27 16:06 PDT, Josh Matthews [:jdm]
no flags Details | Diff | Splinter Review
DON'T LAND: Re-entrancy test, with change of wording (2.76 KB, patch)
2011-07-01 21:08 PDT, Jason Duell [:jduell] (needinfo me)
jduell.mcbugs: review+
Details | Diff | Splinter Review
interdiff of changes to main patch (23.15 KB, patch)
2011-07-01 21:54 PDT, Jason Duell [:jduell] (needinfo me)
no flags Details | Diff | Splinter Review
Remote Websockets v4 (70.18 KB, patch)
2011-07-01 21:58 PDT, Jason Duell [:jduell] (needinfo me)
jduell.mcbugs: review+
Details | Diff | Splinter Review

Description Jason Duell [:jduell] (needinfo me) 2010-01-04 12:59:25 PST
This is not a must-have (or even a strong want-have) for the next fennec release, but at some point we'll want to make web sockets work under e10s.  We'll want a separate IPDL protocol (PWebSocket) for it.

Hopefully it won't be much work, as the trickier stuff (like authentication) should be similar enough to whatever we cook up for HTTP, and web socket messages should map pretty straightforwardly onto IPDL msgs or shmem.
Comment 1 Josh Matthews [:jdm] 2010-07-22 08:14:53 PDT
*** Bug 581033 has been marked as a duplicate of this bug. ***
Comment 2 [:fabrice] Fabrice Desré 2010-10-04 05:14:36 PDT
*** Bug 601582 has been marked as a duplicate of this bug. ***
Comment 3 Paul Rouget [:paul] 2010-10-04 09:44:17 PDT
I think it's a must-have, at least for parity with Fx4 Desktop.
Comment 4 Lars Gunther 2010-10-04 09:50:33 PDT
I'm confused. I saw Paul demo using Web Sockets to control a presentation in another computer just a couple of weeks ago. Did e10s disable that feature?
Comment 5 Paul Rouget [:paul] 2010-10-04 09:52:33 PDT
@Lars: Yes:

Error: docShell: Not Remotable
Source File: chrome://global/content/bindings/browser.xml
Firefox can't establish a connection to the server at ws://.../
Comment 6 Josh Matthews [:jdm] 2010-10-05 10:27:43 PDT
I'll see what I can do with this.
Comment 7 Manuel Serrano 2010-11-08 01:53:01 PST
Sorry for this naive comment. I don't really understand all the details of this
discussion (for instance, I'm not really sure of what e10s is) so if my remark is
stupid, please, just ignore it.

If there is no plan to integrate correctly the websockets for the next stable
Fennec version, could it be possible to disable them by default (network.websocket.enabled set to false)? This will give a change to applications that need server pushes to switch smoothly to another implementation method such multipart XHRs.
Comment 8 Manuel Serrano 2010-11-08 02:00:18 PST
Just another comment that might interest you. If you are looking for incentive
for adding websockets to Fennec you might find interesting watching this video.
Go to the time position 7:03 and you will see the demo. Of course, everything is implemented with Firefox and Fennec (this is acknowledged at the end of the talk).
Thanks to all of you.

http://www.college-de-france.fr/default/EN/all/cha_inf2009/Cours_et_seminaire_du_20_janvi.jsp
Comment 9 Jason Duell [:jduell] (needinfo me) 2010-11-09 16:20:02 PST
> If there is no plan to integrate correctly the websockets for the next stable
Fennec version, could it be possible to disable them by default
(network.websocket.enabled set to false)?

Yes--we should check this in now, in case there's any fennec release before we ship e10 websockets.
Comment 10 Matt Brubeck (:mbrubeck) 2010-11-10 10:10:33 PST
(In reply to comment #7)
> If there is no plan to integrate correctly the websockets for the next stable
> Fennec version, could it be possible to disable them by default
> (network.websocket.enabled set to false)?

Even with this pref change, sites still seem to think that Fennec supports web sockets.  The window.WebSocket property still exists.  Is this a bug?
Comment 11 Josh Matthews [:jdm] 2010-11-10 10:58:24 PST
I'm inclined to think that window.WebSocket existing is not a bug.  For one thing, that's controlled by the DOMClassInfo stuff as far as I can tell, and I don't believe that's easy to hide based on a pref.  For another, we check the pref during websocket initialization and throw a NS_ERROR_DOM_SECURITY_ERROR - I have no idea if this is to spec and people should be catching this and simply aren't.
Comment 12 Stuart Parmenter 2010-11-10 16:39:38 PST
Just for clarity, this is a blocker for release.
Comment 13 Andy Green 2010-11-17 14:28:04 PST
> This is not a must-have (or even a strong want-have)

At the moment there is no websockets + canvas solution on Android.  When there is one, it'll extend realtime network-aware UIs that would previously have needed a native applet / app to Android.  There are people who "strongly want to have" it ;-) and I hope it'll be possible to ship with it.
Comment 14 Josh Matthews [:jdm] 2010-11-17 14:34:50 PST
I'm working on the implementation right now, and the bug is marked as blocking the final release of mobile Firefox.  There is no need for advocacy.
Comment 15 Josh Matthews [:jdm] 2010-11-19 14:35:32 PST
Created attachment 491957 [details] [diff] [review]
WIP

This patch allows sites like http://websockets.org/echo.html and http://mrdoob.com/projects/multiuserpad to work seemingly correctly.  There are still problems with the implementation (for example, cookies don't work yet), but I think it's the right architecture.
Comment 16 Josh Matthews [:jdm] 2010-11-23 15:34:36 PST
Created attachment 492835 [details] [diff] [review]
WIP v2

Rebased on top of bug 574897. Cookies should now work, and theoretically GetInterface for an auth prompt on the channel should also work.  I'm stumped about what to do with the nsILoadContext block that bug 574897 added in GetInterface, however.
Comment 17 Doug Turner (:dougt) 2010-11-30 12:14:15 PST
jdm, should someone be looking at this wip patch?
Comment 18 Josh Matthews [:jdm] 2010-11-30 12:24:07 PST
Comment on attachment 492835 [details] [diff] [review]
WIP v2

I suppose it wouldn't hurt if jduell or anybody else knowledgeable wanted to look over it.
Comment 19 Honza Bambas (:mayhemer) 2010-11-30 13:59:06 PST
I could take a look, if anyone is going to do this sooner, please drop a note.
Comment 20 Josh Matthews [:jdm] 2010-11-30 17:11:45 PST
Created attachment 494244 [details] [diff] [review]
Add cross-process websocket support.
Comment 21 Josh Matthews [:jdm] 2010-11-30 17:12:53 PST
Now passes all cookie tests in bug 574897 with the help of SpecialPowers.
Comment 22 Josh Matthews [:jdm] 2010-12-06 14:31:55 PST
Created attachment 495639 [details] [diff] [review]
Add cross-process websocket support.
Comment 23 Josh Matthews [:jdm] 2010-12-06 14:41:43 PST
Comment on attachment 495639 [details] [diff] [review]
Add cross-process websocket support.

Alright, I think this is good to go.  I've verified that no objects leak, random browsing of websockets-enabled websites works flawlessly, all websockets tests in the tree pass, and I've got a comfortable mental model of how the various proxy and concrete objects on the parent and child interact.  Honza, if you're not the right person for this then please reassign.
Comment 24 Josh Matthews [:jdm] 2010-12-06 15:06:52 PST
Honza, looks like this can wait until bug 616733 is resolved one way or the other.
Comment 25 Brad Lassey [:blassey] (use needinfo?) 2010-12-07 11:25:47 PST
As I understand it, firefox is pref'ing this off for 4.0, so this shouldn't block the release anymore. If my understanding is incorrect, please leave a comment. 

Also, to be clear, I don't see any reason for this not to land if the patches are ready.
Comment 26 Doug Turner (:dougt) 2011-04-27 13:38:43 PDT
honza any update on this review?
Comment 27 Josh Matthews [:jdm] 2011-04-27 13:44:06 PDT
Comment on attachment 495639 [details] [diff] [review]
Add cross-process websocket support.

This review isn't worth Honza's time. The websocket design has changed significantly in the new implementation, so I (or someone else) needs to sit down an reevaluate how best to remote them. In fact, I think I'll try to do that during the train rides I'll be taking in the next few days.
Comment 28 Josh Matthews [:jdm] 2011-04-28 13:37:03 PDT
Hooray, it looks like remoting the new websockets patch should be significantly easier.  We'll want a proxy listener object in the parent process that relays to the child, and some kind of proxy protocol handler in the child that relays the initial AsyncOpen to the parent, I think. I haven't sorted out all the details, but I'm hopeful. I'd be happy to put together a patch when I start full time at the end of May.
Comment 29 Jason Duell [:jduell] (needinfo me) 2011-04-29 11:33:54 PDT
I think we're going to want to move on this sooner than the end of May, assuming that biesi will get a chance to review the main websockets patches before then, and that we want to land e10s support concurrently (I don't care personally about landing them at the same time, but I seem to remember other people feeling it was a requirement).

jdm:  please unassign yourself if you don't think you can get to this in a few weeks or less, and we'll find someone to do it.
Comment 30 Josh Matthews [:jdm] 2011-05-01 04:41:39 PDT
Turns out that I've spent the majority of the past couple days on trains, so I'll be able to put up a proof-of-concept semi-patch in the near future. We can see where to go from there.
Comment 31 Josh Matthews [:jdm] 2011-05-03 12:39:55 PDT
Created attachment 529807 [details] [diff] [review]
Make websockets work across processes.

This patch is conceptually complete. I've manually put together a diff based off of the most recent proposed websockets patch, so it may or may not apply to any given tree. It also conceptually builds, as I've gone to fairly painstaking trouble of reading over all my code changes. If someone wants to take it any run with it from here, that'd be swell.
Comment 32 Josh Matthews [:jdm] 2011-05-03 16:00:34 PDT
Created attachment 529865 [details] [diff] [review]
Remote websockets.

I got access to a real tree, so this is actually a patch that can be applied. I also moved the IPC classes into new files, because the originals were long and complicated enough already.
Comment 33 Josh Matthews [:jdm] 2011-05-04 06:43:57 PDT
Created attachment 529987 [details] [diff] [review]
Remote websockets.

Now buildable, thanks to a few hours spent in the Paris office.
Comment 34 Josh Matthews [:jdm] 2011-05-04 11:42:47 PDT
Created attachment 530102 [details] [diff] [review]
Pqtch
Comment 35 Josh Matthews [:jdm] 2011-05-18 06:00:36 PDT
The attached patch represents the sum of my work. I'm not sure how much else I'll be able to do before I return on the 29th, so I'm unassigning myself. My work was at the point where I was attempting to test fennec against updated websocket tests to see what was still broken, last I recall.
Comment 36 Josh Matthews [:jdm] 2011-05-23 16:46:47 PDT
Created attachment 534623 [details] [diff] [review]
Remote websockets.

Psyke! Here's a patch that passes all the websocket tests in the tree. The only remaining issues are that I haven't added any new logging, and the mochitest currently leaks like a bucket with no bottom.
Comment 37 Josh Matthews [:jdm] 2011-05-23 16:48:12 PDT
Created attachment 534625 [details] [diff] [review]
Use SpecialPowers in tests

You can never have too many GC methods in SpecialPowers.
Comment 38 Josh Matthews [:jdm] 2011-05-29 21:18:51 PDT
Created attachment 535997 [details] [diff] [review]
Remote websockets.
Comment 39 Josh Matthews [:jdm] 2011-05-29 21:21:27 PDT
Created attachment 535998 [details] [diff] [review]
Update websocket test to use SpecialPowers.
Comment 40 Josh Matthews [:jdm] 2011-05-29 21:26:57 PDT
Comment on attachment 535997 [details] [diff] [review]
Remote websockets.

This patch is the best one to date! Now with fewer leaks, fewer crashes and more logging. All mochitests also pass with flying colours. Jason, do you feel like taking this?
Comment 41 Jason Duell [:jduell] (needinfo me) 2011-06-17 12:00:40 PDT
Comment on attachment 535997 [details] [diff] [review]
Remote websockets.

jdm already discussed much of this on IRC, but I've found some new things.   I'll want to have a look at the next patch too.

Test cases: I haven't looked at the mochitest(s), but let's make sure we cover
- bogus URI in websocket constructor
- valid but refused/unavailable URI
- sync XHR in onmessage() (have server close WS: make sure readyState doesn't change to CLOSED during onmessage()).
- test that involves an HTTP redirect (both failed and succeeded redirects would be good)

>diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp
>
>+static BaseWebSocketHandler*
>+WebSocketHandlerConstructor(bool aSecure)
>+{
>+  if (XRE_GetProcessType() != GeckoProcessType_Default) {
>+      return new nsWebSocketHandlerChild(aSecure);
>+  }

Use IsNeckoChild()?  Are you sure you want the check to be !GeckoProcessType_Default, or is ==GeckoProcessType_Content good enough?  We're only supporting tab processes, right?  In which case I'd think IsNeckoChild() should work fine.  

>diff --git a/netwerk/protocol/websocket/PWebSocket.ipdl b/netwerk/protocol/websocket/PWebSocket.ipdl
>new file mode 100644

Your new files seem to be using DOS line-endings (I see lots of ^M in vim).  Convert to unix (dos2unix is one util for doing that).

Also, not all of your new files have emacs/vim modelines.

>+  // Forwarded methods corresponding to methods on nsIWebSocketProtocolHandler

s/nsIWebSocketProtocolHandler/nsIWebSocketListener/

>diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.cpp b/netwerk/protocol/websocket/nsWebSocketHandler.cpp

>+#include "mozilla/net/NeckoChild.h"

See comments on logging below.  Also may need to remove #include of prlog.h below this.

> #if defined(PR_LOGGING)
>-static PRLogModuleInfo *webSocketLog = nsnull;
>+PRLogModuleInfo *webSocketLog = nsnull;
> #endif
> #define LOG(args) PR_LOG(webSocketLog, PR_LOG_DEBUG, args)

Hmm, we're going to want logging on when !DEBUG, which means we need to have FORCE_PR_LOG on AFICT.  Look at how nsHttp.h does it in lines 43-61.  I'm surprised we don't run into an error re-#defining LOG here--it's probably a warning?  Anyway, I think you'll want to centralize this in BaseWebChannel.h.  Make sure to compile an opt build and make sure that logging works in non-debug mode. 

Our logging is a real mess.

>diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.h b/netwerk/protocol/websocket/nsWebSocketHandler.h
> 
>+class BaseWebSocketHandler : public nsIWebSocketProtocol,

As mentioned on IRC, rename "BaseWebSocketChannel" (per bug 664860) and move into its own .h/.cpp files.

>+public:
>+    BaseWebSocketHandler();
>+
>+    NS_DECL_NSIPROTOCOLHANDLER
>+
>+    NS_SCRIPTABLE NS_IMETHOD QueryInterface(const nsIID & uuid, void **result NS_OUTPARAM) = 0;
>+    NS_IMETHOD_(nsrefcnt ) AddRef(void) = 0;
>+    NS_IMETHOD_(nsrefcnt ) Release(void) = 0;

As mentioned on IRC, I don't think you need to declare methods you're inheriting from interfaces unless you're actually defining them, so these can be eliminated.

>+
>+    NS_SCRIPTABLE NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI);
>+    NS_SCRIPTABLE NS_IMETHOD GetURI(nsIURI **aURI);
>+    NS_SCRIPTABLE NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aNotificationCallbacks);
>+    NS_SCRIPTABLE NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aNotificationCallbacks);

80 columns max, please.  Maybe break after NS_IMETHOD?  I'm not used to having NS_SCRIPTABLE in the decls, which makes lines (and even the column of the 1st param) very long.  We can probably scrap the NS_SCRIPTABLE decls--we don't use them in necko except a few scattered places, and they're just for dehydra analysis.  

>+    NS_SCRIPTABLE NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo) = 0;
>+
>+    NS_SCRIPTABLE NS_IMETHOD AsyncOpen(nsIURI *aURI,
>+                         const nsACString &aOrigin,
>+                         nsIWebSocketListener *aListener,
>+                         nsISupports *aContext) = 0;
>+    NS_SCRIPTABLE NS_IMETHOD Close() = 0;
>+    NS_SCRIPTABLE NS_IMETHOD SendMsg(const nsACString &aMsg) = 0;
>+    NS_SCRIPTABLE NS_IMETHOD SendBinaryMsg(const nsACString &aMsg) = 0;

I think these pure virtual decls can also be eliminated.

>+protected:
>+    nsCOMPtr<nsIURI>                mOriginalURI;
>+    nsCOMPtr<nsIURI>                mURI;
>+    nsCOMPtr<nsIWebSocketListener>  mListener;
>+    nsCOMPtr<nsISupports>           mContext;
>+    nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
>+    nsCOMPtr<nsILoadGroup>          mLoadGroup;
>+
>+    nsCString                       mProtocol;
>+    nsCString                       mOrigin;
>+
>+    PRBool  mEncrypted;

indent mEncrypted to same level as other data members.

> public:
>-    nsWebSocketSSLHandler() {nsWebSocketHandler::mEncrypted = PR_TRUE;}
>+    nsWebSocketSSLHandler() {BaseWebSocketHandler::mEncrypted = PR_TRUE;}

Put space between { and BaseWebSocketHandler, and btw ; and }

>diff --git a/netwerk/protocol/websocket/nsWebSocketHandlerIPC.cpp b/netwerk/protocol/websocket/nsWebSocketHandlerIPC.cpp

per IRC, split each class into its own file, and name WebSocketChannelChild|Parent.  And we need ChannelEventQueue for all incoming IPDL traffic to child.

>+bool
>+nsWebSocketHandlerParent::RecvDeleteSelf()
>+{
>+  LOG(("nsWebSocketHandlerParent::RecvDeleteSelf() %p\n", this));
>+  mProtocol = nsnull;
>+  mAuthProvider = nsnull;
>+  return Send__delete__(this);
>+}

Send__delete__ should be guarded with mIPCOpen.  The child process could conceivably drop dead at any point.

>+
>+bool
>+nsWebSocketHandlerParent::RecvAsyncOpen(const IPC::URI& aURI,
>+                                        const nsCString& aOrigin,
>+                                        const nsCString& aProtocol,
>+                                        const bool& aSecure)
>+{
>+  LOG(("nsWebSocketHandlerParent::RecvAsyncOpen() %p\n", this));
>+  nsresult rv;
>+  if (aSecure) {
>+    mProtocol =
>+        do_CreateInstance("@mozilla.org/network/protocol;1?name=wss", &rv);
>+  } else {
>+    mProtocol =
>+        do_CreateInstance("@mozilla.org/network/protocol;1?name=ws", &rv);

indent do_CreateInstance by 2, not 4

>+bool
>+nsWebSocketHandlerParent::CancelEarly()
>+{
>+  LOG(("nsWebSocketHandlerParent::CancelEarly() %p\n", this));
>+  return SendAsyncOpenFailed();
>+}

Also guard this with mIPCOpen.

>diff --git a/netwerk/protocol/websocket/nsWebSocketHandlerIPC.h b/netwerk/protocol/websocket/nsWebSocketHandlerIPC.h
>+
>+class nsWebSocketHandlerParent : public PWebSocketParent,
>+                                 public nsIWebSocketListener,
>+                                 public nsIInterfaceRequestor
>+{
>+private:
>+  bool RecvAsyncOpen(const IPC::URI& aURI,
>+                     const nsCString& aOrigin,
>+                     const nsCString& aProtocol,
>+                     const bool& aSecure);
>+  bool RecvClose();
>+  bool RecvSendMsg(const nsCString& aMsg);
>+  bool RecvSendBinaryMsg(const nsCString& aMsg);
>+  bool RecvDeleteSelf();
>+  bool CancelEarly();
>+
>+  void ActorDestroy(ActorDestroyReason why);
>+
>+  nsCOMPtr<nsIAuthPromptProvider> mAuthProvider;
>+  nsCOMPtr<nsIWebSocketProtocol> mProtocol;

In anticipation of bug 664860 (and to avoid confusion with the Base class' String mProtocol field), let's rename mProtocol -> mChannel.
Comment 42 Josh Matthews [:jdm] 2011-06-17 12:57:12 PDT
(In reply to comment #41)

>>+  // Forwarded methods corresponding to methods on nsIWebSocketProtocolHandler
>
>s/nsIWebSocketProtocolHandler/nsIWebSocketListener/

Nope, these are from the ProtocolHandler (which is actually the channel).

> >diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.cpp b/netwerk/protocol/websocket/nsWebSocketHandler.cpp
> 
> >+#include "mozilla/net/NeckoChild.h"
> 
> See comments on logging below.  Also may need to remove #include of prlog.h
> below this.
> 
> > #if defined(PR_LOGGING)
> >-static PRLogModuleInfo *webSocketLog = nsnull;
> >+PRLogModuleInfo *webSocketLog = nsnull;
> > #endif
> > #define LOG(args) PR_LOG(webSocketLog, PR_LOG_DEBUG, args)
> 
> Hmm, we're going to want logging on when !DEBUG, which means we need to have
> FORCE_PR_LOG on AFICT.  Look at how nsHttp.h does it in lines 43-61.  I'm
> surprised we don't run into an error re-#defining LOG here--it's probably a
> warning?  Anyway, I think you'll want to centralize this in
> BaseWebChannel.h.  Make sure to compile an opt build and make sure that
> logging works in non-debug mode. 
> 
> Our logging is a real mess.

I really want to keep these sorts of things out of header files, because it just perpetuates the mess. What I've done in my updated patch is add LOG defines per file as needed, store webSocketLog in BaseWebSocketChannel.cpp, and add extern definitions to the other consumers, which is an acceptable duplication/cleanliness tradeoff in my opinion.
 
> >diff --git a/netwerk/protocol/websocket/nsWebSocketHandler.h b/netwerk/protocol/websocket/nsWebSocketHandler.h
> >+public:
> >+    BaseWebSocketHandler();
> >+
> >+    NS_DECL_NSIPROTOCOLHANDLER
> >+
> >+    NS_SCRIPTABLE NS_IMETHOD QueryInterface(const nsIID & uuid, void **result NS_OUTPARAM) = 0;
> >+    NS_IMETHOD_(nsrefcnt ) AddRef(void) = 0;
> >+    NS_IMETHOD_(nsrefcnt ) Release(void) = 0;
> 
> As mentioned on IRC, I don't think you need to declare methods you're
> inheriting from interfaces unless you're actually defining them, so these
> can be eliminated.

Turns out we refuse to link without these here. It might be an ambiguity thing since it's inheriting from multiple nsISupports bases?
 
> >+bool
> >+nsWebSocketHandlerParent::RecvDeleteSelf()
> >+{
> >+  LOG(("nsWebSocketHandlerParent::RecvDeleteSelf() %p\n", this));
> >+  mProtocol = nsnull;
> >+  mAuthProvider = nsnull;
> >+  return Send__delete__(this);
> >+}
> 
> Send__delete__ should be guarded with mIPCOpen.  The child process could
> conceivably drop dead at any point.

Well, any point is a bit much. I mean, I guess if nulling out a member triggered a destructor which spun the event loop... (ok, I'll fix it.)
Comment 43 Josh Matthews [:jdm] 2011-06-17 13:00:07 PDT
Created attachment 540111 [details] [diff] [review]
Remote websockets.

Haven't done anything further with tests, but this makes all the other requested changes.
Comment 44 Josh Matthews [:jdm] 2011-06-17 13:12:48 PDT
From test_websocket.html comments:

>Test cases: I haven't looked at the mochitest(s), but let's make sure we cover
>- bogus URI in websocket constructor

 *  1. client tries to connect to a http scheme location;
 *  4. client tries to connect using a relative url;

>- valid but refused/unavailable URI

 *  3. client tries to connect to an non-existent ws server;
 *  5. client uses an invalid protocol value;

>- sync XHR in onmessage() (have server close WS: make sure readyState doesn't change to CLOSED during onmessage()).
>- test that involves an HTTP redirect (both failed and succeeded redirects would be good)

I'll see what I can do about these last two.
Comment 45 Josh Matthews [:jdm] 2011-06-20 13:29:39 PDT
>Hmm, we're going to want logging on when !DEBUG, which means we need to have >FORCE_PR_LOG on AFICT.  Look at how nsHttp.h does it in lines 43-61.  I'm >surprised we don't run into an error re-#defining LOG here--it's probably a >warning?  Anyway, I think you'll want to centralize this in BaseWebChannel.h.  >Make sure to compile an opt build and make sure that logging works in non-debug >mode. 

NSPR logging is not part of opt builds.
Comment 46 Josh Matthews [:jdm] 2011-06-20 13:31:09 PDT
Created attachment 540579 [details] [diff] [review]
Test to make sure websocket callbacks don't reenter.

Reentrancy test.
Comment 47 Josh Matthews [:jdm] 2011-06-20 13:32:36 PDT
Created attachment 540580 [details] [diff] [review]
Test to make sure websocket callbacks don't reenter.
Comment 48 Josh Matthews [:jdm] 2011-06-20 15:50:15 PDT
Created attachment 540609 [details] [diff] [review]
Remote websockets.

Now with working nspr logging.
Comment 49 Josh Matthews [:jdm] 2011-06-27 16:06:46 PDT
Created attachment 542313 [details] [diff] [review]
Test to make sure websocket callbacks don't reenter.

Test updated to pass with new protocol restrictions. I also confirmed that it does in fact fail without the IPDL buffering present.
Comment 50 Jason Duell [:jduell] (needinfo me) 2011-07-01 21:08:45 PDT
Created attachment 543566 [details] [diff] [review]
DON'T LAND: Re-entrancy test, with change of wording

Nice test.  So good, in fact, that it breaks non-e10s WS.  (did you check?  It breaks for me, at least, with 

  TEST-UNEXPECTED-FAIL |  | onclose called before onmessage!  (I changed wording--yours was wrong?)

  TEST-UNEXPECTED-FAIL |  | readystate should not be CLOSED - didn't expect 3, but got it
TEST-UNEXPECTED-FAIL |  | got a close callback before finishing onmessage

Not checking in--I'll move to a new bug.
Comment 51 Jason Duell [:jduell] (needinfo me) 2011-07-01 21:51:21 PDT
Comment on attachment 543566 [details] [diff] [review]
DON'T LAND: Re-entrancy test, with change of wording

Moved to bug 668948
Comment 52 Jason Duell [:jduell] (needinfo me) 2011-07-01 21:54:22 PDT
Created attachment 543572 [details] [diff] [review]
interdiff of changes to main patch
Comment 53 Jason Duell [:jduell] (needinfo me) 2011-07-01 21:58:59 PDT
Created attachment 543574 [details] [diff] [review]
Remote Websockets v4

Looks good.  The level of error/state checking is less in the e10s code than the mainline, but that looks like a good thing--the nsWebsocket.cpp code does enough checking that many of the things nsWebSocketHandler.cpp is checking for are not possible.  Should cleanup all that logic at some point.  Added some of those checks in e10s in form of assertions.

Running through try one last time, then will land.
Comment 54 Jason Duell [:jduell] (needinfo me) 2011-07-02 17:34:11 PDT
http://hg.mozilla.org/integration/mozilla-inbound/rev/4a894d4dc4da

I'm landing the main patch separately from the SpecialPowers patch, as with it I'm occasionally seeing 

 SpecialPowers is not defined at 
 http://mochi.test:8888/tests/Harness_sanity/file_SpecialPowersFrame1.html:11

mainly only on windows debug.  I don't see any reason why it could be causing that, but just in case..
Comment 55 Jason Duell [:jduell] (needinfo me) 2011-07-02 17:35:37 PDT
Comment on attachment 535998 [details] [diff] [review]
Update websocket test to use SpecialPowers.

Special powers patch landed as

http://hg.mozilla.org/integration/mozilla-inbound/rev/7a747adc8303
Comment 56 Josh Matthews [:jdm] 2011-07-02 20:14:35 PDT
Adding dev-doc-needed for the SpecialPowers API addition.
Comment 58 Dão Gottwald [:dao] 2011-07-04 23:21:56 PDT
(In reply to comment #55)
> Comment on attachment 535998 [details] [diff] [review] [review]
> Update websocket test to use SpecialPowers.
> 
> Special powers patch landed as
> 
> http://hg.mozilla.org/integration/mozilla-inbound/rev/7a747adc8303

Please check your commits (hg out) before pushing stuff.
Comment 59 Andreea Pod 2011-08-04 09:09:46 PDT
I tried http://websockets.org/echo.html and http://mrdoob.com/projects/multiuserpad with browser.tabs.remote=true and the pages work. With browser.tabs.remote=false they don't work, is this the expected result?

Mozilla /5.0 (Android;Linux armv7l;rv:7.0a2) Gecko/20110804 Firefox/7.0a2 Fennec/7.0a2
Device: LG Opyimus 2X
Comment 60 Eric Shepherd [:sheppy] 2011-08-05 12:24:37 PDT
From a developer standpoint, is the key issue here that WebSockets now work on mobile?
Comment 61 Josh Matthews [:jdm] 2011-08-05 12:42:44 PDT
Yes. The problem with testing this is that there are not many public tests that exercise the more recent websocket protocol, plus virtually no tests make use of the prefixed version.
Comment 62 Eric Shepherd [:sheppy] 2011-08-05 12:47:46 PDT
OK, the compatibility tables for WebSockets have been updated.
Comment 63 Martijn Wargers [:mwargers] (not working for Mozilla) 2011-08-17 04:53:40 PDT
Note that there are virtually no demos online on the web that work in Mozilla, because WebSocket was prefixed with "Moz" in bug 659324.
Comment 64 Martijn Wargers [:mwargers] (not working for Mozilla) 2011-08-17 09:38:43 PDT
It turns out there is one site that supports MozWebSocket, that is http://websocketstest.com/ . I used that for a litmus test.
https://litmus.mozilla.org/show_test.cgi?searchType=by_id&id=26364
Comment 65 Camelia Urian 2011-08-31 07:08:39 PDT
Mozilla /5.0 (Android;Linux armv7l;rv:7.0) Gecko/20110830 Firefox/7.0 Fennec/7.0
Device: Motorola DROID2

Verified site: http://websocketstest.com/ and every thing was reported as working on that page, except for the 'HTTP Proxy' part.

Marking bug as verified fixed.

Note You need to log in before you can comment on or make changes to this bug.