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 "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() |
12 : location(Extension::INVALID), | 12 : location(Extension::INVALID), |
13 creation_flags(Extension::NO_FLAGS){} | 13 creation_flags(Extension::NO_FLAGS){} |
14 | 14 |
15 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} | 15 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} |
16 | 16 |
17 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 17 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
18 const ExtensionMsg_Loaded_Params& other) | |
19 : manifest(other.manifest), | |
20 location(other.location), | |
21 path(other.path), | |
22 apis(other.apis), | |
23 explicit_hosts(other.explicit_hosts), | |
24 scriptable_hosts(other.scriptable_hosts), | |
25 id(other.id), | |
26 creation_flags(other.creation_flags) {} | |
27 | |
28 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | |
29 const Extension* extension) | 18 const Extension* extension) |
30 : manifest(new DictionaryValue()), | 19 : manifest(extension->manifest()->value()->DeepCopy()), |
31 location(extension->location()), | 20 location(extension->location()), |
32 path(extension->path()), | 21 path(extension->path()), |
33 apis(extension->GetActivePermissions()->apis()), | |
34 explicit_hosts(extension->GetActivePermissions()->explicit_hosts()), | |
35 scriptable_hosts(extension->GetActivePermissions()->scriptable_hosts()), | |
36 id(extension->id()), | 22 id(extension->id()), |
37 creation_flags(extension->creation_flags()) { | 23 creation_flags(extension->creation_flags()) { |
38 // As we need more bits of extension data in the renderer, add more keys to | |
39 // this list. | |
40 const char* kRendererExtensionKeys[] = { | |
41 extension_manifest_keys::kApp, | |
42 extension_manifest_keys::kContentScripts, | |
43 extension_manifest_keys::kIcons, | |
44 extension_manifest_keys::kManifestVersion, | |
45 extension_manifest_keys::kName, | |
46 extension_manifest_keys::kPageAction, | |
47 extension_manifest_keys::kPageActions, | |
48 extension_manifest_keys::kPermissions, | |
49 extension_manifest_keys::kPlatformApp, | |
50 extension_manifest_keys::kPublicKey, | |
51 extension_manifest_keys::kVersion, | |
52 }; | |
53 | |
54 // Copy only the data we need and bypass the manifest type checks. | |
55 DictionaryValue* source = extension->manifest()->value(); | |
56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) { | |
57 Value* temp = NULL; | |
58 if (source->Get(kRendererExtensionKeys[i], &temp)) | |
59 manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy()); | |
60 } | |
61 } | 24 } |
62 | 25 |
63 scoped_refptr<Extension> | 26 scoped_refptr<Extension> |
64 ExtensionMsg_Loaded_Params::ConvertToExtension() const { | 27 ExtensionMsg_Loaded_Params::ConvertToExtension() const { |
65 std::string error; | 28 std::string error; |
66 | 29 |
67 scoped_refptr<Extension> extension( | 30 scoped_refptr<Extension> extension( |
68 Extension::Create(path, location, *manifest, creation_flags, | 31 Extension::Create(path, location, *manifest, creation_flags, |
69 &error)); | 32 &error)); |
70 if (!extension.get()) | 33 if (!extension.get()) |
71 DLOG(ERROR) << "Error deserializing extension: " << error; | 34 DLOG(ERROR) << "Error deserializing extension: " << error; |
72 else | |
73 extension->SetActivePermissions( | |
74 new ExtensionPermissionSet(apis, explicit_hosts, scriptable_hosts)); | |
75 | 35 |
76 return extension; | 36 return extension; |
77 } | 37 } |
78 | 38 |
79 namespace IPC { | 39 namespace IPC { |
80 | 40 |
81 template <> | 41 template <> |
82 struct ParamTraits<Extension::Location> { | 42 struct ParamTraits<Extension::Location> { |
83 typedef Extension::Location param_type; | 43 typedef Extension::Location param_type; |
84 static void Write(Message* m, const param_type& p) { | 44 static void Write(Message* m, const param_type& p) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 const param_type& p, std::string* l) { | 127 const param_type& p, std::string* l) { |
168 LogParam(static_cast<int>(p), l); | 128 LogParam(static_cast<int>(p), l); |
169 } | 129 } |
170 | 130 |
171 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 131 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
172 const param_type& p) { | 132 const param_type& p) { |
173 WriteParam(m, p.location); | 133 WriteParam(m, p.location); |
174 WriteParam(m, p.path); | 134 WriteParam(m, p.path); |
175 WriteParam(m, *(p.manifest)); | 135 WriteParam(m, *(p.manifest)); |
176 WriteParam(m, p.creation_flags); | 136 WriteParam(m, p.creation_flags); |
177 WriteParam(m, p.apis); | |
178 WriteParam(m, p.explicit_hosts); | |
179 WriteParam(m, p.scriptable_hosts); | |
180 } | 137 } |
181 | 138 |
182 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, | 139 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, |
183 void** iter, | 140 void** iter, |
184 param_type* p) { | 141 param_type* p) { |
185 p->manifest.reset(new DictionaryValue()); | 142 p->manifest.reset(new DictionaryValue()); |
186 return ReadParam(m, iter, &p->location) && | 143 return ReadParam(m, iter, &p->location) && |
187 ReadParam(m, iter, &p->path) && | 144 ReadParam(m, iter, &p->path) && |
188 ReadParam(m, iter, p->manifest.get()) && | 145 ReadParam(m, iter, p->manifest.get()) && |
189 ReadParam(m, iter, &p->creation_flags) && | 146 ReadParam(m, iter, &p->creation_flags); |
190 ReadParam(m, iter, &p->apis) && | |
191 ReadParam(m, iter, &p->explicit_hosts) && | |
192 ReadParam(m, iter, &p->scriptable_hosts); | |
193 } | 147 } |
194 | 148 |
195 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 149 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
196 std::string* l) { | 150 std::string* l) { |
197 l->append(p.id); | 151 l->append(p.id); |
198 } | 152 } |
199 | 153 |
200 } // namespace IPC | 154 } // namespace IPC |
OLD | NEW |