2017-03-27 21:19:34 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/renderer/renderer_client_base.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "atom/common/color_util.h"
|
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
|
|
|
#include "atom/common/options_switches.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
#include "atom/renderer/atom_autofill_agent.h"
|
2017-04-08 14:54:58 +00:00
|
|
|
#include "atom/renderer/atom_render_frame_observer.h"
|
2018-03-09 09:31:09 +00:00
|
|
|
#include "atom/renderer/atom_render_view_observer.h"
|
2017-03-27 21:19:34 +00:00
|
|
|
#include "atom/renderer/content_settings_observer.h"
|
|
|
|
#include "atom/renderer/guest_view_container.h"
|
|
|
|
#include "atom/renderer/preferences_manager.h"
|
|
|
|
#include "base/command_line.h"
|
2017-08-04 17:41:34 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
2017-03-27 21:19:34 +00:00
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "chrome/renderer/media/chrome_key_systems.h"
|
|
|
|
#include "chrome/renderer/pepper/pepper_helper.h"
|
|
|
|
#include "chrome/renderer/printing/print_web_view_helper.h"
|
|
|
|
#include "chrome/renderer/tts_dispatcher.h"
|
|
|
|
#include "content/public/common/content_constants.h"
|
|
|
|
#include "content/public/renderer/render_view.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2018-03-09 09:31:09 +00:00
|
|
|
#include "third_party/WebKit/Source/platform/weborigin/SchemeRegistry.h"
|
2018-03-09 09:49:07 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebCustomElement.h" // NOLINT(build/include_alpha)
|
2017-03-27 21:19:34 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebFrameWidget.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebKit.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebPluginParams.h"
|
2017-04-08 13:43:19 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebScriptSource.h"
|
2017-03-27 21:19:34 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "base/mac/mac_util.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <shlobj.h>
|
|
|
|
#endif
|
|
|
|
|
2018-03-15 08:51:48 +00:00
|
|
|
#if defined(ENABLE_PDF_VIEWER)
|
|
|
|
#include "atom/common/atom_constants.h"
|
|
|
|
#endif // defined(ENABLE_PDF_VIEWER)
|
|
|
|
|
2017-03-27 21:19:34 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
v8::Local<v8::Value> GetRenderProcessPreferences(
|
|
|
|
const PreferencesManager* preferences_manager, v8::Isolate* isolate) {
|
|
|
|
if (preferences_manager->preferences())
|
|
|
|
return mate::ConvertToV8(isolate, *preferences_manager->preferences());
|
|
|
|
else
|
|
|
|
return v8::Null(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> ParseSchemesCLISwitch(const char* switch_name) {
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
std::string custom_schemes = command_line->GetSwitchValueASCII(switch_name);
|
|
|
|
return base::SplitString(
|
|
|
|
custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
RendererClientBase::RendererClientBase() {
|
|
|
|
// Parse --standard-schemes=scheme1,scheme2
|
|
|
|
std::vector<std::string> standard_schemes_list =
|
|
|
|
ParseSchemesCLISwitch(switches::kStandardSchemes);
|
|
|
|
for (const std::string& scheme : standard_schemes_list)
|
|
|
|
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
2017-07-28 00:08:24 +00:00
|
|
|
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
switches::kContextIsolation);
|
2017-03-27 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RendererClientBase::~RendererClientBase() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererClientBase::AddRenderBindings(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> binding_object) {
|
|
|
|
mate::Dictionary dict(isolate, binding_object);
|
|
|
|
dict.SetMethod(
|
|
|
|
"getRenderProcessPreferences",
|
|
|
|
base::Bind(GetRenderProcessPreferences, preferences_manager_.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererClientBase::RenderThreadStarted() {
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::WebCustomElement::AddEmbedderCustomElementName("webview");
|
|
|
|
blink::WebCustomElement::AddEmbedderCustomElementName("browserplugin");
|
2017-03-27 21:19:34 +00:00
|
|
|
|
2017-09-15 07:48:55 +00:00
|
|
|
WTF::String extension_scheme("chrome-extension");
|
|
|
|
// Extension resources are HTTP-like and safe to expose to the fetch API. The
|
|
|
|
// rules for the fetch API are consistent with XHR.
|
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSupportingFetchAPI(
|
|
|
|
extension_scheme);
|
|
|
|
// Extension resources, when loaded as the top-level document, should bypass
|
|
|
|
// Blink's strict first-party origin checks.
|
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsFirstPartyWhenTopLevel(
|
|
|
|
extension_scheme);
|
|
|
|
// In Chrome we should set extension's origins to match the pages they can
|
|
|
|
// work on, but in Electron currently we just let extensions do anything.
|
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSecure(extension_scheme);
|
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsCORSEnabled(extension_scheme);
|
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsBypassingContentSecurityPolicy(
|
|
|
|
extension_scheme);
|
|
|
|
|
2017-04-20 08:44:25 +00:00
|
|
|
// Parse --secure-schemes=scheme1,scheme2
|
|
|
|
std::vector<std::string> secure_schemes_list =
|
|
|
|
ParseSchemesCLISwitch(switches::kSecureSchemes);
|
|
|
|
for (const std::string& scheme : secure_schemes_list)
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSecure(
|
|
|
|
WTF::String::FromUTF8(scheme.data(), scheme.length()));
|
2017-04-20 08:44:25 +00:00
|
|
|
|
2017-12-17 20:56:53 +00:00
|
|
|
// Allow file scheme to handle service worker by default.
|
|
|
|
// FIXME(zcbenz): Can this be moved elsewhere?
|
|
|
|
blink::WebSecurityPolicy::RegisterURLSchemeAsAllowingServiceWorkers("file");
|
2017-12-18 09:29:28 +00:00
|
|
|
blink::SchemeRegistry::RegisterURLSchemeAsSupportingFetchAPI("file");
|
2017-12-17 20:56:53 +00:00
|
|
|
|
2017-03-27 21:19:34 +00:00
|
|
|
preferences_manager_.reset(new PreferencesManager);
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Set ApplicationUserModelID in renderer process.
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
base::string16 app_id =
|
|
|
|
command_line->GetSwitchValueNative(switches::kAppUserModelId);
|
|
|
|
if (!app_id.empty()) {
|
|
|
|
SetCurrentProcessExplicitAppUserModelID(app_id.c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2017-04-06 22:42:37 +00:00
|
|
|
bool scroll_bounce = command_line->HasSwitch(switches::kScrollBounce);
|
|
|
|
base::ScopedCFTypeRef<CFStringRef> rubber_banding_key(
|
|
|
|
base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding"));
|
|
|
|
CFPreferencesSetAppValue(rubber_banding_key,
|
|
|
|
scroll_bounce ? kCFBooleanTrue : kCFBooleanFalse,
|
|
|
|
kCFPreferencesCurrentApplication);
|
|
|
|
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
2017-03-27 21:19:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererClientBase::RenderFrameCreated(
|
|
|
|
content::RenderFrame* render_frame) {
|
2018-04-05 00:53:51 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2017-05-19 19:35:13 +00:00
|
|
|
new AutofillAgent(render_frame);
|
2018-04-05 00:53:51 +00:00
|
|
|
#endif
|
2017-03-27 21:19:34 +00:00
|
|
|
new PepperHelper(render_frame);
|
|
|
|
new ContentSettingsObserver(render_frame);
|
|
|
|
new printing::PrintWebViewHelper(render_frame);
|
|
|
|
|
|
|
|
// This is required for widevine plugin detection provided during runtime.
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::ResetPluginCache();
|
2017-03-27 21:19:34 +00:00
|
|
|
|
2018-03-15 08:51:48 +00:00
|
|
|
#if defined(ENABLE_PDF_VIEWER)
|
2017-03-27 21:19:34 +00:00
|
|
|
// Allow access to file scheme from pdf viewer.
|
2017-06-16 20:42:33 +00:00
|
|
|
blink::WebSecurityPolicy::AddOriginAccessWhitelistEntry(
|
2017-03-27 21:19:34 +00:00
|
|
|
GURL(kPdfViewerUIOrigin), "file", "", true);
|
2018-03-15 08:51:48 +00:00
|
|
|
#endif // defined(ENABLE_PDF_VIEWER)
|
2017-03-27 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RendererClientBase::RenderViewCreated(content::RenderView* render_view) {
|
2018-03-09 09:31:09 +00:00
|
|
|
new AtomRenderViewObserver(render_view);
|
2017-03-27 21:19:34 +00:00
|
|
|
blink::WebFrameWidget* web_frame_widget = render_view->GetWebFrameWidget();
|
|
|
|
if (!web_frame_widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
|
|
|
|
if (cmd->HasSwitch(switches::kGuestInstanceID)) { // webview.
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_widget->SetBaseBackgroundColor(SK_ColorTRANSPARENT);
|
2017-03-27 21:19:34 +00:00
|
|
|
} else { // normal window.
|
|
|
|
std::string name = cmd->GetSwitchValueASCII(switches::kBackgroundColor);
|
2018-02-19 14:07:28 +00:00
|
|
|
SkColor color = name.empty() ? SK_ColorTRANSPARENT : ParseHexColor(name);
|
2017-06-16 20:42:33 +00:00
|
|
|
web_frame_widget->SetBaseBackgroundColor(color);
|
2017-03-27 21:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:43:19 +00:00
|
|
|
void RendererClientBase::DidClearWindowObject(
|
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
// Make sure every page will get a script context created.
|
2017-06-16 20:42:33 +00:00
|
|
|
render_frame->GetWebFrame()->ExecuteScript(blink::WebScriptSource("void 0"));
|
2017-04-08 13:43:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 17:41:34 +00:00
|
|
|
std::unique_ptr<blink::WebSpeechSynthesizer>
|
|
|
|
RendererClientBase::OverrideSpeechSynthesizer(
|
2017-03-27 21:19:34 +00:00
|
|
|
blink::WebSpeechSynthesizerClient* client) {
|
2017-08-04 17:41:34 +00:00
|
|
|
return base::MakeUnique<TtsDispatcher>(client);
|
2017-03-27 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RendererClientBase::OverrideCreatePlugin(
|
|
|
|
content::RenderFrame* render_frame,
|
|
|
|
const blink::WebPluginParams& params,
|
|
|
|
blink::WebPlugin** plugin) {
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2017-06-16 20:42:33 +00:00
|
|
|
if (params.mime_type.Utf8() == content::kBrowserPluginMimeType ||
|
2018-03-15 08:51:48 +00:00
|
|
|
#if defined(ENABLE_PDF_VIEWER)
|
2017-06-16 20:42:33 +00:00
|
|
|
params.mime_type.Utf8() == kPdfPluginMimeType ||
|
2018-03-15 08:51:48 +00:00
|
|
|
#endif // defined(ENABLE_PDF_VIEWER)
|
2017-03-27 21:19:34 +00:00
|
|
|
command_line->HasSwitch(switches::kEnablePlugins))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*plugin = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BrowserPluginDelegate* RendererClientBase::CreateBrowserPluginDelegate(
|
|
|
|
content::RenderFrame* render_frame,
|
|
|
|
const std::string& mime_type,
|
|
|
|
const GURL& original_url) {
|
|
|
|
if (mime_type == content::kBrowserPluginMimeType) {
|
|
|
|
return new GuestViewContainer(render_frame);
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererClientBase::AddSupportedKeySystems(
|
|
|
|
std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems) {
|
|
|
|
AddChromeKeySystems(key_systems);
|
|
|
|
}
|
|
|
|
|
2017-07-28 00:08:24 +00:00
|
|
|
v8::Local<v8::Context> RendererClientBase::GetContext(
|
2017-08-21 23:09:28 +00:00
|
|
|
blink::WebLocalFrame* frame, v8::Isolate* isolate) {
|
2017-08-09 00:10:44 +00:00
|
|
|
if (isolated_world())
|
2017-08-24 21:31:25 +00:00
|
|
|
return frame->WorldScriptContext(isolate, World::ISOLATED_WORLD);
|
2017-08-09 00:10:44 +00:00
|
|
|
else
|
2017-08-24 21:31:25 +00:00
|
|
|
return frame->MainWorldScriptContext();
|
2017-07-28 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-27 21:19:34 +00:00
|
|
|
} // namespace atom
|