aw_content_settings_client.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/renderer/aw_content_settings_client.h"
  5. #include "content/public/common/url_constants.h"
  6. #include "content/public/renderer/render_frame.h"
  7. #include "third_party/blink/public/common/web_preferences/web_preferences.h"
  8. #include "third_party/blink/public/platform/web_url.h"
  9. #include "third_party/blink/public/web/web_local_frame.h"
  10. #include "url/gurl.h"
  11. namespace android_webview {
  12. namespace {
  13. bool AllowMixedContent(const blink::WebURL& url) {
  14. // We treat non-standard schemes as "secure" in the WebView to allow them to
  15. // be used for request interception.
  16. // TODO(benm): Tighten this restriction by requiring embedders to register
  17. // their custom schemes? See b/9420953.
  18. GURL gurl(url);
  19. return !gurl.IsStandard();
  20. }
  21. } // namespace
  22. AwContentSettingsClient::AwContentSettingsClient(
  23. content::RenderFrame* render_frame)
  24. : content::RenderFrameObserver(render_frame) {
  25. render_frame->GetWebFrame()->SetContentSettingsClient(this);
  26. }
  27. AwContentSettingsClient::~AwContentSettingsClient() {
  28. }
  29. bool AwContentSettingsClient::AllowImage(bool enabled_per_settings,
  30. const blink::WebURL& image_url) {
  31. if (ShouldAllowlistForContentSettings()) {
  32. return true;
  33. }
  34. return blink::WebContentSettingsClient::AllowImage(enabled_per_settings,
  35. image_url);
  36. }
  37. bool AwContentSettingsClient::AllowScript(bool enabled_per_settings) {
  38. if (ShouldAllowlistForContentSettings()) {
  39. return true;
  40. }
  41. return blink::WebContentSettingsClient::AllowScript(enabled_per_settings);
  42. }
  43. bool AwContentSettingsClient::AllowRunningInsecureContent(
  44. bool enabled_per_settings,
  45. const blink::WebURL& url) {
  46. return enabled_per_settings ? true : AllowMixedContent(url);
  47. }
  48. bool AwContentSettingsClient::ShouldAutoupgradeMixedContent() {
  49. return render_frame()->GetBlinkPreferences().allow_mixed_content_upgrades;
  50. }
  51. void AwContentSettingsClient::OnDestruct() {
  52. delete this;
  53. }
  54. bool AwContentSettingsClient::ShouldAllowlistForContentSettings() const {
  55. return render_frame()->GetWebFrame()->GetDocument().Url().GetString() ==
  56. content::kUnreachableWebDataURL;
  57. }
  58. } // namespace android_webview