worker: Fix a bad static-cast. (issue 1047953002 by sadrul@chromium.org)

0 views
Skip to first unread message

sad...@chromium.org

unread,
Mar 30, 2015, 11:49:49 PM3/30/15
to tk...@chromium.org, blink-...@chromium.org, kinuko...@chromium.org, horo+...@chromium.org, fal...@chromium.org
Reviewers: tkent,

Description:
worker: Fix a bad static-cast.

For CompositorWorker, the WorkerGlobalScope is a
CompositorWorkerGlobalScope,
and not
a DedicatedWorkerGlobalScope. So fix the bad cast by teaching the task
about the
WorkerObjectProxy on creation (since WorkerMessagagingProxy already knows
about
it
without having to depend on the WorkerGlobalScope or the WorkerThread).

BUG=471785

Please review this at https://codereview.chromium.org/1047953002/

Base URL: svn://svn.chromium.org/blink/trunk

Affected files (+12, -10 lines):
M Source/core/workers/WorkerMessagingProxy.cpp


Index: Source/core/workers/WorkerMessagingProxy.cpp
diff --git a/Source/core/workers/WorkerMessagingProxy.cpp
b/Source/core/workers/WorkerMessagingProxy.cpp
index
071d3a20ba8940b8593ee0bf2b2c051129d4cc48..4a1687a96875c78d88fce71c8846eddfa8c67493
100644
--- a/Source/core/workers/WorkerMessagingProxy.cpp
+++ b/Source/core/workers/WorkerMessagingProxy.cpp
@@ -43,7 +43,6 @@
#include "core/inspector/WorkerDebuggerAgent.h"
#include "core/loader/DocumentLoadTiming.h"
#include "core/loader/DocumentLoader.h"
-#include "core/workers/DedicatedWorkerGlobalScope.h"
#include "core/workers/DedicatedWorkerThread.h"
#include "core/workers/Worker.h"
#include "core/workers/WorkerClients.h"
@@ -58,30 +57,32 @@ namespace blink {

class MessageWorkerGlobalScopeTask : public ExecutionContextTask {
public:
- static PassOwnPtr<MessageWorkerGlobalScopeTask>
create(PassRefPtr<SerializedScriptValue> message,
PassOwnPtr<MessagePortChannelArray> channels)
+ static PassOwnPtr<MessageWorkerGlobalScopeTask>
create(PassRefPtr<SerializedScriptValue> message,
PassOwnPtr<MessagePortChannelArray> channels, WorkerObjectProxy&
workerObjectProxy)
{
- return adoptPtr(new MessageWorkerGlobalScopeTask(message,
channels));
+ return adoptPtr(new MessageWorkerGlobalScopeTask(message,
channels, workerObjectProxy));
}

private:
- MessageWorkerGlobalScopeTask(PassRefPtr<SerializedScriptValue>
message, PassOwnPtr<MessagePortChannelArray> channels)
+ MessageWorkerGlobalScopeTask(PassRefPtr<SerializedScriptValue>
message, PassOwnPtr<MessagePortChannelArray> channels, WorkerObjectProxy&
workerObjectProxy)
: m_message(message)
, m_channels(channels)
+ , m_workerObjectProxy(workerObjectProxy)
{
}

virtual void performTask(ExecutionContext* scriptContext)
{

ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isWorkerGlobalScope());
- DedicatedWorkerGlobalScope* context =
static_cast<DedicatedWorkerGlobalScope*>(scriptContext);
OwnPtrWillBeRawPtr<MessagePortArray> ports =
MessagePort::entanglePorts(*scriptContext, m_channels.release());
- context->dispatchEvent(MessageEvent::create(ports.release(),
m_message));
-
context->thread()->workerObjectProxy().confirmMessageFromWorkerObject(context->hasPendingActivity());
+ WorkerGlobalScope* globalScope =
static_cast<WorkerGlobalScope*>(scriptContext);
+ globalScope->dispatchEvent(MessageEvent::create(ports.release(),
m_message));
+
m_workerObjectProxy.confirmMessageFromWorkerObject(scriptContext->hasPendingActivity());
}

private:
RefPtr<SerializedScriptValue> m_message;
OwnPtr<MessagePortChannelArray> m_channels;
+ WorkerObjectProxy& m_workerObjectProxy;
};

WorkerMessagingProxy::WorkerMessagingProxy(Worker* workerObject,
PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
@@ -147,9 +148,10 @@ void
WorkerMessagingProxy::postMessageToWorkerGlobalScope(PassRefPtr<SerializedS

if (m_workerThread) {
++m_unconfirmedMessageCount;
- m_workerThread->postTask(FROM_HERE,
MessageWorkerGlobalScopeTask::create(message, channels));
- } else
-
m_queuedEarlyTasks.append(MessageWorkerGlobalScopeTask::create(message,
channels));
+ m_workerThread->postTask(FROM_HERE,
MessageWorkerGlobalScopeTask::create(message, channels,
workerObjectProxy()));
+ } else {
+
m_queuedEarlyTasks.append(MessageWorkerGlobalScopeTask::create(message,
channels, workerObjectProxy()));
+ }
}

bool
WorkerMessagingProxy::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>
task)


tk...@chromium.org

unread,
Mar 30, 2015, 11:53:40 PM3/30/15
to sad...@chromium.org, blink-...@chromium.org, kinuko...@chromium.org, horo+...@chromium.org, fal...@chromium.org

commi...@chromium.org

unread,
Mar 30, 2015, 11:53:50 PM3/30/15
to sad...@chromium.org, tk...@chromium.org, blink-...@chromium.org, kinuko...@chromium.org, horo+...@chromium.org, fal...@chromium.org

commi...@chromium.org

unread,
Mar 31, 2015, 3:08:18 AM3/31/15
to sad...@chromium.org, tk...@chromium.org, blink-...@chromium.org, kinuko...@chromium.org, horo+...@chromium.org, fal...@chromium.org
Reply all
Reply to author
Forward
0 new messages