• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "WebPermissions.h"
32 
33 #include "TestCommon.h"
34 #include "public/platform/WebCString.h"
35 #include "public/platform/WebURL.h"
36 #include "public/testing/WebTestDelegate.h"
37 
38 using namespace std;
39 
40 namespace WebTestRunner {
41 
WebPermissions()42 WebPermissions::WebPermissions()
43     : m_delegate(0)
44 {
45     reset();
46 }
47 
~WebPermissions()48 WebPermissions::~WebPermissions()
49 {
50 }
51 
allowImage(blink::WebFrame *,bool enabledPerSettings,const blink::WebURL & imageURL)52 bool WebPermissions::allowImage(blink::WebFrame*, bool enabledPerSettings, const blink::WebURL& imageURL)
53 {
54     bool allowed = enabledPerSettings && m_imagesAllowed;
55     if (m_dumpCallbacks && m_delegate)
56         m_delegate->printMessage(std::string("PERMISSION CLIENT: allowImage(") + normalizeLayoutTestURL(imageURL.spec()) + "): " + (allowed ? "true" : "false") + "\n");
57     return allowed;
58 }
59 
allowScriptFromSource(blink::WebFrame *,bool enabledPerSettings,const blink::WebURL & scriptURL)60 bool WebPermissions::allowScriptFromSource(blink::WebFrame*, bool enabledPerSettings, const blink::WebURL& scriptURL)
61 {
62     bool allowed = enabledPerSettings && m_scriptsAllowed;
63     if (m_dumpCallbacks && m_delegate)
64         m_delegate->printMessage(std::string("PERMISSION CLIENT: allowScriptFromSource(") + normalizeLayoutTestURL(scriptURL.spec()) + "): " + (allowed ? "true" : "false") + "\n");
65     return allowed;
66 }
67 
allowStorage(blink::WebFrame *,bool)68 bool WebPermissions::allowStorage(blink::WebFrame*, bool)
69 {
70     return m_storageAllowed;
71 }
72 
allowPlugins(blink::WebFrame *,bool enabledPerSettings)73 bool WebPermissions::allowPlugins(blink::WebFrame*, bool enabledPerSettings)
74 {
75     return enabledPerSettings && m_pluginsAllowed;
76 }
77 
allowDisplayingInsecureContent(blink::WebFrame *,bool enabledPerSettings,const blink::WebSecurityOrigin &,const blink::WebURL &)78 bool WebPermissions::allowDisplayingInsecureContent(blink::WebFrame*, bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&)
79 {
80     return enabledPerSettings || m_displayingInsecureContentAllowed;
81 }
82 
allowRunningInsecureContent(blink::WebFrame *,bool enabledPerSettings,const blink::WebSecurityOrigin &,const blink::WebURL &)83 bool WebPermissions::allowRunningInsecureContent(blink::WebFrame*, bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&)
84 {
85     return enabledPerSettings || m_runningInsecureContentAllowed;
86 }
87 
setImagesAllowed(bool imagesAllowed)88 void WebPermissions::setImagesAllowed(bool imagesAllowed)
89 {
90     m_imagesAllowed = imagesAllowed;
91 }
92 
setScriptsAllowed(bool scriptsAllowed)93 void WebPermissions::setScriptsAllowed(bool scriptsAllowed)
94 {
95     m_scriptsAllowed = scriptsAllowed;
96 }
97 
setStorageAllowed(bool storageAllowed)98 void WebPermissions::setStorageAllowed(bool storageAllowed)
99 {
100     m_storageAllowed = storageAllowed;
101 }
102 
setPluginsAllowed(bool pluginsAllowed)103 void WebPermissions::setPluginsAllowed(bool pluginsAllowed)
104 {
105     m_pluginsAllowed = pluginsAllowed;
106 }
107 
setDisplayingInsecureContentAllowed(bool allowed)108 void WebPermissions::setDisplayingInsecureContentAllowed(bool allowed)
109 {
110     m_displayingInsecureContentAllowed = allowed;
111 }
112 
setRunningInsecureContentAllowed(bool allowed)113 void WebPermissions::setRunningInsecureContentAllowed(bool allowed)
114 {
115     m_runningInsecureContentAllowed = allowed;
116 }
117 
setDelegate(WebTestDelegate * delegate)118 void WebPermissions::setDelegate(WebTestDelegate* delegate)
119 {
120     m_delegate = delegate;
121 }
122 
setDumpCallbacks(bool dumpCallbacks)123 void WebPermissions::setDumpCallbacks(bool dumpCallbacks)
124 {
125     m_dumpCallbacks = dumpCallbacks;
126 }
127 
reset()128 void WebPermissions::reset()
129 {
130     m_dumpCallbacks = false;
131     m_imagesAllowed = true;
132     m_scriptsAllowed = true;
133     m_storageAllowed = true;
134     m_pluginsAllowed = true;
135     m_displayingInsecureContentAllowed = false;
136     m_runningInsecureContentAllowed = false;
137 }
138 
139 }
140