Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / dom_storage / dom_storage_message_filter.h
1 // Copyright (c) 2012 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_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/dom_storage/dom_storage_context_impl.h"
11 #include "content/common/dom_storage/dom_storage_types.h"
12 #include "content/public/browser/browser_message_filter.h"
13
14 class GURL;
15
16 namespace base {
17 class NullableString16;
18 }
19
20 namespace content {
21
22 class DOMStorageArea;
23 class DOMStorageContextImpl;
24 class DOMStorageContextWrapper;
25 class DOMStorageHost;
26
27 // This class handles the logistics of DOM Storage within the browser process.
28 // It mostly ferries information between IPCs and the dom_storage classes.
29 class DOMStorageMessageFilter
30     : public BrowserMessageFilter,
31       public DOMStorageContextImpl::EventObserver {
32  public:
33   explicit DOMStorageMessageFilter(int render_process_id,
34                                    DOMStorageContextWrapper* context);
35
36  private:
37   ~DOMStorageMessageFilter() override;
38
39   void InitializeInSequence();
40   void UninitializeInSequence();
41
42   // BrowserMessageFilter implementation
43   void OnFilterAdded(IPC::Sender* sender) override;
44   void OnFilterRemoved() override;
45   base::TaskRunner* OverrideTaskRunnerForMessage(
46       const IPC::Message& message) override;
47   bool OnMessageReceived(const IPC::Message& message) override;
48
49   // Message Handlers.
50   void OnOpenStorageArea(int connection_id, int64 namespace_id,
51                          const GURL& origin);
52   void OnCloseStorageArea(int connection_id);
53   void OnLoadStorageArea(int connection_id, DOMStorageValuesMap* map,
54                          bool* send_log_get_messages);
55   void OnSetItem(int connection_id, const base::string16& key,
56                  const base::string16& value, const GURL& page_url);
57   void OnLogGetItem(int connection_id, const base::string16& key,
58                     const base::NullableString16& value);
59   void OnRemoveItem(int connection_id, const base::string16& key,
60                     const GURL& page_url);
61   void OnClear(int connection_id, const GURL& page_url);
62   void OnFlushMessages();
63
64   // DOMStorageContextImpl::EventObserver implementation which
65   // sends events back to our renderer process.
66   void OnDOMStorageItemSet(const DOMStorageArea* area,
67                            const base::string16& key,
68                            const base::string16& new_value,
69                            const base::NullableString16& old_value,
70                            const GURL& page_url) override;
71   void OnDOMStorageItemRemoved(const DOMStorageArea* area,
72                                const base::string16& key,
73                                const base::string16& old_value,
74                                const GURL& page_url) override;
75   void OnDOMStorageAreaCleared(const DOMStorageArea* area,
76                                const GURL& page_url) override;
77   void OnDOMSessionStorageReset(int64 namespace_id) override;
78
79   void SendDOMStorageEvent(
80       const DOMStorageArea* area,
81       const GURL& page_url,
82       const base::NullableString16& key,
83       const base::NullableString16& new_value,
84       const base::NullableString16& old_value);
85
86   int render_process_id_;
87   scoped_refptr<DOMStorageContextImpl> context_;
88   scoped_ptr<DOMStorageHost> host_;
89   int connection_dispatching_message_for_;
90
91   DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
92 };
93
94 }  // namespace content
95
96 #endif  // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_