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

Unified Diff: content/public/browser/incognito_marker.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved the feature to 'content' layer 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 side-by-side diff with in-line comments
Download patch
Index: content/public/browser/incognito_marker.cc
diff --git a/content/public/browser/incognito_marker.cc b/content/public/browser/incognito_marker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5f631c678dbf2e9b24e813b80f4a58a4e9ba032
--- /dev/null
+++ b/content/public/browser/incognito_marker.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/incognito_marker.h"
+#include <cstddef>
jam 2013/02/04 16:01:59 nit: per style guide, should be a blank line befor
+#include <cstring>
+#include <vector>
+#include "content/public/browser/browser_context.h"
+
+namespace content {
+
+namespace {
+
+const std::size_t kPointerSize = sizeof(void*);
+
+union Pointer2BinaryHelper {
+ void* ptr;
+ char bytes[kPointerSize];
+};
+
+// IncognitoMarker is to be stored in the clipboard whenever
+// current clipboard data is from incognito window.
+// 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
+class IncognitoMarker {
+ public:
+ explicit IncognitoMarker(void* profile_ptr) : profile_ptr_(profile_ptr) {}
+
+ void* profile_ptr() const { return profile_ptr_; }
+ std::vector<char> Serialize() const;
+ static void* Deserialize(const std::string& serialization);
+
+ private:
+ // Pointer to OffTheRecordProfileImpl
+ void* profile_ptr_;
+};
+
+std::vector<char> IncognitoMarker::Serialize() const {
+ Pointer2BinaryHelper helper;
+ helper.ptr = profile_ptr_;
+ return std::vector<char>(helper.bytes, helper.bytes + kPointerSize);
+}
+
+void* IncognitoMarker::Deserialize(const std::string& serialization) {
+ if (serialization.size() != kPointerSize)
+ return NULL;
+ Pointer2BinaryHelper helper;
+ memcpy(helper.bytes, serialization.c_str(), kPointerSize);
+ return helper.ptr;
+}
+} // anonymous namespace
+
+void AddIncognitoMarkerForOffTheRecordProfile(
+ BrowserContext* profile,
+ ui::Clipboard::ObjectMap* objects) {
+ if (profile && profile->IsOffTheRecord()) {
+ IncognitoMarker marker(profile);
+ ui::Clipboard::ObjectMapParams incognito_marker_params;
+ incognito_marker_params.push_back(marker.Serialize());
+ (*objects)[ui::Clipboard::CBF_INCOGNITO_MARKER].swap(
+ incognito_marker_params);
+ }
+}
+
+bool IsThisIncognitoMarkerInClipboard(BrowserContext* profile) {
+ if (profile) {
+#if defined(TOOLKIT_GTK)
+ // Only linux for now, other platforms don't implement
+ // Clipboard::GetIncognitoMarkerFormatType().
+ // TODO(vasilii): support other platforms.
+ std::string result;
+ ui::Clipboard::GetForCurrentThread()->ReadData(
+ ui::Clipboard::GetIncognitoMarkerFormatType(), &result);
+ return profile == IncognitoMarker::Deserialize(result);
+#endif
+ }
+ return false;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698