• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 
5 #include "content/shell/renderer/test_runner/web_permissions.h"
6 
7 #include "content/shell/renderer/test_runner/TestCommon.h"
8 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
9 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebURL.h"
11 
12 namespace content {
13 
WebPermissions()14 WebPermissions::WebPermissions() : delegate_(0) {
15   Reset();
16 }
17 
~WebPermissions()18 WebPermissions::~WebPermissions() {}
19 
allowImage(bool enabled_per_settings,const blink::WebURL & image_url)20 bool WebPermissions::allowImage(bool enabled_per_settings,
21                                 const blink::WebURL& image_url) {
22   bool allowed = enabled_per_settings && images_allowed_;
23   if (dump_callbacks_ && delegate_) {
24     delegate_->printMessage(std::string("PERMISSION CLIENT: allowImage(") +
25                              normalizeLayoutTestURL(image_url.spec()) + "): " +
26                              (allowed ? "true" : "false") + "\n");
27   }
28   return allowed;
29 }
30 
allowMedia(const blink::WebURL & image_url)31 bool WebPermissions::allowMedia(const blink::WebURL& image_url) {
32   bool allowed = media_allowed_;
33   if (dump_callbacks_ && delegate_)
34     delegate_->printMessage(std::string("PERMISSION CLIENT: allowMedia(") +
35                              normalizeLayoutTestURL(image_url.spec()) + "): " +
36                              (allowed ? "true" : "false") + "\n");
37   return allowed;
38 }
39 
allowScriptFromSource(bool enabled_per_settings,const blink::WebURL & scriptURL)40 bool WebPermissions::allowScriptFromSource(bool enabled_per_settings,
41                                            const blink::WebURL& scriptURL) {
42   bool allowed = enabled_per_settings && scripts_allowed_;
43   if (dump_callbacks_ && delegate_) {
44     delegate_->printMessage(
45         std::string("PERMISSION CLIENT: allowScriptFromSource(") +
46         normalizeLayoutTestURL(scriptURL.spec()) + "): " +
47         (allowed ? "true" : "false") + "\n");
48   }
49   return allowed;
50 }
51 
allowStorage(bool)52 bool WebPermissions::allowStorage(bool) {
53   return storage_allowed_;
54 }
55 
allowPlugins(bool enabled_per_settings)56 bool WebPermissions::allowPlugins(bool enabled_per_settings) {
57   return enabled_per_settings && plugins_allowed_;
58 }
59 
allowDisplayingInsecureContent(bool enabled_per_settings,const blink::WebSecurityOrigin &,const blink::WebURL &)60 bool WebPermissions::allowDisplayingInsecureContent(
61     bool enabled_per_settings,
62     const blink::WebSecurityOrigin&,
63     const blink::WebURL&) {
64   return enabled_per_settings || displaying_insecure_content_allowed_;
65 }
66 
allowRunningInsecureContent(bool enabled_per_settings,const blink::WebSecurityOrigin &,const blink::WebURL &)67 bool WebPermissions::allowRunningInsecureContent(
68     bool enabled_per_settings,
69     const blink::WebSecurityOrigin&,
70     const blink::WebURL&) {
71   return enabled_per_settings || running_insecure_content_allowed_;
72 }
73 
SetImagesAllowed(bool images_allowed)74 void WebPermissions::SetImagesAllowed(bool images_allowed) {
75   images_allowed_ = images_allowed;
76 }
77 
SetMediaAllowed(bool media_allowed)78 void WebPermissions::SetMediaAllowed(bool media_allowed) {
79   media_allowed_ = media_allowed;
80 }
81 
SetScriptsAllowed(bool scripts_allowed)82 void WebPermissions::SetScriptsAllowed(bool scripts_allowed) {
83   scripts_allowed_ = scripts_allowed;
84 }
85 
SetStorageAllowed(bool storage_allowed)86 void WebPermissions::SetStorageAllowed(bool storage_allowed) {
87   storage_allowed_ = storage_allowed;
88 }
89 
SetPluginsAllowed(bool plugins_allowed)90 void WebPermissions::SetPluginsAllowed(bool plugins_allowed) {
91   plugins_allowed_ = plugins_allowed;
92 }
93 
SetDisplayingInsecureContentAllowed(bool allowed)94 void WebPermissions::SetDisplayingInsecureContentAllowed(bool allowed) {
95   displaying_insecure_content_allowed_ = allowed;
96 }
97 
SetRunningInsecureContentAllowed(bool allowed)98 void WebPermissions::SetRunningInsecureContentAllowed(bool allowed) {
99   running_insecure_content_allowed_ = allowed;
100 }
101 
SetDelegate(WebTestDelegate * delegate)102 void WebPermissions::SetDelegate(WebTestDelegate* delegate) {
103   delegate_ = delegate;
104 }
105 
SetDumpCallbacks(bool dump_callbacks)106 void WebPermissions::SetDumpCallbacks(bool dump_callbacks) {
107   dump_callbacks_ = dump_callbacks;
108 }
109 
Reset()110 void WebPermissions::Reset() {
111   dump_callbacks_ = false;
112   images_allowed_ = true;
113   media_allowed_ = true;
114   scripts_allowed_ = true;
115   storage_allowed_ = true;
116   plugins_allowed_ = true;
117   displaying_insecure_content_allowed_ = false;
118   running_insecure_content_allowed_ = false;
119 }
120 
121 }  // namespace content
122