| 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 16 matching lines...) Expand all Loading... |
| 94 } | 103 } |
| 95 | 104 |
| 96 bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, | 105 bool ParamTraits<URLPattern>::Read(const Message* m, void** iter, |
| 97 param_type* p) { | 106 param_type* p) { |
| 98 int valid_schemes; | 107 int valid_schemes; |
| 99 std::string spec; | 108 std::string spec; |
| 100 if (!ReadParam(m, iter, &valid_schemes) || | 109 if (!ReadParam(m, iter, &valid_schemes) || |
| 101 !ReadParam(m, iter, &spec)) | 110 !ReadParam(m, iter, &spec)) |
| 102 return false; | 111 return false; |
| 103 | 112 |
| 113 // TODO(jstritar): We don't want the URLPattern to fail parsing when the |
| 114 // scheme is invalid. Instead, the pattern should parse but it should not |
| 115 // match the invalid patterns. We get around this by setting the valid |
| 116 // schemes after parsing the pattern. Update these method calls once we can |
| 117 // ignore scheme validation with URLPattern parse options. crbug.com/90544 |
| 118 p->SetValidSchemes(URLPattern::SCHEME_ALL); |
| 119 URLPattern::ParseResult result = p->Parse(spec, URLPattern::IGNORE_PORTS); |
| 104 p->SetValidSchemes(valid_schemes); | 120 p->SetValidSchemes(valid_schemes); |
| 105 return URLPattern::PARSE_SUCCESS == p->Parse(spec, URLPattern::IGNORE_PORTS); | 121 return URLPattern::PARSE_SUCCESS == result; |
| 106 } | 122 } |
| 107 | 123 |
| 108 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { | 124 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { |
| 109 LogParam(p.GetAsString(), l); | 125 LogParam(p.GetAsString(), l); |
| 110 } | 126 } |
| 111 | 127 |
| 112 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { | 128 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { |
| 113 WriteParam(m, p.patterns()); | 129 WriteParam(m, p.patterns()); |
| 114 } | 130 } |
| 115 | 131 |
| 116 bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, | 132 bool ParamTraits<URLPatternSet>::Read(const Message* m, void** iter, |
| 117 param_type* p) { | 133 param_type* p) { |
| 118 std::set<URLPattern> patterns; | 134 std::set<URLPattern> patterns; |
| 119 bool success = | 135 if (!ReadParam(m, iter, &patterns)) |
| 120 ReadParam(m, iter, &patterns); | |
| 121 if (!success) | |
| 122 return false; | 136 return false; |
| 123 | 137 |
| 124 for (std::set<URLPattern>::iterator i = patterns.begin(); | 138 for (std::set<URLPattern>::iterator i = patterns.begin(); |
| 125 i != patterns.end(); ++i) | 139 i != patterns.end(); ++i) |
| 126 p->AddPattern(*i); | 140 p->AddPattern(*i); |
| 127 return true; | 141 return true; |
| 128 } | 142 } |
| 129 | 143 |
| 130 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { | 144 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { |
| 131 LogParam(p.patterns(), l); | 145 LogParam(p.patterns(), l); |
| 132 } | 146 } |
| 133 | 147 |
| 148 void ParamTraits<ExtensionAPIPermission::ID>::Write( |
| 149 Message* m, const param_type& p) { |
| 150 WriteParam(m, static_cast<int>(p)); |
| 151 } |
| 152 |
| 153 bool ParamTraits<ExtensionAPIPermission::ID>::Read( |
| 154 const Message* m, void** iter, param_type* p) { |
| 155 int api_id = -2; |
| 156 if (!ReadParam(m, iter, &api_id)) |
| 157 return false; |
| 158 |
| 159 *p = static_cast<ExtensionAPIPermission::ID>(api_id); |
| 160 return true; |
| 161 } |
| 162 |
| 163 void ParamTraits<ExtensionAPIPermission::ID>::Log( |
| 164 const param_type& p, std::string* l) { |
| 165 LogParam(static_cast<int>(p), l); |
| 166 } |
| 167 |
| 134 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 168 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
| 135 const param_type& p) { | 169 const param_type& p) { |
| 136 WriteParam(m, p.location); | 170 WriteParam(m, p.location); |
| 137 WriteParam(m, p.path); | 171 WriteParam(m, p.path); |
| 138 WriteParam(m, *(p.manifest)); | 172 WriteParam(m, *(p.manifest)); |
| 139 WriteParam(m, p.creation_flags); | 173 WriteParam(m, p.creation_flags); |
| 174 WriteParam(m, p.apis); |
| 175 WriteParam(m, p.explicit_hosts); |
| 176 WriteParam(m, p.scriptable_hosts); |
| 140 } | 177 } |
| 141 | 178 |
| 142 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, | 179 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, |
| 143 void** iter, | 180 void** iter, |
| 144 param_type* p) { | 181 param_type* p) { |
| 145 p->manifest.reset(new DictionaryValue()); | 182 p->manifest.reset(new DictionaryValue()); |
| 146 return ReadParam(m, iter, &p->location) && | 183 return ReadParam(m, iter, &p->location) && |
| 147 ReadParam(m, iter, &p->path) && | 184 ReadParam(m, iter, &p->path) && |
| 148 ReadParam(m, iter, p->manifest.get()) && | 185 ReadParam(m, iter, p->manifest.get()) && |
| 149 ReadParam(m, iter, &p->creation_flags); | 186 ReadParam(m, iter, &p->creation_flags) && |
| 187 ReadParam(m, iter, &p->apis) && |
| 188 ReadParam(m, iter, &p->explicit_hosts) && |
| 189 ReadParam(m, iter, &p->scriptable_hosts); |
| 150 } | 190 } |
| 151 | 191 |
| 152 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 192 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
| 153 std::string* l) { | 193 std::string* l) { |
| 154 l->append(p.id); | 194 l->append(p.id); |
| 155 } | 195 } |
| 156 | 196 |
| 157 } // namespace IPC | 197 } // namespace IPC |
| OLD | NEW |