blob: 2ec928a4732bce497b9ebabbdced51ad193834b1 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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"
Ben Murdochbb1529c2013-08-08 10:24:53 +010010#include "content/browser/dom_storage/dom_storage_context_impl.h"
11#include "content/common/dom_storage/dom_storage_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "content/public/browser/browser_message_filter.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013
14class GURL;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010015
16namespace base {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017class NullableString16;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010018}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019
Torne (Richard Coles)58218062012-11-14 11:43:16 +000020namespace content {
Ben Murdochbb1529c2013-08-08 10:24:53 +010021
22class DOMStorageArea;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023class DOMStorageContextImpl;
Ben Murdochbb1529c2013-08-08 10:24:53 +010024class DOMStorageContextWrapper;
25class DOMStorageHost;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026
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.
29class DOMStorageMessageFilter
30 : public BrowserMessageFilter,
Ben Murdochbb1529c2013-08-08 10:24:53 +010031 public DOMStorageContextImpl::EventObserver {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000032 public:
Ben Murdochbb1529c2013-08-08 10:24:53 +010033 explicit DOMStorageMessageFilter(int unused,
34 DOMStorageContextWrapper* context);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000035
36 private:
37 virtual ~DOMStorageMessageFilter();
38
39 void InitializeInSequence();
40 void UninitializeInSequence();
41
42 // BrowserMessageFilter implementation
43 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
44 virtual void OnFilterRemoved() OVERRIDE;
45 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
46 const IPC::Message& message) OVERRIDE;
47 virtual bool OnMessageReceived(const IPC::Message& message,
48 bool* message_was_ok) OVERRIDE;
49
50 // Message Handlers.
51 void OnOpenStorageArea(int connection_id, int64 namespace_id,
52 const GURL& origin);
53 void OnCloseStorageArea(int connection_id);
Ben Murdochbb1529c2013-08-08 10:24:53 +010054 void OnLoadStorageArea(int connection_id, DOMStorageValuesMap* map);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000055 void OnSetItem(int connection_id, const string16& key,
56 const string16& value, const GURL& page_url);
57 void OnRemoveItem(int connection_id, const string16& key,
58 const GURL& page_url);
59 void OnClear(int connection_id, const GURL& page_url);
60 void OnFlushMessages();
61
Ben Murdochbb1529c2013-08-08 10:24:53 +010062 // DOMStorageContextImpl::EventObserver implementation which
Torne (Richard Coles)58218062012-11-14 11:43:16 +000063 // sends events back to our renderer process.
Ben Murdochbb1529c2013-08-08 10:24:53 +010064 virtual void OnDOMStorageItemSet(
65 const DOMStorageArea* area,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000066 const string16& key,
67 const string16& new_value,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010068 const base::NullableString16& old_value,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000069 const GURL& page_url) OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +010070 virtual void OnDOMStorageItemRemoved(
71 const DOMStorageArea* area,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000072 const string16& key,
73 const string16& old_value,
74 const GURL& page_url) OVERRIDE;
Ben Murdochbb1529c2013-08-08 10:24:53 +010075 virtual void OnDOMStorageAreaCleared(
76 const DOMStorageArea* area,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000077 const GURL& page_url) OVERRIDE;
78
Ben Murdochbb1529c2013-08-08 10:24:53 +010079 void SendDOMStorageEvent(
80 const DOMStorageArea* area,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000081 const GURL& page_url,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010082 const base::NullableString16& key,
83 const base::NullableString16& new_value,
84 const base::NullableString16& old_value);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000085
Ben Murdochbb1529c2013-08-08 10:24:53 +010086 scoped_refptr<DOMStorageContextImpl> context_;
87 scoped_ptr<DOMStorageHost> host_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000088 int connection_dispatching_message_for_;
89
90 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
91};
92
93} // namespace content
94
95#endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_