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( ...@@ -343,7 +343,8 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
} }
if (property_name == kPropertyPlayStoreStatus) { if (property_name == kPropertyPlayStoreStatus) {
if (arc::IsArcAllowedForProfile(Profile::FromBrowserContext(context_))) if (arc::IsArcAllowedForProfile(
Profile::FromBrowserContext(browser_context())))
return std::make_unique<base::Value>(kPlayStoreStatusEnabled); return std::make_unique<base::Value>(kPlayStoreStatusEnabled);
if (arc::IsArcAvailable()) if (arc::IsArcAvailable())
return std::make_unique<base::Value>(kPlayStoreStatusAvailable); return std::make_unique<base::Value>(kPlayStoreStatusAvailable);
...@@ -396,8 +397,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue( ...@@ -396,8 +397,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
if (property_name == kPropertyTimezone) { if (property_name == kPropertyTimezone) {
if (chromeos::system::PerUserTimezoneEnabled()) { if (chromeos::system::PerUserTimezoneEnabled()) {
const PrefService::Preference* timezone = const PrefService::Preference* timezone =
Profile::FromBrowserContext(context_)->GetPrefs()->FindPreference( Profile::FromBrowserContext(browser_context())
prefs::kUserTimezone); ->GetPrefs()
->FindPreference(prefs::kUserTimezone);
return std::make_unique<base::Value>(timezone->GetValue()->Clone()); return std::make_unique<base::Value>(timezone->GetValue()->Clone());
} }
// TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr. // TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr.
...@@ -414,8 +416,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue( ...@@ -414,8 +416,9 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str());
if (pref_name) { if (pref_name) {
return std::make_unique<base::Value>( return std::make_unique<base::Value>(
Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean( Profile::FromBrowserContext(browser_context())
pref_name)); ->GetPrefs()
->GetBoolean(pref_name));
} }
DLOG(ERROR) << "Unknown property request: " << property_name; DLOG(ERROR) << "Unknown property request: " << property_name;
...@@ -435,12 +438,13 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { ...@@ -435,12 +438,13 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() {
std::string param_value; std::string param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &param_value)); EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &param_value));
if (chromeos::system::PerUserTimezoneEnabled()) { if (chromeos::system::PerUserTimezoneEnabled()) {
Profile::FromBrowserContext(context_)->GetPrefs()->SetString( Profile::FromBrowserContext(browser_context())
prefs::kUserTimezone, param_value); ->GetPrefs()
->SetString(prefs::kUserTimezone, param_value);
} else { } else {
const user_manager::User* user = const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile( chromeos::ProfileHelper::Get()->GetUserByProfile(
Profile::FromBrowserContext(context_)); Profile::FromBrowserContext(browser_context()));
if (user) if (user)
chromeos::system::SetSystemTimezone(user, param_value); chromeos::system::SetSystemTimezone(user, param_value);
} }
...@@ -450,9 +454,9 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { ...@@ -450,9 +454,9 @@ ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() {
if (pref_name) { if (pref_name) {
bool param_value; bool param_value;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &param_value)); EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &param_value));
Profile::FromBrowserContext(context_)->GetPrefs()->SetBoolean( Profile::FromBrowserContext(browser_context())
pref_name, ->GetPrefs()
param_value); ->SetBoolean(pref_name, param_value);
} else { } else {
return RespondNow(Error(kPropertyNotFound, param_name)); return RespondNow(Error(kPropertyNotFound, param_name));
} }
......
...@@ -180,8 +180,8 @@ InputMethodPrivateGetInputMethodsFunction::Run() { ...@@ -180,8 +180,8 @@ InputMethodPrivateGetInputMethodsFunction::Run() {
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
InputMethodPrivateFetchAllDictionaryWordsFunction::Run() { InputMethodPrivateFetchAllDictionaryWordsFunction::Run() {
SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext( SpellcheckService* spellcheck =
context_); SpellcheckServiceFactory::GetForContext(browser_context());
if (!spellcheck) { if (!spellcheck) {
return RespondNow( return RespondNow(
Error(InformativeError(kErrorSpellCheckNotAvailable, function_name()))); Error(InformativeError(kErrorSpellCheckNotAvailable, function_name())));
...@@ -205,8 +205,8 @@ InputMethodPrivateAddWordToDictionaryFunction::Run() { ...@@ -205,8 +205,8 @@ InputMethodPrivateAddWordToDictionaryFunction::Run() {
std::unique_ptr<AddWordToDictionary::Params> params( std::unique_ptr<AddWordToDictionary::Params> params(
AddWordToDictionary::Params::Create(*args_)); AddWordToDictionary::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext( SpellcheckService* spellcheck =
context_); SpellcheckServiceFactory::GetForContext(browser_context());
if (!spellcheck) { if (!spellcheck) {
return RespondNow( return RespondNow(
Error(InformativeError(kErrorSpellCheckNotAvailable, function_name()))); Error(InformativeError(kErrorSpellCheckNotAvailable, function_name())));
...@@ -391,7 +391,7 @@ ExtensionFunction::ResponseAction InputMethodPrivateSetSettingsFunction::Run() { ...@@ -391,7 +391,7 @@ ExtensionFunction::ResponseAction InputMethodPrivateSetSettingsFunction::Run() {
extensions::events::INPUT_METHOD_PRIVATE_ON_SETTINGS_CHANGED, extensions::events::INPUT_METHOD_PRIVATE_ON_SETTINGS_CHANGED,
OnSettingsChanged::kEventName, OnSettingsChanged::kEventName,
OnSettingsChanged::Create(params->engine_id, params->settings), OnSettingsChanged::Create(params->engine_id, params->settings),
context_); browser_context());
router->BroadcastEvent(std::move(event)); router->BroadcastEvent(std::move(event));
} }
......
...@@ -41,7 +41,8 @@ ExtensionFunction::ResponseAction GuestViewInternalCreateGuestFunction::Run() { ...@@ -41,7 +41,8 @@ ExtensionFunction::ResponseAction GuestViewInternalCreateGuestFunction::Run() {
if (!guest_view_manager) { if (!guest_view_manager) {
guest_view_manager = GuestViewManager::CreateWithDelegate( guest_view_manager = GuestViewManager::CreateWithDelegate(
browser_context(), browser_context(),
ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(context_)); ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(
browser_context()));
} }
content::WebContents* sender_web_contents = GetSenderWebContents(); content::WebContents* sender_web_contents = GetSenderWebContents();
......
...@@ -39,7 +39,8 @@ ExtensionFunction::ResponseAction IdleQueryStateFunction::Run() { ...@@ -39,7 +39,8 @@ ExtensionFunction::ResponseAction IdleQueryStateFunction::Run() {
threshold = ClampThreshold(threshold); threshold = ClampThreshold(threshold);
ui::IdleState state = ui::IdleState state =
IdleManagerFactory::GetForBrowserContext(context_)->QueryState(threshold); IdleManagerFactory::GetForBrowserContext(browser_context())
->QueryState(threshold);
return RespondNow(OneArgument(IdleManager::CreateIdleValue(state))); return RespondNow(OneArgument(IdleManager::CreateIdleValue(state)));
} }
...@@ -54,8 +55,8 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() { ...@@ -54,8 +55,8 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold); threshold = ClampThreshold(threshold);
IdleManagerFactory::GetForBrowserContext(context_)->SetThreshold( IdleManagerFactory::GetForBrowserContext(browser_context())
extension_id(), threshold); ->SetThreshold(extension_id(), threshold);
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
...@@ -63,7 +64,7 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() { ...@@ -63,7 +64,7 @@ ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() {
IdleGetAutoLockDelayFunction::~IdleGetAutoLockDelayFunction() = default; IdleGetAutoLockDelayFunction::~IdleGetAutoLockDelayFunction() = default;
ExtensionFunction::ResponseAction IdleGetAutoLockDelayFunction::Run() { ExtensionFunction::ResponseAction IdleGetAutoLockDelayFunction::Run() {
const int delay = IdleManagerFactory::GetForBrowserContext(context_) const int delay = IdleManagerFactory::GetForBrowserContext(browser_context())
->GetAutoLockDelay() ->GetAutoLockDelay()
.InSeconds(); .InSeconds();
return RespondNow(OneArgument(std::make_unique<base::Value>(delay))); return RespondNow(OneArgument(std::make_unique<base::Value>(delay)));
......
...@@ -460,10 +460,6 @@ class ExtensionFunction : public base::RefCountedThreadSafe< ...@@ -460,10 +460,6 @@ class ExtensionFunction : public base::RefCountedThreadSafe<
// The arguments to the API. Only non-null if argument were specified. // The arguments to the API. Only non-null if argument were specified.
std::unique_ptr<base::ListValue> args_; 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: private:
friend struct content::BrowserThread::DeleteOnThread< friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>; content::BrowserThread::UI>;
...@@ -529,6 +525,9 @@ class ExtensionFunction : public base::RefCountedThreadSafe< ...@@ -529,6 +525,9 @@ class ExtensionFunction : public base::RefCountedThreadSafe<
extensions::functions::HistogramValue histogram_value_ = extensions::functions::HistogramValue histogram_value_ =
extensions::functions::UNKNOWN; extensions::functions::UNKNOWN;
// The BrowserContext associated with the requesting renderer
content::BrowserContext* context_ = nullptr;
// The type of the JavaScript context where this call originated. // The type of the JavaScript context where this call originated.
extensions::Feature::Context source_context_type_ = extensions::Feature::Context source_context_type_ =
extensions::Feature::UNSPECIFIED_CONTEXT; 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