shared_worker_message_filter.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 6#define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 7 8#include "content/browser/worker_host/worker_storage_partition.h" 9#include "content/common/content_export.h" 10#include "content/public/browser/browser_message_filter.h" 11 12class GURL; 13struct ViewHostMsg_CreateWorker_Params; 14 15namespace content { 16class MessagePortMessageFilter; 17class ResourceContext; 18 19// If "enable-embedded-shared-worker" is set this class will be used instead of 20// WorkerMessageFilter. 21class CONTENT_EXPORT SharedWorkerMessageFilter : public BrowserMessageFilter { 22 public: 23 SharedWorkerMessageFilter(int render_process_id, 24 ResourceContext* resource_context, 25 const WorkerStoragePartition& partition, 26 MessagePortMessageFilter* message_port_filter); 27 28 // BrowserMessageFilter implementation. 29 virtual void OnChannelClosing() OVERRIDE; 30 virtual bool OnMessageReceived(const IPC::Message& message, 31 bool* message_was_ok) OVERRIDE; 32 33 int GetNextRoutingID(); 34 int render_process_id() const { return render_process_id_; } 35 36 MessagePortMessageFilter* message_port_message_filter() const { 37 return message_port_message_filter_; 38 } 39 40 protected: 41 // This is protected, so we can define sub classes for testing. 42 virtual ~SharedWorkerMessageFilter(); 43 44 private: 45 // Message handlers. 46 void OnCreateWorker(const ViewHostMsg_CreateWorker_Params& params, 47 int* route_id); 48 void OnForwardToWorker(const IPC::Message& message); 49 void OnDocumentDetached(unsigned long long document_id); 50 void OnWorkerContextClosed(int worker_route_id); 51 void OnWorkerContextDestroyed(int worker_route_id); 52 void OnWorkerScriptLoaded(int worker_route_id); 53 void OnWorkerScriptLoadFailed(int worker_route_id); 54 void OnWorkerConnected(int message_port_id, int worker_route_id); 55 void OnAllowDatabase(int worker_route_id, 56 const GURL& url, 57 const base::string16& name, 58 const base::string16& display_name, 59 unsigned long estimated_size, 60 bool* result); 61 void OnAllowFileSystem(int worker_route_id, 62 const GURL& url, 63 bool* result); 64 void OnAllowIndexedDB(int worker_route_id, 65 const GURL& url, 66 const base::string16& name, 67 bool* result); 68 69 const int render_process_id_; 70 ResourceContext* const resource_context_; 71 const WorkerStoragePartition partition_; 72 MessagePortMessageFilter* const message_port_message_filter_; 73 74 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedWorkerMessageFilter); 75}; 76 77} // namespace content 78 79#endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ 80