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 "content/shell/renderer/test_runner/web_permissions.h"
7 #include "content/shell/renderer/test_runner/test_common.h"
8 #include "content/shell/renderer/test_runner/web_test_delegate.h"
9 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebURL.h"
14 WebPermissions::WebPermissions() : delegate_(0) {
18 WebPermissions::~WebPermissions() {}
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");
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");
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");
52 bool WebPermissions::allowStorage(bool) {
53 return storage_allowed_;
56 bool WebPermissions::allowPlugins(bool enabled_per_settings) {
57 return enabled_per_settings && plugins_allowed_;
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_;
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_;
74 void WebPermissions::SetImagesAllowed(bool images_allowed) {
75 images_allowed_ = images_allowed;
78 void WebPermissions::SetMediaAllowed(bool media_allowed) {
79 media_allowed_ = media_allowed;
82 void WebPermissions::SetScriptsAllowed(bool scripts_allowed) {
83 scripts_allowed_ = scripts_allowed;
86 void WebPermissions::SetStorageAllowed(bool storage_allowed) {
87 storage_allowed_ = storage_allowed;
90 void WebPermissions::SetPluginsAllowed(bool plugins_allowed) {
91 plugins_allowed_ = plugins_allowed;
94 void WebPermissions::SetDisplayingInsecureContentAllowed(bool allowed) {
95 displaying_insecure_content_allowed_ = allowed;
98 void WebPermissions::SetRunningInsecureContentAllowed(bool allowed) {
99 running_insecure_content_allowed_ = allowed;
102 void WebPermissions::SetDelegate(WebTestDelegate* delegate) {
103 delegate_ = delegate;
106 void WebPermissions::SetDumpCallbacks(bool dump_callbacks) {
107 dump_callbacks_ = dump_callbacks;
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;
121 } // namespace content