diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-21 08:03:50 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-22 12:32:40 +0200 |
commit | d1ad513cb1a0f3d9eba7ab8bb66ffe370b9daf2c (patch) | |
tree | 6f7cf5d9f1e9ab96fd46325966b8bbbc7b263b2d /Userland/Applications/BrowserSettings | |
parent | 5089766af68f6aa9c39d829bafb5ffde6b1e76ca (diff) | |
download | serenity-d1ad513cb1a0f3d9eba7ab8bb66ffe370b9daf2c.zip |
BrowserSettings: Port content filters to String
Diffstat (limited to 'Userland/Applications/BrowserSettings')
3 files changed, 45 insertions, 36 deletions
diff --git a/Userland/Applications/BrowserSettings/AutoplaySettingsWidget.cpp b/Userland/Applications/BrowserSettings/AutoplaySettingsWidget.cpp index e51cc98b19..32e718f181 100644 --- a/Userland/Applications/BrowserSettings/AutoplaySettingsWidget.cpp +++ b/Userland/Applications/BrowserSettings/AutoplaySettingsWidget.cpp @@ -55,7 +55,7 @@ ErrorOr<NonnullRefPtr<AutoplaySettingsWidget>> AutoplaySettingsWidget::create() String text; if (GUI::InputBox::show(widget->window(), text, "Website:"sv, "Add website to autoplay allowlist"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) { - widget->m_allowlist_model->add_domain(text.to_deprecated_string()); + widget->m_allowlist_model->add_domain(move(text)); widget->set_modified(true); } }; diff --git a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp index d4c6dc8c4b..162d6884d5 100644 --- a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp +++ b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp @@ -31,10 +31,16 @@ ErrorOr<void> DomainListModel::load() auto file = TRY(Core::File::open(TRY(filter_list_file_path()), Core::File::OpenMode::Read)); auto content_filter_list = TRY(Core::BufferedFile::create(move(file))); auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); + + m_domain_list.clear_with_capacity(); + while (TRY(content_filter_list->can_read_line())) { auto line = TRY(content_filter_list->read_line(buffer)); - if (!line.is_empty()) - m_domain_list.append(line); + if (line.is_empty()) + continue; + + auto pattern = TRY(String::from_utf8(line)); + TRY(m_domain_list.try_append(move(pattern))); } return {}; @@ -55,7 +61,7 @@ ErrorOr<void> DomainListModel::save() return {}; } -void DomainListModel::add_domain(DeprecatedString name) +void DomainListModel::add_domain(String name) { begin_insert_rows({}, m_domain_list.size(), m_domain_list.size()); m_domain_list.append(move(name)); @@ -76,32 +82,37 @@ void DomainListModel::delete_domain(size_t index) void DomainListModel::reset_default_values() { // FIXME: This probably should not be hardcoded. - m_domain_list = { - "207.net", - "247realmedia.com", - "2o7.net", - "adbrite.com", - "admob.com", - "adthis.com", - "advertising.com", - "aquantive.com", - "atwola.com", - "channelintelligence.com", - "doubleclick.com", - "doubleclick.net", - "esomniture.com", - "google-analytics.com", - "googleadservices.com", - "googlesyndication.com", - "gravity.com", - "hitbox.com", - "intellitxt.com", - "nielsen-online.com", - "omniture.com", - "quantcast.com", - "quantserve.com", - "scorecardresearch.com", + static constexpr Array default_domain_list { + "207.net"sv, + "247realmedia.com"sv, + "2o7.net"sv, + "adbrite.com"sv, + "admob.com"sv, + "adthis.com"sv, + "advertising.com"sv, + "aquantive.com"sv, + "atwola.com"sv, + "channelintelligence.com"sv, + "doubleclick.com"sv, + "doubleclick.net"sv, + "esomniture.com"sv, + "google-analytics.com"sv, + "googleadservices.com"sv, + "googlesyndication.com"sv, + "gravity.com"sv, + "hitbox.com"sv, + "intellitxt.com"sv, + "nielsen-online.com"sv, + "omniture.com"sv, + "quantcast.com"sv, + "quantserve.com"sv, + "scorecardresearch.com"sv, }; + + m_domain_list.clear_with_capacity(); + for (auto domain : default_domain_list) + m_domain_list.append(String::from_utf8(domain).release_value_but_fixme_should_propagate_errors()); + m_was_modified = true; did_update(UpdateFlag::InvalidateAllIndices); } @@ -120,14 +131,13 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget() String text; if (GUI::InputBox::show(window(), text, "Enter domain name"sv, "Add domain to Content Filter"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) { - m_domain_list_model->add_domain(move(text).to_deprecated_string()); + m_domain_list_model->add_domain(move(text)); set_modified(true); } }; m_domain_list_model = make_ref_counted<DomainListModel>(); - // FIXME: Propagate errors - MUST(m_domain_list_model->load()); + m_domain_list_model->load().release_value_but_fixme_should_propagate_errors(); m_domain_list_view->set_model(m_domain_list_model); auto delete_action = GUI::CommonActions::make_delete_action([&](GUI::Action const&) { @@ -147,8 +157,7 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget() void ContentFilterSettingsWidget::apply_settings() { - // FIXME: Propagate errors - MUST(m_domain_list_model->save()); + m_domain_list_model->save().release_value_but_fixme_should_propagate_errors(); Config::write_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, m_enable_content_filtering_checkbox->is_checked()); } diff --git a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.h b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.h index a83522d558..6ec2d9ed13 100644 --- a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.h +++ b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.h @@ -22,12 +22,12 @@ public: virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 1; } virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole = GUI::ModelRole::Display) const override { return m_domain_list[index.row()]; } - void add_domain(DeprecatedString name); + void add_domain(String name); void delete_domain(size_t index); protected: bool m_was_modified { false }; - Vector<DeprecatedString> m_domain_list; + Vector<String> m_domain_list; }; class ContentFilterSettingsWidget : public GUI::SettingsWindow::Tab { |