Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Side by Side Diff: chrome/common/extensions/extension_messages.cc

Issue 6735004: Move extension messages to their own file and add a RenderViewObserver to start moving the extens... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension_messages.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/extension_messages.h"
6
7 #include "chrome/common/extensions/extension_constants.h"
8 #include "content/common/common_param_traits.h"
9
10 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params()
11 : location(Extension::INVALID) {
12 }
13
14 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {
15 }
16
17 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
18 const ExtensionMsg_Loaded_Params& other)
19 : manifest(other.manifest->DeepCopy()),
20 location(other.location),
21 path(other.path),
22 id(other.id) {
23 }
24
25 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params(
26 const Extension* extension)
27 : manifest(new DictionaryValue()),
28 location(extension->location()),
29 path(extension->path()),
30 id(extension->id()) {
31 // As we need more bits of extension data in the renderer, add more keys to
32 // this list.
33 const char* kRendererExtensionKeys[] = {
34 extension_manifest_keys::kPublicKey,
35 extension_manifest_keys::kName,
36 extension_manifest_keys::kVersion,
37 extension_manifest_keys::kIcons,
38 extension_manifest_keys::kPermissions,
39 extension_manifest_keys::kApp
40 };
41
42 // Copy only the data we need.
43 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRendererExtensionKeys); ++i) {
44 Value* temp = NULL;
45 if (extension->manifest_value()->Get(kRendererExtensionKeys[i], &temp))
46 manifest->Set(kRendererExtensionKeys[i], temp->DeepCopy());
47 }
48 }
49
50 scoped_refptr<Extension>
51 ExtensionMsg_Loaded_Params::ConvertToExtension() const {
52 // Extensions that are loaded unpacked won't have a key.
53 const bool kRequireKey = false;
54
55 // The extension may have been loaded in a way that does not require
56 // strict error checks to pass. Do not do strict checks here.
57 const bool kStrictErrorChecks = false;
58 std::string error;
59
60 scoped_refptr<Extension> extension(
61 Extension::Create(path, location, *manifest, kRequireKey,
62 kStrictErrorChecks, &error));
63 if (!extension.get())
64 LOG(ERROR) << "Error deserializing extension: " << error;
65
66 return extension;
67 }
68
69 namespace IPC {
70
71 template <>
72 struct ParamTraits<Extension::Location> {
73 typedef Extension::Location param_type;
74 static void Write(Message* m, const param_type& p) {
75 int val = static_cast<int>(p);
76 WriteParam(m, val);
77 }
78 static bool Read(const Message* m, void** iter, param_type* p) {
79 int val = 0;
80 if (!ReadParam(m, iter, &val) ||
81 val < Extension::INVALID ||
82 val >= Extension::NUM_LOCATIONS)
83 return false;
84 *p = static_cast<param_type>(val);
85 return true;
86 }
87 static void Log(const param_type& p, std::string* l) {
88 ParamTraits<int>::Log(static_cast<int>(p), l);
89 }
90 };
91
92 void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) {
93 WriteParam(m, p.valid_schemes());
94 WriteParam(m, p.GetAsString());
95 }
96
97 bool ParamTraits<URLPattern>::Read(const Message* m, void** iter,
98 param_type* p) {
99 int valid_schemes;
100 std::string spec;
101 if (!ReadParam(m, iter, &valid_schemes) ||
102 !ReadParam(m, iter, &spec))
103 return false;
104
105 p->set_valid_schemes(valid_schemes);
106 return URLPattern::PARSE_SUCCESS == p->Parse(spec, URLPattern::PARSE_LENIENT);
107 }
108
109 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) {
110 LogParam(p.GetAsString(), l);
111 }
112
113 void ParamTraits<ExtensionExtent>::Write(Message* m, const param_type& p) {
114 WriteParam(m, p.patterns());
115 }
116
117 bool ParamTraits<ExtensionExtent>::Read(const Message* m, void** iter,
118 param_type* p) {
119 std::vector<URLPattern> patterns;
120 bool success =
121 ReadParam(m, iter, &patterns);
122 if (!success)
123 return false;
124
125 for (size_t i = 0; i < patterns.size(); ++i)
126 p->AddPattern(patterns[i]);
127 return true;
128 }
129
130 void ParamTraits<ExtensionExtent>::Log(const param_type& p, std::string* l) {
131 LogParam(p.patterns(), l);
132 }
133
134 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m,
135 const param_type& p) {
136 WriteParam(m, p.location);
137 WriteParam(m, p.path);
138 WriteParam(m, *(p.manifest));
139 }
140
141 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m,
142 void** iter,
143 param_type* p) {
144 p->manifest.reset(new DictionaryValue());
145 return ReadParam(m, iter, &p->location) &&
146 ReadParam(m, iter, &p->path) &&
147 ReadParam(m, iter, p->manifest.get());
148 }
149
150 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p,
151 std::string* l) {
152 l->append(p.id);
153 }
154
155 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_messages.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698