OLD | NEW |
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 "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 EventLogEntry log_entry( | 245 EventLogEntry log_entry( |
246 net::NetLog::TYPE_CHROME_EXTENSION_ABORTED_REQUEST, | 246 net::NetLog::TYPE_CHROME_EXTENSION_ABORTED_REQUEST, |
247 make_scoped_refptr( | 247 make_scoped_refptr( |
248 new NetLogExtensionIdParameter((*i)->extension_id))); | 248 new NetLogExtensionIdParameter((*i)->extension_id))); |
249 event_log_entries->push_back(log_entry); | 249 event_log_entries->push_back(log_entry); |
250 break; | 250 break; |
251 } | 251 } |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 // Helper function for MergeOnBeforeRequestResponses() that allows considering | 255 // Helper function for MergeOnBeforeRequestResponses() that allows ignoring |
256 // only data:// urls. These are considered a special case of cancelling a | 256 // all redirects but those to data:// urls and about:blank. This is important |
257 // request. This helper function allows us to ignore all other redirects | 257 // to treat these URLs as "cancel urls", i.e. URLs that extensions redirect |
258 // in case any extension wants to cancel the request by redirecting to a | 258 // to if they want to express that they want to cancel a request. This reduces |
259 // data:// url. | 259 // the number of conflicts that we need to flag, as canceling is considered |
| 260 // a higher precedence operation that redirects. |
260 // Returns whether a redirect occurred. | 261 // Returns whether a redirect occurred. |
261 static bool MergeOnBeforeRequestResponsesHelper( | 262 static bool MergeOnBeforeRequestResponsesHelper( |
262 const EventResponseDeltas& deltas, | 263 const EventResponseDeltas& deltas, |
263 GURL* new_url, | 264 GURL* new_url, |
264 std::set<std::string>* conflicting_extensions, | 265 std::set<std::string>* conflicting_extensions, |
265 EventLogEntries* event_log_entries, | 266 EventLogEntries* event_log_entries, |
266 bool consider_only_data_scheme_urls) { | 267 bool consider_only_cancel_scheme_urls) { |
267 bool redirected = false; | 268 bool redirected = false; |
268 | 269 |
269 EventResponseDeltas::const_iterator delta; | 270 EventResponseDeltas::const_iterator delta; |
270 for (delta = deltas.begin(); delta != deltas.end(); ++delta) { | 271 for (delta = deltas.begin(); delta != deltas.end(); ++delta) { |
271 if ((*delta)->new_url.is_empty()) | 272 if ((*delta)->new_url.is_empty()) |
272 continue; | 273 continue; |
273 if (consider_only_data_scheme_urls && | 274 if (consider_only_cancel_scheme_urls && |
274 !(*delta)->new_url.SchemeIs(chrome::kDataScheme)) { | 275 !(*delta)->new_url.SchemeIs(chrome::kDataScheme) && |
| 276 (*delta)->new_url.spec() != "about:blank") { |
275 continue; | 277 continue; |
276 } | 278 } |
277 | 279 |
278 if (!redirected || *new_url == (*delta)->new_url) { | 280 if (!redirected || *new_url == (*delta)->new_url) { |
279 *new_url = (*delta)->new_url; | 281 *new_url = (*delta)->new_url; |
280 redirected = true; | 282 redirected = true; |
281 EventLogEntry log_entry( | 283 EventLogEntry log_entry( |
282 net::NetLog::TYPE_CHROME_EXTENSION_REDIRECTED_REQUEST, | 284 net::NetLog::TYPE_CHROME_EXTENSION_REDIRECTED_REQUEST, |
283 make_scoped_refptr( | 285 make_scoped_refptr( |
284 new NetLogExtensionIdParameter((*delta)->extension_id))); | 286 new NetLogExtensionIdParameter((*delta)->extension_id))); |
285 event_log_entries->push_back(log_entry); | 287 event_log_entries->push_back(log_entry); |
286 } else { | 288 } else { |
287 conflicting_extensions->insert((*delta)->extension_id); | 289 conflicting_extensions->insert((*delta)->extension_id); |
288 EventLogEntry log_entry( | 290 EventLogEntry log_entry( |
289 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, | 291 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, |
290 make_scoped_refptr( | 292 make_scoped_refptr( |
291 new NetLogExtensionIdParameter((*delta)->extension_id))); | 293 new NetLogExtensionIdParameter((*delta)->extension_id))); |
292 event_log_entries->push_back(log_entry); | 294 event_log_entries->push_back(log_entry); |
293 } | 295 } |
294 } | 296 } |
295 return redirected; | 297 return redirected; |
296 } | 298 } |
297 | 299 |
298 void MergeOnBeforeRequestResponses( | 300 void MergeOnBeforeRequestResponses( |
299 const EventResponseDeltas& deltas, | 301 const EventResponseDeltas& deltas, |
300 GURL* new_url, | 302 GURL* new_url, |
301 std::set<std::string>* conflicting_extensions, | 303 std::set<std::string>* conflicting_extensions, |
302 EventLogEntries* event_log_entries) { | 304 EventLogEntries* event_log_entries) { |
303 | 305 |
304 // First handle only redirects to data:// URLs. These are a special case as | 306 // First handle only redirects to data:// URLs and about:blank. These are a |
305 // they represent a way of cancelling a request. | 307 // special case as they represent a way of cancelling a request. |
306 if (MergeOnBeforeRequestResponsesHelper( | 308 if (MergeOnBeforeRequestResponsesHelper( |
307 deltas, new_url, conflicting_extensions, event_log_entries, true)) { | 309 deltas, new_url, conflicting_extensions, event_log_entries, true)) { |
308 // If any extension cancelled a request by redirecting to a data:// URL, | 310 // If any extension cancelled a request by redirecting to a data:// URL or |
309 // we don't consider the other redirects. | 311 // about:blank, we don't consider the other redirects. |
310 return; | 312 return; |
311 } | 313 } |
312 | 314 |
313 // Handle all other redirects. | 315 // Handle all other redirects. |
314 MergeOnBeforeRequestResponsesHelper( | 316 MergeOnBeforeRequestResponsesHelper( |
315 deltas, new_url, conflicting_extensions, event_log_entries, false); | 317 deltas, new_url, conflicting_extensions, event_log_entries, false); |
316 } | 318 } |
317 | 319 |
318 void MergeOnBeforeSendHeadersResponses( | 320 void MergeOnBeforeSendHeadersResponses( |
319 const EventResponseDeltas& deltas, | 321 const EventResponseDeltas& deltas, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 new NetLogExtensionIdParameter((*delta)->extension_id))); | 540 new NetLogExtensionIdParameter((*delta)->extension_id))); |
539 event_log_entries->push_back(log_entry); | 541 event_log_entries->push_back(log_entry); |
540 *auth_credentials = *(*delta)->auth_credentials; | 542 *auth_credentials = *(*delta)->auth_credentials; |
541 credentials_set = true; | 543 credentials_set = true; |
542 } | 544 } |
543 } | 545 } |
544 return credentials_set; | 546 return credentials_set; |
545 } | 547 } |
546 | 548 |
547 } // namespace extension_web_request_api_helpers | 549 } // namespace extension_web_request_api_helpers |
OLD | NEW |