Home | History | Annotate | Download | only in web_view
      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.
      4 
      5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_PERMISSION_HELPER_DELEGATE_H_
      6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_PERMISSION_HELPER_DELEGATE_H_
      7 
      8 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
      9 #include "extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h"
     10 
     11 namespace extensions {
     12 class WebViewGuest;
     13 }
     14 
     15 class ChromeWebViewPermissionHelperDelegate :
     16   public extensions::WebViewPermissionHelperDelegate {
     17  public:
     18   explicit ChromeWebViewPermissionHelperDelegate(
     19       extensions::WebViewPermissionHelper* web_view_permission_helper);
     20   virtual ~ChromeWebViewPermissionHelperDelegate();
     21 
     22   // WebViewPermissionHelperDelegate implementation.
     23   virtual void CanDownload(
     24       content::RenderViewHost* render_view_host,
     25       const GURL& url,
     26       const std::string& request_method,
     27       const base::Callback<void(bool)>& callback) OVERRIDE;
     28   virtual void RequestPointerLockPermission(
     29       bool user_gesture,
     30       bool last_unlocked_by_target,
     31       const base::Callback<void(bool)>& callback) OVERRIDE;
     32   virtual void RequestGeolocationPermission(
     33       int bridge_id,
     34       const GURL& requesting_frame,
     35       bool user_gesture,
     36       const base::Callback<void(bool)>& callback) OVERRIDE;
     37   virtual void CancelGeolocationPermissionRequest(int bridge_id) OVERRIDE;
     38   virtual void RequestFileSystemPermission(
     39       const GURL& url,
     40       bool allowed_by_default,
     41       const base::Callback<void(bool)>& callback) OVERRIDE;
     42   virtual void FileSystemAccessedAsync(
     43       int render_process_id,
     44       int render_frame_id,
     45       int request_id,
     46       const GURL& url,
     47       bool blocked_by_policy) OVERRIDE;
     48   virtual void FileSystemAccessedSync(
     49       int render_process_id,
     50       int render_frame_id,
     51       const GURL& url,
     52       bool blocked_by_policy,
     53       IPC::Message* reply_msg) OVERRIDE;
     54 #if defined(ENABLE_PLUGINS)
     55   // content::WebContentsObserver implementation.
     56   virtual bool OnMessageReceived(
     57       const IPC::Message& message,
     58       content::RenderFrameHost* render_frame_host) OVERRIDE;
     59   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     60 #endif  // defined(ENABLE_PLUGINS)
     61 
     62  private:
     63 #if defined(ENABLE_PLUGINS)
     64   // Message handlers:
     65   void OnBlockedUnauthorizedPlugin(const base::string16& name,
     66                                    const std::string& identifier);
     67   void OnCouldNotLoadPlugin(const base::FilePath& plugin_path);
     68   void OnBlockedOutdatedPlugin(int placeholder_id,
     69                                const std::string& identifier);
     70   void OnNPAPINotSupported(const std::string& identifier);
     71   void OnOpenAboutPlugins();
     72 #if defined(ENABLE_PLUGIN_INSTALLATION)
     73   void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type);
     74 
     75   void OnRemovePluginPlaceholderHost(int placeholder_id);
     76 #endif  // defined(ENABLE_PLUGIN_INSTALLATION)
     77 
     78   void OnPermissionResponse(const std::string& identifier,
     79                             bool allow,
     80                             const std::string& user_input);
     81 #endif  // defined(ENABLE_PLUGINS)
     82 
     83   void OnGeolocationPermissionResponse(
     84       int bridge_id,
     85       bool user_gesture,
     86       const base::Callback<void(bool)>& callback,
     87       bool allow,
     88       const std::string& user_input);
     89 
     90   void OnFileSystemPermissionResponse(
     91       const base::Callback<void(bool)>& callback,
     92       bool allow,
     93       const std::string& user_input);
     94 
     95   void OnDownloadPermissionResponse(
     96       const base::Callback<void(bool)>& callback,
     97       bool allow,
     98       const std::string& user_input);
     99 
    100   void OnPointerLockPermissionResponse(
    101       const base::Callback<void(bool)>& callback,
    102       bool allow,
    103       const std::string& user_input);
    104 
    105   // Bridge IDs correspond to a geolocation request. This method will remove
    106   // the bookkeeping for a particular geolocation request associated with the
    107   // provided |bridge_id|. It returns the request ID of the geolocation request.
    108   int RemoveBridgeID(int bridge_id);
    109 
    110   void FileSystemAccessedAsyncResponse(int render_process_id,
    111                                        int render_frame_id,
    112                                        int request_id,
    113                                        const GURL& url,
    114                                        bool allowed);
    115 
    116   void FileSystemAccessedSyncResponse(int render_process_id,
    117                                       int render_frame_id,
    118                                       const GURL& url,
    119                                       IPC::Message* reply_msg,
    120                                       bool allowed);
    121 
    122   extensions::WebViewGuest* web_view_guest() {
    123     return web_view_permission_helper()->web_view_guest();
    124   }
    125 
    126   std::map<int, int> bridge_id_to_request_id_map_;
    127 
    128   base::WeakPtrFactory<ChromeWebViewPermissionHelperDelegate> weak_factory_;
    129 
    130   DISALLOW_COPY_AND_ASSIGN(ChromeWebViewPermissionHelperDelegate);
    131 };
    132 
    133 #endif  // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_PERMISSION_HELPER_DELEGATE_H_
    134