Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Emit more specific security state change events
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas committed Nov 11, 2016
1 parent 591eb13 commit b6eb04e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
66 changes: 52 additions & 14 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -199,6 +200,51 @@ struct Converter<atom::api::WebContents::Type> {
}
};

template<>
struct Converter<content::SecurityStyle> {
static v8::Local<v8::Value> 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<v8::Value> 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


Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/guest-view-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let supportedWebViewEvents = [
'will-navigate',
'did-navigate',
'did-navigate-in-page',
'did-change-security',
'security-style-changed',
'close',
'crashed',
'gpu-crashed',
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/web-view/guest-view-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand Down

0 comments on commit b6eb04e

Please sign in to comment.