Home | History | Annotate | Download | only in shared_worker
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H
      6 #define CONTENT_RENDERER_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H
      7 
      8 #include <vector>
      9 
     10 #include "content/child/child_message_filter.h"
     11 #include "content/child/scoped_child_process_reference.h"
     12 #include "ipc/ipc_listener.h"
     13 #include "third_party/WebKit/public/platform/WebString.h"
     14 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
     15 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
     16 #include "url/gurl.h"
     17 
     18 namespace blink {
     19 class WebApplicationCacheHost;
     20 class WebApplicationCacheHostClient;
     21 class WebMessagePortChannel;
     22 class WebNotificationPresenter;
     23 class WebSecurityOrigin;
     24 class WebSharedWorker;
     25 class WebWorkerPermissionClientProxy;
     26 }
     27 
     28 namespace content {
     29 class SharedWorkerDevToolsAgent;
     30 class WebApplicationCacheHostImpl;
     31 class WebMessagePortChannelImpl;
     32 
     33 class EmbeddedSharedWorkerStub : public IPC::Listener,
     34                                  public blink::WebSharedWorkerClient {
     35  public:
     36   EmbeddedSharedWorkerStub(
     37       const GURL& url,
     38       const base::string16& name,
     39       const base::string16& content_security_policy,
     40       blink::WebContentSecurityPolicyType security_policy_type,
     41       bool pause_on_start,
     42       int route_id);
     43 
     44   // IPC::Listener implementation.
     45   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     46   virtual void OnChannelError() OVERRIDE;
     47 
     48   // blink::WebSharedWorkerClient implementation.
     49   virtual void workerContextClosed() OVERRIDE;
     50   virtual void workerContextDestroyed() OVERRIDE;
     51   virtual void workerReadyForInspection() OVERRIDE;
     52   virtual void workerScriptLoaded() OVERRIDE;
     53   virtual void workerScriptLoadFailed() OVERRIDE;
     54   virtual void selectAppCacheID(long long) OVERRIDE;
     55   virtual blink::WebNotificationPresenter* notificationPresenter() OVERRIDE;
     56   virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
     57       blink::WebApplicationCacheHostClient*) OVERRIDE;
     58   virtual blink::WebWorkerPermissionClientProxy*
     59       createWorkerPermissionClientProxy(
     60           const blink::WebSecurityOrigin& origin) OVERRIDE;
     61   virtual void dispatchDevToolsMessage(
     62       const blink::WebString& message) OVERRIDE;
     63   virtual void saveDevToolsAgentState(const blink::WebString& state) OVERRIDE;
     64 
     65  private:
     66   virtual ~EmbeddedSharedWorkerStub();
     67 
     68   void Shutdown();
     69   bool Send(IPC::Message* message);
     70 
     71   // WebSharedWorker will own |channel|.
     72   void ConnectToChannel(WebMessagePortChannelImpl* channel);
     73 
     74   void OnConnect(int sent_message_port_id, int routing_id);
     75   void OnTerminateWorkerContext();
     76 
     77   int route_id_;
     78   base::string16 name_;
     79   bool runing_;
     80   GURL url_;
     81   blink::WebSharedWorker* impl_;
     82   scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_;
     83 
     84   typedef std::vector<WebMessagePortChannelImpl*> PendingChannelList;
     85   PendingChannelList pending_channels_;
     86 
     87   ScopedChildProcessReference process_ref_;
     88   WebApplicationCacheHostImpl* app_cache_host_;
     89   DISALLOW_COPY_AND_ASSIGN(EmbeddedSharedWorkerStub);
     90 };
     91 
     92 }  // namespace content
     93 
     94 #endif  // CONTENT_RENDERER_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H
     95