content_settings_observer.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/renderer/content_settings_observer.h"
  5. #include "content/public/renderer/render_frame.h"
  6. #include "third_party/WebKit/public/platform/URLConversion.h"
  7. #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
  8. #include "third_party/WebKit/public/web/WebLocalFrame.h"
  9. namespace atom {
  10. ContentSettingsObserver::ContentSettingsObserver(
  11. content::RenderFrame* render_frame)
  12. : content::RenderFrameObserver(render_frame) {
  13. render_frame->GetWebFrame()->SetContentSettingsClient(this);
  14. }
  15. ContentSettingsObserver::~ContentSettingsObserver() {}
  16. bool ContentSettingsObserver::AllowDatabase(
  17. const blink::WebString& name,
  18. const blink::WebString& display_name,
  19. unsigned estimated_size) {
  20. blink::WebFrame* frame = render_frame()->GetWebFrame();
  21. if (frame->GetSecurityOrigin().IsUnique() ||
  22. frame->Top()->GetSecurityOrigin().IsUnique())
  23. return false;
  24. auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
  25. if (!origin.IsStandard())
  26. return false;
  27. return true;
  28. }
  29. bool ContentSettingsObserver::AllowStorage(bool local) {
  30. blink::WebFrame* frame = render_frame()->GetWebFrame();
  31. if (frame->GetSecurityOrigin().IsUnique() ||
  32. frame->Top()->GetSecurityOrigin().IsUnique())
  33. return false;
  34. auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
  35. if (!origin.IsStandard())
  36. return false;
  37. return true;
  38. }
  39. bool ContentSettingsObserver::AllowIndexedDB(
  40. const blink::WebString& name,
  41. const blink::WebSecurityOrigin& security_origin) {
  42. blink::WebFrame* frame = render_frame()->GetWebFrame();
  43. if (frame->GetSecurityOrigin().IsUnique() ||
  44. frame->Top()->GetSecurityOrigin().IsUnique())
  45. return false;
  46. auto origin = blink::WebStringToGURL(frame->GetSecurityOrigin().ToString());
  47. if (!origin.IsStandard())
  48. return false;
  49. return true;
  50. }
  51. void ContentSettingsObserver::OnDestruct() {
  52. delete this;
  53. }
  54. } // namespace atom