1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_INTERSTITIALS_WEB_INTERSTITIAL_IMPL_H_
6 #define IOS_WEB_INTERSTITIALS_WEB_INTERSTITIAL_IMPL_H_
8 #import <UIKit/UIKit.h>
10 #import "ios/web/public/interstitials/web_interstitial.h"
11 #include "ios/web/public/web_state/web_state_observer.h"
12 #import "ios/web/web_state/ui/web_view_js_utils.h"
17 class WebInterstitialDelegate
;
18 class WebInterstitialFacadeDelegate
;
19 class WebInterstitialImpl
;
22 // May be implemented in tests to run JavaScript on interstitials. This function
23 // has access to private EvaluateJavaScript method to be used for testing.
24 void EvaluateScriptForTesting(WebInterstitialImpl
*,
26 JavaScriptCompletion
);
28 // An abstract subclass of WebInterstitial that exposes the views necessary to
29 // embed the interstitial into a WebState.
30 class WebInterstitialImpl
: public WebInterstitial
, public WebStateObserver
{
32 WebInterstitialImpl(WebStateImpl
* web_state
, const GURL
& url
);
33 ~WebInterstitialImpl() override
;
35 // Returns the view and scroll view used to display the interstitial content.
36 virtual UIView
* GetView() const = 0;
37 virtual UIScrollView
* GetScrollView() const = 0;
39 // Returns the url corresponding to this interstitial.
40 const GURL
& GetUrl() const;
42 // Sets the delegate used to drive the InterstitialPage facade.
43 void SetFacadeDelegate(WebInterstitialFacadeDelegate
* facade_delegate
);
44 WebInterstitialFacadeDelegate
* GetFacadeDelegate() const;
46 // WebInterstitial implementation:
49 void DontProceed() override
;
50 void Proceed() override
;
52 // WebStateObserver implementation:
53 void WebStateDestroyed() override
;
56 // Called before the WebInterstitialImpl is shown, giving subclasses a chance
57 // to instantiate its view.
58 virtual void PrepareForDisplay() {}
60 // Returns the WebInterstitialDelegate that will handle Proceed/DontProceed
62 virtual WebInterstitialDelegate
* GetDelegate() const = 0;
64 // Convenience method for getting the WebStateImpl.
65 WebStateImpl
* GetWebStateImpl() const;
67 // Evaluates the given |script| on interstitial's web view if there is one.
68 // Calls |completionHandler| with results of the evaluation.
69 // The |completionHandler| can be nil. Must be used only for testing.
70 virtual void EvaluateJavaScript(NSString
* script
,
71 JavaScriptCompletion completionHandler
) = 0;
74 // The URL corresponding to the page that resulted in this interstitial.
76 // The delegate used to communicate with the InterstitialPageImplsIOS facade.
77 WebInterstitialFacadeDelegate
* facade_delegate_
;
78 // Whether or not either Proceed() or DontProceed() has been called.
81 // Must be implemented only for testing purposes.
82 friend void web::EvaluateScriptForTesting(WebInterstitialImpl
*,
84 JavaScriptCompletion
);
89 #endif // IOS_WEB_INTERSTITIALS_WEB_INTERSTITIAL_IMPL_H_