Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / dragdrop / os_exchange_data_provider_aurax11.h
blob4d6a95f65694f8b2846f05734dd1823e477e1cf2
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.
5 #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_
6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_
8 #include <X11/Xlib.h>
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
11 #undef RootWindow
13 #include <map>
15 #include "base/files/file_path.h"
16 #include "base/pickle.h"
17 #include "ui/base/dragdrop/os_exchange_data.h"
18 #include "ui/base/x/selection_owner.h"
19 #include "ui/base/x/selection_requestor.h"
20 #include "ui/base/x/selection_utils.h"
21 #include "ui/events/platform/platform_event_dispatcher.h"
22 #include "ui/gfx/geometry/vector2d.h"
23 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/x/x11_atom_cache.h"
25 #include "url/gurl.h"
27 namespace ui {
29 class Clipboard;
30 class OSExchangeDataProviderAuraX11Test;
32 // OSExchangeData::Provider implementation for aura on linux.
33 class UI_BASE_EXPORT OSExchangeDataProviderAuraX11
34 : public OSExchangeData::Provider,
35 public ui::PlatformEventDispatcher {
36 public:
37 // |x_window| is the window the cursor is over, and |selection| is the set of
38 // data being offered.
39 OSExchangeDataProviderAuraX11(::Window x_window,
40 const SelectionFormatMap& selection);
42 // Creates a Provider for sending drag information. This creates its own,
43 // hidden X11 window to own send data.
44 OSExchangeDataProviderAuraX11();
46 ~OSExchangeDataProviderAuraX11() override;
48 // After all the Set* methods have built up the data we're offering, call
49 // this to take ownership of the XdndSelection clipboard.
50 void TakeOwnershipOfSelection() const;
52 // Retrieves a list of types we're offering. Noop if we haven't taken the
53 // selection.
54 void RetrieveTargets(std::vector<Atom>* targets) const;
56 // Makes a copy of the format map currently being offered.
57 SelectionFormatMap GetFormatMap() const;
59 const base::FilePath& file_contents_name() const {
60 return file_contents_name_;
63 // Overridden from OSExchangeData::Provider:
64 Provider* Clone() const override;
65 void MarkOriginatedFromRenderer() override;
66 bool DidOriginateFromRenderer() const override;
67 void SetString(const base::string16& data) override;
68 void SetURL(const GURL& url, const base::string16& title) override;
69 void SetFilename(const base::FilePath& path) override;
70 void SetFilenames(const std::vector<FileInfo>& filenames) override;
71 void SetPickledData(const OSExchangeData::CustomFormat& format,
72 const Pickle& pickle) override;
73 bool GetString(base::string16* data) const override;
74 bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy,
75 GURL* url,
76 base::string16* title) const override;
77 bool GetFilename(base::FilePath* path) const override;
78 bool GetFilenames(std::vector<FileInfo>* filenames) const override;
79 bool GetPickledData(const OSExchangeData::CustomFormat& format,
80 Pickle* pickle) const override;
81 bool HasString() const override;
82 bool HasURL(OSExchangeData::FilenameToURLPolicy policy) const override;
83 bool HasFile() const override;
84 bool HasCustomFormat(
85 const OSExchangeData::CustomFormat& format) const override;
87 void SetFileContents(const base::FilePath& filename,
88 const std::string& file_contents) override;
90 void SetHtml(const base::string16& html, const GURL& base_url) override;
91 bool GetHtml(base::string16* html, GURL* base_url) const override;
92 bool HasHtml() const override;
93 void SetDragImage(const gfx::ImageSkia& image,
94 const gfx::Vector2d& cursor_offset) override;
95 const gfx::ImageSkia& GetDragImage() const override;
96 const gfx::Vector2d& GetDragImageOffset() const override;
98 // ui::PlatformEventDispatcher:
99 bool CanDispatchEvent(const PlatformEvent& event) override;
100 uint32_t DispatchEvent(const PlatformEvent& event) override;
102 private:
103 friend class OSExchangeDataProviderAuraX11Test;
104 typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData;
106 // Returns true if |formats_| contains a string format and the string can be
107 // parsed as a URL.
108 bool GetPlainTextURL(GURL* url) const;
110 // Returns the targets in |format_map_|.
111 std::vector< ::Atom> GetTargets() const;
113 // Drag image and offset data.
114 gfx::ImageSkia drag_image_;
115 gfx::Vector2d drag_image_offset_;
117 // Our X11 state.
118 Display* x_display_;
119 ::Window x_root_window_;
121 // In X11, because the IPC parts of drag operations are implemented by
122 // XSelection, we require an x11 window to receive drag messages on. The
123 // OSExchangeDataProvider system is modeled on the Windows implementation,
124 // which does not require a window. We only sometimes have a valid window
125 // available (in the case of drag receiving). Other times, we need to create
126 // our own xwindow just to receive events on it.
127 const bool own_window_;
129 ::Window x_window_;
131 X11AtomCache atom_cache_;
133 // A representation of data. This is either passed to us from the other
134 // process, or built up through a sequence of Set*() calls. It can be passed
135 // to |selection_owner_| when we take the selection.
136 SelectionFormatMap format_map_;
138 // Auxilary data for the X Direct Save protocol.
139 base::FilePath file_contents_name_;
141 // Takes a snapshot of |format_map_| and offers it to other windows.
142 mutable SelectionOwner selection_owner_;
144 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAuraX11);
147 } // namespace ui
149 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_