electron/shell/renderer/content_settings_observer.cc

61 lines
1.9 KiB
C++
Raw Normal View History

// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/renderer/content_settings_observer.h"
#include "content/public/renderer/render_frame.h"
#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"
namespace atom {
ContentSettingsObserver::ContentSettingsObserver(
content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame) {
2017-06-16 20:42:33 +00:00
render_frame->GetWebFrame()->SetContentSettingsClient(this);
}
2018-04-18 01:55:30 +00:00
ContentSettingsObserver::~ContentSettingsObserver() {}
bool ContentSettingsObserver::AllowDatabase() {
blink::WebFrame* frame = render_frame()->GetWebFrame();
2017-06-16 20:42:33 +00:00
if (frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique())
return false;
2017-06-16 20:42:33 +00:00
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
2017-06-16 20:42:33 +00:00
bool ContentSettingsObserver::AllowStorage(bool local) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
2017-06-16 20:42:33 +00:00
if (frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique())
return false;
2017-06-16 20:42:33 +00:00
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
2017-06-16 20:42:33 +00:00
bool ContentSettingsObserver::AllowIndexedDB(
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())
return false;
2017-06-16 20:42:33 +00:00
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
void ContentSettingsObserver::OnDestruct() {
delete this;
}
} // namespace atom