QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / interstitials / web_interstitial_impl.mm
blobb40a1895b06875bac1e1d7c9de7ce89cf524ff93
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 #import "ios/web/interstitials/web_interstitial_impl.h"
7 #include "base/logging.h"
8 #include "ios/web/interstitials/web_interstitial_facade_delegate.h"
9 #include "ios/web/public/interstitials/web_interstitial_delegate.h"
10 #include "ios/web/web_state/web_state_impl.h"
12 namespace web {
14 // static
15 WebInterstitial* WebInterstitial::GetWebInterstitial(web::WebState* web_state) {
16   return web_state->GetWebInterstitial();
19 WebInterstitialImpl::WebInterstitialImpl(WebStateImpl* web_state,
20                                          const GURL& url)
21     : WebStateObserver(web_state),
22       url_(url),
23       facade_delegate_(nullptr),
24       action_taken_(false) {
25   DCHECK(web_state);
28 WebInterstitialImpl::~WebInterstitialImpl() {
29   Hide();
30   if (facade_delegate_)
31     facade_delegate_->WebInterstitialDestroyed();
34 const GURL& WebInterstitialImpl::GetUrl() const {
35   return url_;
38 void WebInterstitialImpl::SetFacadeDelegate(
39     WebInterstitialFacadeDelegate* facade_delegate) {
40   facade_delegate_ = facade_delegate;
43 WebInterstitialFacadeDelegate* WebInterstitialImpl::GetFacadeDelegate() const {
44   return facade_delegate_;
47 void WebInterstitialImpl::Show() {
48   PrepareForDisplay();
49   GetWebStateImpl()->ShowWebInterstitial(this);
52 void WebInterstitialImpl::Hide() {
53   GetWebStateImpl()->ClearTransientContentView();
56 void WebInterstitialImpl::DontProceed() {
57   // Proceed() and DontProceed() are not re-entrant, as they delete |this|.
58   if (action_taken_)
59     return;
60   action_taken_ = true;
61   Hide();
62   // Clean up unsafe nav items.
63   GetDelegate()->OnDontProceed();
64   delete this;
67 void WebInterstitialImpl::Proceed() {
68   // Proceed() and DontProceed() are not re-entrant, as they delete |this|.
69   if (action_taken_)
70     return;
71   action_taken_ = true;
72   Hide();
73   GetDelegate()->OnProceed();
74   delete this;
77 void WebInterstitialImpl::WebStateDestroyed() {
78   DontProceed();
81 WebStateImpl* WebInterstitialImpl::GetWebStateImpl() const {
82   return static_cast<web::WebStateImpl*>(web_state());
85 }  // namespace web