Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/clipboard/incognito_marker.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "chrome/browser/clipboard/incognito_marker.h"
6 #include <cstddef>
7 #include <cstring>
8 #include <vector>
9 #include "chrome/browser/profiles/profile.h"
10
11 namespace chrome {
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.
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 ui::Clipboard::ObjectMap& objects,
55 Profile* profile) {
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(incognito_marker_params);
61 }
62 }
63
64 bool IsThisIncognitoMarkerInClipboard(Profile* profile) {
65 if (profile) {
66 #if defined(TOOLKIT_GTK)
67 // Only linux for now, other platforms don't implement
68 // Clipboard::GetIncognitoMarkerFormatType().
69 // TODO(vasilii): support other platforms.
70 std::string result;
71 ui::Clipboard::GetForCurrentThread()->ReadData(
72 ui::Clipboard::GetIncognitoMarkerFormatType(), &result);
73 return profile == IncognitoMarker::Deserialize(result);
74 #endif
75 }
76 return false;
77 }
78
79 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698