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
|
|
|
|
|
|
|
#include "content/public/renderer/render_frame.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
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-09-21 16:17:30 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
ContentSettingsObserver::~ContentSettingsObserver() {}
|
2016-09-21 16:17:30 +00:00
|
|
|
|
2019-02-21 07:59:38 +00:00
|
|
|
bool ContentSettingsObserver::AllowDatabase() {
|
2016-09-21 16:17:30 +00:00
|
|
|
blink::WebFrame* frame = render_frame()->GetWebFrame();
|
2017-06-16 20:42:33 +00:00
|
|
|
if (frame->GetSecurityOrigin().IsUnique() ||
|
|
|
|
frame->Top()->GetSecurityOrigin().IsUnique())
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-16 20:42:33 +00:00
|
|
|
bool ContentSettingsObserver::AllowStorage(bool local) {
|
2016-09-21 16:17:30 +00:00
|
|
|
blink::WebFrame* frame = render_frame()->GetWebFrame();
|
2017-06-16 20:42:33 +00:00
|
|
|
if (frame->GetSecurityOrigin().IsUnique() ||
|
|
|
|
frame->Top()->GetSecurityOrigin().IsUnique())
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-16 20:42:33 +00:00
|
|
|
bool ContentSettingsObserver::AllowIndexedDB(
|
2016-09-21 16:17:30 +00:00
|
|
|
const blink::WebSecurityOrigin& security_origin) {
|
|
|
|
blink::WebFrame* frame = render_frame()->GetWebFrame();
|
2017-06-16 20:42:33 +00:00
|
|
|
if (frame->GetSecurityOrigin().IsUnique() ||
|
|
|
|
frame->Top()->GetSecurityOrigin().IsUnique())
|
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;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|