Chromium Code Reviews| Index: chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| diff --git a/chrome/browser/extensions/api/content_settings/content_settings_api.cc b/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| index 75351e807674364c4f3dffc7689d539c8e37bdb9..ba7bfd028345f1aa7b56d91e2978ae532ae375c8 100644 |
| --- a/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| +++ b/chrome/browser/extensions/api/content_settings/content_settings_api.cc |
| @@ -21,6 +21,7 @@ |
| #include "chrome/browser/extensions/api/content_settings/content_settings_store.h" |
| #include "chrome/browser/extensions/api/preference/preference_api_constants.h" |
| #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
| +#include "chrome/browser/extensions/chrome_extension_function_details.h" |
| #include "chrome/browser/plugins/plugin_finder.h" |
| #include "chrome/browser/plugins/plugin_installer.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -67,7 +68,8 @@ namespace extensions { |
| namespace helpers = content_settings_helpers; |
| namespace keys = content_settings_api_constants; |
| -bool ContentSettingsContentSettingClearFunction::RunSync() { |
| +ExtensionFunction::ResponseAction |
| +ContentSettingsContentSettingClearFunction::Run() { |
| ContentSettingsType content_type; |
| EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| @@ -85,23 +87,21 @@ bool ContentSettingsContentSettingClearFunction::RunSync() { |
| if (incognito) { |
| // We don't check incognito permissions here, as an extension should be |
| // always allowed to clear its own settings. |
| - } else { |
| + } else if (browser_context()->IsOffTheRecord()) { |
| // Incognito profiles can't access regular mode ever, they only exist in |
| // split mode. |
| - if (GetProfile()->IsOffTheRecord()) { |
| - error_ = keys::kIncognitoContextError; |
| - return false; |
| - } |
| + return RespondNow(Error(keys::kIncognitoContextError)); |
| } |
| scoped_refptr<ContentSettingsStore> store = |
| - ContentSettingsService::Get(GetProfile())->content_settings_store(); |
| + ContentSettingsService::Get(browser_context())->content_settings_store(); |
| store->ClearContentSettingsForExtension(extension_id(), scope); |
| - return true; |
| + return RespondNow(NoArguments()); |
| } |
| -bool ContentSettingsContentSettingGetFunction::RunSync() { |
| +ExtensionFunction::ResponseAction |
| +ContentSettingsContentSettingGetFunction::Run() { |
| ContentSettingsType content_type; |
| EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| @@ -110,18 +110,16 @@ bool ContentSettingsContentSettingGetFunction::RunSync() { |
| GURL primary_url(params->details.primary_url); |
| if (!primary_url.is_valid()) { |
| - error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, |
| - params->details.primary_url); |
| - return false; |
| + return RespondNow( |
| + Error(keys::kInvalidUrlError, params->details.primary_url)); |
| } |
| GURL secondary_url(primary_url); |
| if (params->details.secondary_url.get()) { |
| secondary_url = GURL(*params->details.secondary_url); |
| if (!secondary_url.is_valid()) { |
| - error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, |
| - *params->details.secondary_url); |
| - return false; |
| + return RespondNow( |
| + Error(keys::kInvalidUrlError, *params->details.secondary_url)); |
| } |
| } |
| @@ -132,27 +130,26 @@ bool ContentSettingsContentSettingGetFunction::RunSync() { |
| bool incognito = false; |
| if (params->details.incognito.get()) |
| incognito = *params->details.incognito; |
| - if (incognito && !include_incognito()) { |
| - error_ = pref_keys::kIncognitoErrorMessage; |
| - return false; |
| - } |
| + if (incognito && !include_incognito()) |
| + return RespondNow(Error(pref_keys::kIncognitoErrorMessage)); |
| HostContentSettingsMap* map; |
| content_settings::CookieSettings* cookie_settings; |
| + Profile* profile = ChromeExtensionFunctionDetails(this).GetProfile(); |
|
asargent_no_longer_on_chrome
2016/09/09 05:09:34
Out of curiousity, why do we have this ChromeExten
Devlin
2016/09/09 18:29:04
Excellent question! For some reason, I thought we
|
| if (incognito) { |
| - if (!GetProfile()->HasOffTheRecordProfile()) { |
| + if (!profile->HasOffTheRecordProfile()) { |
| // TODO(bauerb): Allow reading incognito content settings |
| // outside of an incognito session. |
| - error_ = keys::kIncognitoSessionOnlyError; |
| - return false; |
| + return RespondNow(Error(keys::kIncognitoSessionOnlyError)); |
| } |
| map = HostContentSettingsMapFactory::GetForProfile( |
| - GetProfile()->GetOffTheRecordProfile()); |
| - cookie_settings = CookieSettingsFactory::GetForProfile( |
| - GetProfile()->GetOffTheRecordProfile()).get(); |
| + profile->GetOffTheRecordProfile()); |
| + cookie_settings = |
| + CookieSettingsFactory::GetForProfile(profile->GetOffTheRecordProfile()) |
| + .get(); |
| } else { |
| - map = HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| - cookie_settings = CookieSettingsFactory::GetForProfile(GetProfile()).get(); |
| + map = HostContentSettingsMapFactory::GetForProfile(profile); |
| + cookie_settings = CookieSettingsFactory::GetForProfile(profile).get(); |
| } |
| ContentSetting setting; |
| @@ -172,12 +169,11 @@ bool ContentSettingsContentSettingGetFunction::RunSync() { |
| DCHECK(!setting_string.empty()); |
| result->SetString(keys::kContentSettingKey, setting_string); |
| - SetResult(std::move(result)); |
| - |
| - return true; |
| + return RespondNow(OneArgument(std::move(result))); |
| } |
| -bool ContentSettingsContentSettingSetFunction::RunSync() { |
| +ExtensionFunction::ResponseAction |
| +ContentSettingsContentSettingSetFunction::Run() { |
| ContentSettingsType content_type; |
| EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| @@ -188,10 +184,8 @@ bool ContentSettingsContentSettingSetFunction::RunSync() { |
| ContentSettingsPattern primary_pattern = |
| helpers::ParseExtensionPattern(params->details.primary_pattern, |
| &primary_error); |
| - if (!primary_pattern.IsValid()) { |
| - error_ = primary_error; |
| - return false; |
| - } |
| + if (!primary_pattern.IsValid()) |
| + return RespondNow(Error(primary_error)); |
| ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard(); |
| if (params->details.secondary_pattern.get()) { |
| @@ -199,10 +193,8 @@ bool ContentSettingsContentSettingSetFunction::RunSync() { |
| secondary_pattern = |
| helpers::ParseExtensionPattern(*params->details.secondary_pattern, |
| &secondary_error); |
| - if (!secondary_pattern.IsValid()) { |
| - error_ = secondary_error; |
| - return false; |
| - } |
| + if (!secondary_pattern.IsValid()) |
| + return RespondNow(Error(secondary_error)); |
| } |
| std::string resource_identifier; |
| @@ -243,11 +235,9 @@ bool ContentSettingsContentSettingSetFunction::RunSync() { |
| NOTREACHED() << "No human-readable type name defined for this type."; |
| } |
| - error_ = base::StringPrintf( |
| - kUnsupportedDefaultSettingError, |
| - setting_str.c_str(), |
| - readable_type_name.c_str()); |
| - return false; |
| + return RespondNow(Error(base::StringPrintf(kUnsupportedDefaultSettingError, |
| + setting_str.c_str(), |
| + readable_type_name.c_str()))); |
| } |
| ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; |
| @@ -260,31 +250,28 @@ bool ContentSettingsContentSettingSetFunction::RunSync() { |
| if (incognito) { |
| // Regular profiles can't access incognito unless include_incognito is true. |
| - if (!GetProfile()->IsOffTheRecord() && !include_incognito()) { |
| - error_ = pref_keys::kIncognitoErrorMessage; |
| - return false; |
| - } |
| + if (!browser_context()->IsOffTheRecord() && !include_incognito()) |
| + return RespondNow(Error(pref_keys::kIncognitoErrorMessage)); |
| } else { |
| // Incognito profiles can't access regular mode ever, they only exist in |
| // split mode. |
| - if (GetProfile()->IsOffTheRecord()) { |
| - error_ = keys::kIncognitoContextError; |
| - return false; |
| - } |
| + if (browser_context()->IsOffTheRecord()) |
| + return RespondNow(Error(keys::kIncognitoContextError)); |
| } |
| if (scope == kExtensionPrefsScopeIncognitoSessionOnly && |
| - !GetProfile()->HasOffTheRecordProfile()) { |
| - error_ = pref_keys::kIncognitoSessionOnlyErrorMessage; |
| - return false; |
| + !ChromeExtensionFunctionDetails(this) |
| + .GetProfile() |
| + ->HasOffTheRecordProfile()) { |
| + return RespondNow(Error(pref_keys::kIncognitoSessionOnlyErrorMessage)); |
| } |
| scoped_refptr<ContentSettingsStore> store = |
| - ContentSettingsService::Get(GetProfile())->content_settings_store(); |
| + ContentSettingsService::Get(browser_context())->content_settings_store(); |
| store->SetExtensionContentSetting(extension_id(), primary_pattern, |
| secondary_pattern, content_type, |
| resource_identifier, setting, scope); |
| - return true; |
| + return RespondNow(NoArguments()); |
| } |
| bool ContentSettingsContentSettingGetResourceIdentifiersFunction::RunAsync() { |