| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ |
| 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
| 10 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 10 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/common/media_stream_request.h" | 13 #include "content/public/common/media_stream_request.h" |
| 14 #include "extensions/browser/guest_view/guest_view_constants.h" | 14 #include "extensions/browser/guest_view/guest_view_constants.h" |
| 15 | 15 |
| 16 using base::UserMetricsAction; | 16 using base::UserMetricsAction; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 class WebViewGuest; | 20 class WebViewGuest; |
| 21 class WebViewPermissionHelperDelegate; |
| 21 | 22 |
| 22 // WebViewPermissionHelper manages <webview> permission requests. This helper | 23 // WebViewPermissionHelper manages <webview> permission requests. This helper |
| 23 // class is owned by WebViewGuest. Its purpose is to request permission for | 24 // class is owned by WebViewGuest. Its purpose is to request permission for |
| 24 // various operations from the <webview> embedder, and reply back via callbacks | 25 // various operations from the <webview> embedder, and reply back via callbacks |
| 25 // to the callers on a response from the embedder. | 26 // to the callers on a response from the embedder. |
| 26 class WebViewPermissionHelper | 27 class WebViewPermissionHelper |
| 27 : public content::WebContentsObserver { | 28 : public content::WebContentsObserver { |
| 28 public: | 29 public: |
| 29 explicit WebViewPermissionHelper(WebViewGuest* guest); | 30 explicit WebViewPermissionHelper(WebViewGuest* guest); |
| 30 virtual ~WebViewPermissionHelper(); | 31 virtual ~WebViewPermissionHelper(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 SET_PERMISSION_DENIED | 120 SET_PERMISSION_DENIED |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 // Responds to the permission request |request_id| with |action| and | 123 // Responds to the permission request |request_id| with |action| and |
| 123 // |user_input|. Returns whether there was a pending request for the provided | 124 // |user_input|. Returns whether there was a pending request for the provided |
| 124 // |request_id|. | 125 // |request_id|. |
| 125 SetPermissionResult SetPermission(int request_id, | 126 SetPermissionResult SetPermission(int request_id, |
| 126 PermissionResponseAction action, | 127 PermissionResponseAction action, |
| 127 const std::string& user_input); | 128 const std::string& user_input); |
| 128 | 129 |
| 130 void ErasePendingPermissionRequest(int request_id); |
| 131 |
| 132 WebViewGuest* web_view_guest() { return web_view_guest_; } |
| 133 |
| 129 private: | 134 private: |
| 130 #if defined(ENABLE_PLUGINS) | 135 #if defined(ENABLE_PLUGINS) |
| 131 // content::WebContentsObserver implementation. | 136 // content::WebContentsObserver implementation. |
| 132 virtual bool OnMessageReceived( | 137 virtual bool OnMessageReceived( |
| 133 const IPC::Message& message, | 138 const IPC::Message& message, |
| 134 content::RenderFrameHost* render_frame_host) OVERRIDE; | 139 content::RenderFrameHost* render_frame_host) OVERRIDE; |
| 135 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 140 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 136 | 141 #endif // defined(ENABLE_PLUGINS) |
| 137 // Message handlers: | |
| 138 void OnBlockedUnauthorizedPlugin(const base::string16& name, | |
| 139 const std::string& identifier); | |
| 140 void OnCouldNotLoadPlugin(const base::FilePath& plugin_path); | |
| 141 void OnBlockedOutdatedPlugin(int placeholder_id, | |
| 142 const std::string& identifier); | |
| 143 void OnNPAPINotSupported(const std::string& identifier); | |
| 144 void OnOpenAboutPlugins(); | |
| 145 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
| 146 void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type); | |
| 147 | |
| 148 void OnRemovePluginPlaceholderHost(int placeholder_id); | |
| 149 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | |
| 150 | |
| 151 void OnPermissionResponse(const std::string& identifier, | |
| 152 bool allow, | |
| 153 const std::string& user_input); | |
| 154 #endif // defiend(ENABLE_PLUGINS) | |
| 155 | |
| 156 void OnGeolocationPermissionResponse( | |
| 157 int bridge_id, | |
| 158 bool user_gesture, | |
| 159 const base::Callback<void(bool)>& callback, | |
| 160 bool allow, | |
| 161 const std::string& user_input); | |
| 162 | |
| 163 void OnFileSystemPermissionResponse( | |
| 164 const base::Callback<void(bool)>& callback, | |
| 165 bool allow, | |
| 166 const std::string& user_input); | |
| 167 | |
| 168 void OnMediaPermissionResponse( | |
| 169 const content::MediaStreamRequest& request, | |
| 170 const content::MediaResponseCallback& callback, | |
| 171 bool allow, | |
| 172 const std::string& user_input); | |
| 173 | |
| 174 void OnDownloadPermissionResponse( | |
| 175 const base::Callback<void(bool)>& callback, | |
| 176 bool allow, | |
| 177 const std::string& user_input); | |
| 178 | |
| 179 void OnPointerLockPermissionResponse( | |
| 180 const base::Callback<void(bool)>& callback, | |
| 181 bool allow, | |
| 182 const std::string& user_input); | |
| 183 | |
| 184 // Bridge IDs correspond to a geolocation request. This method will remove | |
| 185 // the bookkeeping for a particular geolocation request associated with the | |
| 186 // provided |bridge_id|. It returns the request ID of the geolocation request. | |
| 187 int RemoveBridgeID(int bridge_id); | |
| 188 | |
| 189 void FileSystemAccessedAsyncResponse(int render_process_id, | |
| 190 int render_frame_id, | |
| 191 int request_id, | |
| 192 const GURL& url, | |
| 193 bool allowed); | |
| 194 | |
| 195 void FileSystemAccessedSyncResponse(int render_process_id, | |
| 196 int render_frame_id, | |
| 197 const GURL& url, | |
| 198 IPC::Message* reply_msg, | |
| 199 bool allowed); | |
| 200 | 142 |
| 201 // A counter to generate a unique request id for a permission request. | 143 // A counter to generate a unique request id for a permission request. |
| 202 // We only need the ids to be unique for a given WebViewGuest. | 144 // We only need the ids to be unique for a given WebViewGuest. |
| 203 int next_permission_request_id_; | 145 int next_permission_request_id_; |
| 204 | 146 |
| 205 WebViewPermissionHelper::RequestMap pending_permission_requests_; | 147 WebViewPermissionHelper::RequestMap pending_permission_requests_; |
| 206 | 148 |
| 207 std::map<int, int> bridge_id_to_request_id_map_; | 149 scoped_ptr<extensions::WebViewPermissionHelperDelegate> |
| 150 web_view_permission_helper_delegate_; |
| 208 | 151 |
| 209 WebViewGuest* web_view_guest_; | 152 WebViewGuest* web_view_guest_; |
| 210 | 153 |
| 211 base::WeakPtrFactory<WebViewPermissionHelper> weak_factory_; | 154 base::WeakPtrFactory<WebViewPermissionHelper> weak_factory_; |
| 212 | 155 |
| 213 DISALLOW_COPY_AND_ASSIGN(WebViewPermissionHelper); | 156 DISALLOW_COPY_AND_ASSIGN(WebViewPermissionHelper); |
| 214 }; | 157 }; |
| 215 | 158 |
| 216 } // namespace extensions | 159 } // namespace extensions |
| 217 | 160 |
| 218 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | 161 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ |
| OLD | NEW |