summaryrefslogtreecommitdiff
path: root/chromium/content/common/mac
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/content/common/mac
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/content/common/mac')
-rw-r--r--chromium/content/common/mac/OWNERS2
-rw-r--r--chromium/content/common/mac/attributed_string_coder.h132
-rw-r--r--chromium/content/common/mac/attributed_string_coder.mm190
-rw-r--r--chromium/content/common/mac/attributed_string_type_converters.h59
-rw-r--r--chromium/content/common/mac/attributed_string_type_converters.mm133
-rw-r--r--chromium/content/common/mac/attributed_string_type_converters_unittest.mm (renamed from chromium/content/common/mac/attributed_string_coder_unittest.mm)84
-rw-r--r--chromium/content/common/mac/font_loader.h1
-rw-r--r--chromium/content/common/mac/font_loader.mm1
8 files changed, 239 insertions, 363 deletions
diff --git a/chromium/content/common/mac/OWNERS b/chromium/content/common/mac/OWNERS
new file mode 100644
index 00000000000..a1660982293
--- /dev/null
+++ b/chromium/content/common/mac/OWNERS
@@ -0,0 +1,2 @@
+per-file *_type_converter*.*=set noparent
+per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS
diff --git a/chromium/content/common/mac/attributed_string_coder.h b/chromium/content/common/mac/attributed_string_coder.h
deleted file mode 100644
index 7100793b51d..00000000000
--- a/chromium/content/common/mac/attributed_string_coder.h
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_
-#define CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_
-
-#include <set>
-
-#include "base/strings/string16.h"
-#include "content/common/content_export.h"
-#include "ipc/ipc_message_utils.h"
-#include "ui/gfx/range/range.h"
-
-#if __OBJC__
-@class NSAttributedString;
-@class NSDictionary;
-#else
-class NSAttributedString;
-class NSDictionary;
-#endif
-
-namespace base {
-class Pickle;
-class PickleIterator;
-}
-
-namespace mac {
-
-// This class will serialize the font information of an NSAttributedString so
-// that it can be sent over IPC. This class only stores the information of the
-// NSFontAttributeName. The motive is that of security: using NSArchiver and
-// friends to send objects from the renderer to the browser could lead to
-// deserialization of arbitrary objects. This class restricts serialization to
-// a specific object class and specific attributes of that object.
-class CONTENT_EXPORT AttributedStringCoder {
- public:
- // A C++ IPC-friendly representation of the NSFontAttributeName attribute
- // set.
- class FontAttribute {
- public:
- FontAttribute(NSDictionary* ns_attributes, gfx::Range effective_range);
- FontAttribute(const base::string16& font_name,
- float font_point_size,
- const gfx::Range& range);
- FontAttribute();
- ~FontAttribute();
-
- // Creates an autoreleased NSDictionary that can be attached to an
- // NSAttributedString.
- NSDictionary* ToAttributesDictionary() const;
-
- // Whether or not the attribute should be placed in the EncodedString. This
- // can return false, e.g. if the Cocoa-based constructor can't find any
- // information to encode.
- bool ShouldEncode() const;
-
- // Accessors:
- const base::string16& font_name() const { return font_name_; }
- float font_point_size() const { return font_point_size_; }
- const gfx::Range& effective_range() const { return effective_range_; }
-
- private:
- base::string16 font_name_;
- float font_point_size_;
- gfx::Range effective_range_;
- };
-
- // A class that contains the pertinent information from an NSAttributedString,
- // which can be serialized over IPC.
- class EncodedString {
- public:
- explicit EncodedString(base::string16 string);
- EncodedString();
- EncodedString(const EncodedString& other);
- EncodedString& operator=(const EncodedString& other);
- ~EncodedString();
-
- // Accessors:
- base::string16 string() const { return string_; }
- const std::vector<FontAttribute>& attributes() const {
- return attributes_;
- }
- std::vector<FontAttribute>* attributes() { return &attributes_; }
-
- private:
- // The plain-text string.
- base::string16 string_;
- // The set of attributes that style |string_|.
- std::vector<FontAttribute> attributes_;
- };
-
- // Takes an NSAttributedString, extracts the pertinent attributes, and returns
- // an object that represents it. Caller owns the result.
- static const EncodedString* Encode(NSAttributedString* str);
-
- // Returns an autoreleased NSAttributedString from an encoded representation.
- static NSAttributedString* Decode(const EncodedString* str);
-
- private:
- AttributedStringCoder();
-};
-
-} // namespace mac
-
-// IPC ParamTraits specialization //////////////////////////////////////////////
-
-namespace IPC {
-
-template <>
-struct ParamTraits<mac::AttributedStringCoder::EncodedString> {
- typedef mac::AttributedStringCoder::EncodedString param_type;
- static void Write(base::Pickle* m, const param_type& p);
- static bool Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* r);
- static void Log(const param_type& p, std::string* l);
-};
-
-template <>
-struct ParamTraits<mac::AttributedStringCoder::FontAttribute> {
- typedef mac::AttributedStringCoder::FontAttribute param_type;
- static void Write(base::Pickle* m, const param_type& p);
- static bool Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* r);
- static void Log(const param_type& p, std::string* l);
-};
-
-} // namespace IPC
-
-#endif // CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_
diff --git a/chromium/content/common/mac/attributed_string_coder.mm b/chromium/content/common/mac/attributed_string_coder.mm
deleted file mode 100644
index 7cb5f404f2c..00000000000
--- a/chromium/content/common/mac/attributed_string_coder.mm
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright (c) 2012 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/common/mac/attributed_string_coder.h"
-
-#include <AppKit/AppKit.h>
-
-#include "base/check.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/strings/sys_string_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "content/public/common/common_param_traits.h"
-#include "ipc/ipc_message_utils.h"
-
-namespace mac {
-
-// static
-const AttributedStringCoder::EncodedString* AttributedStringCoder::Encode(
- NSAttributedString* str) {
- // Create the return value.
- EncodedString* encoded_string =
- new EncodedString(base::SysNSStringToUTF16([str string]));
- // Iterate over all the attributes in the string.
- NSUInteger length = [str length];
- for (NSUInteger i = 0; i < length; ) {
- NSRange effective_range;
- NSDictionary* ns_attributes = [str attributesAtIndex:i
- effectiveRange:&effective_range];
- // Convert the attributes to IPC-friendly types.
- FontAttribute attrs(ns_attributes, gfx::Range(effective_range));
- // Only encode the attributes if the filtered set contains font information.
- if (attrs.ShouldEncode()) {
- encoded_string->attributes()->push_back(attrs);
- }
- // Advance the iterator to the position outside of the effective range.
- i = NSMaxRange(effective_range);
- }
- return encoded_string;
-}
-
-// static
-NSAttributedString* AttributedStringCoder::Decode(
- const AttributedStringCoder::EncodedString* str) {
- // Create the return value.
- NSString* plain_text = base::SysUTF16ToNSString(str->string());
- base::scoped_nsobject<NSMutableAttributedString> decoded_string(
- [[NSMutableAttributedString alloc] initWithString:plain_text]);
- // Iterate over all the encoded attributes, attaching each to the string.
- const std::vector<FontAttribute> attributes = str->attributes();
- for (std::vector<FontAttribute>::const_iterator it = attributes.begin();
- it != attributes.end(); ++it) {
- // Protect against ranges that are outside the range of the string.
- const gfx::Range& range = it->effective_range();
- if (range.GetMin() > [plain_text length] ||
- range.GetMax() > [plain_text length]) {
- continue;
- }
- [decoded_string addAttributes:it->ToAttributesDictionary()
- range:range.ToNSRange()];
- }
- return [decoded_string.release() autorelease];
-}
-
-// Data Types //////////////////////////////////////////////////////////////////
-
-AttributedStringCoder::EncodedString::EncodedString(base::string16 string)
- : string_(string) {
-}
-
-AttributedStringCoder::EncodedString::EncodedString()
- : string_() {
-}
-
-AttributedStringCoder::EncodedString::EncodedString(
- const EncodedString& other) = default;
-
-AttributedStringCoder::EncodedString& AttributedStringCoder::EncodedString::
-operator=(const EncodedString& other) = default;
-
-AttributedStringCoder::EncodedString::~EncodedString() {
-}
-
-AttributedStringCoder::FontAttribute::FontAttribute(NSDictionary* dict,
- gfx::Range effective_range)
- : font_name_(), font_point_size_(0), effective_range_(effective_range) {
- NSFont* font = [dict objectForKey:NSFontAttributeName];
- if (font) {
- font_name_ = base::SysNSStringToUTF16([font fontName]);
- font_point_size_ = [font pointSize];
- }
-}
-
-AttributedStringCoder::FontAttribute::FontAttribute(
- const base::string16& font_name,
- float font_point_size,
- const gfx::Range& range)
- : font_name_(std::move(font_name)),
- font_point_size_(font_point_size),
- effective_range_(range) {}
-
-AttributedStringCoder::FontAttribute::FontAttribute()
- : font_name_(), font_point_size_(0), effective_range_() {}
-
-AttributedStringCoder::FontAttribute::~FontAttribute() {
-}
-
-NSDictionary*
-AttributedStringCoder::FontAttribute::ToAttributesDictionary() const {
- DCHECK(ShouldEncode());
- NSString* font_name_ns = base::SysUTF16ToNSString(font_name_);
- NSFont* font = [NSFont fontWithName:font_name_ns size:font_point_size_];
- if (!font)
- return [NSDictionary dictionary];
- return [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
-}
-
-bool AttributedStringCoder::FontAttribute::ShouldEncode() const {
- return !font_name_.empty();
-}
-
-} // namespace mac
-
-// IPC ParamTraits specialization //////////////////////////////////////////////
-
-namespace IPC {
-
-using mac::AttributedStringCoder;
-
-void ParamTraits<AttributedStringCoder::EncodedString>::Write(
- base::Pickle* m,
- const param_type& p) {
- WriteParam(m, p.string());
- WriteParam(m, p.attributes());
-}
-
-bool ParamTraits<AttributedStringCoder::EncodedString>::Read(
- const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
- bool success = true;
-
- base::string16 result;
- success &= ReadParam(m, iter, &result);
- *p = AttributedStringCoder::EncodedString(result);
-
- success &= ReadParam(m, iter, p->attributes());
- return success;
-}
-
-void ParamTraits<AttributedStringCoder::EncodedString>::Log(
- const param_type& p, std::string* l) {
- l->append(base::UTF16ToUTF8(p.string()));
-}
-
-void ParamTraits<AttributedStringCoder::FontAttribute>::Write(
- base::Pickle* m,
- const param_type& p) {
- WriteParam(m, p.font_name());
- WriteParam(m, p.font_point_size());
- WriteParam(m, p.effective_range());
-}
-
-bool ParamTraits<AttributedStringCoder::FontAttribute>::Read(
- const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
- bool success = true;
-
- base::string16 font_name;
- success &= ReadParam(m, iter, &font_name);
-
- float font_point_size;
- success &= ReadParam(m, iter, &font_point_size);
-
- gfx::Range range;
- success &= ReadParam(m, iter, &range);
-
- if (success) {
- *p = AttributedStringCoder::FontAttribute(std::move(font_name),
- font_point_size, range);
- }
- return success;
-}
-
-void ParamTraits<AttributedStringCoder::FontAttribute>::Log(
- const param_type& p, std::string* l) {
-}
-
-} // namespace IPC
diff --git a/chromium/content/common/mac/attributed_string_type_converters.h b/chromium/content/common/mac/attributed_string_type_converters.h
new file mode 100644
index 00000000000..1fa044d305f
--- /dev/null
+++ b/chromium/content/common/mac/attributed_string_type_converters.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 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.
+
+#ifndef CONTENT_COMMON_MAC_ATTRIBUTED_STRING_TYPE_CONVERTERS_H_
+#define CONTENT_COMMON_MAC_ATTRIBUTED_STRING_TYPE_CONVERTERS_H_
+
+#include "base/strings/string16.h"
+#include "content/common/content_export.h"
+#include "ipc/ipc_message_utils.h"
+#include "ui/base/mojom/attributed_string.mojom.h"
+#include "ui/gfx/range/range.h"
+
+#if __OBJC__
+@class NSAttributedString;
+#else
+class NSAttributedString;
+#endif
+
+namespace base {
+class Pickle;
+class PickleIterator;
+}
+
+namespace mojo {
+
+template <>
+struct CONTENT_EXPORT
+ TypeConverter<NSAttributedString*, ui::mojom::AttributedStringPtr> {
+ static NSAttributedString* Convert(
+ const ui::mojom::AttributedStringPtr& mojo_attributed_string);
+};
+
+template <>
+struct CONTENT_EXPORT
+ TypeConverter<ui::mojom::AttributedStringPtr, NSAttributedString*> {
+ static ui::mojom::AttributedStringPtr Convert(
+ const NSAttributedString* ns_attributed_string);
+};
+
+} // namespace mojo
+
+// IPC ParamTraits specialization //////////////////////////////////////////////
+
+namespace IPC {
+
+template <>
+struct ParamTraits<ui::mojom::FontAttributePtr> {
+ typedef ui::mojom::FontAttributePtr param_type;
+ static void Write(base::Pickle* m, const param_type& p);
+ static bool Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+} // namespace IPC
+
+#endif // CONTENT_COMMON_MAC_ATTRIBUTED_STRING_TYPE_CONVERTERS_H_
diff --git a/chromium/content/common/mac/attributed_string_type_converters.mm b/chromium/content/common/mac/attributed_string_type_converters.mm
new file mode 100644
index 00000000000..eb67745731a
--- /dev/null
+++ b/chromium/content/common/mac/attributed_string_type_converters.mm
@@ -0,0 +1,133 @@
+// Copyright (c) 2012 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/common/mac/attributed_string_type_converters.h"
+
+#include <AppKit/AppKit.h>
+
+#include "base/check.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/common/common_param_traits.h"
+
+namespace mojo {
+
+namespace {
+
+NSDictionary* ToAttributesDictionary(base::string16 name, float font_size) {
+ DCHECK(!name.empty());
+ NSString* font_name_ns = base::SysUTF16ToNSString(name);
+ NSFont* font = [NSFont fontWithName:font_name_ns size:font_size];
+ if (!font)
+ return [NSDictionary dictionary];
+ return [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
+}
+
+} // namespace
+
+NSAttributedString*
+TypeConverter<NSAttributedString*, ui::mojom::AttributedStringPtr>::Convert(
+ const ui::mojom::AttributedStringPtr& mojo_attributed_string) {
+ // Create the return value.
+ NSString* plain_text =
+ base::SysUTF16ToNSString(mojo_attributed_string->string);
+ base::scoped_nsobject<NSMutableAttributedString> decoded_string(
+ [[NSMutableAttributedString alloc] initWithString:plain_text]);
+ // Iterate over all the encoded attributes, attaching each to the string.
+ const std::vector<ui::mojom::FontAttributePtr>& attributes =
+ mojo_attributed_string->attributes;
+ for (std::vector<ui::mojom::FontAttributePtr>::const_iterator it =
+ attributes.begin();
+ it != attributes.end(); ++it) {
+ // Protect against ranges that are outside the range of the string.
+ const gfx::Range& range = it->get()->effective_range;
+ if (range.GetMin() > [plain_text length] ||
+ range.GetMax() > [plain_text length]) {
+ continue;
+ }
+ [decoded_string
+ addAttributes:ToAttributesDictionary(it->get()->font_name,
+ it->get()->font_point_size)
+ range:range.ToNSRange()];
+ }
+ return [decoded_string.release() autorelease];
+}
+
+ui::mojom::AttributedStringPtr
+TypeConverter<ui::mojom::AttributedStringPtr, NSAttributedString*>::Convert(
+ const NSAttributedString* ns_attributed_string) {
+ // Create the return value.
+ ui::mojom::AttributedStringPtr attributed_string =
+ ui::mojom::AttributedString::New();
+ attributed_string->string =
+ base::SysNSStringToUTF16([ns_attributed_string string]);
+
+ // Iterate over all the attributes in the string.
+ NSUInteger length = [ns_attributed_string length];
+ for (NSUInteger i = 0; i < length;) {
+ NSRange effective_range;
+ NSDictionary* ns_attributes =
+ [ns_attributed_string attributesAtIndex:i
+ effectiveRange:&effective_range];
+
+ NSFont* font = [ns_attributes objectForKey:NSFontAttributeName];
+ base::string16 font_name;
+ float font_point_size;
+ // Only encode the attributes if the filtered set contains font information.
+ if (font) {
+ font_name = base::SysNSStringToUTF16([font fontName]);
+ font_point_size = [font pointSize];
+ if (!font_name.empty()) {
+ // Convert the attributes.
+ ui::mojom::FontAttributePtr attrs = ui::mojom::FontAttribute::New(
+ font_name, font_point_size, gfx::Range(effective_range));
+ attributed_string->attributes.push_back(std::move(attrs));
+ }
+ }
+ // Advance the iterator to the position outside of the effective range.
+ i = NSMaxRange(effective_range);
+ }
+ return attributed_string;
+}
+
+} // namespace mojo
+
+// IPC ParamTraits specialization //////////////////////////////////////////////
+
+namespace IPC {
+
+using ui::mojom::FontAttributePtr;
+
+void ParamTraits<FontAttributePtr>::Write(base::Pickle* m,
+ const param_type& p) {
+ WriteParam(m, p->font_name);
+ WriteParam(m, p->font_point_size);
+ WriteParam(m, p->effective_range);
+}
+
+bool ParamTraits<FontAttributePtr>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* p) {
+ bool success = true;
+
+ base::string16 font_name;
+ success &= ReadParam(m, iter, &font_name);
+
+ float font_point_size;
+ success &= ReadParam(m, iter, &font_point_size);
+
+ gfx::Range range;
+ success &= ReadParam(m, iter, &range);
+
+ if (success) {
+ *p = ui::mojom::FontAttribute::New(std::move(font_name), font_point_size,
+ range);
+ }
+ return success;
+}
+
+void ParamTraits<FontAttributePtr>::Log(const param_type& p, std::string* l) {}
+
+} // namespace IPC
diff --git a/chromium/content/common/mac/attributed_string_coder_unittest.mm b/chromium/content/common/mac/attributed_string_type_converters_unittest.mm
index bc4991bb3fa..38485ff3834 100644
--- a/chromium/content/common/mac/attributed_string_coder_unittest.mm
+++ b/chromium/content/common/mac/attributed_string_type_converters_unittest.mm
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import "content/common/mac/attributed_string_coder.h"
+#import "content/common/mac/attributed_string_type_converters.h"
#include <AppKit/AppKit.h>
@@ -14,9 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
-using mac::AttributedStringCoder;
-
-class AttributedStringCoderTest : public testing::Test {
+class AttributedStringConverterTest : public testing::Test {
public:
NSMutableAttributedString* NewAttrString() {
NSString* str = @"The quick brown fox jumped over the lazy dog.";
@@ -28,29 +26,29 @@ class AttributedStringCoderTest : public testing::Test {
return [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
}
- NSAttributedString* EncodeAndDecode(NSAttributedString* str) {
- std::unique_ptr<const AttributedStringCoder::EncodedString> encoded_str(
- AttributedStringCoder::Encode(str));
- return AttributedStringCoder::Decode(encoded_str.get());
+ NSAttributedString* ConvertAndRestore(NSAttributedString* str) {
+ ui::mojom::AttributedStringPtr attributed_str =
+ ui::mojom::AttributedString::From(str);
+ return attributed_str.To<NSAttributedString*>();
}
};
-TEST_F(AttributedStringCoderTest, SimpleString) {
+TEST_F(AttributedStringConverterTest, SimpleString) {
base::scoped_nsobject<NSMutableAttributedString> attr_str(NewAttrString());
[attr_str addAttributes:FontAttribute(@"Helvetica", 12.5)
range:NSMakeRange(0, [attr_str length])];
- NSAttributedString* decoded = EncodeAndDecode(attr_str.get());
- EXPECT_NSEQ(attr_str.get(), decoded);
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(attr_str.get());
+ EXPECT_NSEQ(attr_str.get(), ns_attributed_string);
}
-TEST_F(AttributedStringCoderTest, NoAttributes) {
+TEST_F(AttributedStringConverterTest, NoAttributes) {
base::scoped_nsobject<NSAttributedString> attr_str(NewAttrString());
- NSAttributedString* decoded = EncodeAndDecode(attr_str.get());
- EXPECT_NSEQ(attr_str.get(), decoded);
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(attr_str.get());
+ EXPECT_NSEQ(attr_str.get(), ns_attributed_string);
}
-TEST_F(AttributedStringCoderTest, StripColor) {
+TEST_F(AttributedStringConverterTest, StripColor) {
base::scoped_nsobject<NSMutableAttributedString> attr_str(NewAttrString());
const NSUInteger kStringLength = [attr_str length];
[attr_str addAttribute:NSFontAttributeName
@@ -60,17 +58,18 @@ TEST_F(AttributedStringCoderTest, StripColor) {
value:[NSColor redColor]
range:NSMakeRange(0, kStringLength)];
- NSAttributedString* decoded = EncodeAndDecode(attr_str.get());
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(attr_str.get());
NSRange range;
- NSDictionary* attrs = [decoded attributesAtIndex:0 effectiveRange:&range];
+ NSDictionary* attrs = [ns_attributed_string attributesAtIndex:0
+ effectiveRange:&range];
EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, kStringLength), range));
EXPECT_NSEQ([NSFont systemFontOfSize:26],
[attrs objectForKey:NSFontAttributeName]);
EXPECT_FALSE([attrs objectForKey:NSForegroundColorAttributeName]);
}
-TEST_F(AttributedStringCoderTest, MultipleFonts) {
+TEST_F(AttributedStringConverterTest, MultipleFonts) {
base::scoped_nsobject<NSMutableAttributedString> attr_str(NewAttrString());
[attr_str setAttributes:FontAttribute(@"Courier", 12)
range:NSMakeRange(0, 10)];
@@ -79,12 +78,12 @@ TEST_F(AttributedStringCoderTest, MultipleFonts) {
[attr_str addAttributes:FontAttribute(@"Helvetica", 14)
range:NSMakeRange(15, 5)];
- NSAttributedString* decoded = EncodeAndDecode(attr_str);
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(attr_str);
- EXPECT_NSEQ(attr_str.get(), decoded);
+ EXPECT_NSEQ(attr_str.get(), ns_attributed_string);
}
-TEST_F(AttributedStringCoderTest, NoPertinentAttributes) {
+TEST_F(AttributedStringConverterTest, NoPertinentAttributes) {
base::scoped_nsobject<NSMutableAttributedString> attr_str(NewAttrString());
[attr_str addAttribute:NSForegroundColorAttributeName
value:[NSColor blueColor]
@@ -96,40 +95,43 @@ TEST_F(AttributedStringCoderTest, NoPertinentAttributes) {
value:[NSNumber numberWithFloat:2.6]
range:NSMakeRange(11, 3)];
- NSAttributedString* decoded = EncodeAndDecode(attr_str.get());
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(attr_str.get());
base::scoped_nsobject<NSAttributedString> expected(NewAttrString());
- EXPECT_NSEQ(expected.get(), decoded);
+ EXPECT_NSEQ(expected.get(), ns_attributed_string);
}
-TEST_F(AttributedStringCoderTest, NilString) {
- NSAttributedString* decoded = EncodeAndDecode(nil);
- EXPECT_TRUE(decoded);
- EXPECT_EQ(0U, [decoded length]);
+TEST_F(AttributedStringConverterTest, NilString) {
+ NSAttributedString* ns_attributed_string = ConvertAndRestore(nil);
+ EXPECT_TRUE(ns_attributed_string);
+ EXPECT_EQ(0U, [ns_attributed_string length]);
}
-TEST_F(AttributedStringCoderTest, OutOfRange) {
+TEST_F(AttributedStringConverterTest, OutOfRange) {
NSFont* system_font = [NSFont systemFontOfSize:10];
base::string16 font_name = base::SysNSStringToUTF16([system_font fontName]);
- AttributedStringCoder::EncodedString encoded(
- base::ASCIIToUTF16("Hello World"));
- encoded.attributes()->push_back(
- AttributedStringCoder::FontAttribute(font_name, 12, gfx::Range(0, 5)));
- encoded.attributes()->push_back(
- AttributedStringCoder::FontAttribute(font_name, 14, gfx::Range(5, 100)));
- encoded.attributes()->push_back(
- AttributedStringCoder::FontAttribute(font_name, 16, gfx::Range(100, 5)));
-
- NSAttributedString* decoded = AttributedStringCoder::Decode(&encoded);
- EXPECT_TRUE(decoded);
+ ui::mojom::AttributedStringPtr attributed_string =
+ ui::mojom::AttributedString::New();
+ attributed_string->string = base::ASCIIToUTF16("Hello World");
+ attributed_string->attributes.push_back(
+ ui::mojom::FontAttribute::New(font_name, 12, gfx::Range(0, 5)));
+ attributed_string->attributes.push_back(
+ ui::mojom::FontAttribute::New(font_name, 14, gfx::Range(5, 100)));
+ attributed_string->attributes.push_back(
+ ui::mojom::FontAttribute::New(font_name, 16, gfx::Range(100, 5)));
+
+ NSAttributedString* ns_attributed_string =
+ attributed_string.To<NSAttributedString*>();
+ EXPECT_TRUE(ns_attributed_string);
NSRange range;
- NSDictionary* attrs = [decoded attributesAtIndex:0 effectiveRange:&range];
+ NSDictionary* attrs = [ns_attributed_string attributesAtIndex:0
+ effectiveRange:&range];
EXPECT_NSEQ([NSFont systemFontOfSize:12],
[attrs objectForKey:NSFontAttributeName]);
EXPECT_TRUE(NSEqualRanges(range, NSMakeRange(0, 5)));
- attrs = [decoded attributesAtIndex:5 effectiveRange:&range];
+ attrs = [ns_attributed_string attributesAtIndex:5 effectiveRange:&range];
EXPECT_FALSE([attrs objectForKey:NSFontAttributeName]);
EXPECT_EQ(0U, [attrs count]);
}
diff --git a/chromium/content/common/mac/font_loader.h b/chromium/content/common/mac/font_loader.h
index c3f9d96c895..1ca8887cc67 100644
--- a/chromium/content/common/mac/font_loader.h
+++ b/chromium/content/common/mac/font_loader.h
@@ -12,6 +12,7 @@
#include "base/callback_forward.h"
#include "base/mac/scoped_cftyperef.h"
+#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/system/buffer.h"
diff --git a/chromium/content/common/mac/font_loader.mm b/chromium/content/common/mac/font_loader.mm
index ce391bb8b57..f0af36a630a 100644
--- a/chromium/content/common/mac/font_loader.mm
+++ b/chromium/content/common/mac/font_loader.mm
@@ -17,6 +17,7 @@
#import "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#import "base/mac/scoped_nsobject.h"
+#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"