Commit 0acb3a48 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Adds the desktop version of the blocked redirect UI

Bug: 624061
Change-Id: I743121dc676720fd92bae8e27a9c1d7e305e54f9
Reviewed-on: https://chromium-review.googlesource.com/755523
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521041}
parent e6ad3229
......@@ -1140,10 +1140,20 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@example.com</
</if>
<!-- Framebust / Blocked Redirection intervention message -->
<message name="IDS_REDIRECT_BLOCKED_MESSAGE" desc="The message stating that a redirect (noun) was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
Chromium stopped this site from taking you to
</message>
<if expr="is_android">
<!-- TODO(https://crbug.com/754754) only implemented in Android for now. -->
<message name="IDS_REDIRECT_BLOCKED_MESSAGE" desc="The message stating that a redirect (noun) was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
Chromium stopped this site from taking you to
<message name="IDS_REDIRECT_BLOCKED_SHORT_MESSAGE" desc="The short message stating that a redirect (noun) was blocked on this page.">
Redirect blocked.
</message>
</if>
<if expr="not is_android">
<message name="IDS_REDIRECT_BLOCKED_TITLE" desc="The short message stating that a redirect (noun) was blocked on this page. Same as IDS_REDIRECT_BLOCKED_SHORT_MESSAGE but without the period.">
Redirect blocked
</message>
<message name="IDS_REDIRECT_BLOCKED_TOOLTIP" desc="Tooltip text that appears when the user hovers over the &quot;Redirect blocked&quot; icon in the address bar. It means that a redirect (noun) was blocked by Chrome on this page.">
Redirect blocked on this page.
</message>
</if>
......
......@@ -1157,10 +1157,20 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@example.com</
</if>
<!-- Framebust / Blocked Redirection intervention message -->
<message name="IDS_REDIRECT_BLOCKED_MESSAGE" desc="The message stating that a redirect (noun) was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
Chrome stopped this site from taking you to
</message>
<if expr="is_android">
<!-- TODO(https://crbug.com/754754) only implemented in Android for now. -->
<message name="IDS_REDIRECT_BLOCKED_MESSAGE" desc="The message stating that a redirect (noun) was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
Chrome stopped this site from taking you to
<message name="IDS_REDIRECT_BLOCKED_SHORT_MESSAGE" desc="The short message stating that a redirect (noun) was blocked on this page.">
Redirect blocked.
</message>
</if>
<if expr="not is_android">
<message name="IDS_REDIRECT_BLOCKED_TITLE" desc="The short message stating that a redirect (noun) was blocked on this page. Same as IDS_REDIRECT_BLOCKED_SHORT_MESSAGE but without the period.">
Redirect blocked
</message>
<message name="IDS_REDIRECT_BLOCKED_TOOLTIP" desc="Tooltip text that appears when the user hovers over the &quot;Redirect blocked&quot; icon in the address bar. It means that a redirect (noun) was blocked by Chrome on this page.">
Redirect blocked on this page.
</message>
</if>
......
......@@ -16,10 +16,11 @@ aggregate_vector_icons("chrome_vector_icons") {
"add.icon",
"apps.icon",
"blocked_badge.icon",
"browser_tools_animated.1x.icon",
"browser_tools_animated.icon",
"blocked_redirect.icon",
"browser_tools.1x.icon",
"browser_tools.icon",
"browser_tools_animated.1x.icon",
"browser_tools_animated.icon",
"browser_tools_error.icon",
"browser_tools_update.icon",
"caret_down.1x.icon",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
MOVE_TO, 32, 12.02f,
LINE_TO, 16, 12,
R_CUBIC_TO, -2.2f, 0, -4, 1.8f, -4, 4,
R_V_LINE_TO, 6,
R_H_LINE_TO, 4,
R_V_LINE_TO, -6,
R_H_LINE_TO, 16,
R_V_LINE_TO, 16,
H_LINE_TO, 16,
R_V_LINE_TO, -6,
R_H_LINE_TO, -4,
R_V_LINE_TO, 6,
R_CUBIC_TO, 0, 2.2f, 1.8f, 4, 4, 4,
R_H_LINE_TO, 16,
R_CUBIC_TO, 2.2f, 0, 4, -1.8f, 4, -4,
V_LINE_TO, 16,
R_CUBIC_TO, 0, -2.2f, -1.8f, -3.98f, -4, -3.98f,
CLOSE,
MOVE_TO, 24, 24,
R_LINE_TO, -6, -6,
R_V_LINE_TO, 4,
R_H_LINE_TO, -6,
R_V_LINE_TO, 4,
R_H_LINE_TO, 6,
R_V_LINE_TO, 4,
CLOSE,
END
......@@ -54,6 +54,10 @@
#include "storage/common/fileapi/file_system_types.h"
#include "url/origin.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#endif
using content::BrowserThread;
using content::NavigationController;
using content::NavigationEntry;
......@@ -732,6 +736,21 @@ void TabSpecificContentSettings::OnAudioBlocked() {
OnContentBlocked(CONTENT_SETTINGS_TYPE_SOUND);
}
void TabSpecificContentSettings::OnFramebustBlocked(const GURL& blocked_url) {
#if !defined(OS_ANDROID)
FramebustBlockTabHelper* framebust_block_tab_helper =
FramebustBlockTabHelper::FromWebContents(web_contents());
if (!framebust_block_tab_helper)
return;
framebust_block_tab_helper->AddBlockedUrl(blocked_url);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::Source<WebContents>(web_contents()),
content::NotificationService::NoDetails());
#endif // !defined(OS_ANDROID)
}
void TabSpecificContentSettings::SetPepperBrokerAllowed(bool allowed) {
if (allowed) {
OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER);
......
......@@ -203,6 +203,9 @@ class TabSpecificContentSettings
// Called when audio has been blocked on the page.
void OnAudioBlocked();
// Updates the blocked framebust icon in the location bar.
void OnFramebustBlocked(const GURL& blocked_url);
// Returns whether a particular kind of content has been blocked for this
// page.
bool IsContentBlocked(ContentSettingsType content_type) const;
......
......@@ -685,6 +685,8 @@ split_static_library("ui") {
"apps/chrome_app_window_client.h",
"apps/directory_access_confirmation_dialog.cc",
"apps/directory_access_confirmation_dialog.h",
"blocked_content/framebust_block_tab_helper.cc",
"blocked_content/framebust_block_tab_helper.h",
"blocked_content/popunder_preventer.cc",
"blocked_content/popunder_preventer.h",
"bluetooth/bluetooth_chooser_controller.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "base/logging.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(FramebustBlockTabHelper);
FramebustBlockTabHelper::~FramebustBlockTabHelper() = default;
// static
void FramebustBlockTabHelper::AddBlockedUrl(const GURL& blocked_url) {
blocked_urls_.push_back(blocked_url);
if (observer_)
observer_->OnBlockedUrlAdded(blocked_url);
}
bool FramebustBlockTabHelper::HasBlockedUrls() const {
return !blocked_urls_.empty();
}
void FramebustBlockTabHelper::OnBlockedUrlClicked(size_t index) {
web_contents_->OpenURL(content::OpenURLParams(
blocked_urls_[index], content::Referrer(),
WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false));
blocked_urls_.clear();
}
void FramebustBlockTabHelper::SetObserver(Observer* observer) {
DCHECK(!observer_);
observer_ = observer;
}
void FramebustBlockTabHelper::ClearObserver() {
DCHECK(observer_);
observer_ = nullptr;
}
FramebustBlockTabHelper::FramebustBlockTabHelper(
content::WebContents* web_contents)
: web_contents_(web_contents) {}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_BLOCKED_CONTENT_FRAMEBUST_BLOCK_TAB_HELPER_H_
#define CHROME_BROWSER_UI_BLOCKED_CONTENT_FRAMEBUST_BLOCK_TAB_HELPER_H_
#include <vector>
#include "base/macros.h"
#include "content/public/browser/web_contents_user_data.h"
#include "url/gurl.h"
// A tab helper that keeps track of blocked Framebusts that happened on each
// page. Only used for the desktop version of the blocked Framebust UI.
class FramebustBlockTabHelper
: public content::WebContentsUserData<FramebustBlockTabHelper> {
public:
// There is expected to be at most one observer at a time.
class Observer {
public:
// Called whenever a new URL was blocked.
virtual void OnBlockedUrlAdded(const GURL& blocked_url) = 0;
protected:
virtual ~Observer() = default;
};
~FramebustBlockTabHelper() override;
// Shows the blocked Framebust icon in the Omnibox for the |blocked_url|.
// If the icon is already visible, that URL is instead added to the vector of
// currently blocked URLs and the bubble view is updated.
void AddBlockedUrl(const GURL& blocked_url);
// Returns true if at least one Framebust was blocked on this page.
bool HasBlockedUrls() const;
// Handles navigating to the blocked URL specified by |index| and clearing the
// vector of blocked URLs.
void OnBlockedUrlClicked(size_t index);
// Sets and clears the current observer.
void SetObserver(Observer* observer);
void ClearObserver();
// Returns all of the currently blocked URLs.
const std::vector<GURL>& blocked_urls() const { return blocked_urls_; }
// Remembers if the animation has run.
void set_animation_has_run() { animation_has_run_ = true; }
bool animation_has_run() const { return animation_has_run_; }
private:
friend class content::WebContentsUserData<FramebustBlockTabHelper>;
explicit FramebustBlockTabHelper(content::WebContents* web_contents);
content::WebContents* web_contents_;
// Remembers all the currently blocked URLs. This is cleared on each
// navigation.
std::vector<GURL> blocked_urls_;
// Remembers if the animation has run.
bool animation_has_run_ = false;
// Points to the unique observer of this class.
Observer* observer_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FramebustBlockTabHelper);
};
#endif // CHROME_BROWSER_UI_BLOCKED_CONTENT_FRAMEBUST_BLOCK_TAB_HELPER_H_
......@@ -89,6 +89,7 @@
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
#include "chrome/browser/ui/blocked_content/popup_tracker.h"
#include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h"
......@@ -1399,6 +1400,14 @@ void Browser::OnAudioStateChanged(content::WebContents* web_contents,
sound_content_setting_observer->OnAudioStateChanged(is_audible);
}
void Browser::OnDidBlockFramebust(content::WebContents* web_contents,
const GURL& url) {
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
DCHECK(content_settings);
content_settings->OnFramebustBlocked(url);
}
bool Browser::IsMouseLocked() const {
return exclusive_access_manager_->mouse_lock_controller()->IsMouseLocked();
}
......
......@@ -487,6 +487,8 @@ class Browser : public TabStripModelObserver,
const GURL& resource_url) override;
void OnAudioStateChanged(content::WebContents* web_contents,
bool is_audible) override;
void OnDidBlockFramebust(content::WebContents* web_contents,
const GURL& url) override;
bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
bool is_type_popup() const { return type_ == TYPE_POPUP; }
......
......@@ -105,6 +105,12 @@ IN_PROC_BROWSER_TEST_F(ContentSettingBubbleControllerTest, Init) {
for (const auto& model : models) {
ContentSettingBubbleModel* bubble =
model->CreateBubbleModel(nullptr, web_contents(), profile());
// Skip this test for the ContentSettingFramebustBlockBubbleModel, which
// doesn't have a Cocoa version.
if (bubble->AsFramebustBlockBubbleModel())
continue;
ContentSettingBubbleController* controller = CreateBubbleController(bubble);
// No bubble except the one for media should have media menus.
if (!bubble->AsMediaStreamBubbleModel())
......
......@@ -299,7 +299,9 @@ bool ContentSettingDecoration::OnMousePressed(NSRect frame, NSPoint location) {
return true;
}
if (chrome::ShowAllDialogsWithViewsToolkit()) {
// The blocked Framebust bubble only has a toolkit-views implementation.
if (chrome::ShowAllDialogsWithViewsToolkit() ||
model->AsFramebustBlockBubbleModel()) {
gfx::Point origin = gfx::ScreenPointFromNSPoint(anchor);
NSWindow* bubble = chrome::ContentSettingBubbleViewsBridge::Show(
[web_contents->GetTopLevelNativeWindow() contentView], model,
......
......@@ -38,6 +38,7 @@
#include "chrome/common/insecure_content_renderer.mojom.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
......@@ -1588,6 +1589,88 @@ void ContentSettingDownloadsBubbleModel::OnManageButtonClicked() {
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS);
}
// ContentSettingFramebustBlockBubbleModel -------------------------------------
ContentSettingFramebustBlockBubbleModel::
ContentSettingFramebustBlockBubbleModel(Delegate* delegate,
WebContents* web_contents,
Profile* profile)
: ContentSettingBubbleModel(delegate, web_contents, profile) {
if (!web_contents)
return;
set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
set_show_learn_more(false);
set_title(l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_MESSAGE));
set_done_button_text(l10n_util::GetStringUTF16(IDS_OK));
auto* helper = FramebustBlockTabHelper::FromWebContents(web_contents);
// Build the blocked urls list.
for (const auto& blocked_url : helper->blocked_urls())
AddListItem(CreateListItem(blocked_url));
helper->SetObserver(this);
}
ContentSettingFramebustBlockBubbleModel::
~ContentSettingFramebustBlockBubbleModel() {
if (web_contents())
FramebustBlockTabHelper::FromWebContents(web_contents())->ClearObserver();
}
void ContentSettingFramebustBlockBubbleModel::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
// The order is important because ContentSettingBubbleModel::Observer() clears
// the value of |web_contents()|.
if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED)
FramebustBlockTabHelper::FromWebContents(web_contents())->ClearObserver();
ContentSettingBubbleModel::Observe(type, source, details);
}
void ContentSettingFramebustBlockBubbleModel::OnListItemClicked(
int index,
int event_flags) {
if (!web_contents())
return;
FramebustBlockTabHelper::FromWebContents(web_contents())
->OnBlockedUrlClicked(index);
}
ContentSettingFramebustBlockBubbleModel*
ContentSettingFramebustBlockBubbleModel::AsFramebustBlockBubbleModel() {
return this;
}
void ContentSettingFramebustBlockBubbleModel::OnBlockedUrlAdded(
const GURL& blocked_url) {
AddListItem(CreateListItem(blocked_url));
}
ContentSettingBubbleModel::ListItem
ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) {
// Skip empty URLS.
base::string16 title = !url.spec().empty()
? base::UTF8ToUTF16(url.spec())
: l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE);
const bool use_md = ui::MaterialDesignController::IsSecondaryUiMaterial();
if (use_md) {
// Format the title to include the unicode single dot bullet code-point
// \u2022 and two spaces.
title = l10n_util::GetStringFUTF16(IDS_LIST_BULLET, title);
}
gfx::Image image =
use_md ? gfx::Image()
: ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_DEFAULT_FAVICON);
return ListItem(image, title, true, 0);
}
// ContentSettingBubbleModel ---------------------------------------------------
// static
......@@ -1716,6 +1799,11 @@ ContentSettingBubbleModel::AsDownloadsBubbleModel() {
return nullptr;
}
ContentSettingFramebustBlockBubbleModel*
ContentSettingBubbleModel::AsFramebustBlockBubbleModel() {
return nullptr;
}
void ContentSettingBubbleModel::AddListItem(const ListItem& item) {
bubble_content_.list_items.push_back(item);
if (owner_)
......
......@@ -15,7 +15,9 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/common/custom_handlers/protocol_handler.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
......@@ -52,12 +54,14 @@ class RapporServiceImpl;
// ContentSettingPopupBubbleModel - popups
// ContentSettingSubresourceFilterBubbleModel - filtered subresources
// ContentSettingDownloadsBubbleModel - automatic downloads
// ContentSettingFramebustBlockBubbleModel - blocked framebusts
// Forward declaration necessary for downcasts.
class ContentSettingMediaStreamBubbleModel;
class ContentSettingSimpleBubbleModel;
class ContentSettingSubresourceFilterBubbleModel;
class ContentSettingDownloadsBubbleModel;
class ContentSettingFramebustBlockBubbleModel;
// This model provides data for ContentSettingBubble, and also controls
// the action triggered when the allow / block radio buttons are triggered.
......@@ -203,6 +207,10 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
// Cast this bubble into ContentSettingDownloadsBubbleModel if possible.
virtual ContentSettingDownloadsBubbleModel* AsDownloadsBubbleModel();
// Cast this bubble into ContentSettingFramebustBlockBubbleModel if possible.
virtual ContentSettingFramebustBlockBubbleModel*
AsFramebustBlockBubbleModel();
// Sets the Rappor service used for testing.
void SetRapporServiceImplForTesting(
rappor::RapporServiceImpl* rappor_service) {
......@@ -443,4 +451,36 @@ class ContentSettingDownloadsBubbleModel : public ContentSettingBubbleModel {
DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsBubbleModel);
};
#if !defined(OS_ANDROID)
// The model for the blocked Framebust bubble.
class ContentSettingFramebustBlockBubbleModel
: public ContentSettingBubbleModel,
public FramebustBlockTabHelper::Observer {
public:
ContentSettingFramebustBlockBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);
~ContentSettingFramebustBlockBubbleModel() override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ContentSettingBubbleModel:
void OnListItemClicked(int index, int event_flags) override;
ContentSettingFramebustBlockBubbleModel* AsFramebustBlockBubbleModel()
override;
// FramebustBlockTabHelper::Observer:
void OnBlockedUrlAdded(const GURL& blocked_url) override;
private:
ListItem CreateListItem(const GURL& url);
DISALLOW_COPY_AND_ASSIGN(ContentSettingFramebustBlockBubbleModel);
};
#endif // !defined(OS_ANDROID)
#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_
......@@ -16,7 +16,9 @@
#include "chrome/browser/plugins/plugin_utils.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/vector_icons/vector_icons.h"
......@@ -40,6 +42,7 @@ using content::WebContents;
// ContentSettingDownloadsImageModel - automatic downloads
// ContentSettingMediaImageModel - media
// ContentSettingSubresourceFilterImageModel - deceptive content
// ContentSettingFramebustBlockImageModel - blocked framebust
class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel {
public:
......@@ -470,6 +473,51 @@ void ContentSettingSubresourceFilterImageModel::SetAnimationHasRun(
}
}
// Blocked Framebust -----------------------------------------------------------
ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel()
: ContentSettingImageModel() {}
void ContentSettingFramebustBlockImageModel::UpdateFromWebContents(
WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
// Early exit if no blocked Framebust.
if (!FramebustBlockTabHelper::FromWebContents(web_contents)->HasBlockedUrls())
return;
set_icon(kBlockedRedirectIcon, kBlockedBadgeIcon);
set_explanatory_string_id(IDS_REDIRECT_BLOCKED_TITLE);
set_tooltip(l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_TOOLTIP));
set_visible(true);
}
ContentSettingBubbleModel*
ContentSettingFramebustBlockImageModel::CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents,
Profile* profile) {
return new ContentSettingFramebustBlockBubbleModel(delegate, web_contents,
profile);
}
bool ContentSettingFramebustBlockImageModel::ShouldRunAnimation(
WebContents* web_contents) {
return web_contents && !FramebustBlockTabHelper::FromWebContents(web_contents)
->animation_has_run();
}
void ContentSettingFramebustBlockImageModel::SetAnimationHasRun(
WebContents* web_contents) {
if (!web_contents)
return;
FramebustBlockTabHelper::FromWebContents(web_contents)
->set_animation_has_run();
}
// Protocol handlers -----------------------------------------------------------
ContentSettingRPHImageModel::ContentSettingRPHImageModel()
......@@ -612,6 +660,12 @@ ContentSettingImageModel::GenerateContentSettingImageModels() {
}
result.push_back(std::move(model));
}
// The framebust blocking UI reuses the code for displaying an icon with
// ContentSettingImageModel and ContentSettingBubbleModel, even though
// framebust blocking is not a content setting.
result.push_back(base::MakeUnique<ContentSettingFramebustBlockImageModel>());
return result;
}
......
......@@ -140,4 +140,22 @@ class ContentSettingSubresourceFilterImageModel
DISALLOW_COPY_AND_ASSIGN(ContentSettingSubresourceFilterImageModel);
};
class ContentSettingFramebustBlockImageModel : public ContentSettingImageModel {
public:
ContentSettingFramebustBlockImageModel();
void UpdateFromWebContents(content::WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents,
Profile* profile) override;
bool ShouldRunAnimation(content::WebContents* web_contents) override;
void SetAnimationHasRun(content::WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingFramebustBlockImageModel);
};
#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "ui/events/event_constants.h"
#include "url/gurl.h"
class ContentSettingFramebustBlockBubbleModelTest
: public InProcessBrowserTest {
public:
content::WebContents* GetWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
void WaitForNavigation() {
content::TestNavigationObserver observer(GetWebContents());
observer.Wait();
}
};
// Tests that clicking an item in the list of blocked URLs trigger a navigation
// to that URL.
IN_PROC_BROWSER_TEST_F(ContentSettingFramebustBlockBubbleModelTest,
AllowRedirection) {
const GURL blocked_urls[] = {
GURL(chrome::kChromeUIHistoryURL), GURL(chrome::kChromeUISettingsURL),
GURL(chrome::kChromeUIVersionURL),
};
// Signal that a blocked redirection happened.
auto* helper = FramebustBlockTabHelper::FromWebContents(GetWebContents());
for (const GURL& url : blocked_urls)
helper->AddBlockedUrl(url);
EXPECT_TRUE(helper->HasBlockedUrls());
// Simulate clicking on the second blocked URL.
ContentSettingFramebustBlockBubbleModel framebust_block_bubble_model(
browser()->content_setting_bubble_model_delegate(), GetWebContents(),
browser()->profile());
framebust_block_bubble_model.OnListItemClicked(/* index = */ 1,
ui::EF_LEFT_MOUSE_BUTTON);
WaitForNavigation();
EXPECT_FALSE(helper->HasBlockedUrls());
EXPECT_EQ(blocked_urls[1], GetWebContents()->GetLastCommittedURL());
}
......@@ -117,6 +117,10 @@
#include "components/zoom/zoom_controller.h"
#endif // defined(OS_ANDROID)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#endif
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
#include "chrome/browser/offline_pages/recent_tab_helper.h"
......@@ -280,6 +284,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
web_contents);
extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
FramebustBlockTabHelper::CreateForWebContents(web_contents);
HungPluginTabHelper::CreateForWebContents(web_contents);
JavaScriptDialogTabHelper::CreateForWebContents(web_contents);
ManagePasswordsUIController::CreateForWebContents(web_contents);
......
......@@ -733,6 +733,7 @@ test("browser_tests") {
"../browser/ui/collected_cookies_browsertest.cc",
"../browser/ui/content_settings/content_setting_bubble_model_browsertest.cc",
"../browser/ui/content_settings/content_setting_image_model_browsertest.cc",
"../browser/ui/content_settings/framebust_block_browsertest.cc",
"../browser/ui/exclusive_access/fullscreen_controller_browsertest.cc",
"../browser/ui/extensions/extension_enable_flow_browsertest.cc",
"../browser/ui/extensions/extension_installed_bubble_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment