Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / guest_view / web_view / chrome_web_view_permission_helper_delegate.h
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 "chrome/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 RequestMediaAccessPermission(
24       content::WebContents* source,
25       const content::MediaStreamRequest& request,
26       const content::MediaResponseCallback& callback) OVERRIDE;
27   virtual void CanDownload(
28       content::RenderViewHost* render_view_host,
29       const GURL& url,
30       const std::string& request_method,
31       const base::Callback<void(bool)>& callback) OVERRIDE;
32   virtual void RequestPointerLockPermission(
33       bool user_gesture,
34       bool last_unlocked_by_target,
35       const base::Callback<void(bool)>& callback) OVERRIDE;
36   virtual void RequestGeolocationPermission(
37       int bridge_id,
38       const GURL& requesting_frame,
39       bool user_gesture,
40       const base::Callback<void(bool)>& callback) OVERRIDE;
41   virtual void CancelGeolocationPermissionRequest(int bridge_id) OVERRIDE;
42   virtual void RequestFileSystemPermission(
43       const GURL& url,
44       bool allowed_by_default,
45       const base::Callback<void(bool)>& callback) OVERRIDE;
46   virtual void FileSystemAccessedAsync(
47       int render_process_id,
48       int render_frame_id,
49       int request_id,
50       const GURL& url,
51       bool blocked_by_policy) OVERRIDE;
52   virtual void FileSystemAccessedSync(
53       int render_process_id,
54       int render_frame_id,
55       const GURL& url,
56       bool blocked_by_policy,
57       IPC::Message* reply_msg) OVERRIDE;
58 #if defined(ENABLE_PLUGINS)
59   // content::WebContentsObserver implementation.
60   virtual bool OnMessageReceived(
61       const IPC::Message& message,
62       content::RenderFrameHost* render_frame_host) OVERRIDE;
63   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
64 #endif  // defined(ENABLE_PLUGINS)
65
66  private:
67 #if defined(ENABLE_PLUGINS)
68   // Message handlers:
69   void OnBlockedUnauthorizedPlugin(const base::string16& name,
70                                    const std::string& identifier);
71   void OnCouldNotLoadPlugin(const base::FilePath& plugin_path);
72   void OnBlockedOutdatedPlugin(int placeholder_id,
73                                const std::string& identifier);
74   void OnNPAPINotSupported(const std::string& identifier);
75   void OnOpenAboutPlugins();
76 #if defined(ENABLE_PLUGIN_INSTALLATION)
77   void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type);
78
79   void OnRemovePluginPlaceholderHost(int placeholder_id);
80 #endif  // defined(ENABLE_PLUGIN_INSTALLATION)
81
82   void OnPermissionResponse(const std::string& identifier,
83                             bool allow,
84                             const std::string& user_input);
85 #endif  // defined(ENABLE_PLUGINS)
86
87   void OnGeolocationPermissionResponse(
88       int bridge_id,
89       bool user_gesture,
90       const base::Callback<void(bool)>& callback,
91       bool allow,
92       const std::string& user_input);
93
94   void OnFileSystemPermissionResponse(
95       const base::Callback<void(bool)>& callback,
96       bool allow,
97       const std::string& user_input);
98
99   void OnMediaPermissionResponse(
100       const content::MediaStreamRequest& request,
101       const content::MediaResponseCallback& callback,
102       bool allow,
103       const std::string& user_input);
104
105   void OnDownloadPermissionResponse(
106       const base::Callback<void(bool)>& callback,
107       bool allow,
108       const std::string& user_input);
109
110   void OnPointerLockPermissionResponse(
111       const base::Callback<void(bool)>& callback,
112       bool allow,
113       const std::string& user_input);
114
115   // Bridge IDs correspond to a geolocation request. This method will remove
116   // the bookkeeping for a particular geolocation request associated with the
117   // provided |bridge_id|. It returns the request ID of the geolocation request.
118   int RemoveBridgeID(int bridge_id);
119
120   void FileSystemAccessedAsyncResponse(int render_process_id,
121                                        int render_frame_id,
122                                        int request_id,
123                                        const GURL& url,
124                                        bool allowed);
125
126   void FileSystemAccessedSyncResponse(int render_process_id,
127                                       int render_frame_id,
128                                       const GURL& url,
129                                       IPC::Message* reply_msg,
130                                       bool allowed);
131
132   extensions::WebViewGuest* web_view_guest() {
133     return web_view_permission_helper_->web_view_guest();
134   }
135
136   extensions::WebViewPermissionHelper* web_view_permission_helper_;
137
138   std::map<int, int> bridge_id_to_request_id_map_;
139
140   base::WeakPtrFactory<ChromeWebViewPermissionHelperDelegate> weak_factory_;
141
142   DISALLOW_COPY_AND_ASSIGN(ChromeWebViewPermissionHelperDelegate);
143 };
144
145 #endif  // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_PERMISSION_HELPER_DELEGATE_H_