Bug 159774 - Use SocketProvider to create SocketStreamHandles
Summary: Use SocketProvider to create SocketStreamHandles
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-14 11:17 PDT by Alex Christensen
Modified: 2016-07-26 07:16 PDT (History)
2 users (show)

See Also:


Attachments
Patch (56.37 KB, patch)
2016-07-14 11:20 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (56.93 KB, patch)
2016-07-14 11:26 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (79.38 KB, patch)
2016-07-14 11:58 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (80.66 KB, patch)
2016-07-14 13:06 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (80.55 KB, patch)
2016-07-14 13:55 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (80.49 KB, patch)
2016-07-14 14:16 PDT, Alex Christensen
beidson: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2016-07-14 11:17:22 PDT
Use SocketProvider to create SocketStreamHandles
Comment 1 Alex Christensen 2016-07-14 11:20:26 PDT
Created attachment 283663 [details]
Patch
Comment 2 Alex Christensen 2016-07-14 11:26:10 PDT
Created attachment 283664 [details]
Patch
Comment 3 Brady Eidson 2016-07-14 11:33:54 PDT
Comment on attachment 283664 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=283664&action=review

> Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:45
> +#include "ThreadableWebSocketChannel.h"
> +
> +#include "Document.h"
> +#include "ScriptExecutionContext.h"
> +#include "ThreadableWebSocketChannelClientWrapper.h"
> +#include "WebSocketChannel.h"
> +#include "WebSocketChannelClient.h"
> +#include "WorkerGlobalScope.h"
> +#include "WorkerRunLoop.h"
> +#include "WorkerThread.h"
> +#include "WorkerThreadableWebSocketChannel.h"
> +#include <wtf/text/StringBuilder.h>

Really needs all of these?

> Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:49
> +static const char webSocketChannelMode[] = "webSocketChannelMode";

ASCIILiteral?

> Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:57
> +        mode.appendLiteral(webSocketChannelMode);

And move the ASCIILiteral here, the only place it's actually used?

> Source/WebKit/mac/Misc/WebSocketProvider.mm:51
> +RefPtr<SocketStreamHandle> WebSocketProvider::createSocketStreamHandle(const URL& url, SocketStreamHandleClient& client, NetworkingContext& context, SessionID sessionID)
>  {
> -    if (is<WorkerGlobalScope>(context)) {
> -        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
> -        WorkerRunLoop& runLoop = workerGlobalScope.thread().runLoop();
> -        StringBuilder mode;
> -        mode.appendLiteral(webSocketChannelMode);
> -        mode.appendNumber(runLoop.createUniqueId());
> -        return WorkerThreadableWebSocketChannel::create(workerGlobalScope, client, mode.toString());
> -    }
> -
> -    return WebSocketChannel::create(downcast<Document>(context), client);
> +    return SocketStreamHandle::create(url, client, context, sessionID);

Default WebCore::SocketProvider should just do this, and the WebKit2 one should override.
Comment 4 Alex Christensen 2016-07-14 11:58:56 PDT
Created attachment 283665 [details]
Patch
Comment 5 Alex Christensen 2016-07-14 12:06:28 PDT
(In reply to comment #3)
> Comment on attachment 283664 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=283664&action=review
> 
> > Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:45
> > +#include "ThreadableWebSocketChannel.h"
> > +
> > +#include "Document.h"
> > +#include "ScriptExecutionContext.h"
> > +#include "ThreadableWebSocketChannelClientWrapper.h"
> > +#include "WebSocketChannel.h"
> > +#include "WebSocketChannelClient.h"
> > +#include "WorkerGlobalScope.h"
> > +#include "WorkerRunLoop.h"
> > +#include "WorkerThread.h"
> > +#include "WorkerThreadableWebSocketChannel.h"
> > +#include <wtf/text/StringBuilder.h>
> 
> Really needs all of these?
Yes.
> 
> > Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:49
> > +static const char webSocketChannelMode[] = "webSocketChannelMode";
> 
> ASCIILiteral?
> 
> > Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:57
> > +        mode.appendLiteral(webSocketChannelMode);
> 
> And move the ASCIILiteral here, the only place it's actually used?
StringBuilder has a nice appendLiteral(const char (&characters)[charactersCount]) which counts the characters at compile time.
> 
> > Source/WebKit/mac/Misc/WebSocketProvider.mm:51
> > +RefPtr<SocketStreamHandle> WebSocketProvider::createSocketStreamHandle(const URL& url, SocketStreamHandleClient& client, NetworkingContext& context, SessionID sessionID)
> >  {
> > -    if (is<WorkerGlobalScope>(context)) {
> > -        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(context);
> > -        WorkerRunLoop& runLoop = workerGlobalScope.thread().runLoop();
> > -        StringBuilder mode;
> > -        mode.appendLiteral(webSocketChannelMode);
> > -        mode.appendNumber(runLoop.createUniqueId());
> > -        return WorkerThreadableWebSocketChannel::create(workerGlobalScope, client, mode.toString());
> > -    }
> > -
> > -    return WebSocketChannel::create(downcast<Document>(context), client);
> > +    return SocketStreamHandle::create(url, client, context, sessionID);
> 
> Default WebCore::SocketProvider should just do this, and the WebKit2 one
> should override.
Done.
Comment 6 Alex Christensen 2016-07-14 13:06:31 PDT
Created attachment 283672 [details]
Patch
Comment 7 Alex Christensen 2016-07-14 13:55:53 PDT
Created attachment 283678 [details]
Patch
Comment 8 Alex Christensen 2016-07-14 14:16:16 PDT
Created attachment 283683 [details]
Patch
Comment 9 Alex Christensen 2016-07-14 14:44:07 PDT
https://trac.webkit.org/changeset/203244
Comment 10 Csaba Osztrogonác 2016-07-26 07:00:08 PDT
(In reply to comment #9)
> https://trac.webkit.org/changeset/203244

It broke the !ENABLE(WEB_SOCKETS) build, because WebCore::SocketProvider
is defined inside guards, but this change uses it without guard:

../../Source/WebCore/inspector/InspectorOverlay.cpp: In member function 'WebCore::Page* WebCore::InspectorOverlay::overlayPage()':
../../Source/WebCore/inspector/InspectorOverlay.cpp:867:77: error: 'create' is not a member of 'WebCore::SocketProvider'
Comment 11 Csaba Osztrogonác 2016-07-26 07:16:46 PDT
This snippet in Source/WebCore/page/SocketProvider.h fixes the build,
but I'm not sure if it is the proper fix here. I don't have any time
to investigate and/or prepare patch, feel free to pick it up or fix
it however you want.

-#if ENABLE(WEB_SOCKETS)
     static Ref<SocketProvider> create() { return adoptRef(*new SocketProvider); }
+#if ENABLE(WEB_SOCKETS)