| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ | 5 #ifndef CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ |
| 6 #define CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ | 6 #define CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/common/mac/font_descriptor.h" | 12 #include "content/common/mac/font_descriptor.h" |
| 13 #include "ipc/ipc_message_utils.h" | 13 #include "ipc/ipc_message_utils.h" |
| 14 #include "ui/base/range/range.h" | 14 #include "ui/gfx/range/range.h" |
| 15 | 15 |
| 16 #if __OBJC__ | 16 #if __OBJC__ |
| 17 @class NSAttributedString; | 17 @class NSAttributedString; |
| 18 @class NSDictionary; | 18 @class NSDictionary; |
| 19 #else | 19 #else |
| 20 class NSAttributedString; | 20 class NSAttributedString; |
| 21 class NSDictionary; | 21 class NSDictionary; |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace mac { | 24 namespace mac { |
| 25 | 25 |
| 26 // This class will serialize the font information of an NSAttributedString so | 26 // This class will serialize the font information of an NSAttributedString so |
| 27 // that it can be sent over IPC. This class only stores the information of the | 27 // that it can be sent over IPC. This class only stores the information of the |
| 28 // NSFontAttributeName. The motive is that of security: using NSArchiver and | 28 // NSFontAttributeName. The motive is that of security: using NSArchiver and |
| 29 // friends to send objects from the renderer to the browser could lead to | 29 // friends to send objects from the renderer to the browser could lead to |
| 30 // deserialization of arbitrary objects. This class restricts serialization to | 30 // deserialization of arbitrary objects. This class restricts serialization to |
| 31 // a specific object class and specific attributes of that object. | 31 // a specific object class and specific attributes of that object. |
| 32 class CONTENT_EXPORT AttributedStringCoder { | 32 class CONTENT_EXPORT AttributedStringCoder { |
| 33 public: | 33 public: |
| 34 // A C++ IPC-friendly representation of the NSFontAttributeName attribute | 34 // A C++ IPC-friendly representation of the NSFontAttributeName attribute |
| 35 // set. | 35 // set. |
| 36 class FontAttribute { | 36 class FontAttribute { |
| 37 public: | 37 public: |
| 38 FontAttribute(NSDictionary* ns_attributes, ui::Range effective_range); | 38 FontAttribute(NSDictionary* ns_attributes, gfx::Range effective_range); |
| 39 FontAttribute(FontDescriptor font, ui::Range range); | 39 FontAttribute(FontDescriptor font, gfx::Range range); |
| 40 FontAttribute(); | 40 FontAttribute(); |
| 41 ~FontAttribute(); | 41 ~FontAttribute(); |
| 42 | 42 |
| 43 // Creates an autoreleased NSDictionary that can be attached to an | 43 // Creates an autoreleased NSDictionary that can be attached to an |
| 44 // NSAttributedString. | 44 // NSAttributedString. |
| 45 NSDictionary* ToAttributesDictionary() const; | 45 NSDictionary* ToAttributesDictionary() const; |
| 46 | 46 |
| 47 // Whether or not the attribute should be placed in the EncodedString. This | 47 // Whether or not the attribute should be placed in the EncodedString. This |
| 48 // can return false, e.g. if the Cocoa-based constructor can't find any | 48 // can return false, e.g. if the Cocoa-based constructor can't find any |
| 49 // information to encode. | 49 // information to encode. |
| 50 bool ShouldEncode() const; | 50 bool ShouldEncode() const; |
| 51 | 51 |
| 52 // Accessors: | 52 // Accessors: |
| 53 FontDescriptor font_descriptor() const { return font_descriptor_; } | 53 FontDescriptor font_descriptor() const { return font_descriptor_; } |
| 54 ui::Range effective_range() const { return effective_range_; } | 54 gfx::Range effective_range() const { return effective_range_; } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 FontDescriptor font_descriptor_; | 57 FontDescriptor font_descriptor_; |
| 58 ui::Range effective_range_; | 58 gfx::Range effective_range_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // A class that contains the pertinent information from an NSAttributedString, | 61 // A class that contains the pertinent information from an NSAttributedString, |
| 62 // which can be serialized over IPC. | 62 // which can be serialized over IPC. |
| 63 class EncodedString { | 63 class EncodedString { |
| 64 public: | 64 public: |
| 65 explicit EncodedString(string16 string); | 65 explicit EncodedString(string16 string); |
| 66 EncodedString(); | 66 EncodedString(); |
| 67 ~EncodedString(); | 67 ~EncodedString(); |
| 68 | 68 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 struct ParamTraits<mac::AttributedStringCoder::FontAttribute> { | 109 struct ParamTraits<mac::AttributedStringCoder::FontAttribute> { |
| 110 typedef mac::AttributedStringCoder::FontAttribute param_type; | 110 typedef mac::AttributedStringCoder::FontAttribute param_type; |
| 111 static void Write(Message* m, const param_type& p); | 111 static void Write(Message* m, const param_type& p); |
| 112 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 112 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
| 113 static void Log(const param_type& p, std::string* l); | 113 static void Log(const param_type& p, std::string* l); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 } // namespace IPC | 116 } // namespace IPC |
| 117 | 117 |
| 118 #endif // CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ | 118 #endif // CONTENT_COMMON_MAC_ATTRIBUTED_STRING_CODER_H_ |
| OLD | NEW |