OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 #include "content/public/browser/incognito_marker.h" | |
6 #include <cstddef> | |
jam
2013/02/04 16:01:59
nit: per style guide, should be a blank line befor
| |
7 #include <cstring> | |
8 #include <vector> | |
9 #include "content/public/browser/browser_context.h" | |
10 | |
11 namespace content { | |
12 | |
13 namespace { | |
14 | |
15 const std::size_t kPointerSize = sizeof(void*); | |
16 | |
17 union Pointer2BinaryHelper { | |
18 void* ptr; | |
19 char bytes[kPointerSize]; | |
20 }; | |
21 | |
22 // IncognitoMarker is to be stored in the clipboard whenever | |
23 // current clipboard data is from incognito window. | |
24 // Such data must be erased upon exit from incognito mode. | |
jam
2013/02/04 16:01:59
nit: in this file refer to "off the record" instea
| |
25 class IncognitoMarker { | |
26 public: | |
27 explicit IncognitoMarker(void* profile_ptr) : profile_ptr_(profile_ptr) {} | |
28 | |
29 void* profile_ptr() const { return profile_ptr_; } | |
30 std::vector<char> Serialize() const; | |
31 static void* Deserialize(const std::string& serialization); | |
32 | |
33 private: | |
34 // Pointer to OffTheRecordProfileImpl | |
35 void* profile_ptr_; | |
36 }; | |
37 | |
38 std::vector<char> IncognitoMarker::Serialize() const { | |
39 Pointer2BinaryHelper helper; | |
40 helper.ptr = profile_ptr_; | |
41 return std::vector<char>(helper.bytes, helper.bytes + kPointerSize); | |
42 } | |
43 | |
44 void* IncognitoMarker::Deserialize(const std::string& serialization) { | |
45 if (serialization.size() != kPointerSize) | |
46 return NULL; | |
47 Pointer2BinaryHelper helper; | |
48 memcpy(helper.bytes, serialization.c_str(), kPointerSize); | |
49 return helper.ptr; | |
50 } | |
51 } // anonymous namespace | |
52 | |
53 void AddIncognitoMarkerForOffTheRecordProfile( | |
54 BrowserContext* profile, | |
55 ui::Clipboard::ObjectMap* objects) { | |
56 if (profile && profile->IsOffTheRecord()) { | |
57 IncognitoMarker marker(profile); | |
58 ui::Clipboard::ObjectMapParams incognito_marker_params; | |
59 incognito_marker_params.push_back(marker.Serialize()); | |
60 (*objects)[ui::Clipboard::CBF_INCOGNITO_MARKER].swap( | |
61 incognito_marker_params); | |
62 } | |
63 } | |
64 | |
65 bool IsThisIncognitoMarkerInClipboard(BrowserContext* profile) { | |
66 if (profile) { | |
67 #if defined(TOOLKIT_GTK) | |
68 // Only linux for now, other platforms don't implement | |
69 // Clipboard::GetIncognitoMarkerFormatType(). | |
70 // TODO(vasilii): support other platforms. | |
71 std::string result; | |
72 ui::Clipboard::GetForCurrentThread()->ReadData( | |
73 ui::Clipboard::GetIncognitoMarkerFormatType(), &result); | |
74 return profile == IncognitoMarker::Deserialize(result); | |
75 #endif | |
76 } | |
77 return false; | |
78 } | |
79 | |
80 } // namespace content | |
OLD | NEW |