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

Emit more specific security state change events #92

Merged
merged 2 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 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,12 @@ 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.displayed_insecure_content &&
security_style == content::SECURITY_STYLE_UNAUTHENTICATED) {
Emit("security-style-changed", "passive-mixed-content");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think we're passing through the wrong info here. passive-mixed-content is additional information about the security style and it should be a 3rd param imo because it's somewhat independent of the security style

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diracdeltas your last comment didn't show up on github and I just now saw the email. I'll merge

} else {
Emit("security-style-changed", security_style);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on name change and converter

}
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