diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-04 14:17:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-05 10:05:06 +0000 |
commit | 39d357e3248f80abea0159765ff39554affb40db (patch) | |
tree | aba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/ui/base/clipboard | |
parent | 87778abf5a1f89266f37d1321b92a21851d8244d (diff) | |
download | qtwebengine-chromium-39d357e3248f80abea0159765ff39554affb40db.tar.gz |
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2
Change-Id: I20d43c737f82764d857ada9a55586901b18b9243
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/base/clipboard')
-rw-r--r-- | chromium/ui/base/clipboard/clipboard.h | 19 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_android.cc | 35 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_android.h | 2 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_android_unittest.cc | 6 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_aurax11.cc | 7 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_mac.h | 9 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_mac.mm | 20 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_mac_unittest.mm | 81 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_monitor.cc | 3 | ||||
-rw-r--r-- | chromium/ui/base/clipboard/clipboard_observer.h | 4 |
10 files changed, 140 insertions, 46 deletions
diff --git a/chromium/ui/base/clipboard/clipboard.h b/chromium/ui/base/clipboard/clipboard.h index 7826b2696df..c164955030b 100644 --- a/chromium/ui/base/clipboard/clipboard.h +++ b/chromium/ui/base/clipboard/clipboard.h @@ -257,13 +257,20 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { // several system-specific FormatTypes. For example, on Linux the CBF_TEXT // ObjectType maps to "text/plain", "STRING", and several other formats. On // windows it maps to CF_UNICODETEXT. + // + // The order below is the order in which data will be written to the + // clipboard, so more specific types must be listed before less specific + // types. For example, placing an image on the clipboard might cause the + // clipboard to contain a bitmap, HTML markup representing the image, a URL to + // the image, and the image's alt text. Having the types follow this order + // maximizes the amount of data that can be extracted by various programs. enum ObjectType { - CBF_TEXT, + CBF_SMBITMAP, // Bitmap from shared memory. CBF_HTML, CBF_RTF, CBF_BOOKMARK, + CBF_TEXT, CBF_WEBKIT, - CBF_SMBITMAP, // Bitmap from shared memory. CBF_DATA, // Arbitrary block of bytes. }; @@ -274,16 +281,16 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { // // Key Arguments Type // ------------------------------------- - // CBF_TEXT text char array + // CBF_SMBITMAP bitmap A pointer to a SkBitmap. The caller must ensure + // the SkBitmap remains live for the duration of + // the WriteObjects call. // CBF_HTML html char array // url* char array // CBF_RTF data byte array // CBF_BOOKMARK html char array // url char array + // CBF_TEXT text char array // CBF_WEBKIT none empty vector - // CBF_SMBITMAP bitmap A pointer to a SkBitmap. The caller must ensure - // the SkBitmap remains live for the duration of - // the WriteObjects call. // CBF_DATA format char array // data byte array typedef std::vector<char> ObjectMapParam; diff --git a/chromium/ui/base/clipboard/clipboard_android.cc b/chromium/ui/base/clipboard/clipboard_android.cc index fa62fb638a0..8e3944deba5 100644 --- a/chromium/ui/base/clipboard/clipboard_android.cc +++ b/chromium/ui/base/clipboard/clipboard_android.cc @@ -64,14 +64,8 @@ class ClipboardMap { base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; ClipboardMap::ClipboardMap() { - JNIEnv* env = AttachCurrentThread(); - DCHECK(env); - - // Get the context. - jobject context = base::android::GetApplicationContext(); - DCHECK(context); - - clipboard_manager_.Reset(Java_Clipboard_create(env, context)); + clipboard_manager_.Reset(Java_Clipboard_create( + AttachCurrentThread(), base::android::GetApplicationContext())); DCHECK(clipboard_manager_.obj()); } @@ -85,7 +79,7 @@ std::string ClipboardMap::Get(const std::string& format) { bool ClipboardMap::HasFormat(const std::string& format) { base::AutoLock lock(lock_); UpdateFromAndroidClipboard(); - return ContainsKey(map_, format); + return base::ContainsKey(map_, format); } void ClipboardMap::Set(const std::string& format, const std::string& data) { @@ -96,10 +90,10 @@ void ClipboardMap::Set(const std::string& format, const std::string& data) { void ClipboardMap::CommitToAndroidClipboard() { JNIEnv* env = AttachCurrentThread(); base::AutoLock lock(lock_); - if (ContainsKey(map_, kHTMLFormat)) { + if (base::ContainsKey(map_, kHTMLFormat)) { // Android's API for storing HTML content on the clipboard requires a plain- // text representation to be available as well. - if (!ContainsKey(map_, kPlainTextFormat)) + if (!base::ContainsKey(map_, kPlainTextFormat)) return; ScopedJavaLocalRef<jstring> html = @@ -108,15 +102,14 @@ void ClipboardMap::CommitToAndroidClipboard() { ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); DCHECK(html.obj() && text.obj()); - Java_Clipboard_setHTMLText(env, clipboard_manager_.obj(), html.obj(), - text.obj()); - } else if (ContainsKey(map_, kPlainTextFormat)) { + Java_Clipboard_setHTMLText(env, clipboard_manager_, html, text); + } else if (base::ContainsKey(map_, kPlainTextFormat)) { ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, map_[kPlainTextFormat].c_str()); DCHECK(str.obj()); - Java_Clipboard_setText(env, clipboard_manager_.obj(), str.obj()); + Java_Clipboard_setText(env, clipboard_manager_, str); } else { - Java_Clipboard_clear(env, clipboard_manager_.obj()); + Java_Clipboard_clear(env, clipboard_manager_); NOTIMPLEMENTED(); } } @@ -125,7 +118,7 @@ void ClipboardMap::Clear() { JNIEnv* env = AttachCurrentThread(); base::AutoLock lock(lock_); map_.clear(); - Java_Clipboard_clear(env, clipboard_manager_.obj()); + Java_Clipboard_clear(env, clipboard_manager_); } // Add a key:jstr pair to map, but only if jstr is not null, and also @@ -161,9 +154,9 @@ void ClipboardMap::UpdateFromAndroidClipboard() { std::map<std::string, std::string> android_clipboard_state; ScopedJavaLocalRef<jstring> jtext = - Java_Clipboard_getCoercedText(env, clipboard_manager_.obj()); + Java_Clipboard_getCoercedText(env, clipboard_manager_); ScopedJavaLocalRef<jstring> jhtml = - Java_Clipboard_getHTMLText(env, clipboard_manager_.obj()); + Java_Clipboard_getHTMLText(env, clipboard_manager_); AddMapEntry(env, &android_clipboard_state, kPlainTextFormat, jtext); AddMapEntry(env, &android_clipboard_state, kHTMLFormat, jhtml); @@ -471,8 +464,4 @@ void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); } -bool RegisterClipboardAndroid(JNIEnv* env) { - return RegisterNativesImpl(env); -} - } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_android.h b/chromium/ui/base/clipboard/clipboard_android.h index 2ec2f46eb9e..f07882bb178 100644 --- a/chromium/ui/base/clipboard/clipboard_android.h +++ b/chromium/ui/base/clipboard/clipboard_android.h @@ -15,8 +15,6 @@ namespace ui { -bool RegisterClipboardAndroid(JNIEnv* env); - class ClipboardAndroid : public Clipboard { private: friend class Clipboard; diff --git a/chromium/ui/base/clipboard/clipboard_android_unittest.cc b/chromium/ui/base/clipboard/clipboard_android_unittest.cc index b6744a2b36e..d52013d4bcb 100644 --- a/chromium/ui/base/clipboard/clipboard_android_unittest.cc +++ b/chromium/ui/base/clipboard/clipboard_android_unittest.cc @@ -44,9 +44,6 @@ TEST_F(ClipboardAndroidTest, InternalClipboardInvalidation) { JNIEnv* env = base::android::AttachCurrentThread(); ASSERT_TRUE(env); - jobject context = base::android::GetApplicationContext(); - ASSERT_TRUE(context); - ScopedJavaLocalRef<jclass> context_class = base::android::GetClass(env, "android/content/Context"); @@ -59,7 +56,8 @@ TEST_F(ClipboardAndroidTest, InternalClipboardInvalidation) { ConvertUTF8ToJavaString(env, "clipboard"); ScopedJavaLocalRef<jobject> clipboard_manager( env, - env->CallObjectMethod(context, get_system_service, service_name.obj())); + env->CallObjectMethod(base::android::GetApplicationContext(), + get_system_service, service_name.obj())); ASSERT_TRUE(clipboard_manager.obj() && !base::android::ClearException(env)); ScopedJavaLocalRef<jclass> clipboard_class = diff --git a/chromium/ui/base/clipboard/clipboard_aurax11.cc b/chromium/ui/base/clipboard/clipboard_aurax11.cc index fb771682948..9a353a14831 100644 --- a/chromium/ui/base/clipboard/clipboard_aurax11.cc +++ b/chromium/ui/base/clipboard/clipboard_aurax11.cc @@ -28,6 +28,7 @@ #include "ui/base/x/selection_requestor.h" #include "ui/base/x/selection_utils.h" #include "ui/base/x/x11_util.h" +#include "ui/base/x/x11_window_event_manager.h" #include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_observer.h" #include "ui/events/platform/platform_event_source.h" @@ -301,6 +302,9 @@ class ClipboardAuraX11::AuraX11Details : public PlatformEventDispatcher { // Input-only window used as a selection owner. ::Window x_window_; + // Events selected on |x_window_|. + std::unique_ptr<XScopedEventSelector> x_window_events_; + X11AtomCache atom_cache_; // Object which requests and receives selection data. @@ -339,7 +343,8 @@ ClipboardAuraX11::AuraX11Details::AuraX11Details() atom_cache_.allow_uncached_atoms(); XStoreName(x_display_, x_window_, "Chromium clipboard"); - XSelectInput(x_display_, x_window_, PropertyChangeMask); + x_window_events_.reset( + new XScopedEventSelector(x_window_, PropertyChangeMask)); if (PlatformEventSource::GetInstance()) PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); diff --git a/chromium/ui/base/clipboard/clipboard_mac.h b/chromium/ui/base/clipboard/clipboard_mac.h index 3a4ef4a40e1..2e264cb0171 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.h +++ b/chromium/ui/base/clipboard/clipboard_mac.h @@ -8,13 +8,19 @@ #include <stddef.h> #include <stdint.h> +#include "base/gtest_prod_util.h" #include "base/macros.h" #include "ui/base/clipboard/clipboard.h" +#include "ui/base/ui_base_export.h" + +@class NSPasteboard; namespace ui { -class ClipboardMac : public Clipboard { +class UI_BASE_EXPORT ClipboardMac : public Clipboard { private: + FRIEND_TEST_ALL_PREFIXES(ClipboardMacTest, ReadImageRetina); + FRIEND_TEST_ALL_PREFIXES(ClipboardMacTest, ReadImageNonRetina); friend class Clipboard; ClipboardMac(); @@ -36,6 +42,7 @@ class ClipboardMac : public Clipboard { uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; + SkBitmap ReadImage(ClipboardType type, NSPasteboard* pb) const; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, const base::string16& type, diff --git a/chromium/ui/base/clipboard/clipboard_mac.mm b/chromium/ui/base/clipboard/clipboard_mac.mm index 8c42c0b7bd9..fcc4a3a662f 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_mac.mm @@ -298,7 +298,7 @@ void ClipboardMac::ReadRTF(ClipboardType type, std::string* result) const { return ReadData(GetRtfFormatType(), result); } -SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { +SkBitmap ClipboardMac::ReadImage(ClipboardType type, NSPasteboard* pb) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); @@ -306,7 +306,6 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { // may throw, and that exception will leak. Prevent a crash in that case; // a blank image is better. base::scoped_nsobject<NSImage> image; - NSPasteboard* pb = GetPasteboard(); @try { if ([[pb types] containsObject:NSFilenamesPboardType]) { // -[NSImage initWithPasteboard:] gets confused with copies of a single @@ -325,12 +324,21 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { } @catch (id exception) { } - SkBitmap bitmap; if (image.get()) { - bitmap = skia::NSImageToSkBitmapWithColorSpace( - image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); + if ([[image representations] count] == 1u) { + NSImageRep* rep = [[image representations] objectAtIndex:0]; + return skia::NSImageRepToSkBitmapWithColorSpace( + rep, NSMakeSize([rep pixelsWide], [rep pixelsHigh]), + /*is_opaque=*/false, base::mac::GetSystemColorSpace()); + } + return skia::NSImageToSkBitmapWithColorSpace( + image.get(), /*is_opaque=*/false, base::mac::GetSystemColorSpace()); } - return bitmap; + return SkBitmap(); +} + +SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { + return ReadImage(type, GetPasteboard()); } void ClipboardMac::ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/clipboard_mac_unittest.mm b/chromium/ui/base/clipboard/clipboard_mac_unittest.mm new file mode 100644 index 00000000000..6a5577cf503 --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_mac_unittest.mm @@ -0,0 +1,81 @@ +// Copyright 2016 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. + +#import "ui/base/clipboard/clipboard_mac.h" + +#include "base/mac/scoped_cftyperef.h" +#include "base/mac/scoped_nsobject.h" +#include "base/memory/free_deleter.h" +#include "base/memory/ref_counted.h" +#include "testing/platform_test.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/clipboard/clipboard_types.h" +#include "ui/base/clipboard/clipboard_util_mac.h" + +namespace ui { + +class ClipboardMacTest : public PlatformTest { + public: + ClipboardMacTest() { } + + base::scoped_nsobject<NSImage> CreateImage(int32_t width, + int32_t height, + bool retina) { + int32_t pixel_width = retina ? width * 2 : width; + int32_t pixel_height = retina ? height * 2 : height; + + // It seems more natural to create an NSBitmapImageRep and set it as the + // representation for an NSImage. This doesn't work, because when the + // result is written, and then read from an NSPasteboard, the new NSImage + // loses its "retina-ness". + std::unique_ptr<uint8_t, base::FreeDeleter> buffer( + static_cast<uint8_t*>(calloc(pixel_width * pixel_height, 4))); + base::ScopedCFTypeRef<CGDataProviderRef> provider( + CGDataProviderCreateWithData( + nullptr, buffer.get(), (pixel_width * pixel_height * 4), nullptr)); + base::ScopedCFTypeRef<CGColorSpaceRef> color_space( + CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); + base::ScopedCFTypeRef<CGImageRef> image_ref( + CGImageCreate(pixel_width, pixel_height, 8, 32, 4 * pixel_width, + color_space.get(), kCGBitmapByteOrderDefault, + provider.get(), nullptr, NO, kCGRenderingIntentDefault)); + return base::scoped_nsobject<NSImage>([[NSImage alloc] + initWithCGImage:image_ref.get() + size:NSMakeSize(width, height)]); + } +}; + +TEST_F(ClipboardMacTest, ReadImageRetina) { + int32_t width = 99; + int32_t height = 101; + scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard; + base::scoped_nsobject<NSImage> image = CreateImage(width, height, true); + [pasteboard->get() writeObjects:@[ image.get() ]]; + + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + ui::ClipboardMac* clipboard_mac = static_cast<ui::ClipboardMac*>(clipboard); + + SkBitmap bitmap = clipboard_mac->ReadImage(ui::CLIPBOARD_TYPE_COPY_PASTE, + pasteboard->get()); + EXPECT_EQ(2 * width, bitmap.width()); + EXPECT_EQ(2 * height, bitmap.height()); +} + +TEST_F(ClipboardMacTest, ReadImageNonRetina) { + int32_t width = 99; + int32_t height = 101; + scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard; + base::scoped_nsobject<NSImage> image = CreateImage(width, height, false); + [pasteboard->get() writeObjects:@[ image.get() ]]; + + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + ui::ClipboardMac* clipboard_mac = static_cast<ui::ClipboardMac*>(clipboard); + + SkBitmap bitmap = clipboard_mac->ReadImage(ui::CLIPBOARD_TYPE_COPY_PASTE, + pasteboard->get()); + EXPECT_EQ(width, bitmap.width()); + EXPECT_EQ(height, bitmap.height()); +} + +} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_monitor.cc b/chromium/ui/base/clipboard/clipboard_monitor.cc index 59ffee78400..89917144469 100644 --- a/chromium/ui/base/clipboard/clipboard_monitor.cc +++ b/chromium/ui/base/clipboard/clipboard_monitor.cc @@ -17,7 +17,8 @@ ClipboardMonitor::~ClipboardMonitor() { // static ClipboardMonitor* ClipboardMonitor::GetInstance() { - return base::Singleton<ClipboardMonitor>::get(); + return base::Singleton<ClipboardMonitor, + base::LeakySingletonTraits<ClipboardMonitor>>::get(); } void ClipboardMonitor::NotifyClipboardDataChanged() { diff --git a/chromium/ui/base/clipboard/clipboard_observer.h b/chromium/ui/base/clipboard/clipboard_observer.h index f181cd8e236..82afdd38a72 100644 --- a/chromium/ui/base/clipboard/clipboard_observer.h +++ b/chromium/ui/base/clipboard/clipboard_observer.h @@ -16,8 +16,8 @@ class UI_BASE_EXPORT ClipboardObserver { // Called when clipboard data is changed. virtual void OnClipboardDataChanged() = 0; - private: - DISALLOW_COPY_AND_ASSIGN(ClipboardObserver); + protected: + virtual ~ClipboardObserver() {} }; } // namespace ui |