~chrisccoulson/oxide/lp1504853

« back to all changes in this revision

Viewing changes to shared/browser/ssl/oxide_certificate_error_proxy.cc

  • Committer: Chris Coulson
  • Date: 2015-10-15 08:32:01 UTC
  • Revision ID: chris.coulson@canonical.com-20151015083201-r9m505zjdm3g605c
Navigate to a placeholder transitional page for main frame certificate errors whilst waiting for a response

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2015 Canonical Ltd.
 
3
 
 
4
// This library is free software; you can redistribute it and/or
 
5
// modify it under the terms of the GNU Lesser General Public
 
6
// License as published by the Free Software Foundation; either
 
7
// version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
// This library is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
// Lesser General Public License for more details.
 
13
 
 
14
// You should have received a copy of the GNU Lesser General Public
 
15
// License along with this library; if not, write to the Free Software
 
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
#include "oxide_certificate_error_proxy.h"
 
19
 
 
20
#include "base/logging.h"
 
21
 
 
22
#include "oxide_certificate_error_placeholder_page.h"
 
23
 
 
24
namespace oxide {
 
25
 
 
26
CertificateErrorProxy::~CertificateErrorProxy() {
 
27
  DCHECK(did_respond_ || is_cancelled_);
 
28
}
 
29
 
 
30
CertificateErrorProxy::CertificateErrorProxy(
 
31
    const base::Callback<void(bool)>& callback)
 
32
    : callback_(callback),
 
33
      is_cancelled_(false),
 
34
      did_respond_(false),
 
35
      placeholder_page_(nullptr) {}
 
36
 
 
37
void CertificateErrorProxy::Allow() {
 
38
  DCHECK(!did_respond_);
 
39
  DCHECK(!is_cancelled_);
 
40
  DCHECK(!callback_.is_null());
 
41
 
 
42
  did_respond_ = true;
 
43
 
 
44
  callback_.Run(true);
 
45
  callback_.Reset();
 
46
 
 
47
  if (placeholder_page_) {
 
48
    placeholder_page_->Proceed();
 
49
    placeholder_page_ = nullptr;
 
50
  }
 
51
}
 
52
 
 
53
void CertificateErrorProxy::Deny() {
 
54
  DCHECK(!did_respond_);
 
55
  DCHECK(!is_cancelled_);
 
56
 
 
57
  did_respond_ = true;
 
58
 
 
59
  if (!callback_.is_null()) {
 
60
    callback_.Run(false);
 
61
    callback_.Reset();
 
62
  }
 
63
 
 
64
  if (placeholder_page_) {
 
65
    placeholder_page_->DontProceed();
 
66
    placeholder_page_ = nullptr;
 
67
  }
 
68
}
 
69
 
 
70
void CertificateErrorProxy::Cancel() {
 
71
  DCHECK(!is_cancelled_);
 
72
  DCHECK(placeholder_page_);
 
73
 
 
74
  if (did_respond_) {
 
75
    // Calling Deny() ends up here via InterstitialPageDelegate::OnDontProceed
 
76
    return;
 
77
  }
 
78
 
 
79
  is_cancelled_ = true;
 
80
  placeholder_page_ = nullptr;
 
81
 
 
82
  if (!callback_.is_null()) {
 
83
    callback_.Run(false);
 
84
    callback_.Reset();
 
85
  }
 
86
 
 
87
  if (!cancel_callback_.is_null()) {
 
88
    cancel_callback_.Run();
 
89
    cancel_callback_.Reset();
 
90
  }
 
91
}
 
92
 
 
93
void CertificateErrorProxy::SetPlaceholderPage(
 
94
    CertificateErrorPlaceholderPage* placeholder) {
 
95
  DCHECK(!did_respond_);
 
96
  DCHECK(!is_cancelled_);
 
97
  placeholder_page_ = placeholder;
 
98
}
 
99
 
 
100
} // namespace oxide