OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extension_util.h" | 5 #include "chrome/browser/extensions/extension_util.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_sync_service.h" | 11 #include "chrome/browser/extensions/extension_sync_service.h" |
| 12 #include "chrome/browser/extensions/permissions_updater.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 14 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 16 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
16 #include "chrome/common/extensions/sync_helper.h" | 17 #include "chrome/common/extensions/sync_helper.h" |
17 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
18 #include "extensions/browser/extension_prefs.h" | 19 #include "extensions/browser/extension_prefs.h" |
19 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
21 #include "extensions/browser/extension_util.h" | 22 #include "extensions/browser/extension_util.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return ExtensionPrefs::Get(context)->ReadPrefAsBoolean( | 177 return ExtensionPrefs::Get(context)->ReadPrefAsBoolean( |
177 extension_id, | 178 extension_id, |
178 kExtensionAllowedOnAllUrlsPrefName, | 179 kExtensionAllowedOnAllUrlsPrefName, |
179 &allowed) && | 180 &allowed) && |
180 allowed; | 181 allowed; |
181 } | 182 } |
182 | 183 |
183 void SetAllowedScriptingOnAllUrls(const std::string& extension_id, | 184 void SetAllowedScriptingOnAllUrls(const std::string& extension_id, |
184 content::BrowserContext* context, | 185 content::BrowserContext* context, |
185 bool allowed) { | 186 bool allowed) { |
| 187 if (allowed == AllowedScriptingOnAllUrls(extension_id, context)) |
| 188 return; // Nothing to do here. |
| 189 |
186 ExtensionPrefs::Get(context)->UpdateExtensionPref( | 190 ExtensionPrefs::Get(context)->UpdateExtensionPref( |
187 extension_id, | 191 extension_id, |
188 kExtensionAllowedOnAllUrlsPrefName, | 192 kExtensionAllowedOnAllUrlsPrefName, |
189 allowed ? new base::FundamentalValue(true) : NULL); | 193 allowed ? new base::FundamentalValue(true) : NULL); |
| 194 |
| 195 const Extension* extension = |
| 196 ExtensionRegistry::Get(context)->enabled_extensions().GetByID( |
| 197 extension_id); |
| 198 if (extension) { |
| 199 PermissionsUpdater updater(context); |
| 200 if (allowed) |
| 201 updater.GrantWithheldImpliedAllHosts(extension); |
| 202 else |
| 203 updater.WithholdImpliedAllHosts(extension); |
| 204 } |
190 } | 205 } |
191 | 206 |
192 bool IsAppLaunchable(const std::string& extension_id, | 207 bool IsAppLaunchable(const std::string& extension_id, |
193 content::BrowserContext* context) { | 208 content::BrowserContext* context) { |
194 int reason = ExtensionPrefs::Get(context)->GetDisableReasons(extension_id); | 209 int reason = ExtensionPrefs::Get(context)->GetDisableReasons(extension_id); |
195 return !((reason & Extension::DISABLE_UNSUPPORTED_REQUIREMENT) || | 210 return !((reason & Extension::DISABLE_UNSUPPORTED_REQUIREMENT) || |
196 (reason & Extension::DISABLE_CORRUPTED)); | 211 (reason & Extension::DISABLE_CORRUPTED)); |
197 } | 212 } |
198 | 213 |
199 bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, | 214 bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 IDR_APP_DEFAULT_ICON); | 304 IDR_APP_DEFAULT_ICON); |
290 } | 305 } |
291 | 306 |
292 const gfx::ImageSkia& GetDefaultExtensionIcon() { | 307 const gfx::ImageSkia& GetDefaultExtensionIcon() { |
293 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 308 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
294 IDR_EXTENSION_DEFAULT_ICON); | 309 IDR_EXTENSION_DEFAULT_ICON); |
295 } | 310 } |
296 | 311 |
297 } // namespace util | 312 } // namespace util |
298 } // namespace extensions | 313 } // namespace extensions |
OLD | NEW |