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_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_
6#define CONTENT_BROWSER_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "content/common/clipboard_format.h"
13#include "content/public/browser/browser_message_filter.h"
14#include "ui/base/clipboard/clipboard.h"
15
16class GURL;
17
18namespace content {
19
20class ClipboardMessageFilter : public BrowserMessageFilter {
21 public:
22  ClipboardMessageFilter();
23
24  virtual void OverrideThreadForMessage(
25      const IPC::Message& message,
26      BrowserThread::ID* thread) OVERRIDE;
27  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
28 private:
29  virtual ~ClipboardMessageFilter();
30
31  void OnWriteObjectsAsync(const ui::Clipboard::ObjectMap& objects);
32  void OnWriteObjectsSync(const ui::Clipboard::ObjectMap& objects,
33                          base::SharedMemoryHandle bitmap_handle);
34  static void WriteObjectsOnUIThread(const ui::Clipboard::ObjectMap* objects);
35
36  void OnGetSequenceNumber(const ui::ClipboardType type,
37                           uint64* sequence_number);
38  void OnIsFormatAvailable(ClipboardFormat format,
39                           ui::ClipboardType type,
40                           bool* result);
41  void OnClear(ui::ClipboardType type);
42  void OnReadAvailableTypes(ui::ClipboardType type,
43                            std::vector<base::string16>* types,
44                            bool* contains_filenames);
45  void OnReadText(ui::ClipboardType type, base::string16* result);
46  void OnReadHTML(ui::ClipboardType type,
47                  base::string16* markup,
48                  GURL* url,
49                  uint32* fragment_start,
50                  uint32* fragment_end);
51  void OnReadRTF(ui::ClipboardType type, std::string* result);
52  void OnReadImage(ui::ClipboardType type, IPC::Message* reply_msg);
53  void OnReadImageReply(const SkBitmap& bitmap, IPC::Message* reply_msg);
54  void OnReadCustomData(ui::ClipboardType clipboard_type,
55                        const base::string16& type,
56                        base::string16* result);
57  void OnReadData(const ui::Clipboard::FormatType& format,
58                  std::string* data);
59
60#if defined(OS_MACOSX)
61  void OnFindPboardWriteString(const base::string16& text);
62#endif
63
64  // We have our own clipboard because we want to access the clipboard on the
65  // IO thread instead of forwarding (possibly synchronous) messages to the UI
66  // thread. This instance of the clipboard should be accessed only on the IO
67  // thread.
68  static ui::Clipboard* GetClipboard();
69
70  DISALLOW_COPY_AND_ASSIGN(ClipboardMessageFilter);
71};
72
73}  // namespace content
74
75#endif  // CONTENT_BROWSER_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_
76