Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 } | 390 } |
| 391 // All pending windows should be removed from the set after Destroy() is | 391 // All pending windows should be removed from the set after Destroy() is |
| 392 // called on all of them. | 392 // called on all of them. |
| 393 DCHECK(pending_new_windows_.empty()); | 393 DCHECK(pending_new_windows_.empty()); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void BrowserPluginGuest::LoadURLWithParams(const GURL& url, | 396 void BrowserPluginGuest::LoadURLWithParams(const GURL& url, |
| 397 const Referrer& referrer, | 397 const Referrer& referrer, |
| 398 PageTransition transition_type, | 398 PageTransition transition_type, |
| 399 WebContents* web_contents) { | 399 WebContents* web_contents) { |
| 400 NavigationController::LoadURLParams load_url_params(url); | 400 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 401 // This will block the embedder trying to load unwanted schemes, e.g. | |
| 402 // chrome://settings. | |
| 403 bool scheme_is_blocked = | |
| 404 (!ChildProcessSecurityPolicyImpl::GetInstance()->IsWebSafeScheme( | |
| 405 url.scheme()) && | |
| 406 !ChildProcessSecurityPolicyImpl::GetInstance()->IsPseudoScheme( | |
| 407 url.scheme())) || | |
| 408 url.SchemeIs(kJavaScriptScheme); | |
| 409 bool can_commit = | |
| 410 GetContentClient()->browser()->CanCommitURL( | |
| 411 GetWebContents()->GetRenderProcessHost(), url); | |
| 412 if (scheme_is_blocked || !url.is_valid() || !can_commit) { | |
| 413 if (delegate_) { | |
| 414 std::string error_type; | |
| 415 base::RemoveChars(net::ErrorToString(net::ERR_ABORTED), "net::", | |
| 416 &error_type); | |
| 417 delegate_->LoadAbort(true /* is_top_level */, url, error_type); | |
| 418 } | |
| 419 return; | |
| 420 } | |
| 421 | |
| 422 GURL validated_url(url); | |
| 423 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | |
| 424 | |
| 425 NavigationController::LoadURLParams load_url_params(validated_url); | |
| 401 load_url_params.referrer = referrer; | 426 load_url_params.referrer = referrer; |
| 402 load_url_params.transition_type = transition_type; | 427 load_url_params.transition_type = transition_type; |
| 403 load_url_params.extra_headers = std::string(); | 428 load_url_params.extra_headers = std::string(); |
| 404 if (delegate_ && delegate_->IsOverridingUserAgent()) { | 429 if (delegate_ && delegate_->IsOverridingUserAgent()) { |
| 405 load_url_params.override_user_agent = | 430 load_url_params.override_user_agent = |
| 406 NavigationController::UA_OVERRIDE_TRUE; | 431 NavigationController::UA_OVERRIDE_TRUE; |
| 407 } | 432 } |
| 408 web_contents->GetController().LoadURLWithParams(load_url_params); | 433 web_contents->GetController().LoadURLWithParams(load_url_params); |
| 409 } | 434 } |
| 410 | 435 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 // focus. | 604 // focus. |
| 580 *renderer_prefs = *embedder_web_contents_->GetMutableRendererPrefs(); | 605 *renderer_prefs = *embedder_web_contents_->GetMutableRendererPrefs(); |
| 581 renderer_prefs->user_agent_override = guest_user_agent_override; | 606 renderer_prefs->user_agent_override = guest_user_agent_override; |
| 582 | 607 |
| 583 // We would like the guest to report changes to frame names so that we can | 608 // We would like the guest to report changes to frame names so that we can |
| 584 // update the BrowserPlugin's corresponding 'name' attribute. | 609 // update the BrowserPlugin's corresponding 'name' attribute. |
| 585 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 610 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
| 586 renderer_prefs->report_frame_name_changes = true; | 611 renderer_prefs->report_frame_name_changes = true; |
| 587 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 612 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
| 588 // navigations still continue to function inside the app. | 613 // navigations still continue to function inside the app. |
| 589 renderer_prefs->browser_handles_all_top_level_requests = false; | 614 renderer_prefs->browser_handles_all_top_level_requests = true; |
|
lazyboy
2014/01/16 22:31:24
I remember creis@ raising concerns doing this befo
Fady Samuel
2014/01/16 23:40:27
Nasko? Thoughts? Charlie is on paternity leave.
| |
| 590 // Disable "client blocked" error page for browser plugin. | 615 // Disable "client blocked" error page for browser plugin. |
| 591 renderer_prefs->disable_client_blocked_error_page = true; | 616 renderer_prefs->disable_client_blocked_error_page = true; |
| 592 | 617 |
| 593 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); | 618 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
| 594 | 619 |
| 595 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); | 620 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); |
| 596 | 621 |
| 597 // Create a swapped out RenderView for the guest in the embedder render | 622 // Create a swapped out RenderView for the guest in the embedder render |
| 598 // process, so that the embedder can access the guest's window object. | 623 // process, so that the embedder can access the guest's window object. |
| 599 int guest_routing_id = | 624 int guest_routing_id = |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); | 831 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); |
| 807 if (it == opener()->pending_new_windows_.end()) | 832 if (it == opener()->pending_new_windows_.end()) |
| 808 return NULL; | 833 return NULL; |
| 809 const NewWindowInfo& old_target_url = it->second; | 834 const NewWindowInfo& old_target_url = it->second; |
| 810 NewWindowInfo new_window_info(params.url, old_target_url.name); | 835 NewWindowInfo new_window_info(params.url, old_target_url.name); |
| 811 new_window_info.changed = new_window_info.url != old_target_url.url; | 836 new_window_info.changed = new_window_info.url != old_target_url.url; |
| 812 it->second = new_window_info; | 837 it->second = new_window_info; |
| 813 return NULL; | 838 return NULL; |
| 814 } | 839 } |
| 815 if (params.disposition == CURRENT_TAB) { | 840 if (params.disposition == CURRENT_TAB) { |
| 816 // This can happen for cross-site redirects. | 841 // This can happen for cross-site redirects and top-level frame navigations. |
| 817 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 842 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
| 818 return source; | 843 return source; |
| 819 } | 844 } |
| 820 | 845 |
| 821 return CreateNewGuestWindow(params)->GetWebContents(); | 846 return CreateNewGuestWindow(params)->GetWebContents(); |
| 822 } | 847 } |
| 823 | 848 |
| 824 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 849 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
| 825 int64 source_frame_id, | 850 int64 source_frame_id, |
| 826 const base::string16& frame_name, | 851 const base::string16& frame_name, |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 pending_lock_request_ = false; | 1449 pending_lock_request_ = false; |
| 1425 if (succeeded) | 1450 if (succeeded) |
| 1426 mouse_locked_ = true; | 1451 mouse_locked_ = true; |
| 1427 } | 1452 } |
| 1428 | 1453 |
| 1429 void BrowserPluginGuest::OnNavigateGuest( | 1454 void BrowserPluginGuest::OnNavigateGuest( |
| 1430 int instance_id, | 1455 int instance_id, |
| 1431 const std::string& src) { | 1456 const std::string& src) { |
| 1432 GURL url = delegate_ ? delegate_->ResolveURL(src) : GURL(src); | 1457 GURL url = delegate_ ? delegate_->ResolveURL(src) : GURL(src); |
| 1433 | 1458 |
| 1434 // Do not allow navigating a guest to schemes other than known safe schemes. | |
| 1435 // This will block the embedder trying to load unwanted schemes, e.g. | |
| 1436 // chrome://settings. | |
| 1437 bool scheme_is_blocked = | |
| 1438 (!ChildProcessSecurityPolicyImpl::GetInstance()->IsWebSafeScheme( | |
| 1439 url.scheme()) && | |
| 1440 !ChildProcessSecurityPolicyImpl::GetInstance()->IsPseudoScheme( | |
| 1441 url.scheme())) || | |
| 1442 url.SchemeIs(kJavaScriptScheme); | |
| 1443 if (scheme_is_blocked || !url.is_valid()) { | |
| 1444 if (delegate_) { | |
| 1445 std::string error_type; | |
| 1446 base::RemoveChars(net::ErrorToString(net::ERR_ABORTED), "net::", | |
| 1447 &error_type); | |
| 1448 delegate_->LoadAbort(true /* is_top_level */, url, error_type); | |
| 1449 } | |
| 1450 return; | |
| 1451 } | |
| 1452 | |
| 1453 GURL validated_url(url); | |
| 1454 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | |
| 1455 // As guests do not swap processes on navigation, only navigations to | 1459 // As guests do not swap processes on navigation, only navigations to |
| 1456 // normal web URLs are supported. No protocol handlers are installed for | 1460 // normal web URLs are supported. No protocol handlers are installed for |
| 1457 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 1461 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 1458 // can be granted to the guest process. | 1462 // can be granted to the guest process. |
| 1459 LoadURLWithParams(validated_url, Referrer(), PAGE_TRANSITION_AUTO_TOPLEVEL, | 1463 LoadURLWithParams(url, Referrer(), PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 1460 GetWebContents()); | 1464 GetWebContents()); |
| 1461 } | 1465 } |
| 1462 | 1466 |
| 1463 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { | 1467 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { |
| 1464 Destroy(); | 1468 Destroy(); |
| 1465 } | 1469 } |
| 1466 | 1470 |
| 1467 void BrowserPluginGuest::OnResizeGuest( | 1471 void BrowserPluginGuest::OnResizeGuest( |
| 1468 int instance_id, | 1472 int instance_id, |
| 1469 const BrowserPluginHostMsg_ResizeGuest_Params& params) { | 1473 const BrowserPluginHostMsg_ResizeGuest_Params& params) { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1852 request_info.Set(browser_plugin::kRequestMethod, | 1856 request_info.Set(browser_plugin::kRequestMethod, |
| 1853 base::Value::CreateStringValue(request_method)); | 1857 base::Value::CreateStringValue(request_method)); |
| 1854 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1858 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1855 | 1859 |
| 1856 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1860 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1857 new DownloadRequest(callback), | 1861 new DownloadRequest(callback), |
| 1858 request_info); | 1862 request_info); |
| 1859 } | 1863 } |
| 1860 | 1864 |
| 1861 } // namespace content | 1865 } // namespace content |
| OLD | NEW |