| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "core/workers/WorkerGlobalScope.h" | 36 #include "core/workers/WorkerGlobalScope.h" |
| 37 #include "core/workers/WorkerLoaderProxy.h" | 37 #include "core/workers/WorkerLoaderProxy.h" |
| 38 #include "platform/network/ResourceError.h" | 38 #include "platform/network/ResourceError.h" |
| 39 #include "platform/network/ResourceResponse.h" | 39 #include "platform/network/ResourceResponse.h" |
| 40 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 42 #include <limits> | 42 #include <limits> |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 PassOwnPtr<ThreadableLoaderClient> WorkerLoaderClientBridge::create(PassRefPtr<T
hreadableLoaderClientWrapper> client, WorkerLoaderProxy& loaderProxy) | 46 PassOwnPtr<ThreadableLoaderClient> WorkerLoaderClientBridge::create(PassRefPtr<T
hreadableLoaderClientWrapper> client, PassRefPtr<WorkerLoaderProxy> loaderProxy) |
| 47 { | 47 { |
| 48 return adoptPtr(new WorkerLoaderClientBridge(client, loaderProxy)); | 48 return adoptPtr(new WorkerLoaderClientBridge(client, loaderProxy)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 WorkerLoaderClientBridge::~WorkerLoaderClientBridge() | 51 WorkerLoaderClientBridge::~WorkerLoaderClientBridge() |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 static void workerGlobalScopeDidSendData(ExecutionContext* context, PassRefPtr<T
hreadableLoaderClientWrapper> workerClientWrapper, unsigned long long bytesSent,
unsigned long long totalBytesToBeSent) | 55 static void workerGlobalScopeDidSendData(ExecutionContext* context, PassRefPtr<T
hreadableLoaderClientWrapper> workerClientWrapper, unsigned long long bytesSent,
unsigned long long totalBytesToBeSent) |
| 56 { | 56 { |
| 57 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 57 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 58 workerClientWrapper->didSendData(bytesSent, totalBytesToBeSent); | 58 workerClientWrapper->didSendData(bytesSent, totalBytesToBeSent); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void WorkerLoaderClientBridge::didSendData(unsigned long long bytesSent, unsigne
d long long totalBytesToBeSent) | 61 void WorkerLoaderClientBridge::didSendData(unsigned long long bytesSent, unsigne
d long long totalBytesToBeSent) |
| 62 { | 62 { |
| 63 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent)); | 63 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static void workerGlobalScopeDidReceiveResponse(ExecutionContext* context, PassR
efPtr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifi
er, PassOwnPtr<CrossThreadResourceResponseData> responseData, PassOwnPtr<WebData
ConsumerHandle> handle) | 66 static void workerGlobalScopeDidReceiveResponse(ExecutionContext* context, PassR
efPtr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifi
er, PassOwnPtr<CrossThreadResourceResponseData> responseData, PassOwnPtr<WebData
ConsumerHandle> handle) |
| 67 { | 67 { |
| 68 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 68 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 69 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); | 69 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); |
| 70 workerClientWrapper->didReceiveResponse(identifier, *response, handle); | 70 workerClientWrapper->didReceiveResponse(identifier, *response, handle); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void WorkerLoaderClientBridge::didReceiveResponse(unsigned long identifier, cons
t ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle) | 73 void WorkerLoaderClientBridge::didReceiveResponse(unsigned long identifier, cons
t ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle) |
| 74 { | 74 { |
| 75 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidReceiveResponse, m_workerClientWrapper, identifier, response, handle)); | 75 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveResponse, m_workerClientWrapper, identifier, response, handle))
; |
| 76 } | 76 } |
| 77 | 77 |
| 78 static void workerGlobalScopeDidReceiveData(ExecutionContext* context, PassRefPt
r<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vector<char> >
vectorData) | 78 static void workerGlobalScopeDidReceiveData(ExecutionContext* context, PassRefPt
r<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vector<char> >
vectorData) |
| 79 { | 79 { |
| 80 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 80 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 81 RELEASE_ASSERT(vectorData->size() <= std::numeric_limits<unsigned>::max()); | 81 RELEASE_ASSERT(vectorData->size() <= std::numeric_limits<unsigned>::max()); |
| 82 workerClientWrapper->didReceiveData(vectorData->data(), vectorData->size()); | 82 workerClientWrapper->didReceiveData(vectorData->data(), vectorData->size()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void WorkerLoaderClientBridge::didReceiveData(const char* data, unsigned dataLen
gth) | 85 void WorkerLoaderClientBridge::didReceiveData(const char* data, unsigned dataLen
gth) |
| 86 { | 86 { |
| 87 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCrossThreadTask. | 87 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCrossThreadTask. |
| 88 memcpy(vector->data(), data, dataLength); | 88 memcpy(vector->data(), data, dataLength); |
| 89 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidReceiveData, m_workerClientWrapper, vector.release())); | 89 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveData, m_workerClientWrapper, vector.release())); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static void workerGlobalScopeDidDownloadData(ExecutionContext* context, PassRefP
tr<ThreadableLoaderClientWrapper> workerClientWrapper, int dataLength) | 92 static void workerGlobalScopeDidDownloadData(ExecutionContext* context, PassRefP
tr<ThreadableLoaderClientWrapper> workerClientWrapper, int dataLength) |
| 93 { | 93 { |
| 94 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 94 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 95 workerClientWrapper->didDownloadData(dataLength); | 95 workerClientWrapper->didDownloadData(dataLength); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void WorkerLoaderClientBridge::didDownloadData(int dataLength) | 98 void WorkerLoaderClientBridge::didDownloadData(int dataLength) |
| 99 { | 99 { |
| 100 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidDownloadData, m_workerClientWrapper, dataLength)); | 100 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidDownloadData, m_workerClientWrapper, dataLength)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 static void workerGlobalScopeDidReceiveCachedMetadata(ExecutionContext* context,
PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vecto
r<char> > vectorData) | 103 static void workerGlobalScopeDidReceiveCachedMetadata(ExecutionContext* context,
PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, PassOwnPtr<Vecto
r<char> > vectorData) |
| 104 { | 104 { |
| 105 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 105 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 106 workerClientWrapper->didReceiveCachedMetadata(vectorData->data(), vectorData
->size()); | 106 workerClientWrapper->didReceiveCachedMetadata(vectorData->data(), vectorData
->size()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void WorkerLoaderClientBridge::didReceiveCachedMetadata(const char* data, int da
taLength) | 109 void WorkerLoaderClientBridge::didReceiveCachedMetadata(const char* data, int da
taLength) |
| 110 { | 110 { |
| 111 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCrossThreadTask. | 111 OwnPtr<Vector<char> > vector = adoptPtr(new Vector<char>(dataLength)); // ne
eds to be an OwnPtr for usage with createCrossThreadTask. |
| 112 memcpy(vector->data(), data, dataLength); | 112 memcpy(vector->data(), data, dataLength); |
| 113 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidReceiveCachedMetadata, m_workerClientWrapper, vector.release())); | 113 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveCachedMetadata, m_workerClientWrapper, vector.release())); |
| 114 } | 114 } |
| 115 | 115 |
| 116 static void workerGlobalScopeDidFinishLoading(ExecutionContext* context, PassRef
Ptr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifier
, double finishTime) | 116 static void workerGlobalScopeDidFinishLoading(ExecutionContext* context, PassRef
Ptr<ThreadableLoaderClientWrapper> workerClientWrapper, unsigned long identifier
, double finishTime) |
| 117 { | 117 { |
| 118 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 118 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 119 workerClientWrapper->didFinishLoading(identifier, finishTime); | 119 workerClientWrapper->didFinishLoading(identifier, finishTime); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void WorkerLoaderClientBridge::didFinishLoading(unsigned long identifier, double
finishTime) | 122 void WorkerLoaderClientBridge::didFinishLoading(unsigned long identifier, double
finishTime) |
| 123 { | 123 { |
| 124 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidFinishLoading, m_workerClientWrapper, identifier, finishTime)); | 124 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidFinishLoading, m_workerClientWrapper, identifier, finishTime)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 static void workerGlobalScopeDidFail(ExecutionContext* context, PassRefPtr<Threa
dableLoaderClientWrapper> workerClientWrapper, const ResourceError& error) | 127 static void workerGlobalScopeDidFail(ExecutionContext* context, PassRefPtr<Threa
dableLoaderClientWrapper> workerClientWrapper, const ResourceError& error) |
| 128 { | 128 { |
| 129 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 129 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 130 workerClientWrapper->didFail(error); | 130 workerClientWrapper->didFail(error); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void WorkerLoaderClientBridge::didFail(const ResourceError& error) | 133 void WorkerLoaderClientBridge::didFail(const ResourceError& error) |
| 134 { | 134 { |
| 135 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidFail, m_workerClientWrapper, error)); | 135 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidFail, m_workerClientWrapper, error)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 static void workerGlobalScopeDidFailAccessControlCheck(ExecutionContext* context
, PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, const ResourceE
rror& error) | 138 static void workerGlobalScopeDidFailAccessControlCheck(ExecutionContext* context
, PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, const ResourceE
rror& error) |
| 139 { | 139 { |
| 140 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 140 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 141 workerClientWrapper->didFailAccessControlCheck(error); | 141 workerClientWrapper->didFailAccessControlCheck(error); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void WorkerLoaderClientBridge::didFailAccessControlCheck(const ResourceError& er
ror) | 144 void WorkerLoaderClientBridge::didFailAccessControlCheck(const ResourceError& er
ror) |
| 145 { | 145 { |
| 146 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidFailAccessControlCheck, m_workerClientWrapper, error)); | 146 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidFailAccessControlCheck, m_workerClientWrapper, error)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 static void workerGlobalScopeDidFailRedirectCheck(ExecutionContext* context, Pas
sRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper) | 149 static void workerGlobalScopeDidFailRedirectCheck(ExecutionContext* context, Pas
sRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper) |
| 150 { | 150 { |
| 151 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 151 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 152 workerClientWrapper->didFailRedirectCheck(); | 152 workerClientWrapper->didFailRedirectCheck(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void WorkerLoaderClientBridge::didFailRedirectCheck() | 155 void WorkerLoaderClientBridge::didFailRedirectCheck() |
| 156 { | 156 { |
| 157 m_loaderProxy.postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGloba
lScopeDidFailRedirectCheck, m_workerClientWrapper)); | 157 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidFailRedirectCheck, m_workerClientWrapper)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 WorkerLoaderClientBridge::WorkerLoaderClientBridge(PassRefPtr<ThreadableLoaderCl
ientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy) | 160 WorkerLoaderClientBridge::WorkerLoaderClientBridge(PassRefPtr<ThreadableLoaderCl
ientWrapper> clientWrapper, PassRefPtr<WorkerLoaderProxy> loaderProxy) |
| 161 : m_workerClientWrapper(clientWrapper) | 161 : m_workerClientWrapper(clientWrapper) |
| 162 , m_loaderProxy(loaderProxy) | 162 , m_loaderProxy(loaderProxy) |
| 163 { | 163 { |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |