| Index: chrome/browser/clipboard/incognito_marker.cc
|
| diff --git a/chrome/browser/clipboard/incognito_marker.cc b/chrome/browser/clipboard/incognito_marker.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..927281fdff3fe493e8a87b07d6f563304bc69924
|
| --- /dev/null
|
| +++ b/chrome/browser/clipboard/incognito_marker.cc
|
| @@ -0,0 +1,79 @@
|
| +// 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 "chrome/browser/clipboard/incognito_marker.h"
|
| +#include <cstddef>
|
| +#include <cstring>
|
| +#include <vector>
|
| +#include "chrome/browser/profiles/profile.h"
|
| +
|
| +namespace chrome {
|
| +
|
| +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.
|
| +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(
|
| + ui::Clipboard::ObjectMap& objects,
|
| + Profile* profile) {
|
| + 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(Profile* 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 chrome
|
|
|