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 "extensions/browser/api/web_request/web_request_api.h" | 5 #include "extensions/browser/api/web_request/web_request_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // Returns true if we're in a Public Session. | 345 // Returns true if we're in a Public Session. |
346 bool IsPublicSession() { | 346 bool IsPublicSession() { |
347 #if defined(OS_CHROMEOS) | 347 #if defined(OS_CHROMEOS) |
348 if (chromeos::LoginState::IsInitialized()) { | 348 if (chromeos::LoginState::IsInitialized()) { |
349 return chromeos::LoginState::Get()->IsPublicSessionUser(); | 349 return chromeos::LoginState::Get()->IsPublicSessionUser(); |
350 } | 350 } |
351 #endif | 351 #endif |
352 return false; | 352 return false; |
353 } | 353 } |
354 | 354 |
| 355 // Returns event details for a given request. |
| 356 std::unique_ptr<WebRequestEventDetails> CreateEventDetails( |
| 357 const net::URLRequest* request, |
| 358 int extra_info_spec) { |
| 359 return base::MakeUnique<WebRequestEventDetails>(request, extra_info_spec); |
| 360 } |
| 361 |
355 } // namespace | 362 } // namespace |
356 | 363 |
357 WebRequestAPI::WebRequestAPI(content::BrowserContext* context) | 364 WebRequestAPI::WebRequestAPI(content::BrowserContext* context) |
358 : browser_context_(context) { | 365 : browser_context_(context) { |
359 EventRouter* event_router = EventRouter::Get(browser_context_); | 366 EventRouter* event_router = EventRouter::Get(browser_context_); |
360 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) { | 367 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) { |
361 // Observe the webRequest event. | 368 // Observe the webRequest event. |
362 std::string event_name = kWebRequestEvents[i]; | 369 std::string event_name = kWebRequestEvents[i]; |
363 event_router->RegisterObserver(this, event_name); | 370 event_router->RegisterObserver(this, event_name); |
364 | 371 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 if (!value.HasKey("urls")) | 493 if (!value.HasKey("urls")) |
487 return false; | 494 return false; |
488 | 495 |
489 for (base::DictionaryValue::Iterator it(value); !it.IsAtEnd(); it.Advance()) { | 496 for (base::DictionaryValue::Iterator it(value); !it.IsAtEnd(); it.Advance()) { |
490 if (it.key() == "urls") { | 497 if (it.key() == "urls") { |
491 const base::ListValue* urls_value = NULL; | 498 const base::ListValue* urls_value = NULL; |
492 if (!it.value().GetAsList(&urls_value)) | 499 if (!it.value().GetAsList(&urls_value)) |
493 return false; | 500 return false; |
494 for (size_t i = 0; i < urls_value->GetSize(); ++i) { | 501 for (size_t i = 0; i < urls_value->GetSize(); ++i) { |
495 std::string url; | 502 std::string url; |
496 URLPattern pattern( | 503 URLPattern pattern(URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | |
497 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | | 504 URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE | |
498 URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE | | 505 URLPattern::SCHEME_EXTENSION | |
499 URLPattern::SCHEME_EXTENSION); | 506 URLPattern::SCHEME_WS | URLPattern::SCHEME_WSS); |
500 if (!urls_value->GetString(i, &url) || | 507 if (!urls_value->GetString(i, &url) || |
501 pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { | 508 pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { |
502 *error = ErrorUtils::FormatErrorMessage( | 509 *error = ErrorUtils::FormatErrorMessage( |
503 keys::kInvalidRequestFilterUrl, url); | 510 keys::kInvalidRequestFilterUrl, url); |
504 return false; | 511 return false; |
505 } | 512 } |
506 urls.AddPattern(pattern); | 513 urls.AddPattern(pattern); |
507 } | 514 } |
508 } else if (it.key() == "types") { | 515 } else if (it.key() == "types") { |
509 const base::ListValue* types_value = NULL; | 516 const base::ListValue* types_value = NULL; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 void* browser_context, | 578 void* browser_context, |
572 int rules_registry_id, | 579 int rules_registry_id, |
573 scoped_refptr<WebRequestRulesRegistry> rules_registry) { | 580 scoped_refptr<WebRequestRulesRegistry> rules_registry) { |
574 RulesRegistryKey key(browser_context, rules_registry_id); | 581 RulesRegistryKey key(browser_context, rules_registry_id); |
575 if (rules_registry.get()) | 582 if (rules_registry.get()) |
576 rules_registries_[key] = rules_registry; | 583 rules_registries_[key] = rules_registry; |
577 else | 584 else |
578 rules_registries_.erase(key); | 585 rules_registries_.erase(key); |
579 } | 586 } |
580 | 587 |
581 std::unique_ptr<WebRequestEventDetails> | |
582 ExtensionWebRequestEventRouter::CreateEventDetails( | |
583 const net::URLRequest* request, | |
584 int extra_info_spec) { | |
585 std::unique_ptr<WebRequestEventDetails> event_details( | |
586 new WebRequestEventDetails(request, extra_info_spec)); | |
587 | |
588 return event_details; | |
589 } | |
590 | |
591 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 588 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
592 void* browser_context, | 589 void* browser_context, |
593 const InfoMap* extension_info_map, | 590 const InfoMap* extension_info_map, |
594 net::URLRequest* request, | 591 net::URLRequest* request, |
595 const net::CompletionCallback& callback, | 592 const net::CompletionCallback& callback, |
596 GURL* new_url) { | 593 GURL* new_url) { |
597 ExtensionNavigationUIData* navigation_ui_data = | 594 ExtensionNavigationUIData* navigation_ui_data = |
598 ExtensionsBrowserClient::Get()->GetExtensionNavigationUIData(request); | 595 ExtensionsBrowserClient::Get()->GetExtensionNavigationUIData(request); |
599 if (ShouldHideEvent(browser_context, extension_info_map, request, | 596 if (ShouldHideEvent(browser_context, extension_info_map, request, |
600 navigation_ui_data)) { | 597 navigation_ui_data)) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 if (!browser_context || | 933 if (!browser_context || |
937 (WebRequestPermissions::HideRequest(extension_info_map, request, | 934 (WebRequestPermissions::HideRequest(extension_info_map, request, |
938 navigation_ui_data) && | 935 navigation_ui_data) && |
939 !WasSignaled(*request))) { | 936 !WasSignaled(*request))) { |
940 return; | 937 return; |
941 } | 938 } |
942 | 939 |
943 request_time_tracker_->LogRequestEndTime(request->identifier(), | 940 request_time_tracker_->LogRequestEndTime(request->identifier(), |
944 base::Time::Now()); | 941 base::Time::Now()); |
945 | 942 |
946 DCHECK_EQ(net::OK, net_error); | 943 // See comment in OnErrorOccurred regarding net::ERR_WS_UPGRADE. |
| 944 DCHECK(net_error == net::OK || net_error == net::ERR_WS_UPGRADE); |
947 | 945 |
948 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); | 946 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); |
949 | 947 |
950 ClearPendingCallbacks(request); | 948 ClearPendingCallbacks(request); |
951 | 949 |
952 int extra_info_spec = 0; | 950 int extra_info_spec = 0; |
953 RawListeners listeners = GetMatchingListeners( | 951 RawListeners listeners = GetMatchingListeners( |
954 browser_context, extension_info_map, navigation_ui_data, | 952 browser_context, extension_info_map, navigation_ui_data, |
955 keys::kOnCompletedEvent, request, &extra_info_spec); | 953 keys::kOnCompletedEvent, request, &extra_info_spec); |
956 if (listeners.empty()) | 954 if (listeners.empty()) |
(...skipping 17 matching lines...) Expand all Loading... |
974 OnCompleted(browser_context, extension_info_map, request, | 972 OnCompleted(browser_context, extension_info_map, request, |
975 request->status().error()); | 973 request->status().error()); |
976 } | 974 } |
977 | 975 |
978 void ExtensionWebRequestEventRouter::OnErrorOccurred( | 976 void ExtensionWebRequestEventRouter::OnErrorOccurred( |
979 void* browser_context, | 977 void* browser_context, |
980 const InfoMap* extension_info_map, | 978 const InfoMap* extension_info_map, |
981 net::URLRequest* request, | 979 net::URLRequest* request, |
982 bool started, | 980 bool started, |
983 int net_error) { | 981 int net_error) { |
| 982 // When WebSocket handshake request finishes, URLRequest is cancelled with an |
| 983 // ERR_WS_UPGRADE code (see WebSocketStreamRequestImpl::PerformUpgrade). |
| 984 // WebRequest API reports this as a completed request. |
| 985 if (net_error == net::ERR_WS_UPGRADE) { |
| 986 OnCompleted(browser_context, extension_info_map, request, net_error); |
| 987 return; |
| 988 } |
| 989 |
984 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); | 990 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); |
985 if (!client) { | 991 if (!client) { |
986 // |client| could be NULL during shutdown. | 992 // |client| could be NULL during shutdown. |
987 return; | 993 return; |
988 } | 994 } |
989 ExtensionNavigationUIData* navigation_ui_data = | 995 ExtensionNavigationUIData* navigation_ui_data = |
990 client->GetExtensionNavigationUIData(request); | 996 client->GetExtensionNavigationUIData(request); |
991 // We hide events from the system context as well as sensitive requests. | 997 // We hide events from the system context as well as sensitive requests. |
992 // However, if the request first became sensitive after redirecting we have | 998 // However, if the request first became sensitive after redirecting we have |
993 // already signaled it and thus we have to signal the end of it. This is | 999 // already signaled it and thus we have to signal the end of it. This is |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 deltas.sort(&helpers::InDecreasingExtensionInstallationTimeOrder); | 1805 deltas.sort(&helpers::InDecreasingExtensionInstallationTimeOrder); |
1800 | 1806 |
1801 bool canceled = false; | 1807 bool canceled = false; |
1802 helpers::MergeCancelOfResponses(blocked_request.response_deltas, &canceled, | 1808 helpers::MergeCancelOfResponses(blocked_request.response_deltas, &canceled, |
1803 blocked_request.net_log); | 1809 blocked_request.net_log); |
1804 | 1810 |
1805 WarningSet warnings; | 1811 WarningSet warnings; |
1806 if (blocked_request.event == kOnBeforeRequest) { | 1812 if (blocked_request.event == kOnBeforeRequest) { |
1807 CHECK(!blocked_request.callback.is_null()); | 1813 CHECK(!blocked_request.callback.is_null()); |
1808 helpers::MergeOnBeforeRequestResponses( | 1814 helpers::MergeOnBeforeRequestResponses( |
1809 blocked_request.response_deltas, | 1815 blocked_request.request->url(), blocked_request.response_deltas, |
1810 blocked_request.new_url, | 1816 blocked_request.new_url, &warnings, blocked_request.net_log); |
1811 &warnings, | |
1812 blocked_request.net_log); | |
1813 } else if (blocked_request.event == kOnBeforeSendHeaders) { | 1817 } else if (blocked_request.event == kOnBeforeSendHeaders) { |
1814 CHECK(!blocked_request.callback.is_null()); | 1818 CHECK(!blocked_request.callback.is_null()); |
1815 helpers::MergeOnBeforeSendHeadersResponses( | 1819 helpers::MergeOnBeforeSendHeadersResponses( |
1816 blocked_request.response_deltas, | 1820 blocked_request.response_deltas, |
1817 blocked_request.request_headers, | 1821 blocked_request.request_headers, |
1818 &warnings, | 1822 &warnings, |
1819 blocked_request.net_log); | 1823 blocked_request.net_log); |
1820 } else if (blocked_request.event == kOnHeadersReceived) { | 1824 } else if (blocked_request.event == kOnHeadersReceived) { |
1821 CHECK(!blocked_request.callback.is_null()); | 1825 CHECK(!blocked_request.callback.is_null()); |
1822 helpers::MergeOnHeadersReceivedResponses( | 1826 helpers::MergeOnHeadersReceivedResponses( |
1823 blocked_request.response_deltas, | 1827 blocked_request.request->url(), blocked_request.response_deltas, |
1824 blocked_request.original_response_headers.get(), | 1828 blocked_request.original_response_headers.get(), |
1825 blocked_request.override_response_headers, | 1829 blocked_request.override_response_headers, blocked_request.new_url, |
1826 blocked_request.new_url, | 1830 &warnings, blocked_request.net_log); |
1827 &warnings, | |
1828 blocked_request.net_log); | |
1829 } else if (blocked_request.event == kOnAuthRequired) { | 1831 } else if (blocked_request.event == kOnAuthRequired) { |
1830 CHECK(blocked_request.callback.is_null()); | 1832 CHECK(blocked_request.callback.is_null()); |
1831 CHECK(!blocked_request.auth_callback.is_null()); | 1833 CHECK(!blocked_request.auth_callback.is_null()); |
1832 credentials_set = helpers::MergeOnAuthRequiredResponses( | 1834 credentials_set = helpers::MergeOnAuthRequiredResponses( |
1833 blocked_request.response_deltas, | 1835 blocked_request.response_deltas, |
1834 blocked_request.auth_credentials, | 1836 blocked_request.auth_credentials, |
1835 &warnings, | 1837 &warnings, |
1836 blocked_request.net_log); | 1838 blocked_request.net_log); |
1837 } else { | 1839 } else { |
1838 NOTREACHED(); | 1840 NOTREACHED(); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 // Since EventListeners are segmented by browser_context, check that | 2390 // Since EventListeners are segmented by browser_context, check that |
2389 // last, as it is exceedingly unlikely to be different. | 2391 // last, as it is exceedingly unlikely to be different. |
2390 return extension_id == that.extension_id && | 2392 return extension_id == that.extension_id && |
2391 sub_event_name == that.sub_event_name && | 2393 sub_event_name == that.sub_event_name && |
2392 web_view_instance_id == that.web_view_instance_id && | 2394 web_view_instance_id == that.web_view_instance_id && |
2393 embedder_process_id == that.embedder_process_id && | 2395 embedder_process_id == that.embedder_process_id && |
2394 browser_context == that.browser_context; | 2396 browser_context == that.browser_context; |
2395 } | 2397 } |
2396 | 2398 |
2397 } // namespace extensions | 2399 } // namespace extensions |
OLD | NEW |