OLD | NEW |
1 // Copyright (c) 2011 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 #include "chrome/common/extensions/extension_messages.h" | 5 #include "chrome/common/extensions/extension_messages.h" |
6 | 6 |
7 #include "chrome/common/extensions/extension_constants.h" | 7 #include "chrome/common/extensions/extension_constants.h" |
8 #include "chrome/common/extensions/manifest.h" | 8 #include "chrome/common/extensions/manifest.h" |
9 #include "content/public/common/common_param_traits.h" | 9 #include "content/public/common/common_param_traits.h" |
10 | 10 |
11 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() | 11 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() |
(...skipping 26 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace IPC { | 39 namespace IPC { |
40 | 40 |
41 template <> | 41 template <> |
42 struct ParamTraits<Extension::Location> { | 42 struct ParamTraits<Extension::Location> { |
43 typedef Extension::Location param_type; | 43 typedef Extension::Location param_type; |
44 static void Write(Message* m, const param_type& p) { | 44 static void Write(Message* m, const param_type& p) { |
45 int val = static_cast<int>(p); | 45 int val = static_cast<int>(p); |
46 WriteParam(m, val); | 46 WriteParam(m, val); |
47 } | 47 } |
48 static bool Read(const Message* m, void** iter, param_type* p) { | 48 static bool Read(const Message* m, PickleIterator* iter, param_type* p) { |
49 int val = 0; | 49 int val = 0; |
50 if (!ReadParam(m, iter, &val) || | 50 if (!ReadParam(m, iter, &val) || |
51 val < Extension::INVALID || | 51 val < Extension::INVALID || |
52 val >= Extension::NUM_LOCATIONS) | 52 val >= Extension::NUM_LOCATIONS) |
53 return false; | 53 return false; |
54 *p = static_cast<param_type>(val); | 54 *p = static_cast<param_type>(val); |
55 return true; | 55 return true; |
56 } | 56 } |
57 static void Log(const param_type& p, std::string* l) { | 57 static void Log(const param_type& p, std::string* l) { |
58 ParamTraits<int>::Log(static_cast<int>(p), l); | 58 ParamTraits<int>::Log(static_cast<int>(p), l); |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { | 62 void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { |
63 WriteParam(m, p.valid_schemes()); | 63 WriteParam(m, p.valid_schemes()); |
64 WriteParam(m, p.GetAsString()); | 64 WriteParam(m, p.GetAsString()); |
65 } | 65 } |
66 | 66 |
67 bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, | 67 bool ParamTraits<URLPattern>::Read(const Message* m, PickleIterator* iter, |
68 param_type* p) { | 68 param_type* p) { |
69 int valid_schemes; | 69 int valid_schemes; |
70 std::string spec; | 70 std::string spec; |
71 if (!ReadParam(m, iter, &valid_schemes) || | 71 if (!ReadParam(m, iter, &valid_schemes) || |
72 !ReadParam(m, iter, &spec)) | 72 !ReadParam(m, iter, &spec)) |
73 return false; | 73 return false; |
74 | 74 |
75 // TODO(jstritar): We don't want the URLPattern to fail parsing when the | 75 // TODO(jstritar): We don't want the URLPattern to fail parsing when the |
76 // scheme is invalid. Instead, the pattern should parse but it should not | 76 // scheme is invalid. Instead, the pattern should parse but it should not |
77 // match the invalid patterns. We get around this by setting the valid | 77 // match the invalid patterns. We get around this by setting the valid |
78 // schemes after parsing the pattern. Update these method calls once we can | 78 // schemes after parsing the pattern. Update these method calls once we can |
79 // ignore scheme validation with URLPattern parse options. crbug.com/90544 | 79 // ignore scheme validation with URLPattern parse options. crbug.com/90544 |
80 p->SetValidSchemes(URLPattern::SCHEME_ALL); | 80 p->SetValidSchemes(URLPattern::SCHEME_ALL); |
81 URLPattern::ParseResult result = p->Parse(spec); | 81 URLPattern::ParseResult result = p->Parse(spec); |
82 p->SetValidSchemes(valid_schemes); | 82 p->SetValidSchemes(valid_schemes); |
83 return URLPattern::PARSE_SUCCESS == result; | 83 return URLPattern::PARSE_SUCCESS == result; |
84 } | 84 } |
85 | 85 |
86 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { | 86 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { |
87 LogParam(p.GetAsString(), l); | 87 LogParam(p.GetAsString(), l); |
88 } | 88 } |
89 | 89 |
90 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { | 90 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { |
91 WriteParam(m, p.patterns()); | 91 WriteParam(m, p.patterns()); |
92 } | 92 } |
93 | 93 |
94 bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, | 94 bool ParamTraits<URLPatternSet>::Read(const Message* m, PickleIterator* iter, |
95 param_type* p) { | 95 param_type* p) { |
96 std::set<URLPattern> patterns; | 96 std::set<URLPattern> patterns; |
97 if (!ReadParam(m, iter, &patterns)) | 97 if (!ReadParam(m, iter, &patterns)) |
98 return false; | 98 return false; |
99 | 99 |
100 for (std::set<URLPattern>::iterator i = patterns.begin(); | 100 for (std::set<URLPattern>::iterator i = patterns.begin(); |
101 i != patterns.end(); ++i) | 101 i != patterns.end(); ++i) |
102 p->AddPattern(*i); | 102 p->AddPattern(*i); |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { | 106 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { |
107 LogParam(p.patterns(), l); | 107 LogParam(p.patterns(), l); |
108 } | 108 } |
109 | 109 |
110 void ParamTraits<ExtensionAPIPermission::ID>::Write( | 110 void ParamTraits<ExtensionAPIPermission::ID>::Write( |
111 Message* m, const param_type& p) { | 111 Message* m, const param_type& p) { |
112 WriteParam(m, static_cast<int>(p)); | 112 WriteParam(m, static_cast<int>(p)); |
113 } | 113 } |
114 | 114 |
115 bool ParamTraits<ExtensionAPIPermission::ID>::Read( | 115 bool ParamTraits<ExtensionAPIPermission::ID>::Read( |
116 const Message* m, void** iter, param_type* p) { | 116 const Message* m, PickleIterator* iter, param_type* p) { |
117 int api_id = -2; | 117 int api_id = -2; |
118 if (!ReadParam(m, iter, &api_id)) | 118 if (!ReadParam(m, iter, &api_id)) |
119 return false; | 119 return false; |
120 | 120 |
121 *p = static_cast<ExtensionAPIPermission::ID>(api_id); | 121 *p = static_cast<ExtensionAPIPermission::ID>(api_id); |
122 return true; | 122 return true; |
123 } | 123 } |
124 | 124 |
125 void ParamTraits<ExtensionAPIPermission::ID>::Log( | 125 void ParamTraits<ExtensionAPIPermission::ID>::Log( |
126 const param_type& p, std::string* l) { | 126 const param_type& p, std::string* l) { |
127 LogParam(static_cast<int>(p), l); | 127 LogParam(static_cast<int>(p), l); |
128 } | 128 } |
129 | 129 |
130 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 130 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
131 const param_type& p) { | 131 const param_type& p) { |
132 WriteParam(m, p.location); | 132 WriteParam(m, p.location); |
133 WriteParam(m, p.path); | 133 WriteParam(m, p.path); |
134 WriteParam(m, *(p.manifest)); | 134 WriteParam(m, *(p.manifest)); |
135 WriteParam(m, p.creation_flags); | 135 WriteParam(m, p.creation_flags); |
136 } | 136 } |
137 | 137 |
138 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, | 138 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, |
139 void** iter, | 139 PickleIterator* iter, |
140 param_type* p) { | 140 param_type* p) { |
141 p->manifest.reset(new DictionaryValue()); | 141 p->manifest.reset(new DictionaryValue()); |
142 return ReadParam(m, iter, &p->location) && | 142 return ReadParam(m, iter, &p->location) && |
143 ReadParam(m, iter, &p->path) && | 143 ReadParam(m, iter, &p->path) && |
144 ReadParam(m, iter, p->manifest.get()) && | 144 ReadParam(m, iter, p->manifest.get()) && |
145 ReadParam(m, iter, &p->creation_flags); | 145 ReadParam(m, iter, &p->creation_flags); |
146 } | 146 } |
147 | 147 |
148 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 148 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
149 std::string* l) { | 149 std::string* l) { |
150 l->append(p.id); | 150 l->append(p.id); |
151 } | 151 } |
152 | 152 |
153 } // namespace IPC | 153 } // namespace IPC |
OLD | NEW |