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#ifndef WebPermissionClient_h
32#define WebPermissionClient_h
33
34#include "public/platform/WebPermissionCallbacks.h"
35
36namespace blink {
37
38class WebDocument;
39class WebSecurityOrigin;
40class WebString;
41class WebURL;
42
43class WebPermissionClient {
44public:
45    // Controls whether access to Web Databases is allowed for this frame.
46    virtual bool allowDatabase(const WebString& name, const WebString& displayName, unsigned long estimatedSize) { return true; }
47
48    // Controls whether access to File System is allowed for this frame.
49    virtual bool requestFileSystemAccessSync() { return true; }
50
51    // Controls whether access to File System is allowed for this frame.
52    virtual void requestFileSystemAccessAsync(const WebPermissionCallbacks& callbacks) { WebPermissionCallbacks permissionCallbacks(callbacks); permissionCallbacks.doAllow(); }
53
54    // Controls whether images are allowed for this frame.
55    virtual bool allowImage(bool enabledPerSettings, const WebURL& imageURL) { return enabledPerSettings; }
56
57    // Controls whether access to Indexed DB are allowed for this frame.
58    virtual bool allowIndexedDB(const WebString& name, const WebSecurityOrigin&) { return true; }
59
60    // Controls whether HTML5 media elements (<audio>, <video>) are allowed for this frame.
61    virtual bool allowMedia(const WebURL& videoURL) { return true; }
62
63    // Controls whether plugins are allowed for this frame.
64    virtual bool allowPlugins(bool enabledPerSettings) { return enabledPerSettings; }
65
66    // Controls whether scripts are allowed to execute for this frame.
67    virtual bool allowScript(bool enabledPerSettings) { return enabledPerSettings; }
68
69    // Controls whether scripts loaded from the given URL are allowed to execute for this frame.
70    virtual bool allowScriptFromSource(bool enabledPerSettings, const WebURL& scriptURL) { return enabledPerSettings; }
71
72    // Controls whether insecrure content is allowed to display for this frame.
73    virtual bool allowDisplayingInsecureContent(bool enabledPerSettings, const WebSecurityOrigin&, const WebURL&) { return enabledPerSettings; }
74
75    // Controls whether insecrure scripts are allowed to execute for this frame.
76    virtual bool allowRunningInsecureContent(bool enabledPerSettings, const WebSecurityOrigin&, const WebURL&) { return enabledPerSettings; }
77
78    // Controls whether the given script extension should run in a new script
79    // context in this frame. If extensionGroup is 0, the script context is the
80    // frame's main context. Otherwise, it is a context created by
81    // WebLocalFrame::executeScriptInIsolatedWorld with that same extensionGroup
82    // value.
83    virtual bool allowScriptExtension(const WebString& extensionName, int extensionGroup) { return true; }
84
85    virtual bool allowScriptExtension(const WebString& extensionName, int extensionGroup, int worldId)
86    {
87        return allowScriptExtension(extensionName, extensionGroup);
88    }
89
90    // Controls whether HTML5 Web Storage is allowed for this frame.
91    // If local is true, then this is for local storage, otherwise it's for session storage.
92    virtual bool allowStorage(bool local) { return true; }
93
94    // Controls whether access to read the clipboard is allowed for this frame.
95    virtual bool allowReadFromClipboard(bool defaultValue) { return defaultValue; }
96
97    // Controls whether access to write the clipboard is allowed for this frame.
98    virtual bool allowWriteToClipboard(bool defaultValue) { return defaultValue; }
99
100    // Controls whether enabling Web Components API for this frame.
101    virtual bool allowWebComponents(bool defaultValue) { return defaultValue; }
102
103    // Controls whether to enable MutationEvents for this frame.
104    // The common use case of this method is actually to selectively disable MutationEvents,
105    // but it's been named for consistency with the rest of the interface.
106    virtual bool allowMutationEvents(bool defaultValue) { return defaultValue; }
107
108    // Controls whether pushState and related History APIs are enabled for this frame.
109    virtual bool allowPushState() { return true; }
110
111    // Notifies the client that the frame would have instantiated a plug-in if plug-ins were enabled.
112    virtual void didNotAllowPlugins() { }
113
114    // Notifies the client that the frame would have executed script if script were enabled.
115    virtual void didNotAllowScript() { }
116
117protected:
118    ~WebPermissionClient() { }
119};
120
121} // namespace blink
122
123#endif
124