2016-09-21 16:17:30 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/renderer/content_settings_observer.h"
|
2016-09-21 16:17:30 +00:00
|
|
|
|
2020-07-22 05:34:34 +00:00
|
|
|
#include "base/command_line.h"
|
2016-09-21 16:17:30 +00:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
2020-05-06 19:52:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2020-11-10 17:06:03 +00:00
|
|
|
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
2018-07-20 16:08:18 +00:00
|
|
|
#include "third_party/blink/public/platform/url_conversion.h"
|
|
|
|
#include "third_party/blink/public/platform/web_security_origin.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2016-09-21 16:17:30 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
ContentSettingsObserver::ContentSettingsObserver(
|
|
|
|
content::RenderFrame* render_frame)
|
|
|
|
: content::RenderFrameObserver(render_frame) {
|
2017-06-16 20:42:33 +00:00
|
|
|
render_frame->GetWebFrame()->SetContentSettingsClient(this);
|
2016-09-21 16:17:30 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ContentSettingsObserver::~ContentSettingsObserver() = default;
|
2016-09-21 16:17:30 +00:00
|
|
|
|
2020-09-21 08:00:36 +00:00
|
|
|
bool ContentSettingsObserver::AllowStorageAccessSync(StorageType storage_type) {
|
|
|
|
if (storage_type == StorageType::kDatabase &&
|
2020-11-10 17:06:03 +00:00
|
|
|
// Command line support is still relevant for extensions.
|
|
|
|
!(base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
switches::kEnableWebSQL) ||
|
|
|
|
render_frame()->GetBlinkPreferences().enable_websql)) {
|
2016-09-21 16:17:30 +00:00
|
|
|
return false;
|
2020-09-21 08:00:36 +00:00
|
|
|
}
|
2016-09-21 16:17:30 +00:00
|
|
|
|
|
|
|
blink::WebFrame* frame = render_frame()->GetWebFrame();
|
2019-12-11 00:22:35 +00:00
|
|
|
if (frame->GetSecurityOrigin().IsOpaque() ||
|
|
|
|
frame->Top()->GetSecurityOrigin().IsOpaque())
|
2016-09-21 16:17:30 +00:00
|
|
|
return false;
|
2017-06-16 20:42:33 +00:00
|
|
|
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
|
2016-09-21 16:17:30 +00:00
|
|
|
if (!origin.IsStandard())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSettingsObserver::OnDestruct() {
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|