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/ui/crw_content_view.h"
12 #include "ios/web/public/web_state/web_state_observer.h"
13 #import "ios/web/web_state/ui/web_view_js_utils.h"
18 class WebInterstitialDelegate
;
19 class WebInterstitialFacadeDelegate
;
20 class WebInterstitialImpl
;
23 // May be implemented in tests to run JavaScript on interstitials. This function
24 // has access to private EvaluateJavaScript method to be used for testing.
25 void EvaluateScriptForTesting(WebInterstitialImpl
*,
27 JavaScriptCompletion
);
29 // An abstract subclass of WebInterstitial that exposes the views necessary to
30 // embed the interstitial into a WebState.
31 class WebInterstitialImpl
: public WebInterstitial
, public WebStateObserver
{
33 WebInterstitialImpl(WebStateImpl
* web_state
, const GURL
& url
);
34 ~WebInterstitialImpl() override
;
36 // Returns the transient content view used to display interstitial content.
37 virtual CRWContentView
* GetContentView() 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_