Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: Source/core/workers/Worker.cpp

Issue 1018863002: compositor-worker: Introduce CompositorWorker. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 26 matching lines...) Expand all
37 #include "core/frame/LocalDOMWindow.h" 37 #include "core/frame/LocalDOMWindow.h"
38 #include "core/frame/UseCounter.h" 38 #include "core/frame/UseCounter.h"
39 #include "core/workers/WorkerGlobalScopeProxy.h" 39 #include "core/workers/WorkerGlobalScopeProxy.h"
40 #include "core/workers/WorkerGlobalScopeProxyProvider.h" 40 #include "core/workers/WorkerGlobalScopeProxyProvider.h"
41 #include "core/workers/WorkerScriptLoader.h" 41 #include "core/workers/WorkerScriptLoader.h"
42 #include "core/workers/WorkerThread.h" 42 #include "core/workers/WorkerThread.h"
43 #include "wtf/MainThread.h" 43 #include "wtf/MainThread.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 inline Worker::Worker(ExecutionContext* context) 47 Worker::Worker(ExecutionContext* context)
48 : AbstractWorker(context) 48 : AbstractWorker(context)
49 , m_contextProxy(nullptr) 49 , m_contextProxy(nullptr)
50 { 50 {
51 } 51 }
52 52
53 PassRefPtrWillBeRawPtr<Worker> Worker::create(ExecutionContext* context, const S tring& url, ExceptionState& exceptionState) 53 PassRefPtrWillBeRawPtr<Worker> Worker::create(ExecutionContext* context, const S tring& url, ExceptionState& exceptionState)
54 { 54 {
55 ASSERT(isMainThread()); 55 ASSERT(isMainThread());
56 Document* document = toDocument(context); 56 Document* document = toDocument(context);
57 UseCounter::count(context, UseCounter::WorkerStart); 57 UseCounter::count(context, UseCounter::WorkerStart);
58 if (!document->page()) { 58 if (!document->page()) {
59 exceptionState.throwDOMException(InvalidAccessError, "The context provid ed is invalid."); 59 exceptionState.throwDOMException(InvalidAccessError, "The context provid ed is invalid.");
60 return nullptr; 60 return nullptr;
61 } 61 }
62 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid er::from(*document->page());
63 ASSERT(proxyProvider);
64
65 RefPtrWillBeRawPtr<Worker> worker = adoptRefWillBeNoop(new Worker(context)); 62 RefPtrWillBeRawPtr<Worker> worker = adoptRefWillBeNoop(new Worker(context));
66 63 if (worker->initialize(context, url, exceptionState))
67 worker->suspendIfNeeded(); 64 return worker.release();
68 65 return nullptr;
69 KURL scriptURL = worker->resolveURL(url, exceptionState);
70 if (scriptURL.isEmpty())
71 return nullptr;
72
73 worker->m_scriptLoader = WorkerScriptLoader::create();
74 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri ginRequests, worker.get());
75 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker. get());
76 return worker.release();
77 } 66 }
78 67
79 Worker::~Worker() 68 Worker::~Worker()
80 { 69 {
81 ASSERT(isMainThread()); 70 ASSERT(isMainThread());
82 if (!m_contextProxy) 71 if (!m_contextProxy)
83 return; 72 return;
84 m_contextProxy->workerObjectDestroyed(); 73 m_contextProxy->workerObjectDestroyed();
85 } 74 }
86 75
87 const AtomicString& Worker::interfaceName() const 76 const AtomicString& Worker::interfaceName() const
88 { 77 {
89 return EventTargetNames::Worker; 78 return EventTargetNames::Worker;
90 } 79 }
91 80
92 void Worker::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> me ssage, const MessagePortArray* ports, ExceptionState& exceptionState) 81 void Worker::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> me ssage, const MessagePortArray* ports, ExceptionState& exceptionState)
93 { 82 {
94 ASSERT(m_contextProxy); 83 ASSERT(m_contextProxy);
95 // Disentangle the port in preparation for sending it to the remote context. 84 // Disentangle the port in preparation for sending it to the remote context.
96 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState); 85 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState);
97 if (exceptionState.hadException()) 86 if (exceptionState.hadException())
98 return; 87 return;
99 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); 88 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release());
100 } 89 }
101 90
91 bool Worker::initialize(ExecutionContext* context, const String& url, ExceptionS tate& exceptionState)
92 {
93 suspendIfNeeded();
94
95 KURL scriptURL = resolveURL(url, exceptionState);
96 if (scriptURL.isEmpty())
97 return false;
98
99 m_scriptLoader = WorkerScriptLoader::create();
100 m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOriginReque sts, this);
101
102 m_contextProxy = createWorkerGlobalScopeProxy(context);
103
104 return true;
105 }
106
107 WorkerGlobalScopeProxy* Worker::createWorkerGlobalScopeProxy(ExecutionContext* c ontext)
108 {
109 Document* document = toDocument(context);
110 WorkerGlobalScopeProxyProvider* proxyProvider = WorkerGlobalScopeProxyProvid er::from(*document->page());
111 ASSERT(proxyProvider);
112 return proxyProvider->createWorkerGlobalScopeProxy(this);
113 }
114
102 void Worker::terminate() 115 void Worker::terminate()
103 { 116 {
104 if (m_contextProxy) 117 if (m_contextProxy)
105 m_contextProxy->terminateWorkerGlobalScope(); 118 m_contextProxy->terminateWorkerGlobalScope();
106 } 119 }
107 120
108 void Worker::stop() 121 void Worker::stop()
109 { 122 {
110 terminate(); 123 terminate();
111 } 124 }
(...skipping 23 matching lines...) Expand all
135 } 148 }
136 m_scriptLoader = nullptr; 149 m_scriptLoader = nullptr;
137 } 150 }
138 151
139 DEFINE_TRACE(Worker) 152 DEFINE_TRACE(Worker)
140 { 153 {
141 AbstractWorker::trace(visitor); 154 AbstractWorker::trace(visitor);
142 } 155 }
143 156
144 } // namespace blink 157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698