Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_LEGAL_MESSAGE_LINE_H_ | |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_LEGAL_MESSAGE_LINE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "ui/gfx/range/range.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 } | |
| 20 | |
| 21 namespace autofill { | |
| 22 | |
| 23 class LegalMessageLine; | |
| 24 | |
| 25 using LegalMessageLines = std::vector<LegalMessageLine>; | |
| 26 | |
| 27 class LegalMessageLine { | |
| 28 public: | |
| 29 struct Link { | |
| 30 gfx::Range range; | |
| 31 GURL url; | |
| 32 }; | |
| 33 | |
| 34 // Parses |legal_message|. Returns false on failure. | |
| 35 // | |
| 36 // Example of valid |legal_message| data: | |
| 37 // { | |
| 38 // "line" : [ { | |
| 39 // "template" : "The legal documents are: {0} and {1}", | |
| 40 // "template_parameter" : [ { | |
| 41 // "display_text" : "Terms of Service", | |
| 42 // "url": "http://www.example.com/tos" | |
| 43 // }, { | |
| 44 // "display_text" : "Privacy Policy", | |
| 45 // "url": "http://www.example.com/pp" | |
| 46 // } ], | |
| 47 // }, { | |
| 48 // "template" : "This is the second line and it has no parameters" | |
| 49 // } ] | |
| 50 // } | |
| 51 // | |
| 52 // Caveats: | |
| 53 // 1. '{' and '}' may be displayed by escaping them with an apostrophe in the | |
| 54 // template string, e.g. "template" : "Here is a literal '{'" | |
|
Peter Kasting
2016/01/14 04:19:25
Nit: I think if you remove the quoted word "templa
please use gerrit instead
2016/01/14 17:51:57
Done.
| |
| 55 // 2. Two or more consecutive dollar signs in the template string will not | |
| 56 // expand correctly. | |
| 57 // 3. "${" anywhere in the template string is invalid. | |
| 58 // 4. "\n" embedded anywhere in the template string, or an empty template | |
| 59 // string, can be used to separate paragraphs. It is not possible to create | |
| 60 // a completely blank line by using two consecutive newlines (they will be | |
| 61 // treated as a single newline by views::StyledLabel). | |
| 62 static bool Parse(const base::DictionaryValue& legal_message, | |
| 63 LegalMessageLines* out); | |
|
Peter Kasting
2016/01/14 04:19:25
Nit: Per the style guide, static methods go below
please use gerrit instead
2016/01/14 17:51:57
Done.
| |
| 64 | |
| 65 LegalMessageLine(); | |
| 66 virtual ~LegalMessageLine(); // Overridden in TestLegalMessageLine. | |
| 67 | |
| 68 const base::string16& text() const { return text_; } | |
| 69 const std::vector<Link>& links() const { return links_; } | |
| 70 | |
| 71 private: | |
| 72 friend class TestLegalMessageLine; | |
| 73 | |
| 74 bool ParseLine(const base::DictionaryValue& line); | |
| 75 | |
| 76 base::string16 text_; | |
| 77 std::vector<Link> links_; | |
| 78 }; | |
| 79 | |
| 80 } // namespace autofill | |
| 81 | |
| 82 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_LEGAL_MESSAGE_LINE_H_ | |
| OLD | NEW |