// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/ssl/ssl_error_handler.h"

#include "base/memory/weak_ptr.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
#include "arkweb/build/features/features.h"

using net::SSLInfo;

namespace content {

SSLErrorHandler::SSLErrorHandler(WebContents* web_contents,
                                 const base::WeakPtr<Delegate>& delegate,
                                 bool is_primary_main_frame_request,
                                 const GURL& url,
                                 int net_error,
                                 const net::SSLInfo& ssl_info,
                                 bool fatal
#if BUILDFLAG(ARKWEB_NETWORK_LOAD)
                                 ,
                                 const GURL& origin_url,
                                 const std::string& referrer
#endif
                                 )
    : delegate_(delegate),
      request_url_(url),
      is_primary_main_frame_request_(is_primary_main_frame_request),
      ssl_info_(ssl_info),
      cert_error_(net_error),
      fatal_(fatal),
#if BUILDFLAG(ARKWEB_NETWORK_LOAD)
      origin_url_(origin_url),
      referrer_(referrer),
#endif
      web_contents_(web_contents) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
}

SSLErrorHandler::~SSLErrorHandler() {}

void SSLErrorHandler::CancelRequest() {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  if (delegate_)
    delegate_->CancelSSLRequest(net::ERR_ABORTED, &ssl_info());
}

void SSLErrorHandler::DenyRequest() {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  if (delegate_)
    delegate_->CancelSSLRequest(cert_error_, &ssl_info());
}

void SSLErrorHandler::ContinueRequest() {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  if (delegate_)
    delegate_->ContinueSSLRequest();
}

}  // namespace content