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

Side by Side Diff: chrome/browser/extensions/permissions_updater.cc

Issue 501273002: Update extension install prompt to reflect withheld permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Permissions helper method, init flag changes in updater Created 6 years, 3 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
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/permissions_updater.h" 5 #include "chrome/browser/extensions/permissions_updater.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (withhold_permissions && iter->ImpliesAllHosts()) 103 if (withhold_permissions && iter->ImpliesAllHosts())
104 withheld->AddPattern(*iter); 104 withheld->AddPattern(*iter);
105 else 105 else
106 granted->AddPattern(*iter); 106 granted->AddPattern(*iter);
107 } 107 }
108 } 108 }
109 109
110 } // namespace 110 } // namespace
111 111
112 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context) 112 PermissionsUpdater::PermissionsUpdater(content::BrowserContext* browser_context)
113 : browser_context_(browser_context) { 113 : browser_context_(browser_context),
114 init_flag_(INIT_FLAG_NONE) {
gpdavis 2014/09/09 20:28:15 How about something like this? The init flag is n
Devlin 2014/09/10 22:00:44 Yeah, we should make another constructor Permissio
gpdavis 2014/09/11 20:09:21 Awesome. Done.
114 } 115 }
115 116
116 PermissionsUpdater::~PermissionsUpdater() {} 117 PermissionsUpdater::~PermissionsUpdater() {}
117 118
118 void PermissionsUpdater::AddPermissions( 119 void PermissionsUpdater::AddPermissions(
119 const Extension* extension, const PermissionSet* permissions) { 120 const Extension* extension, const PermissionSet* permissions) {
120 scoped_refptr<const PermissionSet> existing( 121 scoped_refptr<const PermissionSet> existing(
121 extension->permissions_data()->active_permissions()); 122 extension->permissions_data()->active_permissions());
122 scoped_refptr<PermissionSet> total( 123 scoped_refptr<PermissionSet> total(
123 PermissionSet::CreateUnion(existing.get(), permissions)); 124 PermissionSet::CreateUnion(existing.get(), permissions));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // extensions. 157 // extensions.
157 if (!Manifest::IsUnpackedLocation(extension->location()) && 158 if (!Manifest::IsUnpackedLocation(extension->location()) &&
158 extension->location() != Manifest::INTERNAL) 159 extension->location() != Manifest::INTERNAL)
159 return; 160 return;
160 161
161 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( 162 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions(
162 extension->id(), 163 extension->id(),
163 extension->permissions_data()->active_permissions().get()); 164 extension->permissions_data()->active_permissions().get());
164 } 165 }
165 166
167 void PermissionsUpdater::InitializePermissions(const Extension* extension,
168 InitFlag init_flag) {
169 init_flag_ = init_flag;
170 InitializePermissions(extension);
171 }
172
166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { 173 void PermissionsUpdater::InitializePermissions(const Extension* extension) {
167 scoped_refptr<const PermissionSet> active_permissions = 174 scoped_refptr<const PermissionSet> active_permissions(NULL);
168 ExtensionPrefs::Get(browser_context_) 175 scoped_refptr<const PermissionSet> bounded_active(NULL);
169 ->GetActivePermissions(extension->id()); 176 // If |extension| is a transient dummy extension, we do not want to look for
170 scoped_refptr<const PermissionSet> bounded_active = 177 // it in preferences.
171 GetBoundedActivePermissions(extension, active_permissions); 178 if (init_flag_ & INIT_FLAG_TRANSIENT) {
179 bounded_active = active_permissions =
180 extension->permissions_data()->active_permissions();
181 } else {
182 active_permissions = ExtensionPrefs::Get(browser_context_)
183 ->GetActivePermissions(extension->id());
184 bounded_active = GetBoundedActivePermissions(extension, active_permissions);
185 }
172 186
173 // Withhold permissions only if the switch applies to this extension and the 187 // Withhold permissions only if the switch applies to this extension and the
174 // extension doesn't have the preference to allow scripting on all urls. 188 // extension doesn't have the preference to allow scripting on all urls.
175 bool should_withhold_permissions = 189 bool should_withhold_permissions =
176 util::ScriptsMayRequireActionForExtension(extension) && 190 util::ScriptsMayRequireActionForExtension(extension) &&
177 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); 191 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_);
178 192
179 URLPatternSet granted_explicit_hosts; 193 URLPatternSet granted_explicit_hosts;
180 URLPatternSet withheld_explicit_hosts; 194 URLPatternSet withheld_explicit_hosts;
181 SegregateUrlPermissions(bounded_active->explicit_hosts(), 195 SegregateUrlPermissions(bounded_active->explicit_hosts(),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // TODO(rdevlin.cronin) We should notify the observers/renderer. 293 // TODO(rdevlin.cronin) We should notify the observers/renderer.
280 } 294 }
281 295
282 void PermissionsUpdater::SetPermissions( 296 void PermissionsUpdater::SetPermissions(
283 const Extension* extension, 297 const Extension* extension,
284 const scoped_refptr<const PermissionSet>& active, 298 const scoped_refptr<const PermissionSet>& active,
285 scoped_refptr<const PermissionSet> withheld) { 299 scoped_refptr<const PermissionSet> withheld) {
286 withheld = withheld.get() ? withheld 300 withheld = withheld.get() ? withheld
287 : extension->permissions_data()->withheld_permissions(); 301 : extension->permissions_data()->withheld_permissions();
288 extension->permissions_data()->SetPermissions(active, withheld); 302 extension->permissions_data()->SetPermissions(active, withheld);
289 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( 303 if (init_flag_ & INIT_FLAG_NONE) {
Devlin 2014/09/10 22:00:44 I think more correct would be if (init_flag_ & INI
gpdavis 2014/09/11 20:09:21 I'm not really sure why I didn't do it this way to
290 extension->id(), active.get()); 304 ExtensionPrefs::Get(browser_context_)->SetActivePermissions(
305 extension->id(), active.get());
306 }
291 } 307 }
292 308
293 void PermissionsUpdater::DispatchEvent( 309 void PermissionsUpdater::DispatchEvent(
294 const std::string& extension_id, 310 const std::string& extension_id,
295 const char* event_name, 311 const char* event_name,
296 const PermissionSet* changed_permissions) { 312 const PermissionSet* changed_permissions) {
297 EventRouter* event_router = EventRouter::Get(browser_context_); 313 EventRouter* event_router = EventRouter::Get(browser_context_);
298 if (!event_router) 314 if (!event_router)
299 return; 315 return;
300 316
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 Profile::FromBrowserContext(host->GetBrowserContext()))) { 366 Profile::FromBrowserContext(host->GetBrowserContext()))) {
351 host->Send(new ExtensionMsg_UpdatePermissions(params)); 367 host->Send(new ExtensionMsg_UpdatePermissions(params));
352 } 368 }
353 } 369 }
354 370
355 // Trigger the onAdded and onRemoved events in the extension. 371 // Trigger the onAdded and onRemoved events in the extension.
356 DispatchEvent(extension->id(), event_name, changed); 372 DispatchEvent(extension->id(), event_name, changed);
357 } 373 }
358 374
359 } // namespace extensions 375 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698