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

Side by Side Diff: webkit/api/src/SharedWorkerRepository.cpp

Issue 342064: Fixed style nits. (Closed)
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « webkit/api/public/WebSharedWorkerRepository.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 class Document; 55 class Document;
56 using WebKit::WebMessagePortChannel; 56 using WebKit::WebMessagePortChannel;
57 using WebKit::WebSharedWorker; 57 using WebKit::WebSharedWorker;
58 using WebKit::WebSharedWorkerRepository; 58 using WebKit::WebSharedWorkerRepository;
59 59
60 // Callback class that keeps the Worker object alive while loads are potentially happening, and also translates load errors into error events on the worker. 60 // Callback class that keeps the Worker object alive while loads are potentially happening, and also translates load errors into error events on the worker.
61 class SharedWorkerScriptLoader : public RefCounted<SharedWorkerScriptLoader>, private WorkerScriptLoaderClient { 61 class SharedWorkerScriptLoader : public RefCounted<SharedWorkerScriptLoader>, private WorkerScriptLoaderClient {
62 public: 62 public:
63 SharedWorkerScriptLoader(PassRefPtr<SharedWorker> worker, PassOwnPtr<MessagePortChannel> port, PassOwnPtr<WebSharedWorker> webWorker) 63 SharedWorkerScriptLoader(PassRefPtr<SharedWorker> worker, PassOwnPtr<MessagePortChannel> port, PassOwnPtr<WebSharedWorker> webWorker)
64 : m_worker(worker), 64 : m_worker(worker)
65 m_webWorker(webWorker), 65 , m_webWorker(webWorker)
66 m_port(port) 66 , m_port(port)
67 { 67 {
68 } 68 }
69 69
70 void load(const KURL&); 70 void load(const KURL&);
71 71
72 private: 72 private:
73 // WorkerScriptLoaderClient callback 73 // WorkerScriptLoaderClient callback
74 virtual void notifyFinished(); 74 virtual void notifyFinished();
75 75
76 RefPtr<SharedWorker> m_worker; 76 RefPtr<SharedWorker> m_worker;
77 OwnPtr<WebSharedWorker> m_webWorker; 77 OwnPtr<WebSharedWorker> m_webWorker;
78 OwnPtr<MessagePortChannel> m_port; 78 OwnPtr<MessagePortChannel> m_port;
79 WorkerScriptLoader m_scriptLoader; 79 WorkerScriptLoader m_scriptLoader;
80 }; 80 };
81 81
82 void SharedWorkerScriptLoader::load(const KURL& url) 82 void SharedWorkerScriptLoader::load(const KURL& url)
83 { 83 {
84 m_scriptLoader.loadAsynchronously(m_worker->scriptExecutionContext(), url, DenyCrossOriginRequests, this); 84 m_scriptLoader.loadAsynchronously(m_worker->scriptExecutionContext(), url, DenyCrossOriginRequests, this);
85 } 85 }
86 86
87 // Extracts a WebMessagePortChannel from a MessagePortChannel. 87 // Extracts a WebMessagePortChannel from a MessagePortChannel.
88 static WebMessagePortChannel* getWebPort(PassOwnPtr<MessagePortChannel> port) { 88 static WebMessagePortChannel* getWebPort(PassOwnPtr<MessagePortChannel> port)
89 {
89 // Extract the WebMessagePortChannel to send to the worker. 90 // Extract the WebMessagePortChannel to send to the worker.
90 PlatformMessagePortChannel* platformChannel = port->channel(); 91 PlatformMessagePortChannel* platformChannel = port->channel();
91 WebMessagePortChannel* webPort = platformChannel->webChannelRelease(); 92 WebMessagePortChannel* webPort = platformChannel->webChannelRelease();
92 webPort->setClient(0); 93 webPort->setClient(0);
93 return webPort; 94 return webPort;
94 } 95 }
95 96
96 void SharedWorkerScriptLoader::notifyFinished() 97 void SharedWorkerScriptLoader::notifyFinished()
97 { 98 {
98 if (m_scriptLoader.failed()) 99 if (m_scriptLoader.failed())
99 m_worker->dispatchEvent(Event::create(eventNames().errorEvent, false, true)); 100 m_worker->dispatchEvent(Event::create(eventNames().errorEvent, false, true));
100 else { 101 else {
101 m_webWorker->startWorkerContext(m_scriptLoader.url(), m_worker->scriptExecutionContext()->userAgent(m_scriptLoader.url()), m_scriptLoader.script()); 102 m_webWorker->startWorkerContext(m_scriptLoader.url(), m_worker->scriptExecutionContext()->userAgent(m_scriptLoader.url()), m_scriptLoader.script());
102 m_webWorker->connect(getWebPort(m_port.release())); 103 m_webWorker->connect(getWebPort(m_port.release()));
103 } 104 }
104 105
105 // Connect event has been sent, so free ourselves (this releases the SharedWorker so it can be freed as well if unreferenced). 106 // Connect event has been sent, so free ourselves (this releases the SharedWorker so it can be freed as well if unreferenced).
106 delete this; 107 delete this;
107 } 108 }
108 109
109 bool SharedWorkerRepository::isAvailable() 110 bool SharedWorkerRepository::isAvailable()
110 { 111 {
111 // SharedWorkers are disabled for now until the implementation is further along. 112 // SharedWorkers are disabled for now until the implementation is further along.
112 // TODO(atwilson): Add code to check for a runtime flag like so: 113 // FIXME(atwilson): Add code to check for a runtime flag like so:
113 // return commandLineFlag && WebKit::webKitClient()->sharedWorkerRepository(); 114 // return commandLineFlag && WebKit::webKitClient()->sharedWorkerRepository();
114 return false; 115 return false;
115 } 116 }
116 117
117 static WebSharedWorkerRepository::DocumentID getId(void* document) 118 static WebSharedWorkerRepository::DocumentID getId(void* document)
118 { 119 {
119 ASSERT(document); 120 ASSERT(document);
120 return reinterpret_cast<WebSharedWorkerRepository::DocumentID>(document); 121 return reinterpret_cast<WebSharedWorkerRepository::DocumentID>(document);
121 } 122 }
122 123
(...skipping 15 matching lines...) Expand all
138 if (!webWorker->isStarted()) { 139 if (!webWorker->isStarted()) {
139 // Need to kick off a load for the worker. The loader will connect to the worker once the script has been loaded, then free itself. 140 // Need to kick off a load for the worker. The loader will connect to the worker once the script has been loaded, then free itself.
140 SharedWorkerScriptLoader* loader = new SharedWorkerScriptLoader(worker, port.release(), webWorker.release()); 141 SharedWorkerScriptLoader* loader = new SharedWorkerScriptLoader(worker, port.release(), webWorker.release());
141 loader->load(url); 142 loader->load(url);
142 } else 143 } else
143 webWorker->connect(getWebPort(port.release())); 144 webWorker->connect(getWebPort(port.release()));
144 } 145 }
145 146
146 void SharedWorkerRepository::documentDetached(Document* document) 147 void SharedWorkerRepository::documentDetached(Document* document)
147 { 148 {
148 WebKit::WebSharedWorkerRepository* repo = WebKit::webKitClient()->sharedWorkerRepository(); 149 WebSharedWorkerRepository* repo = WebKit::webKitClient()->sharedWorkerRepository();
149 if (repo) 150 if (repo)
150 repo->documentDetached(getId(document)); 151 repo->documentDetached(getId(document));
151 } 152 }
152 153
153 bool SharedWorkerRepository::hasSharedWorkers(Document* document) 154 bool SharedWorkerRepository::hasSharedWorkers(Document* document)
154 { 155 {
155 WebKit::WebSharedWorkerRepository* repo = WebKit::webKitClient()->sharedWorkerRepository(); 156 WebSharedWorkerRepository* repo = WebKit::webKitClient()->sharedWorkerRepository();
156 return repo && repo->hasSharedWorkers(getId(document)); 157 return repo && repo->hasSharedWorkers(getId(document));
157 } 158 }
158 159
159 160
160 161
161 } // namespace WebCore 162 } // namespace WebCore
162 163
163 #endif // ENABLE(SHARED_WORKERS) 164 #endif // ENABLE(SHARED_WORKERS)
OLDNEW
« no previous file with comments | « webkit/api/public/WebSharedWorkerRepository.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698