Chromium Code Reviews| 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/webview.h" | 17 #include "chrome/common/extensions/api/webview.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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 void RequestGeolocationPermission(int bridge_id, | 196 void RequestGeolocationPermission(int bridge_id, |
| 196 const GURL& requesting_frame, | 197 const GURL& requesting_frame, |
| 197 bool user_gesture, | 198 bool user_gesture, |
| 198 const base::Callback<void(bool)>& callback); | 199 const base::Callback<void(bool)>& callback); |
| 199 void CancelGeolocationPermissionRequest(int bridge_id); | 200 void CancelGeolocationPermissionRequest(int bridge_id); |
| 200 | 201 |
| 201 void RequestFileSystemPermission(const GURL& url, | 202 void RequestFileSystemPermission(const GURL& url, |
| 202 bool allowed_by_default, | 203 bool allowed_by_default, |
| 203 const base::Callback<void(bool)>& callback); | 204 const base::Callback<void(bool)>& callback); |
| 204 | 205 |
| 205 enum PermissionResponseAction { | |
| 206 DENY, | |
| 207 ALLOW, | |
| 208 DEFAULT | |
| 209 }; | |
| 210 | |
| 211 enum SetPermissionResult { | |
| 212 SET_PERMISSION_INVALID, | |
| 213 SET_PERMISSION_ALLOWED, | |
| 214 SET_PERMISSION_DENIED | |
| 215 }; | |
| 216 | |
| 217 // Responds to the permission request |request_id| with |action| and | 206 // Responds to the permission request |request_id| with |action| and |
| 218 // |user_input|. Returns whether there was a pending request for the provided | 207 // |user_input|. Returns whether there was a pending request for the provided |
| 219 // |request_id|. | 208 // |request_id|. |
| 220 SetPermissionResult SetPermission(int request_id, | 209 WebViewPermissionHelper::SetPermissionResult SetPermission( |
| 221 PermissionResponseAction action, | 210 int request_id, |
| 222 const std::string& user_input); | 211 WebViewPermissionHelper::PermissionResponseAction action, |
| 212 const std::string& user_input); | |
| 223 | 213 |
| 224 // Overrides the user agent for this guest. | 214 // Overrides the user agent for this guest. |
| 225 // This affects subsequent guest navigations. | 215 // This affects subsequent guest navigations. |
| 226 void SetUserAgentOverride(const std::string& user_agent_override); | 216 void SetUserAgentOverride(const std::string& user_agent_override); |
| 227 | 217 |
| 228 // Stop loading the guest. | 218 // Stop loading the guest. |
| 229 void Stop(); | 219 void Stop(); |
| 230 | 220 |
| 231 // Kill the guest process. | 221 // Kill the guest process. |
| 232 void Terminate(); | 222 void Terminate(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 // OnContentBlocked. | 262 // OnContentBlocked. |
| 273 static void FileSystemAccessedSync(int render_process_id, | 263 static void FileSystemAccessedSync(int render_process_id, |
| 274 int render_frame_id, | 264 int render_frame_id, |
| 275 const GURL& url, | 265 const GURL& url, |
| 276 bool blocked_by_policy, | 266 bool blocked_by_policy, |
| 277 IPC::Message* reply_msg); | 267 IPC::Message* reply_msg); |
| 278 | 268 |
| 279 private: | 269 private: |
| 280 virtual ~WebViewGuest(); | 270 virtual ~WebViewGuest(); |
| 281 | 271 |
| 282 // A map to store the callback for a request keyed by the request's id. | |
| 283 struct PermissionResponseInfo { | |
| 284 PermissionResponseCallback callback; | |
| 285 WebViewPermissionType permission_type; | |
| 286 bool allowed_by_default; | |
| 287 PermissionResponseInfo(); | |
| 288 PermissionResponseInfo(const PermissionResponseCallback& callback, | |
| 289 WebViewPermissionType permission_type, | |
| 290 bool allowed_by_default); | |
| 291 ~PermissionResponseInfo(); | |
| 292 }; | |
| 293 | |
| 294 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | |
| 295 bool allow); | |
| 296 | |
| 297 // Returns the top level items (ignoring submenus) as Value. | 272 // Returns the top level items (ignoring submenus) as Value. |
| 298 static scoped_ptr<base::ListValue> MenuModelToValue( | 273 static scoped_ptr<base::ListValue> MenuModelToValue( |
| 299 const ui::SimpleMenuModel& menu_model); | 274 const ui::SimpleMenuModel& menu_model); |
| 300 | 275 |
| 301 void OnWebViewGeolocationPermissionResponse( | |
| 302 int bridge_id, | |
| 303 bool user_gesture, | |
| 304 const base::Callback<void(bool)>& callback, | |
| 305 bool allow, | |
| 306 const std::string& user_input); | |
| 307 | |
| 308 void OnWebViewFileSystemPermissionResponse( | |
| 309 const base::Callback<void(bool)>& callback, | |
| 310 bool allow, | |
| 311 const std::string& user_input); | |
| 312 | |
| 313 void OnWebViewMediaPermissionResponse( | |
| 314 const content::MediaStreamRequest& request, | |
| 315 const content::MediaResponseCallback& callback, | |
| 316 bool allow, | |
| 317 const std::string& user_input); | |
| 318 | |
| 319 void OnWebViewDownloadPermissionResponse( | |
| 320 const base::Callback<void(bool)>& callback, | |
| 321 bool allow, | |
| 322 const std::string& user_input); | |
| 323 | |
| 324 void OnWebViewPointerLockPermissionResponse( | |
| 325 const base::Callback<void(bool)>& callback, | |
| 326 bool allow, | |
| 327 const std::string& user_input); | |
| 328 | |
| 329 void OnWebViewNewWindowResponse(int new_window_instance_id, | 276 void OnWebViewNewWindowResponse(int new_window_instance_id, |
| 330 bool allow, | 277 bool allow, |
| 331 const std::string& user_input); | 278 const std::string& user_input); |
| 332 | 279 |
| 333 static void FileSystemAccessedAsyncResponse(int render_process_id, | |
| 334 int render_frame_id, | |
| 335 int request_id, | |
| 336 const GURL& url, | |
| 337 bool allowed); | |
| 338 | |
| 339 static void FileSystemAccessedSyncResponse(int render_process_id, | |
| 340 int render_frame_id, | |
| 341 const GURL& url, | |
| 342 IPC::Message* reply_msg, | |
| 343 bool allowed); | |
| 344 | |
| 345 // WebContentsObserver implementation. | 280 // WebContentsObserver implementation. |
| 346 virtual void DidCommitProvisionalLoadForFrame( | 281 virtual void DidCommitProvisionalLoadForFrame( |
| 347 int64 frame_id, | 282 int64 frame_id, |
| 348 const base::string16& frame_unique_name, | 283 const base::string16& frame_unique_name, |
| 349 bool is_main_frame, | 284 bool is_main_frame, |
| 350 const GURL& url, | 285 const GURL& url, |
| 351 content::PageTransition transition_type, | 286 content::PageTransition transition_type, |
| 352 content::RenderViewHost* render_view_host) OVERRIDE; | 287 content::RenderViewHost* render_view_host) OVERRIDE; |
| 353 virtual void DidFailProvisionalLoad( | 288 virtual void DidFailProvisionalLoad( |
| 354 int64 frame_id, | 289 int64 frame_id, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 content::WebContents* web_contents); | 327 content::WebContents* web_contents); |
| 393 | 328 |
| 394 #if defined(OS_CHROMEOS) | 329 #if defined(OS_CHROMEOS) |
| 395 // Notification of a change in the state of an accessibility setting. | 330 // Notification of a change in the state of an accessibility setting. |
| 396 void OnAccessibilityStatusChanged( | 331 void OnAccessibilityStatusChanged( |
| 397 const chromeos::AccessibilityStatusEventDetails& details); | 332 const chromeos::AccessibilityStatusEventDetails& details); |
| 398 #endif | 333 #endif |
| 399 | 334 |
| 400 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 335 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
| 401 | 336 |
| 402 // Bridge IDs correspond to a geolocation request. This method will remove | |
| 403 // the bookkeeping for a particular geolocation request associated with the | |
| 404 // provided |bridge_id|. It returns the request ID of the geolocation request. | |
| 405 int RemoveBridgeID(int bridge_id); | |
| 406 | |
| 407 void LoadURLWithParams(const GURL& url, | 337 void LoadURLWithParams(const GURL& url, |
| 408 const content::Referrer& referrer, | 338 const content::Referrer& referrer, |
| 409 content::PageTransition transition_type, | 339 content::PageTransition transition_type, |
| 410 content::WebContents* web_contents); | 340 content::WebContents* web_contents); |
| 411 | 341 |
| 412 void RequestNewWindowPermission( | 342 void RequestNewWindowPermission( |
| 413 WindowOpenDisposition disposition, | 343 WindowOpenDisposition disposition, |
| 414 const gfx::Rect& initial_bounds, | 344 const gfx::Rect& initial_bounds, |
| 415 bool user_gesture, | 345 bool user_gesture, |
| 416 content::WebContents* new_contents); | 346 content::WebContents* new_contents); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 438 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 368 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
| 439 script_observers_; | 369 script_observers_; |
| 440 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 370 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 441 | 371 |
| 442 content::NotificationRegistrar notification_registrar_; | 372 content::NotificationRegistrar notification_registrar_; |
| 443 | 373 |
| 444 // A counter to generate a unique request id for a context menu request. | 374 // A counter to generate a unique request id for a context menu request. |
| 445 // We only need the ids to be unique for a given WebViewGuest. | 375 // We only need the ids to be unique for a given WebViewGuest. |
| 446 int pending_context_menu_request_id_; | 376 int pending_context_menu_request_id_; |
| 447 | 377 |
| 448 // A counter to generate a unique request id for a permission request. | |
| 449 // We only need the ids to be unique for a given WebViewGuest. | |
| 450 int next_permission_request_id_; | |
| 451 | |
| 452 typedef std::map<int, PermissionResponseInfo> RequestMap; | |
| 453 RequestMap pending_permission_requests_; | |
| 454 | |
| 455 // True if the user agent is overridden. | 378 // True if the user agent is overridden. |
| 456 bool is_overriding_user_agent_; | 379 bool is_overriding_user_agent_; |
| 457 | 380 |
| 458 // Indicates that the page needs to be reloaded once it has been attached to | 381 // Indicates that the page needs to be reloaded once it has been attached to |
| 459 // an embedder. | 382 // an embedder. |
| 460 bool pending_reload_on_attachment_; | 383 bool pending_reload_on_attachment_; |
| 461 | 384 |
| 462 // Main frame ID of last committed page. | 385 // Main frame ID of last committed page. |
| 463 int64 main_frame_id_; | 386 int64 main_frame_id_; |
| 464 | 387 |
| 465 // Set to |true| if ChromeVox was already injected in main frame. | 388 // Set to |true| if ChromeVox was already injected in main frame. |
| 466 bool chromevox_injected_; | 389 bool chromevox_injected_; |
| 467 | 390 |
| 468 // Stores the current zoom factor. | 391 // Stores the current zoom factor. |
| 469 double current_zoom_factor_; | 392 double current_zoom_factor_; |
| 470 | 393 |
| 471 // Stores the window name of the main frame of the guest. | 394 // Stores the window name of the main frame of the guest. |
| 472 std::string name_; | 395 std::string name_; |
| 473 | 396 |
| 474 // Handles find requests and replies for the webview find API. | 397 // Handles find requests and replies for the webview find API. |
| 475 WebviewFindHelper find_helper_; | 398 WebviewFindHelper find_helper_; |
| 476 | 399 |
| 477 // Handles the JavaScript dialog requests. | 400 // Handles the JavaScript dialog requests. |
| 478 JavaScriptDialogHelper javascript_dialog_helper_; | 401 JavaScriptDialogHelper javascript_dialog_helper_; |
| 479 | 402 |
| 403 // Handels permission requests. | |
| 404 WebViewPermissionHelper* web_view_permission_helper_; | |
|
Fady Samuel
2014/06/20 22:54:33
Don't make this a pointer. Make it a value.
WebVi
| |
| 405 | |
| 480 friend void WebviewFindHelper::DispatchFindUpdateEvent(bool canceled, | 406 friend void WebviewFindHelper::DispatchFindUpdateEvent(bool canceled, |
| 481 bool final_update); | 407 bool final_update); |
| 482 | 408 |
| 483 // Holds the RenderViewContextMenu that has been built but yet to be | 409 // Holds the RenderViewContextMenu that has been built but yet to be |
| 484 // shown. This is .Reset() after ShowContextMenu(). | 410 // shown. This is .Reset() after ShowContextMenu(). |
| 485 scoped_ptr<RenderViewContextMenu> pending_menu_; | 411 scoped_ptr<RenderViewContextMenu> pending_menu_; |
| 486 | 412 |
| 487 #if defined(OS_CHROMEOS) | 413 #if defined(OS_CHROMEOS) |
| 488 // Subscription to receive notifications on changes to a11y settings. | 414 // Subscription to receive notifications on changes to a11y settings. |
| 489 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 415 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
| 490 accessibility_subscription_; | 416 accessibility_subscription_; |
| 491 #endif | 417 #endif |
| 492 | 418 |
| 493 std::map<int, int> bridge_id_to_request_id_map_; | |
| 494 | |
| 495 // Tracks the name, and target URL of the new window. Once the first | 419 // Tracks the name, and target URL of the new window. Once the first |
| 496 // navigation commits, we no longer track this information. | 420 // navigation commits, we no longer track this information. |
| 497 struct NewWindowInfo { | 421 struct NewWindowInfo { |
| 498 GURL url; | 422 GURL url; |
| 499 std::string name; | 423 std::string name; |
| 500 NewWindowInfo(const GURL& url, const std::string& name) : | 424 NewWindowInfo(const GURL& url, const std::string& name) : |
| 501 url(url), | 425 url(url), |
| 502 name(name) {} | 426 name(name) {} |
| 503 }; | 427 }; |
| 504 | 428 |
| 505 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 429 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 506 PendingWindowMap pending_new_windows_; | 430 PendingWindowMap pending_new_windows_; |
| 507 | 431 |
| 508 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 432 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 509 }; | 433 }; |
| 510 | 434 |
| 511 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 435 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
| OLD | NEW |