| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Apple Inc. All rights reserved. | 3 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "platform/weborigin/SecurityOrigin.h" | 47 #include "platform/weborigin/SecurityOrigin.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 inline SharedWorker::SharedWorker(ExecutionContext* context) | 51 inline SharedWorker::SharedWorker(ExecutionContext* context) |
| 52 : AbstractWorker(context) | 52 : AbstractWorker(context) |
| 53 , m_isBeingConnected(false) | 53 , m_isBeingConnected(false) |
| 54 { | 54 { |
| 55 } | 55 } |
| 56 | 56 |
| 57 PassRefPtrWillBeRawPtr<SharedWorker> SharedWorker::create(ExecutionContext* cont
ext, const String& url, const String& name, ExceptionState& exceptionState) | 57 SharedWorker* SharedWorker::create(ExecutionContext* context, const String& url,
const String& name, ExceptionState& exceptionState) |
| 58 { | 58 { |
| 59 ASSERT(isMainThread()); | 59 ASSERT(isMainThread()); |
| 60 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); | 60 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); |
| 61 | 61 |
| 62 UseCounter::count(context, UseCounter::SharedWorkerStart); | 62 UseCounter::count(context, UseCounter::SharedWorkerStart); |
| 63 | 63 |
| 64 RefPtrWillBeRawPtr<SharedWorker> worker = adoptRefWillBeNoop(new SharedWorke
r(context)); | 64 SharedWorker* worker = new SharedWorker(context); |
| 65 | 65 |
| 66 MessageChannel* channel = MessageChannel::create(context); | 66 MessageChannel* channel = MessageChannel::create(context); |
| 67 worker->m_port = channel->port1(); | 67 worker->m_port = channel->port1(); |
| 68 OwnPtr<WebMessagePortChannel> remotePort = channel->port2()->disentangle(); | 68 OwnPtr<WebMessagePortChannel> remotePort = channel->port2()->disentangle(); |
| 69 ASSERT(remotePort); | 69 ASSERT(remotePort); |
| 70 | 70 |
| 71 worker->suspendIfNeeded(); | 71 worker->suspendIfNeeded(); |
| 72 | 72 |
| 73 // We don't currently support nested workers, so workers can only be created
from documents. | 73 // We don't currently support nested workers, so workers can only be created
from documents. |
| 74 Document* document = toDocument(context); | 74 Document* document = toDocument(context); |
| 75 if (!document->securityOrigin()->canAccessSharedWorkers()) { | 75 if (!document->securityOrigin()->canAccessSharedWorkers()) { |
| 76 exceptionState.throwSecurityError("Access to shared workers is denied to
origin '" + document->securityOrigin()->toString() + "'."); | 76 exceptionState.throwSecurityError("Access to shared workers is denied to
origin '" + document->securityOrigin()->toString() + "'."); |
| 77 return nullptr; | 77 return nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 KURL scriptURL = worker->resolveURL(url, exceptionState); | 80 KURL scriptURL = worker->resolveURL(url, exceptionState); |
| 81 if (scriptURL.isEmpty()) | 81 if (scriptURL.isEmpty()) |
| 82 return nullptr; | 82 return nullptr; |
| 83 | 83 |
| 84 if (document->frame()->loader().client()->sharedWorkerRepositoryClient()) | 84 if (document->frame()->loader().client()->sharedWorkerRepositoryClient()) |
| 85 document->frame()->loader().client()->sharedWorkerRepositoryClient()->co
nnect(worker.get(), remotePort.release(), scriptURL, name, exceptionState); | 85 document->frame()->loader().client()->sharedWorkerRepositoryClient()->co
nnect(worker, remotePort.release(), scriptURL, name, exceptionState); |
| 86 | 86 |
| 87 return worker.release(); | 87 return worker; |
| 88 } | 88 } |
| 89 | 89 |
| 90 SharedWorker::~SharedWorker() | 90 SharedWorker::~SharedWorker() |
| 91 { | 91 { |
| 92 } | 92 } |
| 93 | 93 |
| 94 const AtomicString& SharedWorker::interfaceName() const | 94 const AtomicString& SharedWorker::interfaceName() const |
| 95 { | 95 { |
| 96 return EventTargetNames::SharedWorker; | 96 return EventTargetNames::SharedWorker; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool SharedWorker::hasPendingActivity() const | 99 bool SharedWorker::hasPendingActivity() const |
| 100 { | 100 { |
| 101 return m_isBeingConnected; | 101 return m_isBeingConnected; |
| 102 } | 102 } |
| 103 | 103 |
| 104 DEFINE_TRACE(SharedWorker) | 104 DEFINE_TRACE(SharedWorker) |
| 105 { | 105 { |
| 106 #if ENABLE(OILPAN) | |
| 107 visitor->trace(m_port); | 106 visitor->trace(m_port); |
| 108 HeapSupplementable<SharedWorker>::trace(visitor); | 107 HeapSupplementable<SharedWorker>::trace(visitor); |
| 109 #endif | |
| 110 AbstractWorker::trace(visitor); | 108 AbstractWorker::trace(visitor); |
| 111 } | 109 } |
| 112 | 110 |
| 113 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |