electron/shell/renderer/content_settings_observer.cc
Charles Kerr 2b316f3843
refactor: run clang-tidy (#20231)
* refactor: clang-tidy modernize-use-nullptr

* refactor: clang-tidy modernize-use-equals-default

* refactor: clang-tidy modernize-make-unique

* refactor: omit nullptr arg from unique_ptr.reset()

As per comment by @miniak
2019-09-16 18:12:00 -04:00

60 lines
1.9 KiB
C++

// 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 "shell/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 electron {
ContentSettingsObserver::ContentSettingsObserver(
content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame) {
render_frame->GetWebFrame()->SetContentSettingsClient(this);
}
ContentSettingsObserver::~ContentSettingsObserver() = default;
bool ContentSettingsObserver::AllowDatabase() {
blink::WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique())
return false;
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
bool ContentSettingsObserver::AllowStorage(bool local) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique())
return false;
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
bool ContentSettingsObserver::AllowIndexedDB(
const blink::WebSecurityOrigin& security_origin) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique())
return false;
auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
if (!origin.IsStandard())
return false;
return true;
}
void ContentSettingsObserver::OnDestruct() {
delete this;
}
} // namespace electron