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_GUEST_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
12 #include "chrome/browser/guest_view/guest_view.h" | 12 #include "chrome/browser/guest_view/guest_view.h" |
13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" | 13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" |
14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" |
| 15 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 16 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
16 #include "chrome/common/extensions/api/web_view_internal.h" | 17 #include "chrome/common/extensions/api/web_view_internal.h" |
17 #include "content/public/browser/javascript_dialog_manager.h" | 18 #include "content/public/browser/javascript_dialog_manager.h" |
18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
19 #include "third_party/WebKit/public/web/WebFindOptions.h" | 20 #include "third_party/WebKit/public/web/WebFindOptions.h" |
20 | 21 |
21 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 23 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
23 #endif | 24 #endif |
24 | 25 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 void RequestGeolocationPermission(int bridge_id, | 197 void RequestGeolocationPermission(int bridge_id, |
197 const GURL& requesting_frame, | 198 const GURL& requesting_frame, |
198 bool user_gesture, | 199 bool user_gesture, |
199 const base::Callback<void(bool)>& callback); | 200 const base::Callback<void(bool)>& callback); |
200 void CancelGeolocationPermissionRequest(int bridge_id); | 201 void CancelGeolocationPermissionRequest(int bridge_id); |
201 | 202 |
202 void RequestFileSystemPermission(const GURL& url, | 203 void RequestFileSystemPermission(const GURL& url, |
203 bool allowed_by_default, | 204 bool allowed_by_default, |
204 const base::Callback<void(bool)>& callback); | 205 const base::Callback<void(bool)>& callback); |
205 | 206 |
206 enum PermissionResponseAction { | |
207 DENY, | |
208 ALLOW, | |
209 DEFAULT | |
210 }; | |
211 | |
212 enum SetPermissionResult { | |
213 SET_PERMISSION_INVALID, | |
214 SET_PERMISSION_ALLOWED, | |
215 SET_PERMISSION_DENIED | |
216 }; | |
217 | |
218 // Responds to the permission request |request_id| with |action| and | |
219 // |user_input|. Returns whether there was a pending request for the provided | |
220 // |request_id|. | |
221 SetPermissionResult SetPermission(int request_id, | |
222 PermissionResponseAction action, | |
223 const std::string& user_input); | |
224 | |
225 // Overrides the user agent for this guest. | 207 // Overrides the user agent for this guest. |
226 // This affects subsequent guest navigations. | 208 // This affects subsequent guest navigations. |
227 void SetUserAgentOverride(const std::string& user_agent_override); | 209 void SetUserAgentOverride(const std::string& user_agent_override); |
228 | 210 |
229 // Stop loading the guest. | 211 // Stop loading the guest. |
230 void Stop(); | 212 void Stop(); |
231 | 213 |
232 // Kill the guest process. | 214 // Kill the guest process. |
233 void Terminate(); | 215 void Terminate(); |
234 | 216 |
235 // Clears data in the storage partition of this guest. | 217 // Clears data in the storage partition of this guest. |
236 // | 218 // |
237 // Partition data that are newer than |removal_since| will be removed. | 219 // Partition data that are newer than |removal_since| will be removed. |
238 // |removal_mask| corresponds to bitmask in StoragePartition::RemoveDataMask. | 220 // |removal_mask| corresponds to bitmask in StoragePartition::RemoveDataMask. |
239 bool ClearData(const base::Time remove_since, | 221 bool ClearData(const base::Time remove_since, |
240 uint32 removal_mask, | 222 uint32 removal_mask, |
241 const base::Closure& callback); | 223 const base::Closure& callback); |
242 | 224 |
243 extensions::ScriptExecutor* script_executor() { | 225 extensions::ScriptExecutor* script_executor() { |
244 return script_executor_.get(); | 226 return script_executor_.get(); |
245 } | 227 } |
246 | 228 |
247 // Called when file system access is requested by the guest content using the | |
248 // asynchronous HTML5 file system API. The request is plumbed through the | |
249 // <webview> permission request API. The request will be: | |
250 // - Allowed if the embedder explicitly allowed it. | |
251 // - Denied if the embedder explicitly denied. | |
252 // - Determined by the guest's content settings if the embedder does not | |
253 // perform an explicit action. | |
254 // If access was blocked due to the page's content settings, | |
255 // |blocked_by_policy| should be true, and this function should invoke | |
256 // OnContentBlocked. | |
257 static void FileSystemAccessedAsync(int render_process_id, | |
258 int render_frame_id, | |
259 int request_id, | |
260 const GURL& url, | |
261 bool blocked_by_policy); | |
262 | |
263 // Called when file system access is requested by the guest content using the | |
264 // synchronous HTML5 file system API in a worker thread or shared worker. The | |
265 // request is plumbed through the <webview> permission request API. The | |
266 // request will be: | |
267 // - Allowed if the embedder explicitly allowed it. | |
268 // - Denied if the embedder explicitly denied. | |
269 // - Determined by the guest's content settings if the embedder does not | |
270 // perform an explicit action. | |
271 // If access was blocked due to the page's content settings, | |
272 // |blocked_by_policy| should be true, and this function should invoke | |
273 // OnContentBlocked. | |
274 static void FileSystemAccessedSync(int render_process_id, | |
275 int render_frame_id, | |
276 const GURL& url, | |
277 bool blocked_by_policy, | |
278 IPC::Message* reply_msg); | |
279 | |
280 private: | 229 private: |
| 230 friend class WebViewPermissionHelper; |
281 virtual ~WebViewGuest(); | 231 virtual ~WebViewGuest(); |
282 | 232 |
283 // A map to store the callback for a request keyed by the request's id. | |
284 struct PermissionResponseInfo { | |
285 PermissionResponseCallback callback; | |
286 WebViewPermissionType permission_type; | |
287 bool allowed_by_default; | |
288 PermissionResponseInfo(); | |
289 PermissionResponseInfo(const PermissionResponseCallback& callback, | |
290 WebViewPermissionType permission_type, | |
291 bool allowed_by_default); | |
292 ~PermissionResponseInfo(); | |
293 }; | |
294 | |
295 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | |
296 bool allow); | |
297 | |
298 // Returns the top level items (ignoring submenus) as Value. | 233 // Returns the top level items (ignoring submenus) as Value. |
299 static scoped_ptr<base::ListValue> MenuModelToValue( | 234 static scoped_ptr<base::ListValue> MenuModelToValue( |
300 const ui::SimpleMenuModel& menu_model); | 235 const ui::SimpleMenuModel& menu_model); |
301 | 236 |
302 void OnWebViewGeolocationPermissionResponse( | 237 void AttachWebViewHelpers(content::WebContents* contents); |
303 int bridge_id, | |
304 bool user_gesture, | |
305 const base::Callback<void(bool)>& callback, | |
306 bool allow, | |
307 const std::string& user_input); | |
308 | |
309 void OnWebViewFileSystemPermissionResponse( | |
310 const base::Callback<void(bool)>& callback, | |
311 bool allow, | |
312 const std::string& user_input); | |
313 | |
314 void OnWebViewMediaPermissionResponse( | |
315 const content::MediaStreamRequest& request, | |
316 const content::MediaResponseCallback& callback, | |
317 bool allow, | |
318 const std::string& user_input); | |
319 | |
320 void OnWebViewDownloadPermissionResponse( | |
321 const base::Callback<void(bool)>& callback, | |
322 bool allow, | |
323 const std::string& user_input); | |
324 | |
325 void OnWebViewPointerLockPermissionResponse( | |
326 const base::Callback<void(bool)>& callback, | |
327 bool allow, | |
328 const std::string& user_input); | |
329 | 238 |
330 void OnWebViewNewWindowResponse(int new_window_instance_id, | 239 void OnWebViewNewWindowResponse(int new_window_instance_id, |
331 bool allow, | 240 bool allow, |
332 const std::string& user_input); | 241 const std::string& user_input); |
333 | 242 |
334 static void FileSystemAccessedAsyncResponse(int render_process_id, | |
335 int render_frame_id, | |
336 int request_id, | |
337 const GURL& url, | |
338 bool allowed); | |
339 | |
340 static void FileSystemAccessedSyncResponse(int render_process_id, | |
341 int render_frame_id, | |
342 const GURL& url, | |
343 IPC::Message* reply_msg, | |
344 bool allowed); | |
345 | |
346 // WebContentsObserver implementation. | 243 // WebContentsObserver implementation. |
347 virtual void DidCommitProvisionalLoadForFrame( | 244 virtual void DidCommitProvisionalLoadForFrame( |
348 content::RenderFrameHost* render_frame_host, | 245 content::RenderFrameHost* render_frame_host, |
349 const GURL& url, | 246 const GURL& url, |
350 content::PageTransition transition_type) OVERRIDE; | 247 content::PageTransition transition_type) OVERRIDE; |
351 virtual void DidFailProvisionalLoad( | 248 virtual void DidFailProvisionalLoad( |
352 content::RenderFrameHost* render_frame_host, | 249 content::RenderFrameHost* render_frame_host, |
353 const GURL& validated_url, | 250 const GURL& validated_url, |
354 int error_code, | 251 int error_code, |
355 const base::string16& error_description) OVERRIDE; | 252 const base::string16& error_description) OVERRIDE; |
(...skipping 28 matching lines...) Expand all Loading... |
384 content::WebContents* web_contents); | 281 content::WebContents* web_contents); |
385 | 282 |
386 #if defined(OS_CHROMEOS) | 283 #if defined(OS_CHROMEOS) |
387 // Notification of a change in the state of an accessibility setting. | 284 // Notification of a change in the state of an accessibility setting. |
388 void OnAccessibilityStatusChanged( | 285 void OnAccessibilityStatusChanged( |
389 const chromeos::AccessibilityStatusEventDetails& details); | 286 const chromeos::AccessibilityStatusEventDetails& details); |
390 #endif | 287 #endif |
391 | 288 |
392 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 289 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
393 | 290 |
394 // Bridge IDs correspond to a geolocation request. This method will remove | |
395 // the bookkeeping for a particular geolocation request associated with the | |
396 // provided |bridge_id|. It returns the request ID of the geolocation request. | |
397 int RemoveBridgeID(int bridge_id); | |
398 | |
399 void LoadURLWithParams(const GURL& url, | 291 void LoadURLWithParams(const GURL& url, |
400 const content::Referrer& referrer, | 292 const content::Referrer& referrer, |
401 content::PageTransition transition_type, | 293 content::PageTransition transition_type, |
402 content::WebContents* web_contents); | 294 content::WebContents* web_contents); |
403 | 295 |
404 void RequestNewWindowPermission( | 296 void RequestNewWindowPermission( |
405 WindowOpenDisposition disposition, | 297 WindowOpenDisposition disposition, |
406 const gfx::Rect& initial_bounds, | 298 const gfx::Rect& initial_bounds, |
407 bool user_gesture, | 299 bool user_gesture, |
408 content::WebContents* new_contents); | 300 content::WebContents* new_contents); |
(...skipping 24 matching lines...) Expand all Loading... |
433 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 325 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
434 script_observers_; | 326 script_observers_; |
435 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 327 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
436 | 328 |
437 content::NotificationRegistrar notification_registrar_; | 329 content::NotificationRegistrar notification_registrar_; |
438 | 330 |
439 // A counter to generate a unique request id for a context menu request. | 331 // A counter to generate a unique request id for a context menu request. |
440 // We only need the ids to be unique for a given WebViewGuest. | 332 // We only need the ids to be unique for a given WebViewGuest. |
441 int pending_context_menu_request_id_; | 333 int pending_context_menu_request_id_; |
442 | 334 |
443 // A counter to generate a unique request id for a permission request. | |
444 // We only need the ids to be unique for a given WebViewGuest. | |
445 int next_permission_request_id_; | |
446 | |
447 typedef std::map<int, PermissionResponseInfo> RequestMap; | |
448 RequestMap pending_permission_requests_; | |
449 | |
450 // True if the user agent is overridden. | 335 // True if the user agent is overridden. |
451 bool is_overriding_user_agent_; | 336 bool is_overriding_user_agent_; |
452 | 337 |
453 // Main frame ID of last committed page. | 338 // Main frame ID of last committed page. |
454 int64 main_frame_id_; | 339 int64 main_frame_id_; |
455 | 340 |
456 // Set to |true| if ChromeVox was already injected in main frame. | 341 // Set to |true| if ChromeVox was already injected in main frame. |
457 bool chromevox_injected_; | 342 bool chromevox_injected_; |
458 | 343 |
459 // Stores the current zoom factor. | 344 // Stores the current zoom factor. |
460 double current_zoom_factor_; | 345 double current_zoom_factor_; |
461 | 346 |
462 // Stores the window name of the main frame of the guest. | 347 // Stores the window name of the main frame of the guest. |
463 std::string name_; | 348 std::string name_; |
464 | 349 |
465 // Handles find requests and replies for the webview find API. | 350 // Handles find requests and replies for the webview find API. |
466 WebViewFindHelper find_helper_; | 351 WebViewFindHelper find_helper_; |
467 | 352 |
468 // Handles the JavaScript dialog requests. | 353 // Handles the JavaScript dialog requests. |
469 JavaScriptDialogHelper javascript_dialog_helper_; | 354 JavaScriptDialogHelper javascript_dialog_helper_; |
470 | 355 |
| 356 // Handels permission requests. |
| 357 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; |
| 358 |
471 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, | 359 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, |
472 bool final_update); | 360 bool final_update); |
473 | 361 |
474 // Holds the RenderViewContextMenu that has been built but yet to be | 362 // Holds the RenderViewContextMenu that has been built but yet to be |
475 // shown. This is .Reset() after ShowContextMenu(). | 363 // shown. This is .Reset() after ShowContextMenu(). |
476 scoped_ptr<RenderViewContextMenu> pending_menu_; | 364 scoped_ptr<RenderViewContextMenu> pending_menu_; |
477 | 365 |
478 #if defined(OS_CHROMEOS) | 366 #if defined(OS_CHROMEOS) |
479 // Subscription to receive notifications on changes to a11y settings. | 367 // Subscription to receive notifications on changes to a11y settings. |
480 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 368 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
481 accessibility_subscription_; | 369 accessibility_subscription_; |
482 #endif | 370 #endif |
483 | 371 |
484 std::map<int, int> bridge_id_to_request_id_map_; | |
485 | |
486 // Tracks the name, and target URL of the new window. Once the first | 372 // Tracks the name, and target URL of the new window. Once the first |
487 // navigation commits, we no longer track this information. | 373 // navigation commits, we no longer track this information. |
488 struct NewWindowInfo { | 374 struct NewWindowInfo { |
489 GURL url; | 375 GURL url; |
490 std::string name; | 376 std::string name; |
491 bool changed; | 377 bool changed; |
492 NewWindowInfo(const GURL& url, const std::string& name) : | 378 NewWindowInfo(const GURL& url, const std::string& name) : |
493 url(url), | 379 url(url), |
494 name(name), | 380 name(name), |
495 changed(false) {} | 381 changed(false) {} |
496 }; | 382 }; |
497 | 383 |
498 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 384 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
499 PendingWindowMap pending_new_windows_; | 385 PendingWindowMap pending_new_windows_; |
500 | 386 |
501 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 387 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
502 }; | 388 }; |
503 | 389 |
504 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 390 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
OLD | NEW |