From b6eb04e8673756bcf8b2283eec4468c25e22c5e9 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 10 Nov 2016 17:19:18 -0800 Subject: [PATCH 1/2] Emit more specific security state change events Needed for https://github.com/brave/browser-laptop/issues/5524 Auditors: @bridiver @darkdh --- atom/browser/api/atom_api_web_contents.cc | 66 +++++++++++++++----- lib/browser/guest-view-manager.js | 2 +- lib/renderer/web-view/guest-view-internal.js | 2 +- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 0993537caf..e47a6640b2 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -72,6 +72,7 @@ #include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/resource_request_details.h" +#include "content/public/browser/security_style_explanations.h" #include "content/public/browser/service_worker_context.h" #include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" @@ -199,6 +200,51 @@ struct Converter { } }; +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + content::SecurityStyle val) { + std::string type; + switch (val) { + case content::SECURITY_STYLE_UNAUTHENTICATED: + type = "insecure"; + break; + case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: + type = "broken"; + break; + case content::SECURITY_STYLE_WARNING: + type = "warning"; + break; + case content::SECURITY_STYLE_AUTHENTICATED: + type = "secure"; + break; + default: + type = "unknown"; + break; + } + return mate::ConvertToV8(isolate, type); + } + + static bool FromV8(v8::Isolate* isolate, v8::Local val, + content::SecurityStyle* out) { + std::string type; + if (!ConvertFromV8(isolate, val, &type)) + return false; + if (type == "insecure") { + *out = content::SECURITY_STYLE_UNAUTHENTICATED; + } else if (type == "broken") { + *out = content::SECURITY_STYLE_AUTHENTICATION_BROKEN; + } else if (type == "warning") { + *out = content::SECURITY_STYLE_WARNING; + } else if (type == "secure") { + *out = content::SECURITY_STYLE_AUTHENTICATED; + } else { + return false; + } + return true; + } +}; + } // namespace mate @@ -893,21 +939,13 @@ void WebContents::DidFinishNavigation( void WebContents::SecurityStyleChanged( content::SecurityStyle security_style, const content::SecurityStyleExplanations& explanations) { - std::string type = "unknown"; - switch (security_style) { - case content::SECURITY_STYLE_UNAUTHENTICATED: - case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: - type = "insecure"; - break; - case content::SECURITY_STYLE_WARNING: - type = "warning"; - break; - case content::SECURITY_STYLE_AUTHENTICATED: - type = "secure"; - break; - default: break; + if (explanations.ran_insecure_content) { + Emit("security-style-changed", "active-mixed-content"); + } else if (explanations.displayed_insecure_content) { + Emit("security-style-changed", "passive-mixed-content"); + } else { + Emit("security-style-changed", security_style); } - Emit("did-change-security", type); } void WebContents::TitleWasSet(content::NavigationEntry* entry, diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 127713dda5..b156564b34 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -33,7 +33,7 @@ let supportedWebViewEvents = [ 'will-navigate', 'did-navigate', 'did-navigate-in-page', - 'did-change-security', + 'security-style-changed', 'close', 'crashed', 'gpu-crashed', diff --git a/lib/renderer/web-view/guest-view-internal.js b/lib/renderer/web-view/guest-view-internal.js index 10f132769e..99b62a3dd4 100644 --- a/lib/renderer/web-view/guest-view-internal.js +++ b/lib/renderer/web-view/guest-view-internal.js @@ -35,7 +35,7 @@ var WEB_VIEW_EVENTS = { 'gpu-crashed': [], 'plugin-crashed': ['name', 'version'], 'destroyed': [], - 'did-change-security': ['securityState'], + 'security-style-changed': ['securityState'], 'page-title-updated': ['title', 'explicitSet'], 'page-favicon-updated': ['favicons'], 'enter-html-full-screen': [], From bd5a247366eff6ec06d8621048c805a7509c3ab6 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 10 Nov 2016 19:25:02 -0800 Subject: [PATCH 2/2] Treat active-mixed-content as just insecure --- atom/browser/api/atom_api_web_contents.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e47a6640b2..228bddd9c4 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -939,9 +939,8 @@ void WebContents::DidFinishNavigation( void WebContents::SecurityStyleChanged( content::SecurityStyle security_style, const content::SecurityStyleExplanations& explanations) { - if (explanations.ran_insecure_content) { - Emit("security-style-changed", "active-mixed-content"); - } else if (explanations.displayed_insecure_content) { + if (explanations.displayed_insecure_content && + security_style == content::SECURITY_STYLE_UNAUTHENTICATED) { Emit("security-style-changed", "passive-mixed-content"); } else { Emit("security-style-changed", security_style);