1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 */ 30 31 #ifndef WebWorkerClientImpl_h 32 #define WebWorkerClientImpl_h 33 34 #include "core/dom/ScriptExecutionContext.h" 35 #include "core/workers/WorkerGlobalScopeProxy.h" 36 #include "core/workers/WorkerLoaderProxy.h" 37 #include "core/workers/WorkerMessagingProxy.h" 38 #include "core/workers/WorkerObjectProxy.h" 39 40 #include "WebWorkerBase.h" 41 #include "public/platform/WebFileSystem.h" 42 #include "public/platform/WebFileSystemType.h" 43 #include "wtf/OwnPtr.h" 44 #include "wtf/PassOwnPtr.h" 45 #include "wtf/RefPtr.h" 46 47 48 namespace WebKit { 49 class WebWorker; 50 class WebFrameImpl; 51 52 // This class provides chromium implementation for WorkerGlobalScopeProxy, WorkerObjectProxy amd WorkerLoaderProxy 53 // for in-proc dedicated workers. It also acts as a bridge for workers to chromium implementation of file systems, 54 // databases and other related functionality. 55 // 56 // In essence, this class decorates WorkerMessagingProxy. 57 // 58 // It is imperative that this class inherit from WorkerMessagingProxy rather than delegate to an instance of 59 // WorkerMessagingProxy, because that class tracks and reports its activity to outside callers, and manages 60 // its own lifetime, via calls to workerObjectDestroyed, workerGlobalScopeDestroyed, workerGlobalScopeClosed, etc. It 61 // is basically impossible to correctly manage the lifetime of this class separately from WorkerMessagingProxy. 62 class WebWorkerClientImpl : public WebCore::WorkerMessagingProxy 63 , public WebWorkerBase 64 , public WebCommonWorkerClient { 65 public: 66 // WebCore::WorkerGlobalScopeProxy Factory. 67 static WebCore::WorkerGlobalScopeProxy* createWorkerGlobalScopeProxy(WebCore::Worker*); 68 69 // WebCore::WorkerGlobalScopeProxy methods: 70 // These are called on the thread that created the worker. In the renderer 71 // process, this will be the main WebKit thread. 72 virtual void terminateWorkerGlobalScope() OVERRIDE; 73 74 // WebCore::WorkerLoaderProxy methods 75 virtual WebWorkerBase* toWebWorkerBase() OVERRIDE; 76 77 // WebWorkerBase methods: 78 virtual WebCore::WorkerLoaderProxy* workerLoaderProxy() OVERRIDE { return this; } 79 virtual WebCommonWorkerClient* commonClient() OVERRIDE { return this; } 80 virtual WebView* view() const OVERRIDE; 81 82 // WebCommonWorkerClient methods: 83 virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize) OVERRIDE; 84 virtual bool allowFileSystem(); 85 virtual void openFileSystem(WebFileSystemType, long long size, bool create, 86 WebFileSystemCallbacks*) OVERRIDE; 87 virtual bool allowIndexedDB(const WebString& name) OVERRIDE; 88 89 private: 90 WebWorkerClientImpl(WebCore::Worker*, WebFrameImpl*, PassOwnPtr<WebCore::WorkerClients>); 91 virtual ~WebWorkerClientImpl(); 92 93 WebFrameImpl* m_webFrame; 94 }; 95 96 } // namespace WebKit; 97 98 #endif 99