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

Unified Diff: extensions/browser/api/web_request/web_request_api.cc

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: git cl format Created 3 years, 10 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: extensions/browser/api/web_request/web_request_api.cc
diff --git a/extensions/browser/api/web_request/web_request_api.cc b/extensions/browser/api/web_request/web_request_api.cc
index e5cb4cbf13e047581194e448c1cd94eb9c1ab456..b81023248535d3064adaf563327f06568d444b64 100644
--- a/extensions/browser/api/web_request/web_request_api.cc
+++ b/extensions/browser/api/web_request/web_request_api.cc
@@ -352,6 +352,13 @@ bool IsPublicSession() {
return false;
}
+// Returns event details for a given request.
+std::unique_ptr<WebRequestEventDetails> CreateEventDetails(
+ const net::URLRequest* request,
+ int extra_info_spec) {
+ return base::MakeUnique<WebRequestEventDetails>(request, extra_info_spec);
+}
+
} // namespace
WebRequestAPI::WebRequestAPI(content::BrowserContext* context)
@@ -493,10 +500,10 @@ bool ExtensionWebRequestEventRouter::RequestFilter::InitFromValue(
return false;
for (size_t i = 0; i < urls_value->GetSize(); ++i) {
std::string url;
- URLPattern pattern(
- URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS |
- URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE |
- URLPattern::SCHEME_EXTENSION);
+ URLPattern pattern(URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS |
+ URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE |
+ URLPattern::SCHEME_EXTENSION |
+ URLPattern::SCHEME_WS | URLPattern::SCHEME_WSS);
if (!urls_value->GetString(i, &url) ||
pattern.Parse(url) != URLPattern::PARSE_SUCCESS) {
*error = ErrorUtils::FormatErrorMessage(
@@ -578,16 +585,6 @@ void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
rules_registries_.erase(key);
}
-std::unique_ptr<WebRequestEventDetails>
-ExtensionWebRequestEventRouter::CreateEventDetails(
- const net::URLRequest* request,
- int extra_info_spec) {
- std::unique_ptr<WebRequestEventDetails> event_details(
- new WebRequestEventDetails(request, extra_info_spec));
-
- return event_details;
-}
-
int ExtensionWebRequestEventRouter::OnBeforeRequest(
void* browser_context,
const InfoMap* extension_info_map,
@@ -943,7 +940,8 @@ void ExtensionWebRequestEventRouter::OnCompleted(
request_time_tracker_->LogRequestEndTime(request->identifier(),
base::Time::Now());
- DCHECK_EQ(net::OK, net_error);
+ // See comment in OnErrorOccurred regarding net::ERR_WS_UPGRADE.
+ DCHECK(net_error == net::OK || net_error == net::ERR_WS_UPGRADE);
DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted));
@@ -981,6 +979,14 @@ void ExtensionWebRequestEventRouter::OnErrorOccurred(
net::URLRequest* request,
bool started,
int net_error) {
+ // When WebSocket handshake request finishes, URLRequest is cancelled with an
+ // ERR_WS_UPGRADE code (see WebSocketStreamRequestImpl::PerformUpgrade).
+ // WebRequest API reports this as a completed request.
+ if (net_error == net::ERR_WS_UPGRADE) {
+ OnCompleted(browser_context, extension_info_map, request, net_error);
+ return;
+ }
+
ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get();
if (!client) {
// |client| could be NULL during shutdown.
@@ -1806,10 +1812,8 @@ int ExtensionWebRequestEventRouter::ExecuteDeltas(
if (blocked_request.event == kOnBeforeRequest) {
CHECK(!blocked_request.callback.is_null());
helpers::MergeOnBeforeRequestResponses(
- blocked_request.response_deltas,
- blocked_request.new_url,
- &warnings,
- blocked_request.net_log);
+ blocked_request.request->url(), blocked_request.response_deltas,
+ blocked_request.new_url, &warnings, blocked_request.net_log);
} else if (blocked_request.event == kOnBeforeSendHeaders) {
CHECK(!blocked_request.callback.is_null());
helpers::MergeOnBeforeSendHeadersResponses(
@@ -1820,12 +1824,10 @@ int ExtensionWebRequestEventRouter::ExecuteDeltas(
} else if (blocked_request.event == kOnHeadersReceived) {
CHECK(!blocked_request.callback.is_null());
helpers::MergeOnHeadersReceivedResponses(
- blocked_request.response_deltas,
+ blocked_request.request->url(), blocked_request.response_deltas,
blocked_request.original_response_headers.get(),
- blocked_request.override_response_headers,
- blocked_request.new_url,
- &warnings,
- blocked_request.net_log);
+ blocked_request.override_response_headers, blocked_request.new_url,
+ &warnings, blocked_request.net_log);
} else if (blocked_request.event == kOnAuthRequired) {
CHECK(blocked_request.callback.is_null());
CHECK(!blocked_request.auth_callback.is_null());
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.h ('k') | extensions/browser/api/web_request/web_request_api_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698