From 2d5b17552a83dffb45ff6b15fd8a199d0594f2ca Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Jan 2015 12:37:41 -0800 Subject: [PATCH] Add webFrame.registerUrlSchemeAsSecure API --- atom/renderer/api/atom_api_web_frame.cc | 28 ++++++++++++++++++++++++- docs/api/web-frame.md | 10 +++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 7d43428f4d05..f2ab42b219c4 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -4,6 +4,11 @@ #include "atom/renderer/api/atom_api_web_frame.h" +// This defines are required by SchemeRegistry.h. +#define OS(WTF_FEATURE) (defined WTF_OS_##WTF_FEATURE && WTF_OS_##WTF_FEATURE) +#define USE(WTF_FEATURE) (defined WTF_USE_##WTF_FEATURE && WTF_USE_##WTF_FEATURE) +#define ENABLE(WTF_FEATURE) (defined ENABLE_##WTF_FEATURE && ENABLE_##WTF_FEATURE) + #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/renderer/api/atom_api_spell_check_client.h" #include "content/public/renderer/render_frame.h" @@ -12,9 +17,28 @@ #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebView.h" +#include "third_party/WebKit/Source/platform/weborigin/SchemeRegistry.h" #include "atom/common/node_includes.h" +namespace mate { + +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Handle val, + WTF::String* out) { + if (!val->IsString()) + return false; + + v8::String::Value s(val); + *out = WTF::String(reinterpret_cast(*s), s.length()); + return true; + } +}; + +} // namespace mate + namespace atom { namespace api { @@ -82,7 +106,9 @@ mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder( .SetMethod("registerEmbedderCustomElement", &WebFrame::RegisterEmbedderCustomElement) .SetMethod("attachGuest", &WebFrame::AttachGuest) - .SetMethod("setSpellCheckProvider", &WebFrame::SetSpellCheckProvider); + .SetMethod("setSpellCheckProvider", &WebFrame::SetSpellCheckProvider) + .SetMethod("registerUrlSchemeAsSecure", + &blink::SchemeRegistry::registerURLSchemeAsSecure); } // static diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index f5bdd695a3cf..73b9ee50577f 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -53,4 +53,14 @@ require('web-frame').setSpellCheckProvider("en-US", true, { }); ``` +## webFrame.registerUrlSchemeAsSecure(scheme) + +* `scheme` String + +Sets the `scheme` as secure scheme. + +Secure schemes do not trigger mixed content warnings. For example, `https` and +`data` are secure schemes because they cannot be corrupted by active network +attackers. + [spellchecker]: https://github.com/atom/node-spellchecker