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

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

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: Fix unittest; add 'websocket' type to WebRequest API. 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_event_details.cc
diff --git a/extensions/browser/api/web_request/web_request_event_details.cc b/extensions/browser/api/web_request/web_request_event_details.cc
index 007fb3f48fcea65808aa937dcd31f847b71fd2c0..af50cf5b8ec7282af8fbed5051a8d9df815a6d75 100644
--- a/extensions/browser/api/web_request/web_request_event_details.cc
+++ b/extensions/browser/api/web_request/web_request_event_details.cc
@@ -9,6 +9,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/websocket_handshake_request_info.h"
#include "content/public/common/child_process_host.h"
#include "extensions/browser/api/web_request/resource_type_ext.h"
#include "extensions/browser/api/web_request/upload_data_presenter.h"
@@ -33,16 +34,28 @@ WebRequestEventDetails::WebRequestEventDetails(const net::URLRequest* request,
: extra_info_spec_(extra_info_spec),
render_process_id_(content::ChildProcessHost::kInvalidUniqueID),
render_frame_id_(MSG_ROUTING_NONE) {
- content::ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
+ DCHECK(request);
+
+ ResourceTypeExt resource_type(request->url().SchemeIsWSOrWSS());
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (info) {
render_process_id_ = info->GetChildID();
render_frame_id_ = info->GetRenderFrameID();
- resource_type = info->GetResourceType();
+ if (!resource_type.is_websocket)
+ resource_type.resource_type = info->GetResourceType();
+ } else if (resource_type.is_websocket) {
+ // TODO(pkalinnikov): Consider embedding WebSocketHandshakeRequestInfo into
+ // UrlRequestUserData.
+ const content::WebSocketHandshakeRequestInfo* ws_info =
+ content::WebSocketHandshakeRequestInfo::ForRequest(request);
+ if (ws_info) {
+ render_process_id_ = ws_info->GetChildId();
+ render_frame_id_ = ws_info->GetRenderFrameId();
+ }
} else {
- // Fallback for requests that are not allocated by a ResourceDispatcherHost,
- // such as the TemplateURLFetcher.
+ // Fallback for requests that are not allocated by a
+ // ResourceDispatcherHost, such as the TemplateURLFetcher.
content::ResourceRequestInfo::GetRenderFrameForRequest(
request, &render_process_id_, &render_frame_id_);
}

Powered by Google App Engine
This is Rietveld 408576698