Home | History | Annotate | Download | only in web
      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 
     36 namespace blink {
     37 
     38 class WebDocument;
     39 class WebSecurityOrigin;
     40 class WebString;
     41 class WebURL;
     42 
     43 class WebPermissionClient {
     44 public:
     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 plugins are allowed for this frame.
     61     virtual bool allowPlugins(bool enabledPerSettings) { return enabledPerSettings; }
     62 
     63     // Controls whether scripts are allowed to execute for this frame.
     64     virtual bool allowScript(bool enabledPerSettings) { return enabledPerSettings; }
     65 
     66     // Controls whether scripts loaded from the given URL are allowed to execute for this frame.
     67     virtual bool allowScriptFromSource(bool enabledPerSettings, const WebURL& scriptURL) { return enabledPerSettings; }
     68 
     69     // Controls whether insecrure content is allowed to display for this frame.
     70     virtual bool allowDisplayingInsecureContent(bool enabledPerSettings, const WebSecurityOrigin&, const WebURL&) { return enabledPerSettings; }
     71 
     72     // Controls whether insecrure scripts are allowed to execute for this frame.
     73     virtual bool allowRunningInsecureContent(bool enabledPerSettings, const WebSecurityOrigin&, const WebURL&) { return enabledPerSettings; }
     74 
     75     // Controls whether the given script extension should run in a new script
     76     // context in this frame. If extensionGroup is 0, the script context is the
     77     // frame's main context. Otherwise, it is a context created by
     78     // WebLocalFrame::executeScriptInIsolatedWorld with that same extensionGroup
     79     // value.
     80     virtual bool allowScriptExtension(const WebString& extensionName, int extensionGroup) { return true; }
     81 
     82     virtual bool allowScriptExtension(const WebString& extensionName, int extensionGroup, int worldId)
     83     {
     84         return allowScriptExtension(extensionName, extensionGroup);
     85     }
     86 
     87     // Controls whether HTML5 Web Storage is allowed for this frame.
     88     // If local is true, then this is for local storage, otherwise it's for session storage.
     89     virtual bool allowStorage(bool local) { return true; }
     90 
     91     // Controls whether access to read the clipboard is allowed for this frame.
     92     virtual bool allowReadFromClipboard(bool defaultValue) { return defaultValue; }
     93 
     94     // Controls whether access to write the clipboard is allowed for this frame.
     95     virtual bool allowWriteToClipboard(bool defaultValue) { return defaultValue; }
     96 
     97     // Controls whether enabling Web Components API for this frame.
     98     virtual bool allowWebComponents(bool defaultValue) { return defaultValue; }
     99 
    100     // Controls whether to enable MutationEvents for this frame.
    101     // The common use case of this method is actually to selectively disable MutationEvents,
    102     // but it's been named for consistency with the rest of the interface.
    103     virtual bool allowMutationEvents(bool defaultValue) { return defaultValue; }
    104 
    105     // Controls whether pushState and related History APIs are enabled for this frame.
    106     virtual bool allowPushState() { return true; }
    107 
    108     // Notifies the client that the frame would have instantiated a plug-in if plug-ins were enabled.
    109     virtual void didNotAllowPlugins() { }
    110 
    111     // Notifies the client that the frame would have executed script if script were enabled.
    112     virtual void didNotAllowScript() { }
    113 
    114 protected:
    115     ~WebPermissionClient() { }
    116 };
    117 
    118 } // namespace blink
    119 
    120 #endif
    121