|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 | + * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +#include "brave/browser/ui/content_settings/brave_content_setting_bubble_model.h" |
| 6 | + |
| 7 | +#include "brave/components/brave_shields/common/brave_shield_constants.h" |
| 8 | +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 | +#include "chrome/browser/plugins/plugin_utils.h" |
| 10 | +#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
| 11 | +#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h" |
| 12 | +#include "chrome/grit/generated_resources.h" |
| 13 | +#include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 | +#include "ui/base/l10n/l10n_util.h" |
| 15 | + |
| 16 | +BraveContentSettingPluginBubbleModel::BraveContentSettingPluginBubbleModel( |
| 17 | + Delegate* delegate, content::WebContents* web_contents, Profile* profile) |
| 18 | + : ContentSettingSimpleBubbleModel(delegate, |
| 19 | + web_contents, |
| 20 | + profile, |
| 21 | + CONTENT_SETTINGS_TYPE_PLUGINS), profile_(profile) { |
| 22 | + content_settings::SettingInfo info; |
| 23 | + HostContentSettingsMap* map = |
| 24 | + HostContentSettingsMapFactory::GetForProfile(profile); |
| 25 | + GURL url = web_contents->GetURL(); |
| 26 | + std::unique_ptr<base::Value> value = |
| 27 | + map->GetWebsiteSetting(url, url, content_type(), std::string(), &info); |
| 28 | + // If the setting is not managed by the user, hide the "Manage" button. |
| 29 | + if (info.source != content_settings::SETTING_SOURCE_USER) |
| 30 | + set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone); |
| 31 | + set_custom_link(l10n_util::GetStringUTF16(IDS_BLOCKED_PLUGINS_LOAD_ALL)); |
| 32 | + set_custom_link_enabled( |
| 33 | + web_contents && |
| 34 | + TabSpecificContentSettings::FromWebContents(web_contents) |
| 35 | + ->load_plugins_link_enabled()); |
| 36 | + set_show_learn_more(true); |
| 37 | +} |
| 38 | + |
| 39 | +void BraveContentSettingPluginBubbleModel::OnLearnMoreClicked() { |
| 40 | + if (delegate()) |
| 41 | + delegate()->ShowLearnMorePage(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 42 | +} |
| 43 | + |
| 44 | +void BraveContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
| 45 | + RunPluginsOnPage(); |
| 46 | +} |
| 47 | + |
| 48 | +void BraveContentSettingPluginBubbleModel::RunPluginsOnPage() { |
| 49 | + // Web contents can be NULL if the tab was closed while the plugins |
| 50 | + // settings bubble is visible. |
| 51 | + if (!web_contents()) |
| 52 | + return; |
| 53 | + |
| 54 | + HostContentSettingsMap* map = |
| 55 | + HostContentSettingsMapFactory::GetForProfile(profile_); |
| 56 | + map->SetContentSettingDefaultScope( |
| 57 | + web_contents()->GetURL(), |
| 58 | + GURL(), |
| 59 | + CONTENT_SETTINGS_TYPE_PLUGINS, |
| 60 | + std::string(), |
| 61 | + CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 62 | + |
| 63 | + ChromeSubresourceFilterClient::FromWebContents(web_contents()) |
| 64 | + ->OnReloadRequested(); |
| 65 | +} |
0 commit comments