OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google 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 | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 PassRefPtrWillBeRawPtr<Worker> Worker::create(ExecutionContext* context, const S
tring& url, ExceptionState& exceptionState) | 52 PassRefPtrWillBeRawPtr<Worker> Worker::create(ExecutionContext* context, const S
tring& url, ExceptionState& exceptionState) |
53 { | 53 { |
54 ASSERT(isMainThread()); | 54 ASSERT(isMainThread()); |
55 Document* document = toDocument(context); | 55 Document* document = toDocument(context); |
56 UseCounter::count(context, UseCounter::WorkerStart); | 56 UseCounter::count(context, UseCounter::WorkerStart); |
57 if (!document->page()) { | 57 if (!document->page()) { |
58 exceptionState.throwDOMException(InvalidAccessError, "The context provid
ed is invalid."); | 58 exceptionState.throwDOMException(InvalidAccessError, "The context provid
ed is invalid."); |
59 return nullptr; | 59 return nullptr; |
60 } | 60 } |
61 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid
er::from(*document->page()); | |
62 ASSERT(proxyProvider); | |
63 | |
64 RefPtrWillBeRawPtr<Worker> worker = adoptRefWillBeNoop(new Worker(context)); | 61 RefPtrWillBeRawPtr<Worker> worker = adoptRefWillBeNoop(new Worker(context)); |
65 | 62 if (worker->initialize(context, url, exceptionState)) |
66 worker->suspendIfNeeded(); | 63 return worker.release(); |
67 | 64 return nullptr; |
68 KURL scriptURL = worker->resolveURL(url, exceptionState); | |
69 if (scriptURL.isEmpty()) | |
70 return nullptr; | |
71 | |
72 worker->m_scriptLoader = WorkerScriptLoader::create(); | |
73 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri
ginRequests, worker.get()); | |
74 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker.
get()); | |
75 return worker.release(); | |
76 } | 65 } |
77 | 66 |
78 Worker::~Worker() | 67 Worker::~Worker() |
79 { | 68 { |
80 ASSERT(isMainThread()); | 69 ASSERT(isMainThread()); |
81 if (!m_contextProxy) | 70 if (!m_contextProxy) |
82 return; | 71 return; |
83 m_contextProxy->workerObjectDestroyed(); | 72 m_contextProxy->workerObjectDestroyed(); |
84 } | 73 } |
85 | 74 |
86 const AtomicString& Worker::interfaceName() const | 75 const AtomicString& Worker::interfaceName() const |
87 { | 76 { |
88 return EventTargetNames::Worker; | 77 return EventTargetNames::Worker; |
89 } | 78 } |
90 | 79 |
91 void Worker::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> me
ssage, const MessagePortArray* ports, ExceptionState& exceptionState) | 80 void Worker::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> me
ssage, const MessagePortArray* ports, ExceptionState& exceptionState) |
92 { | 81 { |
93 ASSERT(m_contextProxy); | 82 ASSERT(m_contextProxy); |
94 // Disentangle the port in preparation for sending it to the remote context. | 83 // Disentangle the port in preparation for sending it to the remote context. |
95 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); | 84 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); |
96 if (exceptionState.hadException()) | 85 if (exceptionState.hadException()) |
97 return; | 86 return; |
98 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); | 87 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); |
99 } | 88 } |
100 | 89 |
| 90 bool Worker::initialize(ExecutionContext* context, const String& url, ExceptionS
tate& exceptionState) |
| 91 { |
| 92 suspendIfNeeded(); |
| 93 |
| 94 Document* document = toDocument(context); |
| 95 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid
er::from(*document->page()); |
| 96 ASSERT(proxyProvider); |
| 97 |
| 98 KURL scriptURL = resolveURL(url, exceptionState); |
| 99 if (scriptURL.isEmpty()) |
| 100 return false; |
| 101 |
| 102 m_scriptLoader = WorkerScriptLoader::create(); |
| 103 m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOriginReque
sts, this); |
| 104 m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(this); |
| 105 return true; |
| 106 } |
| 107 |
101 void Worker::terminate() | 108 void Worker::terminate() |
102 { | 109 { |
103 if (m_contextProxy) | 110 if (m_contextProxy) |
104 m_contextProxy->terminateWorkerGlobalScope(); | 111 m_contextProxy->terminateWorkerGlobalScope(); |
105 } | 112 } |
106 | 113 |
107 void Worker::stop() | 114 void Worker::stop() |
108 { | 115 { |
109 terminate(); | 116 terminate(); |
110 } | 117 } |
(...skipping 23 matching lines...) Expand all Loading... |
134 } | 141 } |
135 m_scriptLoader = nullptr; | 142 m_scriptLoader = nullptr; |
136 } | 143 } |
137 | 144 |
138 void Worker::trace(Visitor* visitor) | 145 void Worker::trace(Visitor* visitor) |
139 { | 146 { |
140 AbstractWorker::trace(visitor); | 147 AbstractWorker::trace(visitor); |
141 } | 148 } |
142 | 149 |
143 } // namespace blink | 150 } // namespace blink |
OLD | NEW |