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

Unified Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc

Issue 1148793008: Check for embedded PAC scripts when migrating proxy pref for DRP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
index f01181a7c2f0870e703b2d7c2a941dfc68422341..22e476ed0c259a70f25a091376983eb74b9dda15 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/base64.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/prefs/pref_service.h"
@@ -59,6 +60,15 @@ bool ContainsDataReductionProxyDefaultHostSuffix(
proxy_rules.proxies_for_https);
}
+// Extract the embedded |pac_script| from the given |pac_url|. Returns true if
+// extraction was successful, otherwise returns false.
+bool GetEmbeddedPacScript(const std::string& pac_url, std::string* pac_script) {
bengr 2015/06/08 18:26:33 Can the pac_script be const? Can it ever be null?
sclittle 2015/06/08 18:47:45 I've updated the comment to clarify that pac_scrip
+ const std::string kPacURLPrefix =
+ "data:application/x-ns-proxy-autoconfig;base64,";
+ return StartsWithASCII(pac_url, kPacURLPrefix, true) &&
+ base::Base64Decode(pac_url.substr(kPacURLPrefix.size()), pac_script);
bengr 2015/06/08 18:26:33 Will the pac always be base64?
sclittle 2015/06/08 18:47:45 Yes, according to the way that the DRP was enabled
+}
+
} // namespace
// The Data Reduction Proxy has been turned into a "best effort" proxy,
@@ -70,6 +80,8 @@ void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs(
PrefService* prefs) {
ProxyPrefMigrationResult proxy_pref_status =
MigrateDataReductionProxyOffProxyPrefsHelper(prefs);
+ LOG(WARNING) << "MigrateDataReductionProxyOffProxyPrefs "
+ << proxy_pref_status;
UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.ProxyPrefMigrationResult",
proxy_pref_status,
DataReductionProxyChromeSettings::PROXY_PREF_MAX);
@@ -98,27 +110,54 @@ DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefsHelper(
prefs->ClearPref(prefs::kProxy);
return PROXY_PREF_CLEARED_MODE_SYSTEM;
}
- if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) != mode)
- return PROXY_PREF_NOT_CLEARED;
- std::string proxy_server;
- if (!dict->GetString("server", &proxy_server))
- return PROXY_PREF_NOT_CLEARED;
- net::ProxyConfig::ProxyRules proxy_rules;
- proxy_rules.ParseFromString(proxy_server);
- // Clear the proxy pref if it matches a currently configured Data Reduction
- // Proxy, or if the proxy host ends with ".googlezip.net", in order to ensure
- // that any DRP in the pref is cleared even if the DRP configuration was
- // changed. See http://crbug.com/476610.
- ProxyPrefMigrationResult rv;
- if (Config()->ContainsDataReductionProxy(proxy_rules))
- rv = PROXY_PREF_CLEARED_DRP;
- else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules))
- rv = PROXY_PREF_CLEARED_GOOGLEZIP;
- else
- return PROXY_PREF_NOT_CLEARED;
- prefs->ClearPref(prefs::kProxy);
- return rv;
+ // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the
+ // proxy pref.
+ if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) {
+ std::string proxy_server;
+ if (!dict->GetString("server", &proxy_server))
+ return PROXY_PREF_NOT_CLEARED;
+ net::ProxyConfig::ProxyRules proxy_rules;
+ proxy_rules.ParseFromString(proxy_server);
+ // Clear the proxy pref if it matches a currently configured Data Reduction
+ // Proxy, or if the proxy host ends with ".googlezip.net", in order to
+ // ensure that any DRP in the pref is cleared even if the DRP configuration
+ // was changed. See http://crbug.com/476610.
+ ProxyPrefMigrationResult rv;
+ if (Config()->ContainsDataReductionProxy(proxy_rules))
+ rv = PROXY_PREF_CLEARED_DRP;
+ else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules))
+ rv = PROXY_PREF_CLEARED_GOOGLEZIP;
+ else
+ return PROXY_PREF_NOT_CLEARED;
+
+ prefs->ClearPref(prefs::kProxy);
+ return rv;
+ }
+
+ // Before M35, the DRP was configured using a PAC script base64 encoded into a
+ // PAC url.
+ if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) {
+ std::string pac_url;
+ std::string pac_script;
+ if (!dict->GetString("pac_url", &pac_url) ||
+ !GetEmbeddedPacScript(pac_url, &pac_script)) {
+ return PROXY_PREF_NOT_CLEARED;
+ }
+
+ // In M35 and earlier, the way of specifying the DRP in a PAC script would
+ // always include the port number after the host even if the port number
+ // could be implied, so searching for ".googlezip.net:" in the PAC script
+ // indicates whether there's a proxy in that PAC script with a host of the
+ // form "*.googlezip.net".
+ if (pac_script.find(".googlezip.net:") == std::string::npos)
+ return PROXY_PREF_NOT_CLEARED;
+
+ prefs->ClearPref(prefs::kProxy);
+ return PROXY_PREF_CLEARED_PAC_GOOGLEZIP;
+ }
+
+ return PROXY_PREF_NOT_CLEARED;
}
DataReductionProxyChromeSettings::DataReductionProxyChromeSettings()

Powered by Google App Engine
This is Rietveld 408576698