| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // perform an explicit action. | 259 // perform an explicit action. |
| 270 // If access was blocked due to the page's content settings, | 260 // If access was blocked due to the page's content settings, |
| 271 // |blocked_by_policy| should be true, and this function should invoke | 261 // |blocked_by_policy| should be true, and this function should invoke |
| 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 |
| 269 WebViewPermissionHelper* GetWebViewPermissionHelper() { |
| 270 return web_view_permission_helper_.get(); |
| 271 } |
| 279 private: | 272 private: |
| 280 virtual ~WebViewGuest(); | 273 virtual ~WebViewGuest(); |
| 281 | 274 |
| 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. | 275 // Returns the top level items (ignoring submenus) as Value. |
| 298 static scoped_ptr<base::ListValue> MenuModelToValue( | 276 static scoped_ptr<base::ListValue> MenuModelToValue( |
| 299 const ui::SimpleMenuModel& menu_model); | 277 const ui::SimpleMenuModel& menu_model); |
| 300 | 278 |
| 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, | 279 void OnWebViewNewWindowResponse(int new_window_instance_id, |
| 330 bool allow, | 280 bool allow, |
| 331 const std::string& user_input); | 281 const std::string& user_input); |
| 332 | 282 |
| 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. | 283 // WebContentsObserver implementation. |
| 346 virtual void DidCommitProvisionalLoadForFrame( | 284 virtual void DidCommitProvisionalLoadForFrame( |
| 347 int64 frame_id, | 285 int64 frame_id, |
| 348 const base::string16& frame_unique_name, | 286 const base::string16& frame_unique_name, |
| 349 bool is_main_frame, | 287 bool is_main_frame, |
| 350 const GURL& url, | 288 const GURL& url, |
| 351 content::PageTransition transition_type, | 289 content::PageTransition transition_type, |
| 352 content::RenderViewHost* render_view_host) OVERRIDE; | 290 content::RenderViewHost* render_view_host) OVERRIDE; |
| 353 virtual void DidFailProvisionalLoad( | 291 virtual void DidFailProvisionalLoad( |
| 354 int64 frame_id, | 292 int64 frame_id, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 content::WebContents* web_contents); | 330 content::WebContents* web_contents); |
| 393 | 331 |
| 394 #if defined(OS_CHROMEOS) | 332 #if defined(OS_CHROMEOS) |
| 395 // Notification of a change in the state of an accessibility setting. | 333 // Notification of a change in the state of an accessibility setting. |
| 396 void OnAccessibilityStatusChanged( | 334 void OnAccessibilityStatusChanged( |
| 397 const chromeos::AccessibilityStatusEventDetails& details); | 335 const chromeos::AccessibilityStatusEventDetails& details); |
| 398 #endif | 336 #endif |
| 399 | 337 |
| 400 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 338 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
| 401 | 339 |
| 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, | 340 void LoadURLWithParams(const GURL& url, |
| 408 const content::Referrer& referrer, | 341 const content::Referrer& referrer, |
| 409 content::PageTransition transition_type, | 342 content::PageTransition transition_type, |
| 410 content::WebContents* web_contents); | 343 content::WebContents* web_contents); |
| 411 | 344 |
| 412 void RequestNewWindowPermission( | 345 void RequestNewWindowPermission( |
| 413 WindowOpenDisposition disposition, | 346 WindowOpenDisposition disposition, |
| 414 const gfx::Rect& initial_bounds, | 347 const gfx::Rect& initial_bounds, |
| 415 bool user_gesture, | 348 bool user_gesture, |
| 416 content::WebContents* new_contents); | 349 content::WebContents* new_contents); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 441 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 374 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
| 442 script_observers_; | 375 script_observers_; |
| 443 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 376 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 444 | 377 |
| 445 content::NotificationRegistrar notification_registrar_; | 378 content::NotificationRegistrar notification_registrar_; |
| 446 | 379 |
| 447 // A counter to generate a unique request id for a context menu request. | 380 // A counter to generate a unique request id for a context menu request. |
| 448 // We only need the ids to be unique for a given WebViewGuest. | 381 // We only need the ids to be unique for a given WebViewGuest. |
| 449 int pending_context_menu_request_id_; | 382 int pending_context_menu_request_id_; |
| 450 | 383 |
| 451 // A counter to generate a unique request id for a permission request. | |
| 452 // We only need the ids to be unique for a given WebViewGuest. | |
| 453 int next_permission_request_id_; | |
| 454 | |
| 455 typedef std::map<int, PermissionResponseInfo> RequestMap; | |
| 456 RequestMap pending_permission_requests_; | |
| 457 | |
| 458 // True if the user agent is overridden. | 384 // True if the user agent is overridden. |
| 459 bool is_overriding_user_agent_; | 385 bool is_overriding_user_agent_; |
| 460 | 386 |
| 461 // Main frame ID of last committed page. | 387 // Main frame ID of last committed page. |
| 462 int64 main_frame_id_; | 388 int64 main_frame_id_; |
| 463 | 389 |
| 464 // Set to |true| if ChromeVox was already injected in main frame. | 390 // Set to |true| if ChromeVox was already injected in main frame. |
| 465 bool chromevox_injected_; | 391 bool chromevox_injected_; |
| 466 | 392 |
| 467 // Stores the current zoom factor. | 393 // Stores the current zoom factor. |
| 468 double current_zoom_factor_; | 394 double current_zoom_factor_; |
| 469 | 395 |
| 470 // Stores the window name of the main frame of the guest. | 396 // Stores the window name of the main frame of the guest. |
| 471 std::string name_; | 397 std::string name_; |
| 472 | 398 |
| 473 // Handles find requests and replies for the webview find API. | 399 // Handles find requests and replies for the webview find API. |
| 474 WebviewFindHelper find_helper_; | 400 WebviewFindHelper find_helper_; |
| 475 | 401 |
| 476 // Handles the JavaScript dialog requests. | 402 // Handles the JavaScript dialog requests. |
| 477 JavaScriptDialogHelper javascript_dialog_helper_; | 403 JavaScriptDialogHelper javascript_dialog_helper_; |
| 478 | 404 |
| 405 // Handels permission requests. |
| 406 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; |
| 407 |
| 479 friend void WebviewFindHelper::DispatchFindUpdateEvent(bool canceled, | 408 friend void WebviewFindHelper::DispatchFindUpdateEvent(bool canceled, |
| 480 bool final_update); | 409 bool final_update); |
| 481 | 410 |
| 482 // Holds the RenderViewContextMenu that has been built but yet to be | 411 // Holds the RenderViewContextMenu that has been built but yet to be |
| 483 // shown. This is .Reset() after ShowContextMenu(). | 412 // shown. This is .Reset() after ShowContextMenu(). |
| 484 scoped_ptr<RenderViewContextMenu> pending_menu_; | 413 scoped_ptr<RenderViewContextMenu> pending_menu_; |
| 485 | 414 |
| 486 #if defined(OS_CHROMEOS) | 415 #if defined(OS_CHROMEOS) |
| 487 // Subscription to receive notifications on changes to a11y settings. | 416 // Subscription to receive notifications on changes to a11y settings. |
| 488 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 417 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
| 489 accessibility_subscription_; | 418 accessibility_subscription_; |
| 490 #endif | 419 #endif |
| 491 | 420 |
| 492 std::map<int, int> bridge_id_to_request_id_map_; | |
| 493 | |
| 494 // Tracks the name, and target URL of the new window. Once the first | 421 // Tracks the name, and target URL of the new window. Once the first |
| 495 // navigation commits, we no longer track this information. | 422 // navigation commits, we no longer track this information. |
| 496 struct NewWindowInfo { | 423 struct NewWindowInfo { |
| 497 GURL url; | 424 GURL url; |
| 498 std::string name; | 425 std::string name; |
| 499 bool changed; | 426 bool changed; |
| 500 NewWindowInfo(const GURL& url, const std::string& name) : | 427 NewWindowInfo(const GURL& url, const std::string& name) : |
| 501 url(url), | 428 url(url), |
| 502 name(name), | 429 name(name), |
| 503 changed(false) {} | 430 changed(false) {} |
| 504 }; | 431 }; |
| 505 | 432 |
| 506 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 433 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 507 PendingWindowMap pending_new_windows_; | 434 PendingWindowMap pending_new_windows_; |
| 508 | 435 |
| 509 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 436 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 510 }; | 437 }; |
| 511 | 438 |
| 512 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 439 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
| OLD | NEW |