diff --git a/browser/ui/content_settings/brave_content_setting_image_models.cc b/browser/ui/content_settings/brave_content_setting_image_models.cc index f59efc12ff91..ec4645cf29ca 100644 --- a/browser/ui/content_settings/brave_content_setting_image_models.cc +++ b/browser/ui/content_settings/brave_content_setting_image_models.cc @@ -1,26 +1,28 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/ui/content_settings/brave_content_setting_image_models.h" +#include "base/ranges/algorithm.h" #include "brave/browser/ui/content_settings/brave_autoplay_blocked_image_model.h" #include "third_party/widevine/cdm/buildflags.h" +using ImageType = ContentSettingImageModel::ImageType; + void BraveGenerateContentSettingImageModels( - std::vector>& result) { - // Remove the cookies content setting image model + std::vector>* result) { + // Remove the cookies and javascript content setting image model // https://github.com/brave/brave-browser/issues/1197 - // TODO(iefremov): This changes break internal image models ordering which is - // based on enum values. This breaks tests and probably should be fixed - // (by adding more diff of course). - for (size_t i = 0; i < result.size(); i++) { - if (result[i]->image_type() == - ContentSettingImageModel::ImageType::COOKIES) { - result.erase(result.begin() + i); - break; - } - } + // https://github.com/brave/brave-browser/issues/199 + result->erase( + base::ranges::remove_if(*result, + [](const auto& m) { + return m->image_type() == ImageType::COOKIES || + m->image_type() == ImageType::JAVASCRIPT; + }), + result->end()); - result.push_back(std::make_unique()); + result->push_back(std::make_unique()); } diff --git a/browser/ui/content_settings/brave_content_setting_image_models.h b/browser/ui/content_settings/brave_content_setting_image_models.h index 3c16ae07e3b3..7a5e91142f2b 100644 --- a/browser/ui/content_settings/brave_content_setting_image_models.h +++ b/browser/ui/content_settings/brave_content_setting_image_models.h @@ -1,11 +1,17 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ +#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ + #include #include class ContentSettingImageModel; void BraveGenerateContentSettingImageModels( - std::vector>&); + std::vector>*); + +#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_CONTENT_SETTING_IMAGE_MODELS_H_ diff --git a/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.cc b/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.cc new file mode 100644 index 000000000000..faebb703576f --- /dev/null +++ b/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.cc @@ -0,0 +1,21 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "chrome/browser/ui/content_settings/content_setting_image_model.h" + +#include "brave/browser/ui/content_settings/brave_content_setting_image_models.h" + +#define GenerateContentSettingImageModels \ + GenerateContentSettingImageModels_ChromiumImpl +#include "../../../../../../chrome/browser/ui/content_settings/content_setting_image_model.cc" +#undef GenerateContentSettingImageModels + +std::vector> +ContentSettingImageModel::GenerateContentSettingImageModels() { + std::vector> result = + GenerateContentSettingImageModels_ChromiumImpl(); + BraveGenerateContentSettingImageModels(&result); + return result; +} diff --git a/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.h b/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.h new file mode 100644 index 000000000000..1a53cb0cd4a1 --- /dev/null +++ b/chromium_src/chrome/browser/ui/content_settings/content_setting_image_model.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ + +#define GenerateContentSettingImageModels \ + GenerateContentSettingImageModels_ChromiumImpl(); \ + static std::vector> \ + GenerateContentSettingImageModels + +#include "../../../../../../chrome/browser/ui/content_settings/content_setting_image_model.h" +#undef GenerateContentSettingImageModels + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ diff --git a/patches/chrome-browser-ui-content_settings-content_setting_image_model.cc.patch b/patches/chrome-browser-ui-content_settings-content_setting_image_model.cc.patch deleted file mode 100644 index bab1e2f38a31..000000000000 --- a/patches/chrome-browser-ui-content_settings-content_setting_image_model.cc.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.cc b/chrome/browser/ui/content_settings/content_setting_image_model.cc -index 4f8182d209673801407db8955c370a026511deed..55361a1022b7cb2b683c336894834b20096c8473 100644 ---- a/chrome/browser/ui/content_settings/content_setting_image_model.cc -+++ b/chrome/browser/ui/content_settings/content_setting_image_model.cc -@@ -11,6 +11,7 @@ - #include "base/macros.h" - #include "base/metrics/field_trial_params.h" - #include "base/metrics/histogram_macros.h" -+#include "brave/browser/ui/content_settings/brave_content_setting_image_models.h" - #include "build/build_config.h" - #include "chrome/app/vector_icons/vector_icons.h" - #include "chrome/browser/browser_process.h" -@@ -1038,6 +1039,9 @@ ContentSettingImageModel::GenerateContentSettingImageModels() { - std::vector> result; - for (auto type : kContentSettingImageOrder) - result.push_back(CreateForContentType(type)); -+#if defined(BRAVE_CHROMIUM_BUILD) -+ BraveGenerateContentSettingImageModels(result); -+#endif - - return result; - }