mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:32:44 +00:00 
			
		
		
		
	Browser+Ladybird+LibWeb: Port content filters to String
This commit is contained in:
		
							parent
							
								
									76ae60da15
								
							
						
					
					
						commit
						5089766af6
					
				
					 11 changed files with 23 additions and 22 deletions
				
			
		|  | @ -126,14 +126,15 @@ static ErrorOr<void> load_content_filters() | ||||||
|     auto ad_filter_list = TRY(Core::BufferedFile::create(move(file))); |     auto ad_filter_list = TRY(Core::BufferedFile::create(move(file))); | ||||||
|     auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); |     auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); | ||||||
| 
 | 
 | ||||||
|     Vector<DeprecatedString> patterns; |     Vector<String> patterns; | ||||||
| 
 | 
 | ||||||
|     while (TRY(ad_filter_list->can_read_line())) { |     while (TRY(ad_filter_list->can_read_line())) { | ||||||
|         auto line = TRY(ad_filter_list->read_line(buffer)); |         auto line = TRY(ad_filter_list->read_line(buffer)); | ||||||
|         if (line.is_empty()) |         if (line.is_empty()) | ||||||
|             continue; |             continue; | ||||||
| 
 | 
 | ||||||
|         TRY(patterns.try_append(line)); |         auto pattern = TRY(String::from_utf8(line)); | ||||||
|  |         TRY(patterns.try_append(move(pattern))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto& content_filter = Web::ContentFilter::the(); |     auto& content_filter = Web::ContentFilter::the(); | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ namespace Browser { | ||||||
| extern DeprecatedString g_home_url; | extern DeprecatedString g_home_url; | ||||||
| extern DeprecatedString g_new_tab_url; | extern DeprecatedString g_new_tab_url; | ||||||
| extern DeprecatedString g_search_engine; | extern DeprecatedString g_search_engine; | ||||||
| extern Vector<DeprecatedString> g_content_filters; | extern Vector<String> g_content_filters; | ||||||
| extern bool g_content_filters_enabled; | extern bool g_content_filters_enabled; | ||||||
| extern Vector<String> g_autoplay_allowlist; | extern Vector<String> g_autoplay_allowlist; | ||||||
| extern bool g_autoplay_allowed_on_all_websites; | extern bool g_autoplay_allowed_on_all_websites; | ||||||
|  |  | ||||||
|  | @ -126,11 +126,7 @@ Tab::Tab(BrowserWindow& window) | ||||||
|     auto preferred_color_scheme = Web::CSS::preferred_color_scheme_from_string(Config::read_string("Browser"sv, "Preferences"sv, "ColorScheme"sv, "auto"sv)); |     auto preferred_color_scheme = Web::CSS::preferred_color_scheme_from_string(Config::read_string("Browser"sv, "Preferences"sv, "ColorScheme"sv, "auto"sv)); | ||||||
|     m_web_content_view->set_preferred_color_scheme(preferred_color_scheme); |     m_web_content_view->set_preferred_color_scheme(preferred_color_scheme); | ||||||
| 
 | 
 | ||||||
|     if (g_content_filters_enabled) |     content_filters_changed(); | ||||||
|         m_web_content_view->set_content_filters(g_content_filters); |  | ||||||
|     else |  | ||||||
|         m_web_content_view->set_content_filters({}); |  | ||||||
| 
 |  | ||||||
|     autoplay_allowlist_changed(); |     autoplay_allowlist_changed(); | ||||||
| 
 | 
 | ||||||
|     m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings); |     m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings); | ||||||
|  |  | ||||||
|  | @ -34,7 +34,7 @@ namespace Browser { | ||||||
| DeprecatedString g_search_engine; | DeprecatedString g_search_engine; | ||||||
| DeprecatedString g_home_url; | DeprecatedString g_home_url; | ||||||
| DeprecatedString g_new_tab_url; | DeprecatedString g_new_tab_url; | ||||||
| Vector<DeprecatedString> g_content_filters; | Vector<String> g_content_filters; | ||||||
| bool g_content_filters_enabled { true }; | bool g_content_filters_enabled { true }; | ||||||
| Vector<String> g_autoplay_allowlist; | Vector<String> g_autoplay_allowlist; | ||||||
| bool g_autoplay_allowed_on_all_websites { false }; | bool g_autoplay_allowed_on_all_websites { false }; | ||||||
|  | @ -47,7 +47,7 @@ DeprecatedString g_webdriver_content_ipc_path; | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> load_content_filters() | static ErrorOr<void> load_content_filters() | ||||||
| { | { | ||||||
|     auto file = TRY(Core::File::open(DeprecatedString::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::File::OpenMode::Read)); |     auto file = TRY(Core::File::open(TRY(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory())), Core::File::OpenMode::Read)); | ||||||
|     auto ad_filter_list = TRY(Core::BufferedFile::create(move(file))); |     auto ad_filter_list = TRY(Core::BufferedFile::create(move(file))); | ||||||
|     auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); |     auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); | ||||||
| 
 | 
 | ||||||
|  | @ -55,8 +55,11 @@ static ErrorOr<void> load_content_filters() | ||||||
| 
 | 
 | ||||||
|     while (TRY(ad_filter_list->can_read_line())) { |     while (TRY(ad_filter_list->can_read_line())) { | ||||||
|         auto line = TRY(ad_filter_list->read_line(buffer)); |         auto line = TRY(ad_filter_list->read_line(buffer)); | ||||||
|         if (!line.is_empty()) |         if (line.is_empty()) | ||||||
|             Browser::g_content_filters.append(line); |             continue; | ||||||
|  | 
 | ||||||
|  |         auto pattern = TRY(String::from_utf8(line)); | ||||||
|  |         TRY(Browser::g_content_filters.try_append(move(pattern))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ bool ContentFilter::is_filtered(const AK::URL& url) const | ||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> ContentFilter::set_patterns(ReadonlySpan<DeprecatedString> patterns) | ErrorOr<void> ContentFilter::set_patterns(ReadonlySpan<String> patterns) | ||||||
| { | { | ||||||
|     m_patterns.clear_with_capacity(); |     m_patterns.clear_with_capacity(); | ||||||
| 
 | 
 | ||||||
|  | @ -46,7 +46,7 @@ ErrorOr<void> ContentFilter::set_patterns(ReadonlySpan<DeprecatedString> pattern | ||||||
|         if (!pattern.ends_with('*')) |         if (!pattern.ends_with('*')) | ||||||
|             TRY(builder.try_append('*')); |             TRY(builder.try_append('*')); | ||||||
| 
 | 
 | ||||||
|         TRY(m_patterns.try_empend(builder.to_deprecated_string())); |         TRY(m_patterns.try_empend(TRY(builder.to_string()))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <AK/String.h> | ||||||
| #include <AK/URL.h> | #include <AK/URL.h> | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| 
 | 
 | ||||||
|  | @ -16,14 +17,14 @@ public: | ||||||
|     static ContentFilter& the(); |     static ContentFilter& the(); | ||||||
| 
 | 
 | ||||||
|     bool is_filtered(const AK::URL&) const; |     bool is_filtered(const AK::URL&) const; | ||||||
|     ErrorOr<void> set_patterns(ReadonlySpan<DeprecatedString>); |     ErrorOr<void> set_patterns(ReadonlySpan<String>); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     ContentFilter(); |     ContentFilter(); | ||||||
|     ~ContentFilter(); |     ~ContentFilter(); | ||||||
| 
 | 
 | ||||||
|     struct Pattern { |     struct Pattern { | ||||||
|         DeprecatedString text; |         String text; | ||||||
|     }; |     }; | ||||||
|     Vector<Pattern> m_patterns; |     Vector<Pattern> m_patterns; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -595,9 +595,9 @@ OrderedHashMap<DeprecatedString, DeprecatedString> OutOfProcessWebView::get_sess | ||||||
|     return client().get_session_storage_entries(); |     return client().get_session_storage_entries(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OutOfProcessWebView::set_content_filters(Vector<DeprecatedString> filters) | void OutOfProcessWebView::set_content_filters(Vector<String> filters) | ||||||
| { | { | ||||||
|     client().async_set_content_filters(filters); |     client().async_set_content_filters(move(filters)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OutOfProcessWebView::set_autoplay_allowed_on_all_websites() | void OutOfProcessWebView::set_autoplay_allowed_on_all_websites() | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ public: | ||||||
|     OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries(); |     OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries(); | ||||||
|     OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries(); |     OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries(); | ||||||
| 
 | 
 | ||||||
|     void set_content_filters(Vector<DeprecatedString>); |     void set_content_filters(Vector<String>); | ||||||
|     void set_autoplay_allowed_on_all_websites(); |     void set_autoplay_allowed_on_all_websites(); | ||||||
|     void set_autoplay_allowlist(Vector<String>); |     void set_autoplay_allowlist(Vector<String>); | ||||||
|     void set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString, size_t> mappings); |     void set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString, size_t> mappings); | ||||||
|  |  | ||||||
|  | @ -634,7 +634,7 @@ Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_la | ||||||
|     return builder.to_deprecated_string(); |     return builder.to_deprecated_string(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ConnectionFromClient::set_content_filters(Vector<DeprecatedString> const& filters) | void ConnectionFromClient::set_content_filters(Vector<String> const& filters) | ||||||
| { | { | ||||||
|     Web::ContentFilter::the().set_patterns(filters).release_value_but_fixme_should_propagate_errors(); |     Web::ContentFilter::the().set_patterns(filters).release_value_but_fixme_should_propagate_errors(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ private: | ||||||
|     virtual void inspect_accessibility_tree() override; |     virtual void inspect_accessibility_tree() override; | ||||||
|     virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override; |     virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override; | ||||||
|     virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; |     virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; | ||||||
|     virtual void set_content_filters(Vector<DeprecatedString> const&) override; |     virtual void set_content_filters(Vector<String> const&) override; | ||||||
|     virtual void set_autoplay_allowed_on_all_websites() override; |     virtual void set_autoplay_allowed_on_all_websites() override; | ||||||
|     virtual void set_autoplay_allowlist(Vector<String> const& allowlist) override; |     virtual void set_autoplay_allowlist(Vector<String> const& allowlist) override; | ||||||
|     virtual void set_proxy_mappings(Vector<DeprecatedString> const&, HashMap<DeprecatedString, size_t> const&) override; |     virtual void set_proxy_mappings(Vector<DeprecatedString> const&, HashMap<DeprecatedString, size_t> const&) override; | ||||||
|  |  | ||||||
|  | @ -54,7 +54,7 @@ endpoint WebContentServer | ||||||
|     get_selected_text() => (DeprecatedString selection) |     get_selected_text() => (DeprecatedString selection) | ||||||
|     select_all() =| |     select_all() =| | ||||||
| 
 | 
 | ||||||
|     set_content_filters(Vector<DeprecatedString> filters) =| |     set_content_filters(Vector<String> filters) =| | ||||||
|     set_autoplay_allowed_on_all_websites() =| |     set_autoplay_allowed_on_all_websites() =| | ||||||
|     set_autoplay_allowlist(Vector<String> allowlist) =| |     set_autoplay_allowlist(Vector<String> allowlist) =| | ||||||
|     set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString,size_t> mappings) =| |     set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString,size_t> mappings) =| | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn