Fix memory leak in DocumentRecentTabsManager
[chromium-blink-merge.git] / ios / web / interstitials / web_interstitial_impl.h
blobc1826ca99609ef4c785d8435f4ec32aa5853c84b
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"
14 #include "url/gurl.h"
16 namespace web {
18 class WebInterstitialDelegate;
19 class WebInterstitialFacadeDelegate;
20 class WebInterstitialImpl;
21 class WebStateImpl;
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*,
26 NSString*,
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 {
32 public:
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:
47 void Show() override;
48 void Hide() override;
49 void DontProceed() override;
50 void Proceed() override;
52 // WebStateObserver implementation:
53 void WebStateDestroyed() override;
55 protected:
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
61 // user actions.
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;
73 private:
74 // The URL corresponding to the page that resulted in this interstitial.
75 GURL url_;
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.
79 bool action_taken_;
81 // Must be implemented only for testing purposes.
82 friend void web::EvaluateScriptForTesting(WebInterstitialImpl*,
83 NSString*,
84 JavaScriptCompletion);
87 } // namespace web
89 #endif // IOS_WEB_INTERSTITIALS_WEB_INTERSTITIAL_IMPL_H_