Commit 1d00cca6 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Remove NativeWebInterstitial class as it is unused.

Additional changes:
  - Removed NativeWebInterstitialDelegate class
  - Merged HtmlWebInterstitialDelegate to base class
  - Update test to only test WebInterstitial interface

Bug: None
Change-Id: Ic44f309edf8dd85f9a55e45ed731d7abde188039
Reviewed-on: https://chromium-review.googlesource.com/c/1316831
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605423}
parent 827abd88
......@@ -21,7 +21,7 @@ class WebInterstitial;
class WebState;
}
class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate {
class IOSSecurityInterstitialPage : public web::WebInterstitialDelegate {
public:
IOSSecurityInterstitialPage(web::WebState* web_state,
const GURL& request_url);
......@@ -42,7 +42,7 @@ class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate {
// |web_interstitial_| will now have a value.
virtual void AfterShow() = 0;
// web::HtmlWebInterstitialDelegate implementation.
// web::WebInterstitialDelegate implementation.
std::string GetHtmlContents() const override;
// Returns the formatted host name for the request url.
......
......@@ -35,9 +35,9 @@ IOSSecurityInterstitialPage::~IOSSecurityInterstitialPage() {}
void IOSSecurityInterstitialPage::Show() {
DCHECK(!web_interstitial_);
web_interstitial_ = web::WebInterstitial::CreateHtmlInterstitial(
web_interstitial_ = web::WebInterstitial::CreateInterstitial(
web_state_, ShouldCreateNewNavigation(), request_url_,
std::unique_ptr<web::HtmlWebInterstitialDelegate>(this));
std::unique_ptr<web::WebInterstitialDelegate>(this));
web_interstitial_->Show();
AfterShow();
}
......
......@@ -15,10 +15,6 @@ source_set("interstitials") {
]
sources = [
"html_web_interstitial_impl.h",
"html_web_interstitial_impl.mm",
"native_web_interstitial_impl.h",
"native_web_interstitial_impl.mm",
"web_interstitial_impl.h",
"web_interstitial_impl.mm",
]
......@@ -45,6 +41,6 @@ source_set("interstitials_unittests") {
]
sources = [
"html_web_interstitial_unittest.mm",
"web_interstitial_unittest.mm",
]
}
// Copyright 2015 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 IOS_WEB_INTERSTITIALS_HTML_WEB_INTERSTITIAL_IMPL_H_
#define IOS_WEB_INTERSTITIALS_HTML_WEB_INTERSTITIAL_IMPL_H_
#import <WebKit/WebKit.h>
#include <memory>
#import "ios/web/interstitials/web_interstitial_impl.h"
namespace web {
class HtmlWebInterstitialDelegate;
class HtmlWebInterstitialImpl;
// A concrete subclass of WebInterstitialImpl that is used to display
// interstitials created via HTML.
class HtmlWebInterstitialImpl : public WebInterstitialImpl {
public:
HtmlWebInterstitialImpl(
WebStateImpl* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<HtmlWebInterstitialDelegate> delegate);
~HtmlWebInterstitialImpl() override;
// Called by |web_view_controller_delegate_| when |web_view_controller_|
// receives a JavaScript command.
void CommandReceivedFromWebView(NSString* command);
// WebInterstitialImpl implementation:
CRWContentView* GetContentView() const override;
protected:
// WebInterstitialImpl implementation:
void PrepareForDisplay() override;
WebInterstitialDelegate* GetDelegate() const override;
void ExecuteJavaScript(NSString* script,
JavaScriptResultBlock completion_handler) override;
private:
// The HTML interstitial delegate.
std::unique_ptr<HtmlWebInterstitialDelegate> delegate_;
// The |web_view_|'s delegate. Used to forward JavaScript commands
// resulting from user interaction with the interstitial content.
id<WKNavigationDelegate> web_view_delegate_;
// The web view used to show the content. View needs to be resized by the
// caller.
WKWebView* web_view_; // strong
// The CRWContentView used to display |web_view_controller_|'s view.
CRWContentView* content_view_;
};
} // namespace web
#endif // IOS_WEB_INTERSTITIALS_HTML_WEB_INTERSTITIAL_IMPL_H_
// Copyright 2015 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.
#import "ios/web/interstitials/html_web_interstitial_impl.h"
#include <utility>
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/web/public/interstitials/web_interstitial_delegate.h"
#import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/web_state/ui/web_view_js_utils.h"
#import "ios/web/web_state/web_state_impl.h"
#import "net/base/mac/url_conversions.h"
#include "ui/gfx/geometry/size.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// The delegate of the web view that is used to display the HTML content.
// It intercepts JavaScript-triggered commands and forwards them
// to the interstitial.
@interface CRWWebInterstitialImplWKWebViewDelegate
: NSObject<WKNavigationDelegate>
// Initializes a CRWWebInterstitialImplWKWebViewDelegate which will
// forward JavaScript commands from its WKWebView to |interstitial|.
- (instancetype)initWithInterstitial:
(web::HtmlWebInterstitialImpl*)interstitial;
@end
@implementation CRWWebInterstitialImplWKWebViewDelegate {
web::HtmlWebInterstitialImpl* _interstitial;
}
- (instancetype)initWithInterstitial:
(web::HtmlWebInterstitialImpl*)interstitial {
self = [super init];
if (self)
_interstitial = interstitial;
return self;
}
- (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request {
NSString* requestString = [[request URL] absoluteString];
// If the request is a JavaScript-triggered command, parse it and forward the
// command to |interstitial_|.
NSString* const commandPrefix = @"js-command:";
if ([requestString hasPrefix:commandPrefix]) {
DCHECK(_interstitial);
_interstitial->CommandReceivedFromWebView(
[requestString substringFromIndex:commandPrefix.length]);
return NO;
}
return YES;
}
#pragma mark -
#pragma mark WKNavigationDelegate methods
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction
decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler {
decisionHandler([self shouldStartLoadWithRequest:navigationAction.request]
? WKNavigationActionPolicyAllow
: WKNavigationActionPolicyCancel);
}
@end
#pragma mark -
namespace web {
// static
WebInterstitial* WebInterstitial::CreateHtmlInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<HtmlWebInterstitialDelegate> delegate) {
WebStateImpl* web_state_impl = static_cast<WebStateImpl*>(web_state);
return new HtmlWebInterstitialImpl(web_state_impl, new_navigation, url,
std::move(delegate));
}
HtmlWebInterstitialImpl::HtmlWebInterstitialImpl(
WebStateImpl* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<HtmlWebInterstitialDelegate> delegate)
: WebInterstitialImpl(web_state, new_navigation, url),
delegate_(std::move(delegate)) {
DCHECK(delegate_);
}
HtmlWebInterstitialImpl::~HtmlWebInterstitialImpl() {
}
void HtmlWebInterstitialImpl::CommandReceivedFromWebView(NSString* command) {
delegate_->CommandReceived(base::SysNSStringToUTF8(command));
}
CRWContentView* HtmlWebInterstitialImpl::GetContentView() const {
return content_view_;
}
void HtmlWebInterstitialImpl::PrepareForDisplay() {
if (!content_view_) {
web_view_delegate_ = [[CRWWebInterstitialImplWKWebViewDelegate alloc]
initWithInterstitial:this];
web_view_ =
web::BuildWKWebView(CGRectZero, GetWebStateImpl()->GetBrowserState());
[web_view_ setNavigationDelegate:web_view_delegate_];
[web_view_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight)];
NSString* html = base::SysUTF8ToNSString(delegate_->GetHtmlContents());
[web_view_ loadHTMLString:html baseURL:net::NSURLWithGURL(GetUrl())];
content_view_ =
[[CRWWebViewContentView alloc] initWithWebView:web_view_
scrollView:[web_view_ scrollView]];
}
}
WebInterstitialDelegate* HtmlWebInterstitialImpl::GetDelegate() const {
return delegate_.get();
}
void HtmlWebInterstitialImpl::ExecuteJavaScript(
NSString* script,
JavaScriptResultBlock completion_handler) {
web::ExecuteJavaScript(web_view_, script, completion_handler);
}
} // namespace web
// Copyright 2015 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 IOS_WEB_INTERSTITIALS_NATIVE_WEB_INTERSTITIAL_IMPL_H_
#define IOS_WEB_INTERSTITIALS_NATIVE_WEB_INTERSTITIAL_IMPL_H_
#import "ios/web/interstitials/web_interstitial_impl.h"
#include <memory>
namespace web {
class NativeWebInterstitialDelegate;
// A concrete subclass of WebInterstitialImpl that is used to display
// interstitials created via native views.
class NativeWebInterstitialImpl : public WebInterstitialImpl {
public:
NativeWebInterstitialImpl(
WebStateImpl* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<NativeWebInterstitialDelegate> delegate);
~NativeWebInterstitialImpl() override;
// WebInterstitialImpl implementation:
CRWContentView* GetContentView() const override;
protected:
// WebInterstitialImpl implementation:
void PrepareForDisplay() override;
WebInterstitialDelegate* GetDelegate() const override;
void ExecuteJavaScript(NSString* script,
JavaScriptResultBlock completion_handler) override;
private:
// The native interstitial delegate.
std::unique_ptr<NativeWebInterstitialDelegate> delegate_;
// The transient content view containing interstitial content.
CRWContentView* content_view_;
};
} // namespace web
#endif // IOS_WEB_INTERSTITIALS_NATIVE_WEB_INTERSTITIAL_IMPL_H_
// Copyright 2015 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.
#import "ios/web/interstitials/native_web_interstitial_impl.h"
#include <utility>
#include "base/logging.h"
#import "ios/web/public/interstitials/web_interstitial_delegate.h"
#import "ios/web/public/web_state/ui/crw_generic_content_view.h"
#import "ios/web/web_state/web_state_impl.h"
#include "ui/gfx/geometry/size.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
// static
WebInterstitial* WebInterstitial::CreateNativeInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<NativeWebInterstitialDelegate> delegate) {
WebStateImpl* web_state_impl = static_cast<WebStateImpl*>(web_state);
return new NativeWebInterstitialImpl(web_state_impl, new_navigation, url,
std::move(delegate));
}
NativeWebInterstitialImpl::NativeWebInterstitialImpl(
WebStateImpl* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<NativeWebInterstitialDelegate> delegate)
: web::WebInterstitialImpl(web_state, new_navigation, url),
delegate_(std::move(delegate)) {
DCHECK(delegate_);
}
NativeWebInterstitialImpl::~NativeWebInterstitialImpl() {
}
CRWContentView* NativeWebInterstitialImpl::GetContentView() const {
return content_view_;
}
void NativeWebInterstitialImpl::PrepareForDisplay() {
if (!content_view_) {
content_view_ = [[CRWGenericContentView alloc]
initWithView:delegate_->GetContentView()];
}
}
WebInterstitialDelegate* NativeWebInterstitialImpl::GetDelegate() const {
return delegate_.get();
}
void NativeWebInterstitialImpl::ExecuteJavaScript(
NSString* script,
JavaScriptResultBlock completion_handler) {
NOTREACHED() << "JavaScript cannot be executed on native interstitials.";
}
} // namespace web
......@@ -13,6 +13,9 @@
#import "ios/web/web_state/ui/web_view_js_utils.h"
#include "url/gurl.h"
@protocol WKNavigationDelegate;
@class WKWebView;
namespace web {
class NavigationManagerImpl;
......@@ -32,11 +35,12 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
public:
WebInterstitialImpl(WebStateImpl* web_state,
bool new_navigation,
const GURL& url);
const GURL& url,
std::unique_ptr<WebInterstitialDelegate> delegate);
~WebInterstitialImpl() override;
// Returns the transient content view used to display interstitial content.
virtual CRWContentView* GetContentView() const = 0;
virtual CRWContentView* GetContentView() const;
// Returns the url corresponding to this interstitial.
const GURL& GetUrl() const;
......@@ -50,23 +54,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
// WebStateObserver implementation:
void WebStateDestroyed(WebState* web_state) override;
protected:
// Called before the WebInterstitialImpl is shown, giving subclasses a chance
// to instantiate its view.
virtual void PrepareForDisplay() {}
// Returns the WebInterstitialDelegate that will handle Proceed/DontProceed
// user actions.
virtual WebInterstitialDelegate* GetDelegate() const = 0;
// Convenience method for getting the WebStateImpl.
WebStateImpl* GetWebStateImpl() const;
// Called by |web_view_controller_delegate_| when |web_view_controller_|
// receives a JavaScript command. This method forwards the command to
// WebInterstitialDelegate::CommandReceived.
void CommandReceivedFromWebView(NSString* command);
// Executes the given |script| on interstitial's web view if there is one.
// Calls |completionHandler| with results of the evaluation.
// The |completionHandler| can be nil. Must be used only for testing.
virtual void ExecuteJavaScript(NSString* script,
JavaScriptResultBlock completion_handler) = 0;
JavaScriptResultBlock completion_handler);
private:
// The WebState this instance is observing. Will be null after
......@@ -83,6 +80,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
// Whether or not either Proceed() or DontProceed() has been called.
bool action_taken_;
std::unique_ptr<WebInterstitialDelegate> delegate_;
// The |web_view_|'s delegate. Used to forward JavaScript commands
// resulting from user interaction with the interstitial content.
id<WKNavigationDelegate> web_view_delegate_;
// The web view used to show the content. View needs to be resized by the
// caller.
WKWebView* web_view_;
// View that encapsulates interstitial's web view and scroll view.
CRWContentView* content_view_;
// Must be implemented only for testing purposes.
friend void web::ExecuteScriptForTesting(WebInterstitialImpl*,
NSString*,
......
......@@ -4,28 +4,97 @@
#import "ios/web/interstitials/web_interstitial_impl.h"
#import <WebKit/WebKit.h>
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/web/navigation/navigation_manager_impl.h"
#import "ios/web/public/interstitials/web_interstitial_delegate.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/reload_type.h"
#import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/web_state/web_state_impl.h"
#import "net/base/mac/url_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// The delegate of the web view that is used to display the HTML content.
// It intercepts JavaScript-triggered commands and forwards them
// to the interstitial.
@interface CRWWebInterstitialImplWKWebViewDelegate
: NSObject<WKNavigationDelegate>
// Initializes a CRWWebInterstitialImplWKWebViewDelegate which will
// forward JavaScript commands from its WKWebView to |interstitial|.
- (instancetype)initWithInterstitial:(web::WebInterstitialImpl*)interstitial;
@end
@implementation CRWWebInterstitialImplWKWebViewDelegate {
web::WebInterstitialImpl* _interstitial;
}
- (instancetype)initWithInterstitial:(web::WebInterstitialImpl*)interstitial {
self = [super init];
if (self)
_interstitial = interstitial;
return self;
}
- (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request {
NSString* requestString = request.URL.absoluteString;
// If the request is a JavaScript-triggered command, parse it and forward the
// command to |interstitial_|.
NSString* const kCommandPrefix = @"js-command:";
if ([requestString hasPrefix:kCommandPrefix]) {
DCHECK(_interstitial);
_interstitial->CommandReceivedFromWebView(
[requestString substringFromIndex:kCommandPrefix.length]);
return NO;
}
return YES;
}
#pragma mark -
#pragma mark WKNavigationDelegate methods
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction
decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler {
decisionHandler([self shouldStartLoadWithRequest:navigationAction.request]
? WKNavigationActionPolicyAllow
: WKNavigationActionPolicyCancel);
}
@end
namespace web {
WebInterstitialImpl::WebInterstitialImpl(WebStateImpl* web_state,
bool new_navigation,
const GURL& url)
// static
WebInterstitial* WebInterstitial::CreateInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<WebInterstitialDelegate> delegate) {
WebStateImpl* web_state_impl = static_cast<WebStateImpl*>(web_state);
return new WebInterstitialImpl(web_state_impl, new_navigation, url,
std::move(delegate));
}
WebInterstitialImpl::WebInterstitialImpl(
WebStateImpl* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<WebInterstitialDelegate> delegate)
: web_state_(web_state),
navigation_manager_(&web_state->GetNavigationManagerImpl()),
url_(url),
new_navigation_(new_navigation),
action_taken_(false) {
DCHECK(web_state_);
action_taken_(false),
delegate_(std::move(delegate)) {
DCHECK(delegate_);
web_state_->AddObserver(this);
}
......@@ -37,13 +106,30 @@ WebInterstitialImpl::~WebInterstitialImpl() {
}
}
CRWContentView* WebInterstitialImpl::GetContentView() const {
return content_view_;
}
const GURL& WebInterstitialImpl::GetUrl() const {
return url_;
}
void WebInterstitialImpl::Show() {
PrepareForDisplay();
GetWebStateImpl()->ShowWebInterstitial(this);
if (!content_view_) {
web_view_delegate_ = [[CRWWebInterstitialImplWKWebViewDelegate alloc]
initWithInterstitial:this];
web_view_ = web::BuildWKWebView(CGRectZero, web_state_->GetBrowserState());
[web_view_ setNavigationDelegate:web_view_delegate_];
[web_view_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight)];
NSString* html = base::SysUTF8ToNSString(delegate_->GetHtmlContents());
[web_view_ loadHTMLString:html baseURL:net::NSURLWithGURL(GetUrl())];
content_view_ =
[[CRWWebViewContentView alloc] initWithWebView:web_view_
scrollView:[web_view_ scrollView]];
}
web_state_->ShowWebInterstitial(this);
if (new_navigation_) {
// TODO(crbug.com/706578): Plumb transient entry handling through
......@@ -51,14 +137,14 @@ void WebInterstitialImpl::Show() {
navigation_manager_->AddTransientItem(url_);
// Give delegates a chance to set some states on the navigation item.
GetDelegate()->OverrideItem(navigation_manager_->GetTransientItem());
delegate_->OverrideItem(navigation_manager_->GetTransientItem());
web_state_->DidChangeVisibleSecurityState();
}
}
void WebInterstitialImpl::Hide() {
GetWebStateImpl()->ClearTransientContent();
web_state_->ClearTransientContent();
}
void WebInterstitialImpl::DontProceed() {
......@@ -69,11 +155,11 @@ void WebInterstitialImpl::DontProceed() {
// Clear the pending entry, since that's the page that's not being
// proceeded to.
GetWebStateImpl()->GetNavigationManager()->DiscardNonCommittedItems();
web_state_->GetNavigationManager()->DiscardNonCommittedItems();
Hide();
GetDelegate()->OnDontProceed();
delegate_->OnDontProceed();
delete this;
}
......@@ -84,7 +170,7 @@ void WebInterstitialImpl::Proceed() {
return;
action_taken_ = true;
Hide();
GetDelegate()->OnProceed();
delegate_->OnProceed();
delete this;
}
......@@ -97,8 +183,14 @@ void WebInterstitialImpl::WebStateDestroyed(WebState* web_state) {
DontProceed();
}
WebStateImpl* WebInterstitialImpl::GetWebStateImpl() const {
return web_state_;
void WebInterstitialImpl::CommandReceivedFromWebView(NSString* command) {
delegate_->CommandReceived(base::SysNSStringToUTF8(command));
}
void WebInterstitialImpl::ExecuteJavaScript(
NSString* script,
JavaScriptResultBlock completion_handler) {
web::ExecuteJavaScript(web_view_, script, completion_handler);
}
} // namespace web
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/interstitials/html_web_interstitial_impl.h"
#import "ios/web/public/interstitials/web_interstitial.h"
#include <memory>
......@@ -25,8 +25,8 @@ const char kTestHostName[] = "https://chromium.test/";
} // namespace
// Test fixture for HtmlWebInterstitialImpl class.
class HtmlWebInterstitialImplTest : public WebTest {
// Test fixture for WebInterstitial class.
class WebInterstitialTest : public WebTest {
protected:
void SetUp() override {
WebTest::SetUp();
......@@ -46,7 +46,7 @@ class HtmlWebInterstitialImplTest : public WebTest {
};
// Tests that the interstitial is shown and dismissed on Proceed call.
TEST_F(HtmlWebInterstitialImplTest, Proceed) {
TEST_F(WebInterstitialTest, Proceed) {
ASSERT_FALSE(web_state_->IsShowingWebInterstitial());
GURL url(kTestHostName);
......@@ -55,7 +55,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) {
EXPECT_CALL(*delegate.get(), OnProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed.
HtmlWebInterstitialImpl* interstitial = new HtmlWebInterstitialImpl(
WebInterstitial* interstitial = WebInterstitial::CreateInterstitial(
web_state_.get(), true, url, std::move(delegate));
interstitial->Show();
ASSERT_TRUE(web_state_->IsShowingWebInterstitial());
......@@ -65,7 +65,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) {
}
// Tests that the interstitial is shown and dismissed on DontProceed call.
TEST_F(HtmlWebInterstitialImplTest, DontProceed) {
TEST_F(WebInterstitialTest, DontProceed) {
ASSERT_FALSE(web_state_->IsShowingWebInterstitial());
std::unique_ptr<MockInterstitialDelegate> delegate =
......@@ -73,7 +73,7 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) {
EXPECT_CALL(*delegate.get(), OnDontProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed.
HtmlWebInterstitialImpl* interstitial = new HtmlWebInterstitialImpl(
WebInterstitial* interstitial = WebInterstitial::CreateInterstitial(
web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show();
ASSERT_TRUE(web_state_->IsShowingWebInterstitial());
......@@ -83,13 +83,13 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) {
}
// Tests that presenting an interstitial changes the visible security state.
TEST_F(HtmlWebInterstitialImplTest, VisibleSecurityStateChanged) {
TEST_F(WebInterstitialTest, VisibleSecurityStateChanged) {
TestWebStateObserver observer(web_state_.get());
std::unique_ptr<MockInterstitialDelegate> delegate =
std::make_unique<MockInterstitialDelegate>();
// Raw pointer to |interstitial| because it deletes itself when dismissed.
HtmlWebInterstitialImpl* interstitial = new HtmlWebInterstitialImpl(
WebInterstitial* interstitial = WebInterstitial::CreateInterstitial(
web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show();
......@@ -100,14 +100,14 @@ TEST_F(HtmlWebInterstitialImplTest, VisibleSecurityStateChanged) {
}
// Tests that the interstitial is dismissed when the web state is destroyed.
TEST_F(HtmlWebInterstitialImplTest, WebStateDestroyed) {
TEST_F(WebInterstitialTest, WebStateDestroyed) {
std::unique_ptr<MockInterstitialDelegate> delegate =
std::make_unique<MockInterstitialDelegate>();
// Interstitial should be dismissed if web state is destroyed.
EXPECT_CALL(*delegate.get(), OnDontProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed.
HtmlWebInterstitialImpl* interstitial = new HtmlWebInterstitialImpl(
WebInterstitial* interstitial = WebInterstitial::CreateInterstitial(
web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show();
......
......@@ -11,8 +11,7 @@ class GURL;
namespace web {
class HtmlWebInterstitialDelegate;
class NativeWebInterstitialDelegate;
class WebInterstitialDelegate;
class WebState;
// This class is used for showing interstitial pages, pages that show some
......@@ -28,16 +27,11 @@ class WebInterstitial {
// |delegate|. Reloading the interstitial page will result in a new navigation
// to |url|. The pointers returned by these functions are self-owning; they
// manage their own deletion after calling |Show()|.
static WebInterstitial* CreateHtmlInterstitial(
static WebInterstitial* CreateInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<HtmlWebInterstitialDelegate> delegate);
static WebInterstitial* CreateNativeInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<NativeWebInterstitialDelegate> delegate);
std::unique_ptr<WebInterstitialDelegate> delegate);
virtual ~WebInterstitial() {}
......
......@@ -32,11 +32,7 @@ class WebInterstitialDelegate {
// Note that this is only called if the WebInterstitial was constructed with
// |new_navigation| set to true.
virtual void OverrideItem(NavigationItem* item) {}
};
// Provides HTML to an HTMLWebInterstitialImpl.
class HtmlWebInterstitialDelegate : public WebInterstitialDelegate {
public:
// Returns the HTML that should be displayed in the page.
virtual std::string GetHtmlContents() const = 0;
......@@ -44,16 +40,6 @@ class HtmlWebInterstitialDelegate : public WebInterstitialDelegate {
virtual void CommandReceived(const std::string& command) {}
};
// Provides a native content view to NativeWebInterstitialImpls.
class NativeWebInterstitialDelegate : public WebInterstitialDelegate {
public:
// Returns the content view for native interstitials.
virtual UIView* GetContentView() = 0;
// The desired background color for the interstitial's scroll view.
virtual UIColor* GetScrollViewBackgroundColor() const = 0;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_INTERSTITIALS_WEB_INTERSTITIAL_DELEGATE_H_
......@@ -9,7 +9,7 @@
#include "testing/gmock/include/gmock/gmock.h"
// A mock html web interstitial delegate.
class MockInterstitialDelegate : public web::HtmlWebInterstitialDelegate {
class MockInterstitialDelegate : public web::WebInterstitialDelegate {
public:
MockInterstitialDelegate();
~MockInterstitialDelegate();
......
......@@ -16,7 +16,7 @@
#import "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#import "ios/web/interstitials/html_web_interstitial_impl.h"
#import "ios/web/interstitials/web_interstitial_impl.h"
#import "ios/web/navigation/navigation_item_impl.h"
#import "ios/web/navigation/wk_navigation_util.h"
#import "ios/web/public/crw_navigation_item_storage.h"
......@@ -233,8 +233,8 @@ class WebStateImplTest
WebInterstitialImpl* ShowInterstitial() {
auto delegate = std::make_unique<MockInterstitialDelegate>();
WebInterstitialImpl* result =
new HtmlWebInterstitialImpl(web_state_.get(), /*new_navigation=*/true,
GURL::EmptyGURL(), std::move(delegate));
new WebInterstitialImpl(web_state_.get(), /*new_navigation=*/true,
GURL::EmptyGURL(), std::move(delegate));
result->Show();
return result;
}
......
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