| 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 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/singleton.h" | |
| 20 #include "base/memory/weak_ptr.h" | |
| 21 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 22 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 23 #include "extensions/browser/api/declarative/rules_registry.h" | 21 #include "extensions/browser/api/declarative/rules_registry.h" |
| 24 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 22 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
| 25 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 23 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
| 26 #include "extensions/browser/api/web_request/web_request_permissions.h" | 24 #include "extensions/browser/api/web_request/web_request_permissions.h" |
| 27 #include "extensions/browser/browser_context_keyed_api_factory.h" | 25 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 28 #include "extensions/browser/event_router.h" | 26 #include "extensions/browser/event_router.h" |
| 29 #include "extensions/browser/extension_function.h" | 27 #include "extensions/browser/extension_function.h" |
| 30 #include "extensions/common/url_pattern_set.h" | 28 #include "extensions/common/url_pattern_set.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 static const bool kServiceIsNULLWhileTesting = true; | 85 static const bool kServiceIsNULLWhileTesting = true; |
| 88 | 86 |
| 89 content::BrowserContext* browser_context_; | 87 content::BrowserContext* browser_context_; |
| 90 | 88 |
| 91 DISALLOW_COPY_AND_ASSIGN(WebRequestAPI); | 89 DISALLOW_COPY_AND_ASSIGN(WebRequestAPI); |
| 92 }; | 90 }; |
| 93 | 91 |
| 94 // This class observes network events and routes them to the appropriate | 92 // This class observes network events and routes them to the appropriate |
| 95 // extensions listening to those events. All methods must be called on the IO | 93 // extensions listening to those events. All methods must be called on the IO |
| 96 // thread unless otherwise specified. | 94 // thread unless otherwise specified. |
| 97 class ExtensionWebRequestEventRouter | 95 class ExtensionWebRequestEventRouter { |
| 98 : public base::SupportsWeakPtr<ExtensionWebRequestEventRouter> { | |
| 99 public: | 96 public: |
| 100 struct BlockedRequest; | 97 struct BlockedRequest; |
| 101 | 98 |
| 102 enum EventTypes { | 99 enum EventTypes { |
| 103 kInvalidEvent = 0, | 100 kInvalidEvent = 0, |
| 104 kOnBeforeRequest = 1 << 0, | 101 kOnBeforeRequest = 1 << 0, |
| 105 kOnBeforeSendHeaders = 1 << 1, | 102 kOnBeforeSendHeaders = 1 << 1, |
| 106 kOnSendHeaders = 1 << 2, | 103 kOnSendHeaders = 1 << 2, |
| 107 kOnHeadersReceived = 1 << 3, | 104 kOnHeadersReceived = 1 << 3, |
| 108 kOnBeforeRedirect = 1 << 4, | 105 kOnBeforeRedirect = 1 << 4, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 events::HistogramValue histogram_value = events::UNKNOWN; | 361 events::HistogramValue histogram_value = events::UNKNOWN; |
| 365 RequestFilter filter; | 362 RequestFilter filter; |
| 366 int extra_info_spec = 0; | 363 int extra_info_spec = 0; |
| 367 base::WeakPtr<IPC::Sender> ipc_sender; | 364 base::WeakPtr<IPC::Sender> ipc_sender; |
| 368 std::unordered_set<uint64_t> blocked_requests; | 365 std::unordered_set<uint64_t> blocked_requests; |
| 369 | 366 |
| 370 private: | 367 private: |
| 371 DISALLOW_COPY_AND_ASSIGN(EventListener); | 368 DISALLOW_COPY_AND_ASSIGN(EventListener); |
| 372 }; | 369 }; |
| 373 | 370 |
| 374 friend struct base::DefaultSingletonTraits<ExtensionWebRequestEventRouter>; | |
| 375 | |
| 376 using RawListeners = std::vector<EventListener*>; | 371 using RawListeners = std::vector<EventListener*>; |
| 377 using ListenerIDs = std::vector<EventListener::ID>; | 372 using ListenerIDs = std::vector<EventListener::ID>; |
| 378 using Listeners = std::vector<std::unique_ptr<EventListener>>; | 373 using Listeners = std::vector<std::unique_ptr<EventListener>>; |
| 379 using ListenerMapForBrowserContext = std::map<std::string, Listeners>; | 374 using ListenerMapForBrowserContext = std::map<std::string, Listeners>; |
| 380 using ListenerMap = std::map<void*, ListenerMapForBrowserContext>; | 375 using ListenerMap = std::map<void*, ListenerMapForBrowserContext>; |
| 381 using BlockedRequestMap = std::map<uint64_t, BlockedRequest>; | 376 using BlockedRequestMap = std::map<uint64_t, BlockedRequest>; |
| 382 // Map of request_id -> bit vector of EventTypes already signaled | 377 // Map of request_id -> bit vector of EventTypes already signaled |
| 383 using SignaledRequestMap = std::map<uint64_t, int>; | 378 using SignaledRequestMap = std::map<uint64_t, int>; |
| 384 // For each browser_context: a bool indicating whether it is an incognito | 379 // For each browser_context: a bool indicating whether it is an incognito |
| 385 // browser_context, and a pointer to the corresponding (non-)incognito | 380 // browser_context, and a pointer to the corresponding (non-)incognito |
| 386 // browser_context. | 381 // browser_context. |
| 387 using CrossBrowserContextMap = std::map<void*, std::pair<bool, void*>>; | 382 using CrossBrowserContextMap = std::map<void*, std::pair<bool, void*>>; |
| 388 using CallbacksForPageLoad = std::list<base::Closure>; | 383 using CallbacksForPageLoad = std::list<base::Closure>; |
| 389 | 384 |
| 390 ExtensionWebRequestEventRouter(); | 385 ExtensionWebRequestEventRouter(); |
| 391 ~ExtensionWebRequestEventRouter(); | 386 |
| 387 // This instance is leaked. |
| 388 ~ExtensionWebRequestEventRouter() = delete; |
| 392 | 389 |
| 393 // Returns the EventListener with the given |id|, or nullptr. Must be called | 390 // Returns the EventListener with the given |id|, or nullptr. Must be called |
| 394 // from the IO thread. | 391 // from the IO thread. |
| 395 EventListener* FindEventListener(const EventListener::ID& id); | 392 EventListener* FindEventListener(const EventListener::ID& id); |
| 396 | 393 |
| 397 // Returns the EventListener with the given |id| from |listeners|. | 394 // Returns the EventListener with the given |id| from |listeners|. |
| 398 EventListener* FindEventListenerInContainer(const EventListener::ID& id, | 395 EventListener* FindEventListenerInContainer(const EventListener::ID& id, |
| 399 Listeners& listeners); | 396 Listeners& listeners); |
| 400 | 397 |
| 401 // Removes the listener for the given sub-event. Must be called from the IO | 398 // Removes the listener for the given sub-event. Must be called from the IO |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 extensions::QuotaLimitHeuristics* heuristics) const override; | 619 extensions::QuotaLimitHeuristics* heuristics) const override; |
| 623 // Handle quota exceeded gracefully: Only warn the user but still execute the | 620 // Handle quota exceeded gracefully: Only warn the user but still execute the |
| 624 // function. | 621 // function. |
| 625 void OnQuotaExceeded(const std::string& error) override; | 622 void OnQuotaExceeded(const std::string& error) override; |
| 626 ResponseAction Run() override; | 623 ResponseAction Run() override; |
| 627 }; | 624 }; |
| 628 | 625 |
| 629 } // namespace extensions | 626 } // namespace extensions |
| 630 | 627 |
| 631 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 628 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| OLD | NEW |