Commit 0330875f authored by Nicolas Dossou-gbete's avatar Nicolas Dossou-gbete Committed by Commit Bot

👮 Unify intervention infobar callback paths

Simplifies the code path for the Framebust block infobar that was
trying to share code with the desktop intrvention UI but ended up
being unused. Makes the implementation closer to the one for the
Near-OOM intervention.
Most importantly, exposes Accept and DeclineIntervention methods
for the Framebust Block intervention, that now enables callers
to react when the intervention is accepted.

Bug: 781890
Change-Id: I845f76bdbddf85f49c8e0fe8548a2e78d2e213b3
Reviewed-on: https://chromium-review.googlesource.com/779521
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518319}
parent 2c85cdb9
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.infobar;
import android.net.Uri;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
......@@ -12,38 +13,33 @@ import android.widget.TextView;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.interventions.FramebustBlockMessageDelegate;
import org.chromium.chrome.browser.interventions.FramebustBlockMessageDelegateBridge;
import org.chromium.components.url_formatter.UrlFormatter;
/**
* This InfoBar is shown to let the user know about a blocked Framebust and offer to
* continue the redirection by tapping on a link.
*
* {@link FramebustBlockMessageDelegate} defines the messages shown in the infobar and
* the target of the link.
*/
public class FramebustBlockInfoBar extends InfoBar {
private final FramebustBlockMessageDelegate mDelegate;
private final String mBlockedUrl;
/** Whether the infobar should be shown as a mini-infobar or a classic expanded one. */
private boolean mIsExpanded;
@VisibleForTesting
public FramebustBlockInfoBar(FramebustBlockMessageDelegate delegate) {
super(delegate.getIconResourceId(), null, null);
mDelegate = delegate;
public FramebustBlockInfoBar(String blockedUrl) {
super(R.drawable.infobar_redirect_blocked, null, null);
mBlockedUrl = blockedUrl;
}
@Override
public void onButtonClicked(boolean isPrimaryButton) {
assert isPrimaryButton;
onCloseButtonClicked();
onButtonClicked(ActionType.OK);
}
@Override
public void createContent(InfoBarLayout layout) {
layout.setMessage(mDelegate.getLongMessage());
layout.setMessage(getString(R.string.redirect_blocked_message));
InfoBarControlLayout control = layout.addControlLayout();
ViewGroup ellipsizerView =
......@@ -53,9 +49,8 @@ public class FramebustBlockInfoBar extends InfoBar {
// Formatting the URL and requesting to omit the scheme might still include it for some of
// them (e.g. file, filesystem). We split the output of the formatting to make sure we don't
// end up duplicating it.
String url = mDelegate.getBlockedUrl();
String formattedUrl = UrlFormatter.formatUrlForSecurityDisplay(url, true);
String scheme = Uri.parse(url).getScheme() + "://";
String formattedUrl = UrlFormatter.formatUrlForSecurityDisplay(mBlockedUrl, true);
String scheme = Uri.parse(mBlockedUrl).getScheme() + "://";
TextView schemeView = ellipsizerView.findViewById(R.id.url_scheme);
schemeView.setText(scheme);
......@@ -72,7 +67,7 @@ public class FramebustBlockInfoBar extends InfoBar {
@Override
protected void createCompactLayoutContent(InfoBarCompactLayout layout) {
new InfoBarCompactLayout.MessageBuilder(layout)
.withText(mDelegate.getShortMessage())
.withText(getString(R.string.redirect_blocked_short_message))
.withLink(R.string.details_link, view -> onLinkClicked())
.buildAndInsert();
}
......@@ -90,12 +85,15 @@ public class FramebustBlockInfoBar extends InfoBar {
return;
}
mDelegate.onLinkTapped();
super.onLinkClicked();
}
private String getString(@StringRes int stringResId) {
return getContext().getString(stringResId);
}
@CalledByNative
private static FramebustBlockInfoBar create(long nativeFramebustBlockMessageDelegateBridge) {
return new FramebustBlockInfoBar(
new FramebustBlockMessageDelegateBridge(nativeFramebustBlockMessageDelegateBridge));
private static FramebustBlockInfoBar create(String blockedUrl) {
return new FramebustBlockInfoBar(blockedUrl);
}
}
......@@ -225,9 +225,9 @@ public abstract class InfoBar implements InfoBarView {
/**
* Performs some action related to the button being clicked.
* @param action The type of action defined as ACTION_* in this class.
* @param action The type of action defined in {@link ActionType} in this class.
*/
protected void onButtonClicked(int action) {
protected void onButtonClicked(@ActionType int action) {
if (mNativeInfoBarPtr != 0) nativeOnButtonClicked(mNativeInfoBarPtr, action);
}
......
// 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.
package org.chromium.chrome.browser.interventions;
import android.support.annotation.DrawableRes;
/**
* Defines the appearance and callbacks for
* {@link org.chromium.chrome.browser.infobar.FramebustBlockInfoBar}.
*/
public interface FramebustBlockMessageDelegate {
/** The full message describing the intervention, visible when the infobar is expanded. */
String getLongMessage();
/** The short message describing the intervention, visible when the infobar is collapsed. */
String getShortMessage();
/** The destination URL for the blocked redirection. */
String getBlockedUrl();
/** The icon to show in this infobar. */
@DrawableRes
int getIconResourceId();
/** Callback called when the featured link is tapped. */
void onLinkTapped();
}
// 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.
package org.chromium.chrome.browser.interventions;
import android.support.annotation.DrawableRes;
import org.chromium.chrome.browser.ResourceId;
/** Implementation of {@link FramebustBlockMessageDelegate} that pulls data from C++. */
public class FramebustBlockMessageDelegateBridge implements FramebustBlockMessageDelegate {
private final long mNativeDelegate;
public FramebustBlockMessageDelegateBridge(long nativeDelegate) {
mNativeDelegate = nativeDelegate;
}
@Override
public String getLongMessage() {
return nativeGetLongMessage(mNativeDelegate);
}
@Override
public String getShortMessage() {
return nativeGetShortMessage(mNativeDelegate);
}
@Override
public String getBlockedUrl() {
return nativeGetBlockedUrl(mNativeDelegate);
}
@Override
@DrawableRes
public int getIconResourceId() {
return ResourceId.mapToDrawableId(nativeGetEnumeratedIcon(mNativeDelegate));
}
@Override
public void onLinkTapped() {
nativeOnLinkTapped(mNativeDelegate);
}
private native String nativeGetLongMessage(long nativeFramebustBlockMessageDelegateBridge);
private native String nativeGetShortMessage(long nativeFramebustBlockMessageDelegateBridge);
private native String nativeGetBlockedUrl(long nativeFramebustBlockMessageDelegateBridge);
private native int nativeGetEnumeratedIcon(long nativeFramebustBlockMessageDelegateBridge);
private native void nativeOnLinkTapped(long nativeFramebustBlockMessageDelegateBridge);
}
......@@ -3243,6 +3243,12 @@ You must have Bluetooth and Location turned on in order to use the Physical Web.
</message>
<!-- Interventions -->
<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>
<message name="IDS_REDIRECT_BLOCKED_SHORT_MESSAGE" desc="The short message stating that a redirect (noun) was blocked on this page.">
Redirect blocked.
</message>
<message name="IDS_NEAR_OOM_INTERVENTION_MESSAGE" desc="The message stating that the browser intervened to stop the page using too much memory.">
This page uses too much memory, so Chrome paused it.
</message>
......
......@@ -549,8 +549,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/instantapps/InstantAppsBannerData.java",
"java/src/org/chromium/chrome/browser/instantapps/InstantAppsHandler.java",
"java/src/org/chromium/chrome/browser/instantapps/InstantAppsSettings.java",
"java/src/org/chromium/chrome/browser/interventions/FramebustBlockMessageDelegate.java",
"java/src/org/chromium/chrome/browser/interventions/FramebustBlockMessageDelegateBridge.java",
"java/src/org/chromium/chrome/browser/invalidation/ChromeBrowserSyncAdapter.java",
"java/src/org/chromium/chrome/browser/invalidation/ChromeBrowserSyncAdapterService.java",
"java/src/org/chromium/chrome/browser/invalidation/ChromeInvalidationClientService.java",
......
......@@ -12,13 +12,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.interventions.FramebustBlockMessageDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.test.ScreenShooter;
import org.chromium.chrome.test.ChromeActivityTestRule;
......@@ -61,35 +58,18 @@ public class InfoBarAppearanceTest {
@Test
@MediumTest
@Feature({"InfoBars", "Catalogue"})
public void testNotifyInfoBar() throws Exception {
TestFramebustBlockMessageDelegate messageDelegate = new TestFramebustBlockMessageDelegate();
FramebustBlockInfoBar infobar = new FramebustBlockInfoBar(messageDelegate);
captureMiniAndRegularInfobar(infobar, messageDelegate);
public void testFramebustBlockInfoBar() throws Exception {
FramebustBlockInfoBar infobar = new FramebustBlockInfoBar("http://very.evil.biz");
captureMiniAndRegularInfobar(infobar);
}
@Test
@MediumTest
@Feature({"InfoBars", "Catalogue"})
public void testNotifyInfoBarWithLongMessages() throws Exception {
TestFramebustBlockMessageDelegate messageDelegate =
new TestFramebustBlockMessageDelegate() {
@Override
public String getShortMessage() {
// Use a long message in the mini-infobar state to verify the behaviour with
// a longer text or for more verbose languages.
return getLongMessage();
}
@Override
public String getBlockedUrl() {
return "https://someverylonglinkthatwilldefinitelynotfitevenwhenremoving"
+ "thefilepath.com/somemorestuff";
}
};
FramebustBlockInfoBar infobar = new FramebustBlockInfoBar(messageDelegate);
captureMiniAndRegularInfobar(infobar, messageDelegate);
public void testFramebustBlockInfoBarWithLongMessages() throws Exception {
FramebustBlockInfoBar infobar = new FramebustBlockInfoBar("https://someverylonglink"
+ "thatwilldefinitelynotfitevenwhenremovingthefilepath.com/somemorestuff");
captureMiniAndRegularInfobar(infobar);
}
@Test
......@@ -102,8 +82,7 @@ public class InfoBarAppearanceTest {
mScreenShooter.shoot("oom_infobar");
}
private void captureMiniAndRegularInfobar(
InfoBar infobar, TestFramebustBlockMessageDelegate delegate)
private void captureMiniAndRegularInfobar(InfoBar infobar)
throws TimeoutException, InterruptedException {
ThreadUtils.runOnUiThreadBlocking(
() -> mTab.getInfoBarContainer().addInfoBarForTesting(infobar));
......@@ -113,38 +92,5 @@ public class InfoBarAppearanceTest {
ThreadUtils.runOnUiThreadBlocking(infobar::onLinkClicked);
mListener.swapInfoBarAnimationFinished("InfoBar did not expand.");
mScreenShooter.shoot("expanded");
ThreadUtils.runOnUiThreadBlocking(infobar::onLinkClicked);
delegate.linkTappedHelper.waitForCallback("link was not tapped.", 0);
}
private static class TestFramebustBlockMessageDelegate
implements FramebustBlockMessageDelegate {
public final CallbackHelper linkTappedHelper = new CallbackHelper();
@Override
public String getLongMessage() {
return "This is the long description for a notify infobar. FYI stuff happened.";
}
@Override
public String getShortMessage() {
return "Stuff happened.";
}
@Override
public String getBlockedUrl() {
return "http://very.evil.biz";
}
@Override
public int getIconResourceId() {
return R.drawable.star_green;
}
@Override
public void onLinkTapped() {
linkTappedHelper.notifyCalled();
}
}
}
......@@ -1142,12 +1142,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@example.com</
<!-- Framebust / Blocked Redirection intervention 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 redirection was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
<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>
<message name="IDS_REDIRECT_BLOCKED_SHORT_MESSAGE" desc="The short message stating that a redirection was blocked on this page.">
Redirect blocked.
</message>
</if>
<!-- OOM intervention message -->
......
......@@ -1159,12 +1159,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@example.com</
<!-- Framebust / Blocked Redirection intervention 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 redirection was blocked on this page. This will be followed on a separate line with the address the user was being redirected to.">
<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>
<message name="IDS_REDIRECT_BLOCKED_SHORT_MESSAGE" desc="The short message stating that a redirection was blocked on this page.">
Redirect blocked.
</message>
</if>
<!-- OOM intervention message -->
......
......@@ -4197,7 +4197,6 @@ if (is_android) {
"../android/java/src/org/chromium/chrome/browser/infobar/TranslateInfoBar.java",
"../android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java",
"../android/java/src/org/chromium/chrome/browser/instantapps/InstantAppsSettings.java",
"../android/java/src/org/chromium/chrome/browser/interventions/FramebustBlockMessageDelegateBridge.java",
"../android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java",
"../android/java/src/org/chromium/chrome/browser/locale/LocaleManager.java",
"../android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java",
......
......@@ -6,6 +6,7 @@
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/ui/android/infobars/near_oom_infobar.h"
#include "chrome/common/chrome_features.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
......
......@@ -9,7 +9,7 @@
#include "base/time/time.h"
#include "chrome/browser/android/oom_intervention/near_oom_monitor.h"
#include "chrome/browser/metrics/oom/out_of_memory_reporter.h"
#include "chrome/browser/ui/android/infobars/near_oom_infobar.h"
#include "chrome/browser/ui/interventions/intervention_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "services/service_manager/public/cpp/interface_provider.h"
......@@ -26,13 +26,13 @@ class OomInterventionTabHelper
: public content::WebContentsObserver,
public content::WebContentsUserData<OomInterventionTabHelper>,
public OutOfMemoryReporter::Observer,
public NearOomMessageDelegate {
public InterventionDelegate {
public:
static bool IsEnabled();
~OomInterventionTabHelper() override;
// NearOomMessageDelegate:
// InterventionDelegate:
void AcceptIntervention() override;
void DeclineIntervention() override;
......
......@@ -120,6 +120,9 @@ split_static_library("ui") {
"history_ui.h",
"interventions/framebust_block_message_delegate.cc",
"interventions/framebust_block_message_delegate.h",
"interventions/intervention_delegate.h",
"interventions/intervention_infobar_delegate.cc",
"interventions/intervention_infobar_delegate.h",
"javascript_dialogs/chrome_javascript_native_dialog_factory.h",
"javascript_dialogs/javascript_dialog.h",
"javascript_dialogs/javascript_dialog_tab_helper.cc",
......@@ -617,8 +620,6 @@ split_static_library("ui") {
"android/infobars/translate_infobar.h",
"android/infobars/update_password_infobar.cc",
"android/infobars/update_password_infobar.h",
"android/interventions/framebust_block_message_delegate_bridge.cc",
"android/interventions/framebust_block_message_delegate_bridge.h",
"android/javascript_app_modal_dialog_android.cc",
"android/javascript_app_modal_dialog_android.h",
"android/javascript_dialog_android.cc",
......
......@@ -13,42 +13,49 @@
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ui/android/interventions/framebust_block_message_delegate_bridge.h"
#include "chrome/browser/ui/interventions/framebust_block_message_delegate.h"
#include "chrome/browser/ui/interventions/intervention_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "content/public/browser/web_contents.h"
#include "jni/FramebustBlockInfoBar_jni.h"
namespace {
class FramebustBlockInfoBarDelegate : public infobars::InfoBarDelegate {
public:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override {
return infobars::InfoBarDelegate::InfoBarIdentifier::
FRAMEBUST_BLOCK_INFOBAR_ANDROID;
}
bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override {
return delegate->GetIdentifier() == GetIdentifier();
}
};
} // namespace
FramebustBlockInfoBar::FramebustBlockInfoBar(
std::unique_ptr<FramebustBlockMessageDelegate> delegate)
: InfoBarAndroid(base::MakeUnique<FramebustBlockInfoBarDelegate>()),
delegate_bridge_(base::MakeUnique<FramebustBlockMessageDelegateBridge>(
std::move(delegate))) {}
std::unique_ptr<FramebustBlockMessageDelegate> message_delegate)
: InfoBarAndroid(std::make_unique<InterventionInfoBarDelegate>(
infobars::InfoBarDelegate::InfoBarIdentifier::
FRAMEBUST_BLOCK_INFOBAR_ANDROID,
message_delegate.get())),
delegate_(std::move(message_delegate)) {
DCHECK(delegate_);
}
FramebustBlockInfoBar::~FramebustBlockInfoBar() = default;
void FramebustBlockInfoBar::ProcessButton(int action) {
// Closes the infobar from the Java UI code.
NOTREACHED();
if (!owner())
return; // We're closing; don't call anything, it might access the owner.
DCHECK_EQ(action, InfoBarAndroid::ACTION_OK);
delegate_->AcceptIntervention();
RemoveSelf();
}
void FramebustBlockInfoBar::OnLinkClicked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
if (!owner())
return; // We're closing; don't call anything, it might access the owner.
// Tapping the link means that the user wants to bypass the intervention by
// navigating to the blocked URL.
delegate_->DeclineIntervention();
RemoveSelf();
}
base::android::ScopedJavaLocalRef<jobject>
FramebustBlockInfoBar::CreateRenderInfoBar(JNIEnv* env) {
return Java_FramebustBlockInfoBar_create(
env, reinterpret_cast<uintptr_t>(delegate_bridge_.get()));
env, base::android::ConvertUTF8ToJavaString(
env, delegate_->GetBlockedUrl().spec()));
}
// static
......
......@@ -9,7 +9,6 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/infobar_android.h"
#include "chrome/browser/ui/android/interventions/framebust_block_message_delegate_bridge.h"
namespace content {
class WebContents;
......@@ -18,8 +17,10 @@ class WebContents;
class FramebustBlockMessageDelegate;
// Communicates to the user about the intervention performed by the browser by
// blocking a framebust. See FramebustBlockInfoBar.java for UI specifics, and
// FramebustBlockMessageDelegate for behavior specifics.
// blocking a framebust.
// That InfoBar shows a link to the URL that was blocked if the user wants to
// bypass the intervention, and a "OK" button to acknowledge and accept it.
// See FramebustBlockInfoBar.java for UI specifics.
class FramebustBlockInfoBar : public InfoBarAndroid {
public:
~FramebustBlockInfoBar() override;
......@@ -35,8 +36,10 @@ class FramebustBlockInfoBar : public InfoBarAndroid {
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override;
void ProcessButton(int action) override;
void OnLinkClicked(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) override;
std::unique_ptr<FramebustBlockMessageDelegateBridge> delegate_bridge_;
std::unique_ptr<FramebustBlockMessageDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(FramebustBlockInfoBar);
};
......
......@@ -13,60 +13,30 @@
#include "base/memory/ptr_util.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ui/interventions/intervention_delegate.h"
#include "chrome/browser/ui/interventions/intervention_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "content/public/browser/web_contents.h"
#include "jni/NearOomInfoBar_jni.h"
namespace {
class NearOomInfoBarDelegate : public infobars::InfoBarDelegate {
public:
explicit NearOomInfoBarDelegate(base::OnceClosure dismiss_callback)
: dismiss_callback_(std::move(dismiss_callback)) {}
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override {
return infobars::InfoBarDelegate::InfoBarIdentifier::
NEAR_OOM_INFOBAR_ANDROID;
}
bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override {
return delegate->GetIdentifier() == GetIdentifier();
}
void InfoBarDismissed() override { std::move(dismiss_callback_).Run(); }
base::OnceClosure dismiss_callback_;
};
} // namespace
NearOomInfoBar::NearOomInfoBar(NearOomMessageDelegate* delegate)
: InfoBarAndroid(std::make_unique<NearOomInfoBarDelegate>(
base::BindOnce(&NearOomInfoBar::AcceptIntervention,
base::Unretained(this)))),
NearOomInfoBar::NearOomInfoBar(InterventionDelegate* delegate)
: InfoBarAndroid(std::make_unique<InterventionInfoBarDelegate>(
infobars::InfoBarDelegate::InfoBarIdentifier::
NEAR_OOM_INFOBAR_ANDROID,
delegate)),
delegate_(delegate) {
DCHECK(delegate_);
}
NearOomInfoBar::~NearOomInfoBar() = default;
void NearOomInfoBar::AcceptIntervention() {
delegate_->AcceptIntervention();
DLOG(WARNING) << "Near-OOM Intervention accepted.";
}
void NearOomInfoBar::DeclineIntervention() {
delegate_->DeclineIntervention();
DLOG(WARNING) << "Near-OOM Intervention declined.";
}
void NearOomInfoBar::OnLinkClicked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
if (!owner())
return; // We're closing; don't call anything, it might access the owner.
DeclineIntervention();
delegate_->DeclineIntervention();
RemoveSelf();
}
......@@ -81,7 +51,7 @@ base::android::ScopedJavaLocalRef<jobject> NearOomInfoBar::CreateRenderInfoBar(
// static
void NearOomInfoBar::Show(content::WebContents* web_contents,
NearOomMessageDelegate* delegate) {
InterventionDelegate* delegate) {
InfoBarService* service = InfoBarService::FromWebContents(web_contents);
service->AddInfoBar(base::WrapUnique(new NearOomInfoBar(delegate)));
}
......@@ -14,15 +14,7 @@ namespace content {
class WebContents;
}
// An interface to handle user actions on NearOomInfoBar.
class NearOomMessageDelegate {
public:
virtual void AcceptIntervention() = 0;
virtual void DeclineIntervention() = 0;
protected:
virtual ~NearOomMessageDelegate() = default;
};
class InterventionDelegate;
// Communicates to the user about the intervention performed by the browser to
// limit the page's memory usage. See NearOomInfoBar.java for UI specifics, and
......@@ -33,12 +25,10 @@ class NearOomInfoBar : public InfoBarAndroid {
// |delegate| must remain alive while showing this info bar.
static void Show(content::WebContents* web_contents,
NearOomMessageDelegate* delegate);
InterventionDelegate* delegate);
private:
explicit NearOomInfoBar(NearOomMessageDelegate* delegate);
void AcceptIntervention();
void DeclineIntervention();
explicit NearOomInfoBar(InterventionDelegate* delegate);
// InfoBarAndroid:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
......@@ -47,7 +37,7 @@ class NearOomInfoBar : public InfoBarAndroid {
const base::android::JavaParamRef<jobject>& obj) override;
void ProcessButton(int action) override;
NearOomMessageDelegate* delegate_;
InterventionDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(NearOomInfoBar);
};
......
......@@ -7,23 +7,11 @@
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/referrer.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/android_theme_resources.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#endif
FramebustBlockMessageDelegate::FramebustBlockMessageDelegate(
content::WebContents* web_contents,
const GURL& blocked_url,
......@@ -34,38 +22,13 @@ FramebustBlockMessageDelegate::FramebustBlockMessageDelegate(
FramebustBlockMessageDelegate::~FramebustBlockMessageDelegate() = default;
int FramebustBlockMessageDelegate::GetIconId() const {
#if defined(OS_ANDROID)
return IDR_ANDROID_INFOBAR_FRAMEBUST;
#else
NOTREACHED();
return 0;
#endif
}
base::string16 FramebustBlockMessageDelegate::GetLongMessage() const {
#if defined(OS_ANDROID)
return l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_MESSAGE);
#else
NOTREACHED();
return base::string16();
#endif
}
base::string16 FramebustBlockMessageDelegate::GetShortMessage() const {
#if defined(OS_ANDROID)
return l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_SHORT_MESSAGE);
#else
NOTREACHED();
return base::string16();
#endif
}
const GURL& FramebustBlockMessageDelegate::GetBlockedUrl() const {
return blocked_url_;
}
void FramebustBlockMessageDelegate::OnLinkClicked() {
void FramebustBlockMessageDelegate::AcceptIntervention() {}
void FramebustBlockMessageDelegate::DeclineIntervention() {
if (!click_closure_.is_null())
std::move(click_closure_).Run();
web_contents_->OpenURL(content::OpenURLParams(
......
......@@ -7,9 +7,10 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "url/gurl.h"
#include "chrome/browser/ui/interventions/intervention_delegate.h"
namespace content {
class WebContents;
}
......@@ -17,18 +18,18 @@ class WebContents;
// Defines the messages shown to the user when the browser intervenes to block
// a framebust attempt, and provides a way to perform the blocked redirection
// if the user decides to do so.
class FramebustBlockMessageDelegate {
class FramebustBlockMessageDelegate : public InterventionDelegate {
public:
FramebustBlockMessageDelegate(content::WebContents* web_contents,
const GURL& blocked_url,
base::OnceClosure click_closure);
virtual ~FramebustBlockMessageDelegate();
~FramebustBlockMessageDelegate() override;
int GetIconId() const;
base::string16 GetLongMessage() const;
base::string16 GetShortMessage() const;
const GURL& GetBlockedUrl() const;
void OnLinkClicked();
// InterventionDelegate:
void AcceptIntervention() override;
void DeclineIntervention() override;
private:
// Closure to be called when the link is clicked.
......
// 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_INTERVENTIONS_INTERVENTION_DELEGATE_H_
#define CHROME_BROWSER_UI_INTERVENTIONS_INTERVENTION_DELEGATE_H_
// An interface to handle user actions assocated to an intervention.
class InterventionDelegate {
public:
virtual void AcceptIntervention() = 0;
virtual void DeclineIntervention() = 0;
protected:
virtual ~InterventionDelegate() = default;
};
#endif // CHROME_BROWSER_UI_INTERVENTIONS_INTERVENTION_DELEGATE_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/interventions/intervention_infobar_delegate.h"
#include "chrome/browser/ui/interventions/intervention_delegate.h"
InterventionInfoBarDelegate::InterventionInfoBarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier identifier,
InterventionDelegate* intervention_delegate)
: identifier_(identifier), intervention_delegate_(intervention_delegate) {
DCHECK(intervention_delegate_);
}
InterventionInfoBarDelegate::~InterventionInfoBarDelegate() = default;
infobars::InfoBarDelegate::InfoBarIdentifier
InterventionInfoBarDelegate::GetIdentifier() const {
return identifier_;
}
bool InterventionInfoBarDelegate::EqualsDelegate(
infobars::InfoBarDelegate* delegate) const {
return delegate->GetIdentifier() == GetIdentifier();
}
void InterventionInfoBarDelegate::InfoBarDismissed() {
// As the infobar allows the user to undo the intervention, dismissing it
// implies accepting the intervention.
intervention_delegate_->AcceptIntervention();
}
// 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_INTERVENTIONS_INTERVENTION_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_UI_INTERVENTIONS_INTERVENTION_INFOBAR_DELEGATE_H_
#include "base/callback.h"
#include "components/infobars/core/infobar_delegate.h"
class InterventionDelegate;
// An specialized implementation of InfoBarDelegate used by intervention
// infobars.
class InterventionInfoBarDelegate : public infobars::InfoBarDelegate {
public:
// |identifier| will be used to uniquely identify the infobar.
//
// |intervention_delegate| should outlive this object. It will notified that
// the intervention is accepted when the user dismisses the infobar.
InterventionInfoBarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier identifier,
InterventionDelegate* intervention_delegate);
~InterventionInfoBarDelegate() override;
// infobars::InfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override;
void InfoBarDismissed() override;
private:
const infobars::InfoBarDelegate::InfoBarIdentifier identifier_;
// Weak pointer, the delegate is guaranteed to outlive this object.
InterventionDelegate* intervention_delegate_;
DISALLOW_COPY_AND_ASSIGN(InterventionInfoBarDelegate);
};
#endif // CHROME_BROWSER_UI_INTERVENTIONS_INTERVENTION_INFOBAR_DELEGATE_H_
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