Commit 6d1d727a authored by cjgrant's avatar cjgrant Committed by Commit bot

Generalize WebContentsObserver::SecurityStyleChanged.

This will put the onus on individual observers to extract the security
information they require, after a change has occurred.  The intent is to
allow chrome/browser-residing observers to monitor security level
changes, independent of style.

BUG=641508

Review-Url: https://codereview.chromium.org/2562503002
Cr-Commit-Position: refs/heads/master@{#437659}
parent 5f8c1ef3
...@@ -22,7 +22,7 @@ VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents, ...@@ -22,7 +22,7 @@ VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents,
ui_interface_(ui_interface), ui_interface_(ui_interface),
vr_shell_(vr_shell) { vr_shell_(vr_shell) {
ui_interface_->SetURL(web_contents->GetVisibleURL()); ui_interface_->SetURL(web_contents->GetVisibleURL());
SetSecurityLevel(); DidChangeVisibleSecurityState();
} }
VrWebContentsObserver::~VrWebContentsObserver() {} VrWebContentsObserver::~VrWebContentsObserver() {}
...@@ -60,16 +60,7 @@ void VrWebContentsObserver::DidFinishNavigation( ...@@ -60,16 +60,7 @@ void VrWebContentsObserver::DidFinishNavigation(
} }
} }
// TODO(cjgrant): We care about security level, not style. Refactor void VrWebContentsObserver::DidChangeVisibleSecurityState() {
// WebContentsObserver (or equivalent) to expose more general security
// information, so we can stop abusing this callback.
void VrWebContentsObserver::SecurityStyleChanged(
blink::WebSecurityStyle security_style,
const content::SecurityStyleExplanations& explanations) {
SetSecurityLevel();
}
void VrWebContentsObserver::SetSecurityLevel() {
const auto* helper = SecurityStateTabHelper::FromWebContents(web_contents()); const auto* helper = SecurityStateTabHelper::FromWebContents(web_contents());
DCHECK(helper); DCHECK(helper);
security_state::SecurityInfo security_info; security_state::SecurityInfo security_info;
......
...@@ -39,9 +39,7 @@ class CONTENT_EXPORT VrWebContentsObserver ...@@ -39,9 +39,7 @@ class CONTENT_EXPORT VrWebContentsObserver
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
void DidToggleFullscreenModeForTab( void DidToggleFullscreenModeForTab(
bool entered_fullscreen, bool will_cause_resize) override; bool entered_fullscreen, bool will_cause_resize) override;
void SecurityStyleChanged( void DidChangeVisibleSecurityState() override;
blink::WebSecurityStyle security_style,
const content::SecurityStyleExplanations& explanations) override;
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
void WasHidden() override; void WasHidden() override;
void RenderViewHostChanged(content::RenderViewHost* old_host, void RenderViewHostChanged(content::RenderViewHost* old_host,
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/security_style_explanations.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
...@@ -1123,10 +1124,10 @@ class SecurityStyleTestObserver : public content::WebContentsObserver { ...@@ -1123,10 +1124,10 @@ class SecurityStyleTestObserver : public content::WebContentsObserver {
} }
// WebContentsObserver: // WebContentsObserver:
void SecurityStyleChanged(blink::WebSecurityStyle security_style, void DidChangeVisibleSecurityState() override {
const content::SecurityStyleExplanations& content::SecurityStyleExplanations security_style_explanations;
security_style_explanations) override { latest_security_style_ = web_contents()->GetDelegate()->GetSecurityStyle(
latest_security_style_ = security_style; web_contents(), &security_style_explanations);
} }
private: private:
......
...@@ -63,9 +63,9 @@ enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE }; ...@@ -63,9 +63,9 @@ enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE };
const base::FilePath::CharType kDocRoot[] = const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("chrome/test/data"); FILE_PATH_LITERAL("chrome/test/data");
// A WebContentsObserver useful for testing the SecurityStyleChanged() // A WebContentsObserver useful for testing the DidChangeVisibleSecurityState()
// method: it keeps track of the latest security style and explanation // method: it keeps track of the latest security style and explanation that was
// that was fired. // fired.
class SecurityStyleTestObserver : public content::WebContentsObserver { class SecurityStyleTestObserver : public content::WebContentsObserver {
public: public:
explicit SecurityStyleTestObserver(content::WebContents* web_contents) explicit SecurityStyleTestObserver(content::WebContents* web_contents)
...@@ -73,11 +73,11 @@ class SecurityStyleTestObserver : public content::WebContentsObserver { ...@@ -73,11 +73,11 @@ class SecurityStyleTestObserver : public content::WebContentsObserver {
latest_security_style_(blink::WebSecurityStyleUnknown) {} latest_security_style_(blink::WebSecurityStyleUnknown) {}
~SecurityStyleTestObserver() override {} ~SecurityStyleTestObserver() override {}
void SecurityStyleChanged(blink::WebSecurityStyle security_style, void DidChangeVisibleSecurityState() override {
const content::SecurityStyleExplanations& content::SecurityStyleExplanations explanations;
security_style_explanations) override { latest_security_style_ = web_contents()->GetDelegate()->GetSecurityStyle(
latest_security_style_ = security_style; web_contents(), &explanations);
latest_explanations_ = security_style_explanations; latest_explanations_ = explanations;
} }
blink::WebSecurityStyle latest_security_style() const { blink::WebSecurityStyle latest_security_style() const {
...@@ -343,9 +343,9 @@ class SecurityStateTabHelperTestWithPasswordCcSwitch ...@@ -343,9 +343,9 @@ class SecurityStateTabHelperTestWithPasswordCcSwitch
DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTestWithPasswordCcSwitch); DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTestWithPasswordCcSwitch);
}; };
class SecurityStyleChangedTest : public InProcessBrowserTest { class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
public: public:
SecurityStyleChangedTest() DidChangeVisibleSecurityStateTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
} }
...@@ -359,7 +359,7 @@ class SecurityStyleChangedTest : public InProcessBrowserTest { ...@@ -359,7 +359,7 @@ class SecurityStyleChangedTest : public InProcessBrowserTest {
net::EmbeddedTestServer https_server_; net::EmbeddedTestServer https_server_;
private: private:
DISALLOW_COPY_AND_ASSIGN(SecurityStyleChangedTest); DISALLOW_COPY_AND_ASSIGN(DidChangeVisibleSecurityStateTest);
}; };
IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) { IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, HttpPage) {
...@@ -1512,9 +1512,10 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, AddedTab) { ...@@ -1512,9 +1512,10 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, AddedTab) {
false /* expect cert status error */); false /* expect cert status error */);
} }
// Tests that the WebContentsObserver::SecurityStyleChanged event fires // Tests that the WebContentsObserver::DidChangeVisibleSecurityState event fires
// with the current style on HTTP, broken HTTPS, and valid HTTPS pages. // with the current style on HTTP, broken HTTPS, and valid HTTPS pages.
IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) { IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
DidChangeVisibleSecurityStateObserver) {
ASSERT_TRUE(https_server_.Start()); ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
...@@ -1650,14 +1651,14 @@ IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) { ...@@ -1650,14 +1651,14 @@ IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) {
// and test that the observed security style matches. // and test that the observed security style matches.
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Flaky on Chrome OS. See https://crbug.com/638576. // Flaky on Chrome OS. See https://crbug.com/638576.
#define MAYBE_SecurityStyleChangedObserverGoBack \ #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
DISABLED_SecurityStyleChangedObserverGoBack DISABLED_DidChangeVisibleSecurityStateObserverGoBack
#else #else
#define MAYBE_SecurityStyleChangedObserverGoBack \ #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
SecurityStyleChangedObserverGoBack DidChangeVisibleSecurityStateObserverGoBack
#endif #endif
IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
MAYBE_SecurityStyleChangedObserverGoBack) { MAYBE_DidChangeVisibleSecurityStateObserverGoBack) {
ASSERT_TRUE(https_server_.Start()); ASSERT_TRUE(https_server_.Start());
net::EmbeddedTestServer https_test_server_expired( net::EmbeddedTestServer https_test_server_expired(
...@@ -1856,7 +1857,7 @@ class BrowserTestNonsecureURLRequest : public InProcessBrowserTest { ...@@ -1856,7 +1857,7 @@ class BrowserTestNonsecureURLRequest : public InProcessBrowserTest {
// Tests that a connection with obsolete TLS settings does not get a // Tests that a connection with obsolete TLS settings does not get a
// secure connection explanation. // secure connection explanation.
IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest, IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest,
SecurityStyleChangedObserverNonsecureConnection) { DidChangeVisibleSecurityStateObserverNonsecureConnection) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
SecurityStyleTestObserver observer(web_contents); SecurityStyleTestObserver observer(web_contents);
......
...@@ -75,13 +75,9 @@ void SecurityHandler::AttachToRenderFrameHost() { ...@@ -75,13 +75,9 @@ void SecurityHandler::AttachToRenderFrameHost() {
WebContents* web_contents = WebContents::FromRenderFrameHost(host_); WebContents* web_contents = WebContents::FromRenderFrameHost(host_);
WebContentsObserver::Observe(web_contents); WebContentsObserver::Observe(web_contents);
// Send an initial SecurityStyleChanged event. // Send an initial DidChangeVisibleSecurityState event.
DCHECK(enabled_); DCHECK(enabled_);
SecurityStyleExplanations security_style_explanations; DidChangeVisibleSecurityState();
blink::WebSecurityStyle security_style =
web_contents->GetDelegate()->GetSecurityStyle(
web_contents, &security_style_explanations);
SecurityStyleChanged(security_style, security_style_explanations);
} }
void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) {
...@@ -90,11 +86,14 @@ void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { ...@@ -90,11 +86,14 @@ void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) {
AttachToRenderFrameHost(); AttachToRenderFrameHost();
} }
void SecurityHandler::SecurityStyleChanged( void SecurityHandler::DidChangeVisibleSecurityState() {
blink::WebSecurityStyle security_style,
const SecurityStyleExplanations& security_style_explanations) {
DCHECK(enabled_); DCHECK(enabled_);
SecurityStyleExplanations security_style_explanations;
blink::WebSecurityStyle security_style =
web_contents()->GetDelegate()->GetSecurityStyle(
web_contents(), &security_style_explanations);
const std::string security_state = const std::string security_state =
SecurityStyleToProtocolSecurityState(security_style); SecurityStyleToProtocolSecurityState(security_style);
......
...@@ -32,9 +32,7 @@ class SecurityHandler : public WebContentsObserver { ...@@ -32,9 +32,7 @@ class SecurityHandler : public WebContentsObserver {
void AttachToRenderFrameHost(); void AttachToRenderFrameHost();
// WebContentsObserver overrides // WebContentsObserver overrides
void SecurityStyleChanged( void DidChangeVisibleSecurityState() override;
blink::WebSecurityStyle security_style,
const SecurityStyleExplanations& security_style_explanations) override;
std::unique_ptr<Client> client_; std::unique_ptr<Client> client_;
bool enabled_; bool enabled_;
......
...@@ -1471,14 +1471,8 @@ void WebContentsImpl::AttachToOuterWebContentsFrame( ...@@ -1471,14 +1471,8 @@ void WebContentsImpl::AttachToOuterWebContentsFrame(
void WebContentsImpl::DidChangeVisibleSecurityState() { void WebContentsImpl::DidChangeVisibleSecurityState() {
if (delegate_) { if (delegate_) {
delegate_->VisibleSecurityStateChanged(this); delegate_->VisibleSecurityStateChanged(this);
for (auto& observer : observers_)
SecurityStyleExplanations security_style_explanations; observer.DidChangeVisibleSecurityState();
blink::WebSecurityStyle security_style =
delegate_->GetSecurityStyle(this, &security_style_explanations);
for (auto& observer : observers_) {
observer.SecurityStyleChanged(security_style,
security_style_explanations);
}
} }
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ipc/ipc_listener.h" #include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h" #include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "third_party/WebKit/public/platform/WebSecurityStyle.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
...@@ -41,7 +40,6 @@ struct LoadCommittedDetails; ...@@ -41,7 +40,6 @@ struct LoadCommittedDetails;
struct Referrer; struct Referrer;
struct ResourceRedirectDetails; struct ResourceRedirectDetails;
struct ResourceRequestDetails; struct ResourceRequestDetails;
struct SecurityStyleExplanations;
// An observer API implemented by classes which are interested in various page // An observer API implemented by classes which are interested in various page
// load events from WebContents. They also get a chance to filter IPC messages. // load events from WebContents. They also get a chance to filter IPC messages.
...@@ -297,13 +295,8 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, ...@@ -297,13 +295,8 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
const base::string16& error_description, const base::string16& error_description,
bool was_ignored_by_handler) {} bool was_ignored_by_handler) {}
// This method is invoked when the SecurityStyle of the WebContents changes. // This method is invoked when the visible security state of the page changes.
// |security_style| is the new SecurityStyle. |security_style_explanations| virtual void DidChangeVisibleSecurityState() {}
// contains human-readable strings explaining why the SecurityStyle of the
// page has been downgraded.
virtual void SecurityStyleChanged(
blink::WebSecurityStyle security_style,
const SecurityStyleExplanations& security_style_explanations) {}
// This method is invoked when content was loaded from an in-memory cache. // This method is invoked when content was loaded from an in-memory cache.
virtual void DidLoadResourceFromMemoryCache( virtual void DidLoadResourceFromMemoryCache(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment