summaryrefslogtreecommitdiffstats
path: root/app/clipboard/clipboard.cc
diff options
context:
space:
mode:
Diffstat (limited to 'app/clipboard/clipboard.cc')
-rw-r--r--app/clipboard/clipboard.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/clipboard/clipboard.cc b/app/clipboard/clipboard.cc
new file mode 100644
index 0000000..bc91408
--- /dev/null
+++ b/app/clipboard/clipboard.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2009 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 "app/clipboard/clipboard.h"
+
+#include "base/gfx/size.h"
+#include "base/logging.h"
+
+namespace {
+
+// A compromised renderer could send us bad data, so validate it.
+bool IsBitmapSafe(const Clipboard::ObjectMapParams& params) {
+ const gfx::Size* size =
+ reinterpret_cast<const gfx::Size*>(&(params[1].front()));
+ return params[0].size() ==
+ static_cast<size_t>(size->width() * size->height() * 4);
+}
+
+} // namespace
+
+void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
+ switch (type) {
+ case CBF_TEXT:
+ WriteText(&(params[0].front()), params[0].size());
+ break;
+
+ case CBF_HTML:
+ if (params.size() == 2)
+ WriteHTML(&(params[0].front()), params[0].size(),
+ &(params[1].front()), params[1].size());
+ else
+ WriteHTML(&(params[0].front()), params[0].size(), NULL, 0);
+ break;
+
+ case CBF_BOOKMARK:
+ WriteBookmark(&(params[0].front()), params[0].size(),
+ &(params[1].front()), params[1].size());
+ break;
+
+ case CBF_FILES:
+ WriteFiles(&(params[0].front()), params[0].size());
+ break;
+
+ case CBF_WEBKIT:
+ WriteWebSmartPaste();
+ break;
+
+#if defined(OS_WIN) || defined(OS_LINUX)
+ case CBF_BITMAP:
+ if (!IsBitmapSafe(params))
+ return;
+ WriteBitmap(&(params[0].front()), &(params[1].front()));
+ break;
+
+ case CBF_DATA:
+ WriteData(&(params[0].front()), params[0].size(),
+ &(params[1].front()), params[1].size());
+ break;
+#endif // defined(OS_WIN) || defined(OS_LINUX)
+
+ default:
+ NOTREACHED();
+ }
+}