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

Side by Side Diff: chrome/browser/extensions/api/permissions/permissions_api_helpers.cc

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working on adding ManifestPermissionSet to PermissionSet. Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/extensions/api/permissions/permissions_api_helpers.h" 5 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/extensions/api/permissions.h" 10 #include "chrome/common/extensions/api/permissions.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (!value) { 49 if (!value) {
50 permissions->permissions->push_back(i->name()); 50 permissions->permissions->push_back(i->name());
51 } else { 51 } else {
52 std::string name(i->name()); 52 std::string name(i->name());
53 std::string json; 53 std::string json;
54 base::JSONWriter::Write(value.get(), &json); 54 base::JSONWriter::Write(value.get(), &json);
55 permissions->permissions->push_back(name + kDelimiter + json); 55 permissions->permissions->push_back(name + kDelimiter + json);
56 } 56 }
57 } 57 }
58 58
59 // TODO(rpaquay): Deal with ManifestPermissionSet
60
59 permissions->origins.reset(new std::vector<std::string>()); 61 permissions->origins.reset(new std::vector<std::string>());
60 URLPatternSet hosts = set->explicit_hosts(); 62 URLPatternSet hosts = set->explicit_hosts();
61 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) 63 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i)
62 permissions->origins->push_back(i->GetAsString()); 64 permissions->origins->push_back(i->GetAsString());
63 65
64 return scoped_ptr<Permissions>(permissions); 66 return scoped_ptr<Permissions>(permissions);
65 } 67 }
66 68
67 scoped_refptr<PermissionSet> UnpackPermissionSet( 69 scoped_refptr<PermissionSet> UnpackPermissionSet(
68 const Permissions& permissions, 70 const Permissions& permissions,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 if (!permission_info) { 116 if (!permission_info) {
115 *error = ErrorUtils::FormatErrorMessage( 117 *error = ErrorUtils::FormatErrorMessage(
116 kUnknownPermissionError, *it); 118 kUnknownPermissionError, *it);
117 return NULL; 119 return NULL;
118 } 120 }
119 apis.insert(permission_info->id()); 121 apis.insert(permission_info->id());
120 } 122 }
121 } 123 }
122 } 124 }
123 125
126 // TODO(rpaquay): Deal with ManifestPermissionSet
127 ManifestPermissionSet manifest_permissions;
128
124 URLPatternSet origins; 129 URLPatternSet origins;
125 if (permissions.origins.get()) { 130 if (permissions.origins.get()) {
126 for (std::vector<std::string>::iterator it = permissions.origins->begin(); 131 for (std::vector<std::string>::iterator it = permissions.origins->begin();
127 it != permissions.origins->end(); ++it) { 132 it != permissions.origins->end(); ++it) {
128 int allowed_schemes = Extension::kValidHostPermissionSchemes; 133 int allowed_schemes = Extension::kValidHostPermissionSchemes;
129 if (!allow_file_access) 134 if (!allow_file_access)
130 allowed_schemes &= ~URLPattern::SCHEME_FILE; 135 allowed_schemes &= ~URLPattern::SCHEME_FILE;
131 URLPattern origin(allowed_schemes); 136 URLPattern origin(allowed_schemes);
132 URLPattern::ParseResult parse_result = origin.Parse(*it); 137 URLPattern::ParseResult parse_result = origin.Parse(*it);
133 if (URLPattern::PARSE_SUCCESS != parse_result) { 138 if (URLPattern::PARSE_SUCCESS != parse_result) {
134 *error = ErrorUtils::FormatErrorMessage( 139 *error = ErrorUtils::FormatErrorMessage(
135 kInvalidOrigin, 140 kInvalidOrigin,
136 *it, 141 *it,
137 URLPattern::GetParseResultString(parse_result)); 142 URLPattern::GetParseResultString(parse_result));
138 return NULL; 143 return NULL;
139 } 144 }
140 origins.AddPattern(origin); 145 origins.AddPattern(origin);
141 } 146 }
142 } 147 }
143 148
144 return scoped_refptr<PermissionSet>( 149 return scoped_refptr<PermissionSet>(
145 new PermissionSet(apis, origins, URLPatternSet())); 150 new PermissionSet(apis, manifest_permissions, origins, URLPatternSet()));
146 } 151 }
147 152
148 } // namespace permissions_api_helpers 153 } // namespace permissions_api_helpers
149 } // namespace extensions 154 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698