OLD | NEW |
---|---|
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 if (!Manifest::IsUnpackedLocation(extension->location()) && | 137 if (!Manifest::IsUnpackedLocation(extension->location()) && |
138 extension->location() != Manifest::INTERNAL) | 138 extension->location() != Manifest::INTERNAL) |
139 return; | 139 return; |
140 | 140 |
141 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( | 141 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( |
142 extension->id(), | 142 extension->id(), |
143 extension->permissions_data()->active_permissions().get()); | 143 extension->permissions_data()->active_permissions().get()); |
144 } | 144 } |
145 | 145 |
146 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 146 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
147 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); | |
147 scoped_refptr<const PermissionSet> bounded_active = | 148 scoped_refptr<const PermissionSet> bounded_active = |
148 GetBoundedActivePermissions(extension, | 149 GetBoundedActivePermissions(extension, prefs); |
149 ExtensionPrefs::Get(browser_context_)); | |
150 | 150 |
151 // We withhold permissions iff the switch to do so is enabled, the extension | 151 // We withhold permissions iff the switch to do so is enabled, the extension |
152 // shows up in chrome:extensions (so the user can grant withheld permissions), | 152 // shows up in chrome:extensions (so the user can grant withheld permissions), |
153 // the extension is not part of chrome or corporate policy, and also not on | 153 // the extension is not part of chrome or corporate policy, and also not on |
154 // the scripting whitelist. Additionally, we don't withhold if the extension | 154 // the scripting whitelist. Additionally, we don't withhold if the extension |
155 // has the preference to allow scripting on all urls. | 155 // has the preference to allow scripting on all urls. |
156 bool should_withhold_permissions = | 156 bool should_withhold_permissions = |
157 FeatureSwitch::scripts_require_action()->IsEnabled() && | 157 FeatureSwitch::scripts_require_action()->IsEnabled() && |
158 extension->ShouldDisplayInExtensionSettings() && | 158 extension->ShouldDisplayInExtensionSettings() && |
159 !Manifest::IsPolicyLocation(extension->location()) && | 159 !Manifest::IsPolicyLocation(extension->location()) && |
160 !Manifest::IsComponentLocation(extension->location()) && | 160 !Manifest::IsComponentLocation(extension->location()) && |
161 !PermissionsData::CanExecuteScriptEverywhere(extension) && | 161 !PermissionsData::CanExecuteScriptEverywhere(extension) && |
162 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 162 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
163 | 163 |
164 URLPatternSet granted_explicit_hosts; | 164 URLPatternSet granted_explicit_hosts; |
165 URLPatternSet withheld_explicit_hosts; | 165 URLPatternSet withheld_explicit_hosts; |
166 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 166 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
167 should_withhold_permissions, | 167 should_withhold_permissions, |
168 &granted_explicit_hosts, | 168 &granted_explicit_hosts, |
169 &withheld_explicit_hosts); | 169 &withheld_explicit_hosts); |
170 | 170 |
171 URLPatternSet granted_scriptable_hosts; | 171 URLPatternSet granted_scriptable_hosts; |
172 URLPatternSet withheld_scriptable_hosts; | 172 URLPatternSet withheld_scriptable_hosts; |
173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), | 173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), |
174 should_withhold_permissions, | 174 should_withhold_permissions, |
175 &granted_scriptable_hosts, | 175 &granted_scriptable_hosts, |
176 &withheld_scriptable_hosts); | 176 &withheld_scriptable_hosts); |
177 | 177 |
178 // Add in persisted permissions from "Allow All" | |
179 URLPatternSet persisted; | |
180 prefs->GetPersistedPermissions(extension->id(), &persisted); | |
181 for (URLPatternSet::const_iterator iter = persisted.begin(); | |
182 iter != persisted.end(); | |
183 ++iter) { | |
184 granted_scriptable_hosts.AddPattern(*iter); | |
185 LOG(WARNING) << "ADDING PATTERN: " << iter->GetAsString(); | |
186 } | |
gpdavis
2014/07/15 21:56:38
Here we retrieve any persisted permissions and add
| |
187 | |
178 bounded_active = new PermissionSet(bounded_active->apis(), | 188 bounded_active = new PermissionSet(bounded_active->apis(), |
179 bounded_active->manifest_permissions(), | 189 bounded_active->manifest_permissions(), |
180 granted_explicit_hosts, | 190 granted_explicit_hosts, |
181 granted_scriptable_hosts); | 191 granted_scriptable_hosts); |
182 | 192 |
183 scoped_refptr<const PermissionSet> withheld = | 193 scoped_refptr<const PermissionSet> withheld = |
184 new PermissionSet(APIPermissionSet(), | 194 new PermissionSet(APIPermissionSet(), |
185 ManifestPermissionSet(), | 195 ManifestPermissionSet(), |
186 withheld_explicit_hosts, | 196 withheld_explicit_hosts, |
187 withheld_scriptable_hosts); | 197 withheld_scriptable_hosts); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 331 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
322 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 332 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
323 } | 333 } |
324 } | 334 } |
325 | 335 |
326 // Trigger the onAdded and onRemoved events in the extension. | 336 // Trigger the onAdded and onRemoved events in the extension. |
327 DispatchEvent(extension->id(), event_name, changed); | 337 DispatchEvent(extension->id(), event_name, changed); |
328 } | 338 } |
329 | 339 |
330 } // namespace extensions | 340 } // namespace extensions |
OLD | NEW |