| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "web/SharedWorkerRepositoryClientImpl.h" | 31 #include "web/SharedWorkerRepositoryClientImpl.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionMessages.h" | |
| 34 #include "bindings/core/v8/ExceptionState.h" | |
| 35 #include "core/dom/ExceptionCode.h" | |
| 36 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
| 37 #include "core/events/Event.h" | 34 #include "core/events/Event.h" |
| 38 #include "core/frame/UseCounter.h" | 35 #include "core/frame/UseCounter.h" |
| 39 #include "core/frame/csp/ContentSecurityPolicy.h" | 36 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 40 #include "core/inspector/InspectorInstrumentation.h" | 37 #include "core/inspector/InspectorInstrumentation.h" |
| 41 #include "core/workers/SharedWorker.h" | 38 #include "core/workers/SharedWorker.h" |
| 42 #include "platform/network/ResourceResponse.h" | 39 #include "platform/network/ResourceResponse.h" |
| 43 #include "public/platform/WebMessagePortChannel.h" | 40 #include "public/platform/WebMessagePortChannel.h" |
| 44 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 45 #include "public/platform/WebURL.h" | 42 #include "public/platform/WebURL.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) { | 104 static WebSharedWorkerRepositoryClient::DocumentID getId(void* document) { |
| 108 DCHECK(document); | 105 DCHECK(document); |
| 109 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>( | 106 return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>( |
| 110 document); | 107 document); |
| 111 } | 108 } |
| 112 | 109 |
| 113 void SharedWorkerRepositoryClientImpl::connect( | 110 void SharedWorkerRepositoryClientImpl::connect( |
| 114 SharedWorker* worker, | 111 SharedWorker* worker, |
| 115 WebMessagePortChannelUniquePtr port, | 112 WebMessagePortChannelUniquePtr port, |
| 116 const KURL& url, | 113 const KURL& url, |
| 117 const String& name, | 114 const String& name) { |
| 118 ExceptionState& exceptionState) { | |
| 119 DCHECK(m_client); | 115 DCHECK(m_client); |
| 120 | 116 |
| 121 // No nested workers (for now) - connect() should only be called from document | 117 // No nested workers (for now) - connect() should only be called from document |
| 122 // context. | 118 // context. |
| 123 DCHECK(worker->getExecutionContext()->isDocument()); | 119 DCHECK(worker->getExecutionContext()->isDocument()); |
| 124 Document* document = toDocument(worker->getExecutionContext()); | 120 Document* document = toDocument(worker->getExecutionContext()); |
| 125 | 121 |
| 126 // TODO(estark): this is broken, as it only uses the first header | 122 // TODO(estark): this is broken, as it only uses the first header |
| 127 // when multiple might have been sent. Fix by making the | 123 // when multiple might have been sent. Fix by making the |
| 128 // SharedWorkerConnector interface take a map that can contain | 124 // SharedWorkerConnector interface take a map that can contain |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 m_client->createSharedWorkerConnector( | 140 m_client->createSharedWorkerConnector( |
| 145 url, name, getId(document), header, headerType, | 141 url, name, getId(document), header, headerType, |
| 146 worker->getExecutionContext()->securityContext().addressSpace(), | 142 worker->getExecutionContext()->securityContext().addressSpace(), |
| 147 isSecureContext ? WebSharedWorkerCreationContextTypeSecure | 143 isSecureContext ? WebSharedWorkerCreationContextTypeSecure |
| 148 : WebSharedWorkerCreationContextTypeNonsecure, | 144 : WebSharedWorkerCreationContextTypeNonsecure, |
| 149 &creationError); | 145 &creationError); |
| 150 | 146 |
| 151 switch (creationError) { | 147 switch (creationError) { |
| 152 case WebWorkerCreationErrorNone: | 148 case WebWorkerCreationErrorNone: |
| 153 break; | 149 break; |
| 154 case WebWorkerCreationErrorURLMismatch: | |
| 155 // Existing worker does not match this url, so return an error back to the | |
| 156 // caller. | |
| 157 exceptionState.throwDOMException( | |
| 158 URLMismatchError, "The location of the SharedWorker named '" + name + | |
| 159 "' does not exactly match the provided URL ('" + | |
| 160 url.elidedString() + "')."); | |
| 161 return; | |
| 162 case WebWorkerCreationErrorSecureContextMismatch: | 150 case WebWorkerCreationErrorSecureContextMismatch: |
| 163 UseCounter::Feature feature = | 151 UseCounter::Feature feature = |
| 164 isSecureContext | 152 isSecureContext |
| 165 ? UseCounter::NonSecureSharedWorkerAccessedFromSecureContext | 153 ? UseCounter::NonSecureSharedWorkerAccessedFromSecureContext |
| 166 : UseCounter::SecureSharedWorkerAccessedFromNonSecureContext; | 154 : UseCounter::SecureSharedWorkerAccessedFromNonSecureContext; |
| 167 UseCounter::count(document, feature); | 155 UseCounter::count(document, feature); |
| 168 break; | 156 break; |
| 169 } | 157 } |
| 170 | 158 |
| 171 // The connector object manages its own lifecycle (and the lifecycles of the | 159 // The connector object manages its own lifecycle (and the lifecycles of the |
| 172 // two worker objects). It will free itself once connecting is completed. | 160 // two worker objects). It will free itself once connecting is completed. |
| 173 SharedWorkerConnector* connector = new SharedWorkerConnector( | 161 SharedWorkerConnector* connector = new SharedWorkerConnector( |
| 174 worker, std::move(port), std::move(webWorkerConnector)); | 162 worker, std::move(port), std::move(webWorkerConnector)); |
| 175 connector->connect(); | 163 connector->connect(); |
| 176 } | 164 } |
| 177 | 165 |
| 178 void SharedWorkerRepositoryClientImpl::documentDetached(Document* document) { | 166 void SharedWorkerRepositoryClientImpl::documentDetached(Document* document) { |
| 179 DCHECK(m_client); | 167 DCHECK(m_client); |
| 180 m_client->documentDetached(getId(document)); | 168 m_client->documentDetached(getId(document)); |
| 181 } | 169 } |
| 182 | 170 |
| 183 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl( | 171 SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl( |
| 184 WebSharedWorkerRepositoryClient* client) | 172 WebSharedWorkerRepositoryClient* client) |
| 185 : m_client(client) {} | 173 : m_client(client) {} |
| 186 | 174 |
| 187 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |