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; ...@@ -21,7 +21,7 @@ class WebInterstitial;
class WebState; class WebState;
} }
class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate { class IOSSecurityInterstitialPage : public web::WebInterstitialDelegate {
public: public:
IOSSecurityInterstitialPage(web::WebState* web_state, IOSSecurityInterstitialPage(web::WebState* web_state,
const GURL& request_url); const GURL& request_url);
...@@ -42,7 +42,7 @@ class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate { ...@@ -42,7 +42,7 @@ class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate {
// |web_interstitial_| will now have a value. // |web_interstitial_| will now have a value.
virtual void AfterShow() = 0; virtual void AfterShow() = 0;
// web::HtmlWebInterstitialDelegate implementation. // web::WebInterstitialDelegate implementation.
std::string GetHtmlContents() const override; std::string GetHtmlContents() const override;
// Returns the formatted host name for the request url. // Returns the formatted host name for the request url.
......
...@@ -35,9 +35,9 @@ IOSSecurityInterstitialPage::~IOSSecurityInterstitialPage() {} ...@@ -35,9 +35,9 @@ IOSSecurityInterstitialPage::~IOSSecurityInterstitialPage() {}
void IOSSecurityInterstitialPage::Show() { void IOSSecurityInterstitialPage::Show() {
DCHECK(!web_interstitial_); DCHECK(!web_interstitial_);
web_interstitial_ = web::WebInterstitial::CreateHtmlInterstitial( web_interstitial_ = web::WebInterstitial::CreateInterstitial(
web_state_, ShouldCreateNewNavigation(), request_url_, web_state_, ShouldCreateNewNavigation(), request_url_,
std::unique_ptr<web::HtmlWebInterstitialDelegate>(this)); std::unique_ptr<web::WebInterstitialDelegate>(this));
web_interstitial_->Show(); web_interstitial_->Show();
AfterShow(); AfterShow();
} }
......
...@@ -15,10 +15,6 @@ source_set("interstitials") { ...@@ -15,10 +15,6 @@ source_set("interstitials") {
] ]
sources = [ 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.h",
"web_interstitial_impl.mm", "web_interstitial_impl.mm",
] ]
...@@ -45,6 +41,6 @@ source_set("interstitials_unittests") { ...@@ -45,6 +41,6 @@ source_set("interstitials_unittests") {
] ]
sources = [ 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 @@ ...@@ -13,6 +13,9 @@
#import "ios/web/web_state/ui/web_view_js_utils.h" #import "ios/web/web_state/ui/web_view_js_utils.h"
#include "url/gurl.h" #include "url/gurl.h"
@protocol WKNavigationDelegate;
@class WKWebView;
namespace web { namespace web {
class NavigationManagerImpl; class NavigationManagerImpl;
...@@ -32,11 +35,12 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver { ...@@ -32,11 +35,12 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
public: public:
WebInterstitialImpl(WebStateImpl* web_state, WebInterstitialImpl(WebStateImpl* web_state,
bool new_navigation, bool new_navigation,
const GURL& url); const GURL& url,
std::unique_ptr<WebInterstitialDelegate> delegate);
~WebInterstitialImpl() override; ~WebInterstitialImpl() override;
// Returns the transient content view used to display interstitial content. // 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. // Returns the url corresponding to this interstitial.
const GURL& GetUrl() const; const GURL& GetUrl() const;
...@@ -50,23 +54,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver { ...@@ -50,23 +54,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
// WebStateObserver implementation: // WebStateObserver implementation:
void WebStateDestroyed(WebState* web_state) override; void WebStateDestroyed(WebState* web_state) override;
protected: // Called by |web_view_controller_delegate_| when |web_view_controller_|
// Called before the WebInterstitialImpl is shown, giving subclasses a chance // receives a JavaScript command. This method forwards the command to
// to instantiate its view. // WebInterstitialDelegate::CommandReceived.
virtual void PrepareForDisplay() {} void CommandReceivedFromWebView(NSString* command);
// Returns the WebInterstitialDelegate that will handle Proceed/DontProceed
// user actions.
virtual WebInterstitialDelegate* GetDelegate() const = 0;
// Convenience method for getting the WebStateImpl.
WebStateImpl* GetWebStateImpl() const;
// Executes the given |script| on interstitial's web view if there is one. // Executes the given |script| on interstitial's web view if there is one.
// Calls |completionHandler| with results of the evaluation. // Calls |completionHandler| with results of the evaluation.
// The |completionHandler| can be nil. Must be used only for testing. // The |completionHandler| can be nil. Must be used only for testing.
virtual void ExecuteJavaScript(NSString* script, virtual void ExecuteJavaScript(NSString* script,
JavaScriptResultBlock completion_handler) = 0; JavaScriptResultBlock completion_handler);
private: private:
// The WebState this instance is observing. Will be null after // The WebState this instance is observing. Will be null after
...@@ -83,6 +80,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver { ...@@ -83,6 +80,16 @@ class WebInterstitialImpl : public WebInterstitial, public WebStateObserver {
// Whether or not either Proceed() or DontProceed() has been called. // Whether or not either Proceed() or DontProceed() has been called.
bool action_taken_; 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. // Must be implemented only for testing purposes.
friend void web::ExecuteScriptForTesting(WebInterstitialImpl*, friend void web::ExecuteScriptForTesting(WebInterstitialImpl*,
NSString*, NSString*,
......
...@@ -4,28 +4,97 @@ ...@@ -4,28 +4,97 @@
#import "ios/web/interstitials/web_interstitial_impl.h" #import "ios/web/interstitials/web_interstitial_impl.h"
#import <WebKit/WebKit.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/web/navigation/navigation_manager_impl.h" #import "ios/web/navigation/navigation_manager_impl.h"
#import "ios/web/public/interstitials/web_interstitial_delegate.h" #import "ios/web/public/interstitials/web_interstitial_delegate.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#include "ios/web/public/reload_type.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 "ios/web/web_state/web_state_impl.h"
#import "net/base/mac/url_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #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 { namespace web {
WebInterstitialImpl::WebInterstitialImpl(WebStateImpl* web_state, // static
WebInterstitial* WebInterstitial::CreateInterstitial(
WebState* web_state,
bool new_navigation, bool new_navigation,
const GURL& url) 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), : web_state_(web_state),
navigation_manager_(&web_state->GetNavigationManagerImpl()), navigation_manager_(&web_state->GetNavigationManagerImpl()),
url_(url), url_(url),
new_navigation_(new_navigation), new_navigation_(new_navigation),
action_taken_(false) { action_taken_(false),
DCHECK(web_state_); delegate_(std::move(delegate)) {
DCHECK(delegate_);
web_state_->AddObserver(this); web_state_->AddObserver(this);
} }
...@@ -37,13 +106,30 @@ WebInterstitialImpl::~WebInterstitialImpl() { ...@@ -37,13 +106,30 @@ WebInterstitialImpl::~WebInterstitialImpl() {
} }
} }
CRWContentView* WebInterstitialImpl::GetContentView() const {
return content_view_;
}
const GURL& WebInterstitialImpl::GetUrl() const { const GURL& WebInterstitialImpl::GetUrl() const {
return url_; return url_;
} }
void WebInterstitialImpl::Show() { void WebInterstitialImpl::Show() {
PrepareForDisplay(); if (!content_view_) {
GetWebStateImpl()->ShowWebInterstitial(this); 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_) { if (new_navigation_) {
// TODO(crbug.com/706578): Plumb transient entry handling through // TODO(crbug.com/706578): Plumb transient entry handling through
...@@ -51,14 +137,14 @@ void WebInterstitialImpl::Show() { ...@@ -51,14 +137,14 @@ void WebInterstitialImpl::Show() {
navigation_manager_->AddTransientItem(url_); navigation_manager_->AddTransientItem(url_);
// Give delegates a chance to set some states on the navigation item. // 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(); web_state_->DidChangeVisibleSecurityState();
} }
} }
void WebInterstitialImpl::Hide() { void WebInterstitialImpl::Hide() {
GetWebStateImpl()->ClearTransientContent(); web_state_->ClearTransientContent();
} }
void WebInterstitialImpl::DontProceed() { void WebInterstitialImpl::DontProceed() {
...@@ -69,11 +155,11 @@ void WebInterstitialImpl::DontProceed() { ...@@ -69,11 +155,11 @@ void WebInterstitialImpl::DontProceed() {
// Clear the pending entry, since that's the page that's not being // Clear the pending entry, since that's the page that's not being
// proceeded to. // proceeded to.
GetWebStateImpl()->GetNavigationManager()->DiscardNonCommittedItems(); web_state_->GetNavigationManager()->DiscardNonCommittedItems();
Hide(); Hide();
GetDelegate()->OnDontProceed(); delegate_->OnDontProceed();
delete this; delete this;
} }
...@@ -84,7 +170,7 @@ void WebInterstitialImpl::Proceed() { ...@@ -84,7 +170,7 @@ void WebInterstitialImpl::Proceed() {
return; return;
action_taken_ = true; action_taken_ = true;
Hide(); Hide();
GetDelegate()->OnProceed(); delegate_->OnProceed();
delete this; delete this;
} }
...@@ -97,8 +183,14 @@ void WebInterstitialImpl::WebStateDestroyed(WebState* web_state) { ...@@ -97,8 +183,14 @@ void WebInterstitialImpl::WebStateDestroyed(WebState* web_state) {
DontProceed(); DontProceed();
} }
WebStateImpl* WebInterstitialImpl::GetWebStateImpl() const { void WebInterstitialImpl::CommandReceivedFromWebView(NSString* command) {
return web_state_; delegate_->CommandReceived(base::SysNSStringToUTF8(command));
}
void WebInterstitialImpl::ExecuteJavaScript(
NSString* script,
JavaScriptResultBlock completion_handler) {
web::ExecuteJavaScript(web_view_, script, completion_handler);
} }
} // namespace web } // namespace web
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/web/interstitials/html_web_interstitial_impl.h" #import "ios/web/public/interstitials/web_interstitial.h"
#include <memory> #include <memory>
...@@ -25,8 +25,8 @@ const char kTestHostName[] = "https://chromium.test/"; ...@@ -25,8 +25,8 @@ const char kTestHostName[] = "https://chromium.test/";
} // namespace } // namespace
// Test fixture for HtmlWebInterstitialImpl class. // Test fixture for WebInterstitial class.
class HtmlWebInterstitialImplTest : public WebTest { class WebInterstitialTest : public WebTest {
protected: protected:
void SetUp() override { void SetUp() override {
WebTest::SetUp(); WebTest::SetUp();
...@@ -46,7 +46,7 @@ class HtmlWebInterstitialImplTest : public WebTest { ...@@ -46,7 +46,7 @@ class HtmlWebInterstitialImplTest : public WebTest {
}; };
// Tests that the interstitial is shown and dismissed on Proceed call. // Tests that the interstitial is shown and dismissed on Proceed call.
TEST_F(HtmlWebInterstitialImplTest, Proceed) { TEST_F(WebInterstitialTest, Proceed) {
ASSERT_FALSE(web_state_->IsShowingWebInterstitial()); ASSERT_FALSE(web_state_->IsShowingWebInterstitial());
GURL url(kTestHostName); GURL url(kTestHostName);
...@@ -55,7 +55,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) { ...@@ -55,7 +55,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) {
EXPECT_CALL(*delegate.get(), OnProceed()); EXPECT_CALL(*delegate.get(), OnProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed. // 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)); web_state_.get(), true, url, std::move(delegate));
interstitial->Show(); interstitial->Show();
ASSERT_TRUE(web_state_->IsShowingWebInterstitial()); ASSERT_TRUE(web_state_->IsShowingWebInterstitial());
...@@ -65,7 +65,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) { ...@@ -65,7 +65,7 @@ TEST_F(HtmlWebInterstitialImplTest, Proceed) {
} }
// Tests that the interstitial is shown and dismissed on DontProceed call. // Tests that the interstitial is shown and dismissed on DontProceed call.
TEST_F(HtmlWebInterstitialImplTest, DontProceed) { TEST_F(WebInterstitialTest, DontProceed) {
ASSERT_FALSE(web_state_->IsShowingWebInterstitial()); ASSERT_FALSE(web_state_->IsShowingWebInterstitial());
std::unique_ptr<MockInterstitialDelegate> delegate = std::unique_ptr<MockInterstitialDelegate> delegate =
...@@ -73,7 +73,7 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) { ...@@ -73,7 +73,7 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) {
EXPECT_CALL(*delegate.get(), OnDontProceed()); EXPECT_CALL(*delegate.get(), OnDontProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed. // 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)); web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show(); interstitial->Show();
ASSERT_TRUE(web_state_->IsShowingWebInterstitial()); ASSERT_TRUE(web_state_->IsShowingWebInterstitial());
...@@ -83,13 +83,13 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) { ...@@ -83,13 +83,13 @@ TEST_F(HtmlWebInterstitialImplTest, DontProceed) {
} }
// Tests that presenting an interstitial changes the visible security state. // Tests that presenting an interstitial changes the visible security state.
TEST_F(HtmlWebInterstitialImplTest, VisibleSecurityStateChanged) { TEST_F(WebInterstitialTest, VisibleSecurityStateChanged) {
TestWebStateObserver observer(web_state_.get()); TestWebStateObserver observer(web_state_.get());
std::unique_ptr<MockInterstitialDelegate> delegate = std::unique_ptr<MockInterstitialDelegate> delegate =
std::make_unique<MockInterstitialDelegate>(); std::make_unique<MockInterstitialDelegate>();
// Raw pointer to |interstitial| because it deletes itself when dismissed. // 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)); web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show(); interstitial->Show();
...@@ -100,14 +100,14 @@ TEST_F(HtmlWebInterstitialImplTest, VisibleSecurityStateChanged) { ...@@ -100,14 +100,14 @@ TEST_F(HtmlWebInterstitialImplTest, VisibleSecurityStateChanged) {
} }
// Tests that the interstitial is dismissed when the web state is destroyed. // 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::unique_ptr<MockInterstitialDelegate> delegate =
std::make_unique<MockInterstitialDelegate>(); std::make_unique<MockInterstitialDelegate>();
// Interstitial should be dismissed if web state is destroyed. // Interstitial should be dismissed if web state is destroyed.
EXPECT_CALL(*delegate.get(), OnDontProceed()); EXPECT_CALL(*delegate.get(), OnDontProceed());
// Raw pointer to |interstitial| because it deletes itself when dismissed. // 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)); web_state_.get(), true, GURL(kTestHostName), std::move(delegate));
interstitial->Show(); interstitial->Show();
......
...@@ -11,8 +11,7 @@ class GURL; ...@@ -11,8 +11,7 @@ class GURL;
namespace web { namespace web {
class HtmlWebInterstitialDelegate; class WebInterstitialDelegate;
class NativeWebInterstitialDelegate;
class WebState; class WebState;
// This class is used for showing interstitial pages, pages that show some // This class is used for showing interstitial pages, pages that show some
...@@ -28,16 +27,11 @@ class WebInterstitial { ...@@ -28,16 +27,11 @@ class WebInterstitial {
// |delegate|. Reloading the interstitial page will result in a new navigation // |delegate|. Reloading the interstitial page will result in a new navigation
// to |url|. The pointers returned by these functions are self-owning; they // to |url|. The pointers returned by these functions are self-owning; they
// manage their own deletion after calling |Show()|. // manage their own deletion after calling |Show()|.
static WebInterstitial* CreateHtmlInterstitial( static WebInterstitial* CreateInterstitial(
WebState* web_state, WebState* web_state,
bool new_navigation, bool new_navigation,
const GURL& url, const GURL& url,
std::unique_ptr<HtmlWebInterstitialDelegate> delegate); std::unique_ptr<WebInterstitialDelegate> delegate);
static WebInterstitial* CreateNativeInterstitial(
WebState* web_state,
bool new_navigation,
const GURL& url,
std::unique_ptr<NativeWebInterstitialDelegate> delegate);
virtual ~WebInterstitial() {} virtual ~WebInterstitial() {}
......
...@@ -32,11 +32,7 @@ class WebInterstitialDelegate { ...@@ -32,11 +32,7 @@ class WebInterstitialDelegate {
// Note that this is only called if the WebInterstitial was constructed with // Note that this is only called if the WebInterstitial was constructed with
// |new_navigation| set to true. // |new_navigation| set to true.
virtual void OverrideItem(NavigationItem* item) {} 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. // Returns the HTML that should be displayed in the page.
virtual std::string GetHtmlContents() const = 0; virtual std::string GetHtmlContents() const = 0;
...@@ -44,16 +40,6 @@ class HtmlWebInterstitialDelegate : public WebInterstitialDelegate { ...@@ -44,16 +40,6 @@ class HtmlWebInterstitialDelegate : public WebInterstitialDelegate {
virtual void CommandReceived(const std::string& command) {} 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 } // namespace web
#endif // IOS_WEB_PUBLIC_INTERSTITIALS_WEB_INTERSTITIAL_DELEGATE_H_ #endif // IOS_WEB_PUBLIC_INTERSTITIALS_WEB_INTERSTITIAL_DELEGATE_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
// A mock html web interstitial delegate. // A mock html web interstitial delegate.
class MockInterstitialDelegate : public web::HtmlWebInterstitialDelegate { class MockInterstitialDelegate : public web::WebInterstitialDelegate {
public: public:
MockInterstitialDelegate(); MockInterstitialDelegate();
~MockInterstitialDelegate(); ~MockInterstitialDelegate();
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#import "base/strings/sys_string_conversions.h" #import "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.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/navigation_item_impl.h"
#import "ios/web/navigation/wk_navigation_util.h" #import "ios/web/navigation/wk_navigation_util.h"
#import "ios/web/public/crw_navigation_item_storage.h" #import "ios/web/public/crw_navigation_item_storage.h"
...@@ -233,7 +233,7 @@ class WebStateImplTest ...@@ -233,7 +233,7 @@ class WebStateImplTest
WebInterstitialImpl* ShowInterstitial() { WebInterstitialImpl* ShowInterstitial() {
auto delegate = std::make_unique<MockInterstitialDelegate>(); auto delegate = std::make_unique<MockInterstitialDelegate>();
WebInterstitialImpl* result = WebInterstitialImpl* result =
new HtmlWebInterstitialImpl(web_state_.get(), /*new_navigation=*/true, new WebInterstitialImpl(web_state_.get(), /*new_navigation=*/true,
GURL::EmptyGURL(), std::move(delegate)); GURL::EmptyGURL(), std::move(delegate));
result->Show(); result->Show();
return result; 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