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

Side by Side Diff: android_webview/browser/net/aw_request_interceptor.cc

Issue 1544863002: [Android WebView] Implement initial settings and callback support for Service Workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more clean-up Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/net/aw_request_interceptor.h" 5 #include "android_webview/browser/net/aw_request_interceptor.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/aw_contents_io_thread_client.h" 9 #include "android_webview/browser/aw_contents_io_thread_client.h"
10 #include "android_webview/browser/input_stream.h" 10 #include "android_webview/browser/input_stream.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 } 108 }
109 109
110 scoped_ptr<AwContentsIoThreadClient> io_thread_client_; 110 scoped_ptr<AwContentsIoThreadClient> io_thread_client_;
111 Callback callback_; 111 Callback callback_;
112 base::WeakPtrFactory<ShouldInterceptRequestAdaptor> weak_factory_; 112 base::WeakPtrFactory<ShouldInterceptRequestAdaptor> weak_factory_;
113 113
114 DISALLOW_COPY_AND_ASSIGN(ShouldInterceptRequestAdaptor); 114 DISALLOW_COPY_AND_ASSIGN(ShouldInterceptRequestAdaptor);
115 }; 115 };
116 116
117 scoped_ptr<AwContentsIoThreadClient> GetCorrespondingIoThreadClient(
118 net::URLRequest* request) {
119 int render_process_id, render_frame_id;
120 if (!content::ResourceRequestInfo::GetRenderFrameForRequest(
121 request, &render_process_id, &render_frame_id)) {
122 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient();
mnaganov (inactive) 2016/01/12 00:42:03 Are you sure it's safe to assume that if a corresp
timvolodine 2016/01/13 17:07:58 Just checked: regular web workers do have a valid
mnaganov (inactive) 2016/01/13 17:55:27 OK, please then add a comment here explaining why
timvolodine 2016/01/14 19:43:55 Done.
123 }
124
125 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
126 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
127
128 if (!io_thread_client)
129 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient();
130
131 return io_thread_client;
132 }
133
117 } // namespace 134 } // namespace
118 135
119 AwRequestInterceptor::AwRequestInterceptor() {} 136 AwRequestInterceptor::AwRequestInterceptor() {}
120 137
121 AwRequestInterceptor::~AwRequestInterceptor() {} 138 AwRequestInterceptor::~AwRequestInterceptor() {}
122 139
123 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest( 140 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
124 net::URLRequest* request, 141 net::URLRequest* request,
125 net::NetworkDelegate* network_delegate) const { 142 net::NetworkDelegate* network_delegate) const {
126 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 143 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
127 144
128 // MaybeInterceptRequest can be called multiple times for the same request. 145 // MaybeInterceptRequest can be called multiple times for the same request.
129 if (request->GetUserData(kRequestAlreadyHasJobDataKey)) 146 if (request->GetUserData(kRequestAlreadyHasJobDataKey))
130 return nullptr; 147 return nullptr;
131 148
132 int render_process_id, render_frame_id;
133 if (!content::ResourceRequestInfo::GetRenderFrameForRequest(
134 request, &render_process_id, &render_frame_id)) {
135 return nullptr;
136 }
137
138 scoped_ptr<AwContentsIoThreadClient> io_thread_client = 149 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
139 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); 150 GetCorrespondingIoThreadClient(request);
140 151
141 if (!io_thread_client) 152 if (!io_thread_client)
142 return nullptr; 153 return nullptr;
143 154
144 GURL referrer(request->referrer()); 155 GURL referrer(request->referrer());
145 if (referrer.is_valid() && 156 if (referrer.is_valid() &&
146 (!request->is_pending() || request->is_redirecting())) { 157 (!request->is_pending() || request->is_redirecting())) {
147 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer, 158 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer,
148 referrer.spec(), true); 159 referrer.spec(), true);
149 } 160 }
150 request->SetUserData(kRequestAlreadyHasJobDataKey, 161 request->SetUserData(kRequestAlreadyHasJobDataKey,
151 new base::SupportsUserData::Data()); 162 new base::SupportsUserData::Data());
152 return new AndroidStreamReaderURLRequestJob( 163 return new AndroidStreamReaderURLRequestJob(
153 request, network_delegate, 164 request, network_delegate,
154 make_scoped_ptr( 165 make_scoped_ptr(
155 new ShouldInterceptRequestAdaptor(std::move(io_thread_client))), 166 new ShouldInterceptRequestAdaptor(std::move(io_thread_client))),
156 true); 167 true);
157 } 168 }
158 169
159 } // namespace android_webview 170 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698