| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | |
| 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/process.h" | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "base/tracked.h" | |
| 12 #include "chrome/browser/in_process_webkit/dom_storage_area.h" | |
| 13 #include "chrome/browser/in_process_webkit/webkit_context.h" | |
| 14 #include "chrome/common/dom_storage_common.h" | |
| 15 #include "ipc/ipc_message.h" | |
| 16 | |
| 17 class DOMStorageContext; | |
| 18 class GURL; | |
| 19 class HostContentSettingsMap; | |
| 20 class ResourceMessageFilter; | |
| 21 class Task; | |
| 22 struct ViewMsg_DOMStorageEvent_Params; | |
| 23 | |
| 24 // This class handles the logistics of DOM Storage within the browser process. | |
| 25 // It mostly ferries information between IPCs and the WebKit implementations, | |
| 26 // but it also handles some special cases like when renderer processes die. | |
| 27 class DOMStorageDispatcherHost | |
| 28 : public base::RefCountedThreadSafe<DOMStorageDispatcherHost> { | |
| 29 public: | |
| 30 // Only call the constructor from the UI thread. | |
| 31 DOMStorageDispatcherHost( | |
| 32 ResourceMessageFilter* resource_message_filter, | |
| 33 WebKitContext* webkit_context); | |
| 34 | |
| 35 // Only call from ResourceMessageFilter on the IO thread. | |
| 36 void Init(int process_id, base::ProcessHandle process_handle); | |
| 37 | |
| 38 // Only call from ResourceMessageFilter on the IO thread. Calls self on the | |
| 39 // WebKit thread in some cases. | |
| 40 void Shutdown(); | |
| 41 | |
| 42 // Only call from ResourceMessageFilter on the IO thread. | |
| 43 bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok); | |
| 44 | |
| 45 // Clones a session storage namespace and returns the cloned namespaces' id. | |
| 46 // Only call on the IO thread. | |
| 47 int64 CloneSessionStorage(int64 original_id); | |
| 48 | |
| 49 // Send a message to the renderer process associated with our | |
| 50 // message_sender_ via the IO thread. May be called from any thread. | |
| 51 void Send(IPC::Message* message); | |
| 52 | |
| 53 // Only call on the WebKit thread. | |
| 54 static void DispatchStorageEvent(const NullableString16& key, | |
| 55 const NullableString16& old_value, const NullableString16& new_value, | |
| 56 const string16& origin, const GURL& url, bool is_local_storage); | |
| 57 | |
| 58 private: | |
| 59 friend class base::RefCountedThreadSafe<DOMStorageDispatcherHost>; | |
| 60 ~DOMStorageDispatcherHost(); | |
| 61 | |
| 62 // Message Handlers. | |
| 63 void OnStorageAreaId(int64 namespace_id, const string16& origin, | |
| 64 IPC::Message* reply_msg); | |
| 65 void OnLength(int64 storage_area_id, IPC::Message* reply_msg); | |
| 66 void OnKey(int64 storage_area_id, unsigned index, IPC::Message* reply_msg); | |
| 67 void OnGetItem(int64 storage_area_id, const string16& key, | |
| 68 IPC::Message* reply_msg); | |
| 69 void OnSetItem(int64 storage_area_id, const string16& key, | |
| 70 const string16& value, const GURL& url, | |
| 71 IPC::Message* reply_msg); | |
| 72 void OnRemoveItem(int64 storage_area_id, const string16& key, | |
| 73 const GURL& url, IPC::Message* reply_msg); | |
| 74 void OnClear(int64 storage_area_id, const GURL& url, IPC::Message* reply_msg); | |
| 75 | |
| 76 // WebKit thread half of OnStorageAreaId | |
| 77 void OnStorageAreaIdWebKit( | |
| 78 int64 namespace_id, const string16& origin, IPC::Message* reply_msg, | |
| 79 HostContentSettingsMap* host_context_settings_map); | |
| 80 | |
| 81 // Only call on the IO thread. | |
| 82 void OnStorageEvent(const ViewMsg_DOMStorageEvent_Params& params); | |
| 83 | |
| 84 // A shortcut for accessing our context. | |
| 85 DOMStorageContext* Context() { | |
| 86 return webkit_context_->dom_storage_context(); | |
| 87 } | |
| 88 | |
| 89 // Use whenever there's a chance OnStorageEvent will be called. | |
| 90 class ScopedStorageEventContext { | |
| 91 public: | |
| 92 ScopedStorageEventContext(DOMStorageDispatcherHost* dispatcher_host, | |
| 93 const GURL* url); | |
| 94 ~ScopedStorageEventContext(); | |
| 95 }; | |
| 96 | |
| 97 // Only access on the WebKit thread! Used for storage events. | |
| 98 static DOMStorageDispatcherHost* storage_event_host_; | |
| 99 static const GURL* storage_event_url_; | |
| 100 | |
| 101 // Data shared between renderer processes with the same profile. | |
| 102 scoped_refptr<WebKitContext> webkit_context_; | |
| 103 | |
| 104 // Only set and use on the IO thread. | |
| 105 ResourceMessageFilter* resource_message_filter_; | |
| 106 | |
| 107 // If we get a corrupt message from a renderer, we need to kill it using this | |
| 108 // handle. | |
| 109 base::ProcessHandle process_handle_; | |
| 110 | |
| 111 // Used to dispatch messages to the correct view host. | |
| 112 int process_id_; | |
| 113 | |
| 114 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageDispatcherHost); | |
| 115 }; | |
| 116 | |
| 117 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_DISPATCHER_HOST_H_ | |
| OLD | NEW |