Commit 5b9cb392 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

Restrict ExtensionFunction::context_ to private.

It can already be (and should be) accessed through browser_context()
getter.

Bug: None
Change-Id: If2518a288b48dabd96c121c235d0a08c8e20e85d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166802
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763434}
parent 07b27976
......@@ -343,7 +343,8 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
}
if (property_name == kPropertyPlayStoreStatus) {
if (arc::IsArcAllowedForProfile(Profile::FromBrowserContext(context_)))
if (arc::IsArcAllowedForProfile(
Profile::FromBrowserContext(browser_context())))
return std::make_unique<base::Value>(kPlayStoreStatusEnabled);
if (arc::IsArcAvailable())
return std::make_unique<base::Value>(kPlayStoreStatusAvailable);
......@@ -396,8 +397,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
if (property_name == kPropertyTimezone) {
if (chromeos::system::PerUserTimezoneEnabled()) {
const PrefService::Preference* timezone =
Profile::FromBrowserContext(context_)->GetPrefs()->FindPreference(
prefs::kUserTimezone);
Profile::FromBrowserContext(browser_context())
->GetPrefs()
->FindPreference(prefs::kUserTimezone);
return std::make_unique<base::Value>(timezone->GetValue()->Clone());
}
// TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr.
......@@ -414,8 +416,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str());
if (pref_name) {
return std::make_unique<base::Value>(
Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean(
pref_name));
Profile::FromBrowserContext(browser_context())
->GetPrefs()
->GetBoolean(pref_name));
}
DLOG(ERROR) << "Unknown property request: " << property_name;
......@@ -435,12 +438,13 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() {
std::string param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &param_value));
if (chromeos::system::PerUserTimezoneEnabled()) {
Profile::FromBrowserContext(context_)->GetPrefs()->SetString(
prefs::kUserTimezone, param_value);
Profile::FromBrowserContext(browser_context())
->GetPrefs()
->SetString(prefs::kUserTimezone, param_value);
} else {
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(
Profile::FromBrowserContext(context_));
Profile::FromBrowserContext(browser_context()));
if (user)
chromeos::system::SetSystemTimezone(user, param_value);
}
......@@ -450,9 +454,9 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() {
if (pref_name) {
bool param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &param_value));
Profile::FromBrowserContext(context_)->GetPrefs()->SetBoolean(
pref_name,
param_value);
Profile::FromBrowserContext(browser_context())
->GetPrefs()
->SetBoolean(pref_name, param_value);
} else {
return RespondNow(Error(kPropertyNotFound, param_name));
}
......
......@@ -180,8 +180,8 @@ InputMethodPrivateGetInputMethodsFunction::Run() {
ExtensionFunction::ResponseAction
InputMethodPrivateFetchAllDictionaryWordsFunction::Run() {
SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext(
context_);
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context());
if (!spellcheck) {
return RespondNow(
Error(InformativeError(kErrorSpellCheckNotAvailable, function_name())));
......@@ -205,8 +205,8 @@ InputMethodPrivateAddWordToDictionaryFunction::Run() {
std::unique_ptr<AddWordToDictionary::Params> params(
AddWordToDictionary::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext(
context_);
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context());
if (!spellcheck) {
return RespondNow(
Error(InformativeError(kErrorSpellCheckNotAvailable, function_name())));
......@@ -391,7 +391,7 @@ ExtensionFunction::ResponseAction InputMethodPrivateSetSettingsFunction::Run() {
extensions::events::INPUT_METHOD_PRIVATE_ON_SETTINGS_CHANGED,
OnSettingsChanged::kEventName,
OnSettingsChanged::Create(params->engine_id, params->settings),
context_);
browser_context());
router->BroadcastEvent(std::move(event));
}
......
......@@ -41,7 +41,8 @@ ExtensionFunction::ResponseAction GuestViewInternalCreateGuestFunction::Run() {
if (!guest_view_manager) {
guest_view_manager = GuestViewManager::CreateWithDelegate(
browser_context(),
ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(context_));
ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(
browser_context()));
}
content::WebContents* sender_web_contents = GetSenderWebContents();
......
......@@ -39,7 +39,8 @@ ExtensionFunction::ResponseAction IdleQueryStateFunction::Run() {
threshold = ClampThreshold(threshold);
ui::IdleState state =
IdleManagerFactory::GetForBrowserContext(context_)->QueryState(threshold);
IdleManagerFactory::GetForBrowserContext(browser_context())
->QueryState(threshold);
return RespondNow(OneArgument(IdleManager::CreateIdleValue(state)));
}
......@@ -54,8 +55,8 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold);
IdleManagerFactory::GetForBrowserContext(context_)->SetThreshold(
extension_id(), threshold);
IdleManagerFactory::GetForBrowserContext(browser_context())
->SetThreshold(extension_id(), threshold);
return RespondNow(NoArguments());
}
......@@ -63,7 +64,7 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() {
IdleGetAutoLockDelayFunction::~IdleGetAutoLockDelayFunction() = default;
ExtensionFunction::ResponseAction IdleGetAutoLockDelayFunction::Run() {
const int delay = IdleManagerFactory::GetForBrowserContext(context_)
const int delay = IdleManagerFactory::GetForBrowserContext(browser_context())
->GetAutoLockDelay()
.InSeconds();
return RespondNow(OneArgument(std::make_unique<base::Value>(delay)));
......
......@@ -460,10 +460,6 @@ class ExtensionFunction : public base::RefCountedThreadSafe<
// The arguments to the API. Only non-null if argument were specified.
std::unique_ptr<base::ListValue> args_;
// The BrowserContext of this function's extension.
// TODO(devlin): Grr... protected members. Move this to be private.
content::BrowserContext* context_ = nullptr;
private:
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
......@@ -529,6 +525,9 @@ class ExtensionFunction : public base::RefCountedThreadSafe<
extensions::functions::HistogramValue histogram_value_ =
extensions::functions::UNKNOWN;
// The BrowserContext associated with the requesting renderer
content::BrowserContext* context_ = nullptr;
// The type of the JavaScript context where this call originated.
extensions::Feature::Context source_context_type_ =
extensions::Feature::UNSPECIFIED_CONTEXT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment