content_utils.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2016 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.
  4. #include "components/security_state/content/content_utils.h"
  5. #include <memory>
  6. #include "components/dom_distiller/core/url_constants.h"
  7. #include "components/security_state/core/security_state.h"
  8. #include "content/public/browser/navigation_entry.h"
  9. #include "content/public/browser/ssl_status.h"
  10. #include "content/public/browser/web_contents.h"
  11. #include "content/public/common/url_constants.h"
  12. namespace security_state {
  13. std::unique_ptr<security_state::VisibleSecurityState> GetVisibleSecurityState(
  14. content::WebContents* web_contents) {
  15. auto state = std::make_unique<security_state::VisibleSecurityState>();
  16. content::NavigationEntry* entry =
  17. web_contents->GetController().GetVisibleEntry();
  18. if (!entry || entry->IsInitialEntry())
  19. return state;
  20. // Set fields that are not dependent on the connection info.
  21. state->is_error_page = entry->GetPageType() == content::PAGE_TYPE_ERROR;
  22. state->is_view_source =
  23. entry->GetVirtualURL().SchemeIs(content::kViewSourceScheme);
  24. state->is_devtools =
  25. entry->GetVirtualURL().SchemeIs(content::kChromeDevToolsScheme);
  26. state->is_reader_mode =
  27. entry->GetURL().SchemeIs(dom_distiller::kDomDistillerScheme);
  28. state->url = entry->GetURL();
  29. if (!entry->GetSSL().initialized)
  30. return state;
  31. state->connection_info_initialized = true;
  32. const content::SSLStatus& ssl = entry->GetSSL();
  33. state->certificate = ssl.certificate;
  34. state->cert_status = ssl.cert_status;
  35. state->connection_status = ssl.connection_status;
  36. state->key_exchange_group = ssl.key_exchange_group;
  37. state->peer_signature_algorithm = ssl.peer_signature_algorithm;
  38. state->pkp_bypassed = ssl.pkp_bypassed;
  39. state->displayed_mixed_content =
  40. !!(ssl.content_status & content::SSLStatus::DISPLAYED_INSECURE_CONTENT);
  41. state->ran_mixed_content =
  42. !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
  43. state->displayed_content_with_cert_errors =
  44. !!(ssl.content_status &
  45. content::SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS);
  46. state->ran_content_with_cert_errors =
  47. !!(ssl.content_status & content::SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS);
  48. state->contained_mixed_form =
  49. !!(ssl.content_status &
  50. content::SSLStatus::DISPLAYED_FORM_WITH_INSECURE_ACTION);
  51. return state;
  52. }
  53. } // namespace security_state