Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: extensions/browser/api/networking_private/networking_private_chromeos.cc

Issue 2471723002: chromeos: networkingPrivate: Set active proxy values (Closed)
Patch Set: Separate out UI changes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/networking_private/networking_private_chromeos.cc
diff --git a/extensions/browser/api/networking_private/networking_private_chromeos.cc b/extensions/browser/api/networking_private/networking_private_chromeos.cc
index 48f13a2ad0f6583d670c19746e57b099d3d785b7..9ce70b280f00d1851aa102ac4d28144517c669d8 100644
--- a/extensions/browser/api/networking_private/networking_private_chromeos.cc
+++ b/extensions/browser/api/networking_private/networking_private_chromeos.cc
@@ -8,6 +8,7 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_manager_client.h"
@@ -25,7 +26,10 @@
#include "chromeos/network/onc/onc_translator.h"
#include "chromeos/network/onc/onc_utils.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
+#include "chromeos/network/proxy/ui_proxy_config.h"
+#include "chromeos/network/proxy/ui_proxy_config_service.h"
#include "components/onc/onc_constants.h"
+#include "components/proxy_config/proxy_prefs.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/api/networking_private/networking_private_api.h"
#include "extensions/browser/extension_registry.h"
@@ -40,6 +44,7 @@ using chromeos::NetworkHandler;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
using chromeos::ShillManagerClient;
+using chromeos::UIProxyConfig;
using extensions::NetworkingPrivateDelegate;
namespace private_api = extensions::api::networking_private;
@@ -214,6 +219,50 @@ const chromeos::DeviceState* GetCellularDeviceState(const std::string& guid) {
return device_state;
}
+base::DictionaryValue* EnsureDictionaryValue(const std::string& key,
michaelpg 2016/11/02 23:55:25 comment, please: ensure dictionary is what? set_ac
stevenjb 2016/11/03 17:48:56 Added comment and split up function.
+ base::DictionaryValue* container,
+ bool set_active) {
+ base::DictionaryValue* dict;
+ if (!container->GetDictionary(key, &dict)) {
+ container->SetWithoutPathExpansion(
+ key, base::MakeUnique<base::DictionaryValue>());
+ container->GetDictionary(key, &dict);
+ }
+ if (set_active) {
+ dict->SetBooleanWithoutPathExpansion(::onc::kAugmentationUserEditable,
+ false);
+ dict->SetStringWithoutPathExpansion(::onc::kAugmentationEffectiveSetting,
+ ::onc::kAugmentationActiveExtension);
+ }
+ return dict;
+}
+
+std::string GetProxySettingsType(const UIProxyConfig::Mode& mode) {
+ switch (mode) {
+ case UIProxyConfig::MODE_DIRECT:
+ return ::onc::proxy::kDirect;
+ case UIProxyConfig::MODE_AUTO_DETECT:
+ return ::onc::proxy::kWPAD;
+ case UIProxyConfig::MODE_PAC_SCRIPT:
+ return ::onc::proxy::kPAC;
+ case UIProxyConfig::MODE_SINGLE_PROXY:
+ case UIProxyConfig::MODE_PROXY_PER_SCHEME:
+ return ::onc::proxy::kManual;
+ }
+ NOTREACHED();
+ return ::onc::proxy::kDirect;
+}
+
+void SetManualProxy(base::DictionaryValue* manual,
+ const std::string& key,
+ const UIProxyConfig::ManualProxy& proxy) {
+ manual->SetStringWithoutPathExpansion(::onc::proxy::kHost,
+ proxy.server.host_port_pair().host());
+ uint16_t port = proxy.server.host_port_pair().port();
+ manual->SetIntegerWithoutPathExpansion(::onc::proxy::kHost,
+ static_cast<int>(port));
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -249,7 +298,8 @@ void NetworkingPrivateChromeOS::GetProperties(
GetManagedConfigurationHandler()->GetProperties(
user_id_hash, service_path,
base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback,
- weak_ptr_factory_.GetWeakPtr(), success_callback),
+ weak_ptr_factory_.GetWeakPtr(), guid, false /* managed */,
+ success_callback),
base::Bind(&NetworkHandlerFailureCallback, failure_callback));
}
@@ -272,7 +322,8 @@ void NetworkingPrivateChromeOS::GetManagedProperties(
GetManagedConfigurationHandler()->GetManagedProperties(
user_id_hash, service_path,
base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback,
- weak_ptr_factory_.GetWeakPtr(), success_callback),
+ weak_ptr_factory_.GetWeakPtr(), guid, true /* managed */,
+ success_callback),
base::Bind(&NetworkHandlerFailureCallback, failure_callback));
}
@@ -625,15 +676,18 @@ bool NetworkingPrivateChromeOS::RequestScan() {
// Private methods
void NetworkingPrivateChromeOS::GetPropertiesCallback(
+ const std::string& guid,
+ bool managed,
const DictionaryCallback& callback,
const std::string& service_path,
const base::DictionaryValue& dictionary) {
std::unique_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy());
AppendThirdPartyProviderName(dictionary_copy.get());
+ if (managed)
+ SetActiveProxyValues(guid, dictionary_copy.get());
callback.Run(std::move(dictionary_copy));
}
-// Populate ThirdPartyVPN.kProviderName for third-party VPNs.
void NetworkingPrivateChromeOS::AppendThirdPartyProviderName(
base::DictionaryValue* dictionary) {
base::DictionaryValue* third_party_vpn =
@@ -656,6 +710,47 @@ void NetworkingPrivateChromeOS::AppendThirdPartyProviderName(
}
}
+void NetworkingPrivateChromeOS::SetActiveProxyValues(
+ const std::string& guid,
+ base::DictionaryValue* dictionary) {
+ chromeos::UIProxyConfigService* ui_proxy_config_service =
+ NetworkHandler::Get()->ui_proxy_config_service();
+ ui_proxy_config_service->UpdateFromPrefs(guid);
+ UIProxyConfig config;
+ ui_proxy_config_service->GetProxyConfig(guid, &config);
+ if (config.state != ProxyPrefs::CONFIG_EXTENSION)
+ return;
+ // Ensure that the ProxySettings dictionary exists.
michaelpg 2016/11/02 23:55:25 nit: line break above
stevenjb 2016/11/03 17:48:56 Done.
+ base::DictionaryValue* proxy_settings = EnsureDictionaryValue(
+ ::onc::network_config::kProxySettings, dictionary, false);
+
+ // Ensure that the ProxySettings.Type dictionary exists.
+ base::DictionaryValue* proxy_type_dict =
+ EnsureDictionaryValue(::onc::network_config::kType, proxy_settings, true);
+ proxy_type_dict->SetStringWithoutPathExpansion(
+ ::onc::kAugmentationActiveSetting, GetProxySettingsType(config.mode));
+ if (config.mode == UIProxyConfig::MODE_SINGLE_PROXY) {
michaelpg 2016/11/02 23:55:25 nit: may be more readable as a switch. I don't nor
michaelpg 2016/11/02 23:55:25 nit: line break above
stevenjb 2016/11/03 17:48:56 There are a couple of modes we don't care about so
+ base::DictionaryValue* manual =
+ EnsureDictionaryValue(::onc::proxy::kManual, proxy_settings, false);
+ SetManualProxy(manual, ::onc::proxy::kHttp, config.single_proxy);
+ manual->RemoveWithoutPathExpansion(::onc::proxy::kHttps, nullptr);
+ manual->RemoveWithoutPathExpansion(::onc::proxy::kFtp, nullptr);
+ manual->RemoveWithoutPathExpansion(::onc::proxy::kSocks, nullptr);
+ } else if (config.mode == UIProxyConfig::MODE_PROXY_PER_SCHEME) {
+ base::DictionaryValue* manual =
+ EnsureDictionaryValue(::onc::proxy::kManual, proxy_settings, false);
+ SetManualProxy(manual, ::onc::proxy::kHttp, config.http_proxy);
+ SetManualProxy(manual, ::onc::proxy::kHttps, config.https_proxy);
+ SetManualProxy(manual, ::onc::proxy::kFtp, config.ftp_proxy);
+ SetManualProxy(manual, ::onc::proxy::kSocks, config.socks_proxy);
+ } else if (config.mode == UIProxyConfig::MODE_PAC_SCRIPT) {
+ base::DictionaryValue* pac =
+ EnsureDictionaryValue(::onc::proxy::kPAC, proxy_settings, true);
+ pac->SetStringWithoutPathExpansion(::onc::kAugmentationActiveSetting,
+ config.automatic_proxy.pac_url.spec());
+ }
+}
+
void NetworkingPrivateChromeOS::ConnectFailureCallback(
const std::string& guid,
const VoidCallback& success_callback,

Powered by Google App Engine
This is Rietveld 408576698