OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_MATCHER_UTIL_H_ |
| 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_MATCHER_UTIL_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include "components/subresource_filter/core/common/url_pattern_index.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "extensions/common/api/declarative_net_request/constants.h" |
| 12 |
| 13 namespace net { |
| 14 class URLRequest; |
| 15 } |
| 16 |
| 17 namespace base { |
| 18 class MemoryMappedFile; |
| 19 class FilePath; |
| 20 } |
| 21 |
| 22 class GURL; |
| 23 |
| 24 namespace url { |
| 25 class Origin; |
| 26 } |
| 27 |
| 28 namespace extensions { |
| 29 class InfoMap; |
| 30 |
| 31 namespace declarative_net_request { |
| 32 |
| 33 namespace flat { |
| 34 struct ExtensionIndexedRuleset; |
| 35 struct ExtensionRuleMetadata; |
| 36 } |
| 37 |
| 38 // This is created on the file thread and used on the IO thread. However, |
| 39 // there are no thread safety issues since this is only accessed on a single |
| 40 // thread at a time. |
| 41 class ExtensionIndexedRulesetMatcher { |
| 42 public: |
| 43 // We should ensure that the buffer passed has been verified. |
| 44 explicit ExtensionIndexedRulesetMatcher( |
| 45 std::unique_ptr<base::MemoryMappedFile, |
| 46 content::BrowserThread::DeleteOnFileThread> ruleset_file); |
| 47 |
| 48 bool ShouldBlockRequest(const GURL& url, |
| 49 const url::Origin& first_party_origin, |
| 50 ElementType element_type, |
| 51 bool is_third_party); |
| 52 |
| 53 private: |
| 54 using UrlPatternIndexMatcher = subresource_filter::UrlPatternIndexMatcher; |
| 55 using ExtensionRuleMetadataList = |
| 56 flatbuffers::Vector<flatbuffers::Offset<flat::ExtensionRuleMetadata>>; |
| 57 |
| 58 // This owns the actual buffer. Are there any potential issues of using |
| 59 // DeleteOnFileThread. |
| 60 std::unique_ptr<base::MemoryMappedFile, |
| 61 content::BrowserThread::DeleteOnFileThread> |
| 62 ruleset_file_; |
| 63 const flat::ExtensionIndexedRuleset* root_; |
| 64 const UrlPatternIndexMatcher blacklist_matcher_; |
| 65 const UrlPatternIndexMatcher whitelist_matcher_; |
| 66 const UrlPatternIndexMatcher redirect_matcher_; |
| 67 const ExtensionRuleMetadataList* extension_metdata_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(ExtensionIndexedRulesetMatcher); |
| 70 }; |
| 71 |
| 72 std::unique_ptr<ExtensionIndexedRulesetMatcher> |
| 73 CreateVerifiedExtensionIndexedRulesetMatcher( |
| 74 const base::FilePath& indexed_ruleset_path); |
| 75 |
| 76 bool ShouldBlockRequest(void* BrowserContext, |
| 77 const InfoMap* info_map, |
| 78 net::URLRequest* request); |
| 79 |
| 80 } // namespace declarative_net_request |
| 81 } // namespace extensions |
| 82 |
| 83 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_MATCHER_UTIL_H_ |
OLD | NEW |