[ServiceWorker] Don't send the UMA related headers to the ServiceWorker.
Chrome add "X-Chrome-UMA-Enabled" (and sometimes "X-Client-Data") headers while accessing Google servers if UMA is enabled.
This header is added before sending the request to the ServiceWorker.
So the request which is passed to the ServiceWorker contains this header.
If event.request.mode is 'cors' and event.request.headers has "x-chrome-uma-enabled", fetch(event.request) send a CORS preflight request.
This preflight request contains "Access-Control-Request-Headers: x-chrome-uma-enabled" header.
But the response from the Google server doesn't contain "Access-Control-Allow-Headers: x-chrome-uma-enabled" header.
So this fetch fails.
To avoid this problem this patch removes these headers before sending the request to the ServiceWorker.
This patch introduces ServiceWorkerContext::AddExcludedHeadersForFetchEvent() method and changes DevToolsNetworkTransactionFactory to call this method.
BUG=425649
Review URL: https://codereview.chromium.org/666973003
Cr-Commit-Position: refs/heads/master@{#302379}
diff --git a/components/variations/net/variations_http_header_provider.cc b/components/variations/net/variations_http_header_provider.cc
index fa630cf..79a935a 100644
--- a/components/variations/net/variations_http_header_provider.cc
+++ b/components/variations/net/variations_http_header_provider.cc
@@ -4,6 +4,8 @@
#include "components/variations/net/variations_http_header_provider.h"
+#include <set>
+#include <string>
#include <vector>
#include "base/base64.h"
@@ -36,6 +38,9 @@
".ytimg.com",
};
+const char kChromeUMAEnabled[] = "X-Chrome-UMA-Enabled";
+const char kClientData[] = "X-Client-Data";
+
} // namespace
VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() {
@@ -61,7 +66,7 @@
return;
if (uma_enabled)
- headers->SetHeaderIfMissing("X-Chrome-UMA-Enabled", "1");
+ headers->SetHeaderIfMissing(kChromeUMAEnabled, "1");
// Lazily initialize the header, if not already done, before attempting to
// transmit it.
@@ -75,8 +80,7 @@
if (!variation_ids_header_copy.empty()) {
// Note that prior to M33 this header was named X-Chrome-Variations.
- headers->SetHeaderIfMissing("X-Client-Data",
- variation_ids_header_copy);
+ headers->SetHeaderIfMissing(kClientData, variation_ids_header_copy);
}
}
@@ -267,4 +271,12 @@
google_util::ALLOW_NON_STANDARD_PORTS);
}
+std::set<std::string> VariationsHttpHeaderProvider::GetVariationHeaderNames()
+ const {
+ std::set<std::string> headers;
+ headers.insert(kChromeUMAEnabled);
+ headers.insert(kClientData);
+ return headers;
+}
+
} // namespace variations