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