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

Commit b6eb04e

Browse files
committed
Emit more specific security state change events
Needed for brave/browser-laptop#5524 Auditors: @bridiver @darkdh
1 parent 591eb13 commit b6eb04e

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

atom/browser/api/atom_api_web_contents.cc

+52-14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "content/public/browser/render_widget_host.h"
7373
#include "content/public/browser/render_widget_host_view.h"
7474
#include "content/public/browser/resource_request_details.h"
75+
#include "content/public/browser/security_style_explanations.h"
7576
#include "content/public/browser/service_worker_context.h"
7677
#include "content/public/browser/site_instance.h"
7778
#include "content/public/browser/storage_partition.h"
@@ -199,6 +200,51 @@ struct Converter<atom::api::WebContents::Type> {
199200
}
200201
};
201202

203+
template<>
204+
struct Converter<content::SecurityStyle> {
205+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
206+
content::SecurityStyle val) {
207+
std::string type;
208+
switch (val) {
209+
case content::SECURITY_STYLE_UNAUTHENTICATED:
210+
type = "insecure";
211+
break;
212+
case content::SECURITY_STYLE_AUTHENTICATION_BROKEN:
213+
type = "broken";
214+
break;
215+
case content::SECURITY_STYLE_WARNING:
216+
type = "warning";
217+
break;
218+
case content::SECURITY_STYLE_AUTHENTICATED:
219+
type = "secure";
220+
break;
221+
default:
222+
type = "unknown";
223+
break;
224+
}
225+
return mate::ConvertToV8(isolate, type);
226+
}
227+
228+
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
229+
content::SecurityStyle* out) {
230+
std::string type;
231+
if (!ConvertFromV8(isolate, val, &type))
232+
return false;
233+
if (type == "insecure") {
234+
*out = content::SECURITY_STYLE_UNAUTHENTICATED;
235+
} else if (type == "broken") {
236+
*out = content::SECURITY_STYLE_AUTHENTICATION_BROKEN;
237+
} else if (type == "warning") {
238+
*out = content::SECURITY_STYLE_WARNING;
239+
} else if (type == "secure") {
240+
*out = content::SECURITY_STYLE_AUTHENTICATED;
241+
} else {
242+
return false;
243+
}
244+
return true;
245+
}
246+
};
247+
202248
} // namespace mate
203249

204250

@@ -893,21 +939,13 @@ void WebContents::DidFinishNavigation(
893939
void WebContents::SecurityStyleChanged(
894940
content::SecurityStyle security_style,
895941
const content::SecurityStyleExplanations& explanations) {
896-
std::string type = "unknown";
897-
switch (security_style) {
898-
case content::SECURITY_STYLE_UNAUTHENTICATED:
899-
case content::SECURITY_STYLE_AUTHENTICATION_BROKEN:
900-
type = "insecure";
901-
break;
902-
case content::SECURITY_STYLE_WARNING:
903-
type = "warning";
904-
break;
905-
case content::SECURITY_STYLE_AUTHENTICATED:
906-
type = "secure";
907-
break;
908-
default: break;
942+
if (explanations.ran_insecure_content) {
943+
Emit("security-style-changed", "active-mixed-content");
944+
} else if (explanations.displayed_insecure_content) {
945+
Emit("security-style-changed", "passive-mixed-content");
946+
} else {
947+
Emit("security-style-changed", security_style);
909948
}
910-
Emit("did-change-security", type);
911949
}
912950

913951
void WebContents::TitleWasSet(content::NavigationEntry* entry,

lib/browser/guest-view-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let supportedWebViewEvents = [
3333
'will-navigate',
3434
'did-navigate',
3535
'did-navigate-in-page',
36-
'did-change-security',
36+
'security-style-changed',
3737
'close',
3838
'crashed',
3939
'gpu-crashed',

lib/renderer/web-view/guest-view-internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var WEB_VIEW_EVENTS = {
3535
'gpu-crashed': [],
3636
'plugin-crashed': ['name', 'version'],
3737
'destroyed': [],
38-
'did-change-security': ['securityState'],
38+
'security-style-changed': ['securityState'],
3939
'page-title-updated': ['title', 'explicitSet'],
4040
'page-favicon-updated': ['favicons'],
4141
'enter-html-full-screen': [],

0 commit comments

Comments
 (0)