| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOURCE
_FILTER_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOURCE
_FILTER_H_ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOURCE
_FILTER_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOURCE
_FILTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // Creates a Core and initializes it asynchronously on a |task_runner| using | 75 // Creates a Core and initializes it asynchronously on a |task_runner| using |
| 76 // the supplied initialization |params| and a VerifiedRuleset taken from the | 76 // the supplied initialization |params| and a VerifiedRuleset taken from the |
| 77 // |ruleset_handle|. The core remains owned by |this| object, but lives on | 77 // |ruleset_handle|. The core remains owned by |this| object, but lives on |
| 78 // (and is accessed on) the |task_runner|. | 78 // (and is accessed on) the |task_runner|. |
| 79 // | 79 // |
| 80 // Once the ActivationState for the current frame is calculated, it is | 80 // Once the ActivationState for the current frame is calculated, it is |
| 81 // reported back via |activation_state_callback| on the task runner associated | 81 // reported back via |activation_state_callback| on the task runner associated |
| 82 // with the current thread. If MemoryMappedRuleset is not present or | 82 // with the current thread. If MemoryMappedRuleset is not present or |
| 83 // malformed, then a default ActivationState is reported (with ActivationLevel | 83 // malformed, then a default ActivationState is reported (with ActivationLevel |
| 84 // equal to DISABLED). | 84 // equal to DISABLED). |
| 85 // | |
| 86 // The |first_disallowed_load_callback|, if it is non-null, is invoked on the | |
| 87 // first ReportDisallowedLoad() call. | |
| 88 AsyncDocumentSubresourceFilter( | 85 AsyncDocumentSubresourceFilter( |
| 89 VerifiedRuleset::Handle* ruleset_handle, | 86 VerifiedRuleset::Handle* ruleset_handle, |
| 90 InitializationParams params, | 87 InitializationParams params, |
| 91 base::Callback<void(ActivationState)> activation_state_callback, | 88 base::Callback<void(ActivationState)> activation_state_callback); |
| 92 base::OnceClosure first_disallowed_load_callback); | |
| 93 | 89 |
| 94 ~AsyncDocumentSubresourceFilter(); | 90 ~AsyncDocumentSubresourceFilter(); |
| 95 | 91 |
| 96 // Computes LoadPolicy on a |task_runner| and returns it back to the calling | 92 // Computes LoadPolicy on a |task_runner| and returns it back to the calling |
| 97 // thread via |result_callback|. If MemoryMappedRuleset is not present or | 93 // thread via |result_callback|. If MemoryMappedRuleset is not present or |
| 98 // malformed, then a LoadPolicy::Allow is returned. | 94 // malformed, then a LoadPolicy::Allow is returned. |
| 99 void GetLoadPolicyForSubdocument(const GURL& subdocument_url, | 95 void GetLoadPolicyForSubdocument(const GURL& subdocument_url, |
| 100 LoadPolicyCallback result_callback); | 96 LoadPolicyCallback result_callback); |
| 101 | 97 |
| 102 // Invokes |first_disallowed_load_callback|, if necessary, and posts a task to | 98 // Invokes |first_disallowed_load_callback|, if necessary, and posts a task to |
| 103 // call DocumentSubresourceFilter::reportDisallowedCallback() on the | 99 // call DocumentSubresourceFilter::reportDisallowedCallback() on the |
| 104 // |task_runner|. | 100 // |task_runner|. |
| 105 void ReportDisallowedLoad(); | 101 void ReportDisallowedLoad(); |
| 106 | 102 |
| 103 // Must be called after activation state computation is finished. |
| 104 const ActivationState& activation_state() const { |
| 105 return activation_state_.value(); |
| 106 } |
| 107 |
| 108 // The |first_disallowed_load_callback|, if it is non-null, is invoked on the |
| 109 // first ReportDisallowedLoad() call. |
| 110 void set_first_disallowed_load_callback(base::OnceClosure callback) { |
| 111 first_disallowed_load_callback_ = std::move(callback); |
| 112 } |
| 113 |
| 107 private: | 114 private: |
| 115 void OnActivateStateCalculated( |
| 116 base::Callback<void(ActivationState)> activation_state_callback, |
| 117 ActivationState activation_state); |
| 118 |
| 108 // Note: Raw pointer, |core_| already holds a reference to |task_runner_|. | 119 // Note: Raw pointer, |core_| already holds a reference to |task_runner_|. |
| 109 base::SequencedTaskRunner* task_runner_; | 120 base::SequencedTaskRunner* task_runner_; |
| 110 std::unique_ptr<Core, base::OnTaskRunnerDeleter> core_; | 121 std::unique_ptr<Core, base::OnTaskRunnerDeleter> core_; |
| 111 base::OnceClosure first_disallowed_load_callback_; | 122 base::OnceClosure first_disallowed_load_callback_; |
| 112 | 123 |
| 124 base::Optional<ActivationState> activation_state_; |
| 125 |
| 113 base::ThreadChecker thread_checker_; | 126 base::ThreadChecker thread_checker_; |
| 114 | 127 |
| 128 base::WeakPtrFactory<AsyncDocumentSubresourceFilter> weak_ptr_factory_; |
| 129 |
| 115 DISALLOW_COPY_AND_ASSIGN(AsyncDocumentSubresourceFilter); | 130 DISALLOW_COPY_AND_ASSIGN(AsyncDocumentSubresourceFilter); |
| 116 }; | 131 }; |
| 117 | 132 |
| 118 // Holds a DocumentSubresourceFilter that is created in a deferred manner in | 133 // Holds a DocumentSubresourceFilter that is created in a deferred manner in |
| 119 // Initialize(), provided there is a valid ruleset to work with. | 134 // Initialize(), provided there is a valid ruleset to work with. |
| 120 class AsyncDocumentSubresourceFilter::Core { | 135 class AsyncDocumentSubresourceFilter::Core { |
| 121 public: | 136 public: |
| 122 Core(); | 137 Core(); |
| 123 ~Core(); | 138 ~Core(); |
| 124 | 139 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 139 | 154 |
| 140 base::Optional<DocumentSubresourceFilter> filter_; | 155 base::Optional<DocumentSubresourceFilter> filter_; |
| 141 base::ThreadChecker thread_checker_; | 156 base::ThreadChecker thread_checker_; |
| 142 | 157 |
| 143 DISALLOW_COPY_AND_ASSIGN(Core); | 158 DISALLOW_COPY_AND_ASSIGN(Core); |
| 144 }; | 159 }; |
| 145 | 160 |
| 146 } // namespace subresource_filter | 161 } // namespace subresource_filter |
| 147 | 162 |
| 148 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOU
RCE_FILTER_H_ | 163 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_ASYNC_DOCUMENT_SUBRESOU
RCE_FILTER_H_ |
| OLD | NEW |