OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/common_param_traits.h" | 8 #include "content/common/common_param_traits.h" |
9 | 9 |
10 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() | 10 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() |
11 : location(Extension::INVALID) { | 11 : location(Extension::INVALID) { |
12 } | 12 } |
13 | 13 |
14 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() { | 14 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() { |
15 } | 15 } |
16 | 16 |
17 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 17 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
18 const ExtensionMsg_Loaded_Params& other) | 18 const ExtensionMsg_Loaded_Params& other) |
19 : manifest(other.manifest->DeepCopy()), | 19 : manifest(other.manifest->DeepCopy()), |
20 location(other.location), | 20 location(other.location), |
21 path(other.path), | 21 path(other.path), |
22 id(other.id) { | 22 id(other.id) { |
23 } | 23 } |
24 | 24 |
25 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 25 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
26 const Extension* extension) | 26 const Extension* extension, |
27 const ExtensionPermissionSet* active) | |
27 : manifest(new DictionaryValue()), | 28 : manifest(new DictionaryValue()), |
28 location(extension->location()), | 29 location(extension->location()), |
29 path(extension->path()), | 30 path(extension->path()), |
31 apis(active->apis()), | |
32 explicit_hosts(active->explicit_hosts()), | |
33 scriptable_hosts(active->scriptable_hosts()), | |
30 id(extension->id()) { | 34 id(extension->id()) { |
31 // As we need more bits of extension data in the renderer, add more keys to | 35 // As we need more bits of extension data in the renderer, add more keys to |
32 // this list. | 36 // this list. |
33 const char* kRendererExtensionKeys[] = { | 37 const char* kRendererExtensionKeys[] = { |
34 extension_manifest_keys::kPublicKey, | 38 extension_manifest_keys::kPublicKey, |
35 extension_manifest_keys::kName, | 39 extension_manifest_keys::kName, |
36 extension_manifest_keys::kVersion, | 40 extension_manifest_keys::kVersion, |
37 extension_manifest_keys::kIcons, | 41 extension_manifest_keys::kIcons, |
38 extension_manifest_keys::kPageAction, | 42 extension_manifest_keys::kPageAction, |
39 extension_manifest_keys::kPageActions, | 43 extension_manifest_keys::kPageActions, |
(...skipping 16 matching lines...) Expand all Loading... | |
56 | 60 |
57 scoped_refptr<Extension> extension( | 61 scoped_refptr<Extension> extension( |
58 Extension::Create(path, location, *manifest, Extension::NO_FLAGS, | 62 Extension::Create(path, location, *manifest, Extension::NO_FLAGS, |
59 &error)); | 63 &error)); |
60 if (!extension.get()) | 64 if (!extension.get()) |
61 LOG(ERROR) << "Error deserializing extension: " << error; | 65 LOG(ERROR) << "Error deserializing extension: " << error; |
62 | 66 |
63 return extension; | 67 return extension; |
64 } | 68 } |
65 | 69 |
70 const ExtensionPermissionSet* | |
71 ExtensionMsg_Loaded_Params::GetActivePermissions() const { | |
72 return new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts); | |
73 } | |
74 | |
66 namespace IPC { | 75 namespace IPC { |
67 | 76 |
68 template <> | 77 template <> |
69 struct ParamTraits<Extension::Location> { | 78 struct ParamTraits<Extension::Location> { |
70 typedef Extension::Location param_type; | 79 typedef Extension::Location param_type; |
71 static void Write(Message* m, const param_type& p) { | 80 static void Write(Message* m, const param_type& p) { |
72 int val = static_cast<int>(p); | 81 int val = static_cast<int>(p); |
73 WriteParam(m, val); | 82 WriteParam(m, val); |
74 } | 83 } |
75 static bool Read(const Message* m, void** iter, param_type* p) { | 84 static bool Read(const Message* m, void** iter, param_type* p) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 LogParam(p.GetAsString(), l); | 116 LogParam(p.GetAsString(), l); |
108 } | 117 } |
109 | 118 |
110 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { | 119 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { |
111 WriteParam(m, p.patterns()); | 120 WriteParam(m, p.patterns()); |
112 } | 121 } |
113 | 122 |
114 bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, | 123 bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, |
115 param_type* p) { | 124 param_type* p) { |
116 std::set<URLPattern> patterns; | 125 std::set<URLPattern> patterns; |
117 bool success = | 126 if (!ReadParam(m, iter, &patterns)) |
118 ReadParam(m, iter, &patterns); | |
119 if (!success) | |
120 return false; | 127 return false; |
121 | 128 |
122 for (std::set<URLPattern>::iterator i = patterns.begin(); | 129 for (std::set<URLPattern>::iterator i = patterns.begin(); |
123 i != patterns.end(); ++i) | 130 i != patterns.end(); ++i) |
124 p->AddPattern(*i); | 131 p->AddPattern(*i); |
125 return true; | 132 return true; |
126 } | 133 } |
127 | 134 |
128 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { | 135 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { |
129 LogParam(p.patterns(), l); | 136 LogParam(p.patterns(), l); |
130 } | 137 } |
131 | 138 |
139 void ParamTraits<ExtensionAPIPermission::ID>::Write( | |
140 Message* m, const param_type& p) { | |
141 WriteParam(m, (int)p); | |
Mihai Parparita -not on Chrome
2011/07/21 21:18:13
static_cast<int>(p) is the casting style preferred
jstritar
2011/07/22 19:21:55
Done.
| |
142 } | |
143 | |
144 bool ParamTraits<ExtensionAPIPermission::ID>::Read( | |
145 const Message* m, void** iter, param_type* p) { | |
146 int api_id = -2; | |
147 if (!ReadParam(m, iter, &api_id)) | |
148 return false; | |
149 | |
150 *p = static_cast<ExtensionAPIPermission::ID>(api_id); | |
151 return true; | |
152 } | |
153 | |
154 void ParamTraits<ExtensionAPIPermission::ID>::Log( | |
155 const param_type& p, std::string* l) { | |
156 LogParam((int)p, l); | |
157 } | |
158 | |
132 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 159 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
133 const param_type& p) { | 160 const param_type& p) { |
134 WriteParam(m, p.location); | 161 WriteParam(m, p.location); |
135 WriteParam(m, p.path); | 162 WriteParam(m, p.path); |
136 WriteParam(m, *(p.manifest)); | 163 WriteParam(m, *(p.manifest)); |
164 WriteParam(m, p.apis); | |
165 WriteParam(m, p.explicit_hosts); | |
166 WriteParam(m, p.scriptable_hosts); | |
137 } | 167 } |
138 | 168 |
139 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, | 169 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, |
140 void** iter, | 170 void** iter, |
141 param_type* p) { | 171 param_type* p) { |
142 p->manifest.reset(new DictionaryValue()); | 172 p->manifest.reset(new DictionaryValue()); |
143 return ReadParam(m, iter, &p->location) && | 173 return ReadParam(m, iter, &p->location) && |
144 ReadParam(m, iter, &p->path) && | 174 ReadParam(m, iter, &p->path) && |
145 ReadParam(m, iter, p->manifest.get()); | 175 ReadParam(m, iter, p->manifest.get()) && |
176 ReadParam(m, iter, &p->apis) && | |
177 ReadParam(m, iter, &p->explicit_hosts) && | |
178 ReadParam(m, iter, &p->scriptable_hosts); | |
146 } | 179 } |
147 | 180 |
148 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 181 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
149 std::string* l) { | 182 std::string* l) { |
150 l->append(p.id); | 183 l->append(p.id); |
151 } | 184 } |
152 | 185 |
153 } // namespace IPC | 186 } // namespace IPC |
OLD | NEW |