| Index: chrome/browser/ssl/chrome_security_state_model.cc
|
| diff --git a/chrome/browser/ssl/chrome_security_state_model.cc b/chrome/browser/ssl/chrome_security_state_model.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..36bf43d4b34063765f928a7419133be4d69b301c
|
| --- /dev/null
|
| +++ b/chrome/browser/ssl/chrome_security_state_model.cc
|
| @@ -0,0 +1,108 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ssl/chrome_security_state_model.h"
|
| +
|
| +#include "build/build_config.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chromeos/policy/policy_cert_service.h"
|
| +#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| +#include "chrome/browser/safe_browsing/ui_manager.h"
|
| +#include "content/public/browser/navigation_entry.h"
|
| +#include "content/public/browser/navigation_handle.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModel);
|
| +
|
| +using safe_browsing::SafeBrowsingUIManager;
|
| +using security_state::SecurityStateModel;
|
| +
|
| +ChromeSecurityStateModel::ChromeSecurityStateModel(
|
| + content::WebContents* web_contents)
|
| + : content::WebContentsObserver(web_contents),
|
| + web_contents_model_(
|
| + new security_state::WebContentsSecurityStateModel(web_contents)),
|
| + logged_http_warning_on_current_navigation_(false) {}
|
| +
|
| +ChromeSecurityStateModel::~ChromeSecurityStateModel() {}
|
| +
|
| +void ChromeSecurityStateModel::GetSecurityInfo(
|
| + SecurityStateModel::SecurityInfo* result) const {
|
| + web_contents_model_->GetSecurityInfo(result, UsedPolicyInstalledCertificate(),
|
| + GetMalwareStatus());
|
| +}
|
| +
|
| +void ChromeSecurityStateModel::VisibleSSLStateChanged() {
|
| + if (logged_http_warning_on_current_navigation_)
|
| + return;
|
| +
|
| + security_state::SecurityStateModel::SecurityInfo security_info;
|
| + GetSecurityInfo(&security_info);
|
| + if (!security_info.displayed_private_user_data_input_on_http)
|
| + return;
|
| +
|
| + std::string warning;
|
| + switch (security_info.security_level) {
|
| + case security_state::SecurityStateModel::HTTP_SHOW_WARNING:
|
| + warning =
|
| + "This page includes a password or credit card input in a non-secure "
|
| + "context. A warning has been added to the URL bar. For more "
|
| + "information, see https://goo.gl/zmWq3m.";
|
| + break;
|
| + case security_state::SecurityStateModel::NONE:
|
| + warning =
|
| + "This page includes a password or credit card input in a non-secure "
|
| + "context. A warning will be added to the URL bar in Chrome 56 (Jan "
|
| + "2017). For more information, see https://goo.gl/zmWq3m.";
|
| + break;
|
| + default:
|
| + return;
|
| + }
|
| +
|
| + logged_http_warning_on_current_navigation_ = true;
|
| + web_contents()->GetMainFrame()->AddMessageToConsole(
|
| + content::CONSOLE_MESSAGE_LEVEL_WARNING, warning);
|
| +}
|
| +
|
| +void ChromeSecurityStateModel::DidFinishNavigation(
|
| + content::NavigationHandle* navigation_handle) {
|
| + if (navigation_handle->IsInMainFrame() &&
|
| + !navigation_handle->IsSynchronousNavigation()) {
|
| + // Only reset the console message flag for main-frame navigations,
|
| + // and not for synchronous navigations like reference fragments and
|
| + // pushState.
|
| + logged_http_warning_on_current_navigation_ = false;
|
| + }
|
| +}
|
| +
|
| +bool ChromeSecurityStateModel::UsedPolicyInstalledCertificate() const {
|
| +#if defined(OS_CHROMEOS)
|
| + policy::PolicyCertService* service =
|
| + policy::PolicyCertServiceFactory::GetForProfile(
|
| + Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
|
| + if (service && service->UsedPolicyCertificates())
|
| + return true;
|
| +#endif
|
| + return false;
|
| +}
|
| +
|
| +bool ChromeSecurityStateModel::GetMalwareStatus() const {
|
| + content::NavigationEntry* entry =
|
| + web_contents()->GetController().GetVisibleEntry();
|
| + if (!entry)
|
| + return false;
|
| + safe_browsing::SafeBrowsingService* sb_service =
|
| + g_browser_process->safe_browsing_service();
|
| + if (!sb_service)
|
| + return false;
|
| + scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager();
|
| + if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents(
|
| + entry->GetURL(), false, entry, web_contents(), false)) {
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
|
|