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.
5 #include "components/test_runner/web_content_settings.h"
7 #include "components/test_runner/test_common.h"
8 #include "components/test_runner/web_test_delegate.h"
9 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebURL.h"
12 namespace test_runner
{
14 WebContentSettings::WebContentSettings() : delegate_(0) {
18 WebContentSettings::~WebContentSettings() {}
20 bool WebContentSettings::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");
31 bool WebContentSettings::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");
40 bool WebContentSettings::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");
52 bool WebContentSettings::allowStorage(bool) {
53 return storage_allowed_
;
56 bool WebContentSettings::allowPlugins(bool enabled_per_settings
) {
57 return enabled_per_settings
&& plugins_allowed_
;
60 bool WebContentSettings::allowDisplayingInsecureContent(
61 bool enabled_per_settings
,
62 const blink::WebSecurityOrigin
&,
63 const blink::WebURL
&) {
64 return enabled_per_settings
|| displaying_insecure_content_allowed_
;
67 bool WebContentSettings::allowRunningInsecureContent(
68 bool enabled_per_settings
,
69 const blink::WebSecurityOrigin
&,
70 const blink::WebURL
&) {
71 return enabled_per_settings
|| running_insecure_content_allowed_
;
74 void WebContentSettings::SetImagesAllowed(bool images_allowed
) {
75 images_allowed_
= images_allowed
;
78 void WebContentSettings::SetMediaAllowed(bool media_allowed
) {
79 media_allowed_
= media_allowed
;
82 void WebContentSettings::SetScriptsAllowed(bool scripts_allowed
) {
83 scripts_allowed_
= scripts_allowed
;
86 void WebContentSettings::SetStorageAllowed(bool storage_allowed
) {
87 storage_allowed_
= storage_allowed
;
90 void WebContentSettings::SetPluginsAllowed(bool plugins_allowed
) {
91 plugins_allowed_
= plugins_allowed
;
94 void WebContentSettings::SetDisplayingInsecureContentAllowed(bool allowed
) {
95 displaying_insecure_content_allowed_
= allowed
;
98 void WebContentSettings::SetRunningInsecureContentAllowed(bool allowed
) {
99 running_insecure_content_allowed_
= allowed
;
102 void WebContentSettings::SetDelegate(WebTestDelegate
* delegate
) {
103 delegate_
= delegate
;
106 void WebContentSettings::SetDumpCallbacks(bool dump_callbacks
) {
107 dump_callbacks_
= dump_callbacks
;
110 void WebContentSettings::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;
121 } // namespace test_runner