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 // TODO(fsamuel): Need better error reporting here. | |
| 415 std::string error_type; | |
| 416 base::RemoveChars(net::ErrorToString(net::ERR_ABORTED), "net::", | |
| 417 &error_type); | |
| 418 delegate_->LoadAbort(true /* is_top_level */, url, error_type); | |
| 419 } | |
| 420 return; | |
| 421 } | |
| 422 | |
| 423 GURL validated_url(url); | |
| 424 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | |
| 425 | |
| 426 NavigationController::LoadURLParams load_url_params(validated_url); | |
| 401 load_url_params.referrer = referrer; | 427 load_url_params.referrer = referrer; |
| 402 load_url_params.transition_type = transition_type; | 428 load_url_params.transition_type = transition_type; |
| 403 load_url_params.extra_headers = std::string(); | 429 load_url_params.extra_headers = std::string(); |
| 404 if (delegate_ && delegate_->IsOverridingUserAgent()) { | 430 if (delegate_ && delegate_->IsOverridingUserAgent()) { |
| 405 load_url_params.override_user_agent = | 431 load_url_params.override_user_agent = |
| 406 NavigationController::UA_OVERRIDE_TRUE; | 432 NavigationController::UA_OVERRIDE_TRUE; |
| 407 } | 433 } |
| 408 web_contents->GetController().LoadURLWithParams(load_url_params); | 434 web_contents->GetController().LoadURLWithParams(load_url_params); |
| 409 } | 435 } |
| 410 | 436 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 // values for caret blinking interval, colors related to selection and | 604 // values for caret blinking interval, colors related to selection and |
| 579 // focus. | 605 // focus. |
| 580 *renderer_prefs = *embedder_web_contents_->GetMutableRendererPrefs(); | 606 *renderer_prefs = *embedder_web_contents_->GetMutableRendererPrefs(); |
| 581 renderer_prefs->user_agent_override = guest_user_agent_override; | 607 renderer_prefs->user_agent_override = guest_user_agent_override; |
| 582 | 608 |
| 583 // We would like the guest to report changes to frame names so that we can | 609 // We would like the guest to report changes to frame names so that we can |
| 584 // update the BrowserPlugin's corresponding 'name' attribute. | 610 // update the BrowserPlugin's corresponding 'name' attribute. |
| 585 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 611 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
| 586 renderer_prefs->report_frame_name_changes = true; | 612 renderer_prefs->report_frame_name_changes = true; |
| 587 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 613 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
| 588 // navigations still continue to function inside the app. | 614 // navigations still continue to function inside the app. |
|
jam
2014/01/17 23:09:15
nit: does this need to be updated?
Fady Samuel
2014/01/18 22:45:58
Updated comment.
| |
| 589 renderer_prefs->browser_handles_all_top_level_requests = false; | 615 renderer_prefs->browser_handles_all_top_level_requests = true; |
| 590 // Disable "client blocked" error page for browser plugin. | 616 // Disable "client blocked" error page for browser plugin. |
| 591 renderer_prefs->disable_client_blocked_error_page = true; | 617 renderer_prefs->disable_client_blocked_error_page = true; |
| 592 | 618 |
| 593 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); | 619 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
| 594 | 620 |
| 595 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); | 621 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); |
| 596 | 622 |
| 597 // Create a swapped out RenderView for the guest in the embedder render | 623 // 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. | 624 // process, so that the embedder can access the guest's window object. |
| 599 int guest_routing_id = | 625 int guest_routing_id = |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 const OpenURLParams& params) { | 825 const OpenURLParams& params) { |
| 800 // If the guest wishes to navigate away prior to attachment then we save the | 826 // If the guest wishes to navigate away prior to attachment then we save the |
| 801 // navigation to perform upon attachment. Navigation initializes a lot of | 827 // navigation to perform upon attachment. Navigation initializes a lot of |
| 802 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. | 828 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. |
| 803 // Navigation also resumes resource loading which we don't want to allow | 829 // Navigation also resumes resource loading which we don't want to allow |
| 804 // until attachment. | 830 // until attachment. |
| 805 if (!attached()) { | 831 if (!attached()) { |
| 806 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); | 832 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); |
| 807 if (it == opener()->pending_new_windows_.end()) | 833 if (it == opener()->pending_new_windows_.end()) |
| 808 return NULL; | 834 return NULL; |
| 809 const NewWindowInfo& old_target_url = it->second; | 835 const NewWindowInfo& old_info = it->second; |
| 810 NewWindowInfo new_window_info(params.url, old_target_url.name); | 836 it->second = NewWindowInfo(params.url, old_info.name); |
| 811 new_window_info.changed = new_window_info.url != old_target_url.url; | |
| 812 it->second = new_window_info; | |
| 813 return NULL; | 837 return NULL; |
| 814 } | 838 } |
| 815 if (params.disposition == CURRENT_TAB) { | 839 if (params.disposition == CURRENT_TAB) { |
| 816 // This can happen for cross-site redirects. | 840 // This can happen for cross-site redirects and top-level frame navigations. |
| 817 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 841 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
| 818 return source; | 842 return source; |
| 819 } | 843 } |
| 820 | 844 |
| 821 return CreateNewGuestWindow(params)->GetWebContents(); | 845 return CreateNewGuestWindow(params)->GetWebContents(); |
| 822 } | 846 } |
| 823 | 847 |
| 824 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 848 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
| 825 int64 source_frame_id, | 849 int64 source_frame_id, |
| 826 const base::string16& frame_name, | 850 const base::string16& frame_name, |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1221 // to initialize the browser-side state now so that the RenderFrameHostManager | 1245 // to initialize the browser-side state now so that the RenderFrameHostManager |
| 1222 // does not create a new RenderView on navigation. | 1246 // does not create a new RenderView on navigation. |
| 1223 if (has_render_view_) { | 1247 if (has_render_view_) { |
| 1224 static_cast<RenderViewHostImpl*>( | 1248 static_cast<RenderViewHostImpl*>( |
| 1225 GetWebContents()->GetRenderViewHost())->Init(); | 1249 GetWebContents()->GetRenderViewHost())->Init(); |
| 1226 WebContentsViewGuest* new_view = | 1250 WebContentsViewGuest* new_view = |
| 1227 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 1251 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 1228 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 1252 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
| 1229 } | 1253 } |
| 1230 | 1254 |
| 1231 // We need to do a navigation here if the target URL has changed between | 1255 // Grab the URL for the initial navigation. |
| 1232 // the time the WebContents was created and the time it was attached. | |
| 1233 // We also need to do an initial navigation if a RenderView was never | |
| 1234 // created for the new window in cases where there is no referrer. | |
| 1235 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); | 1256 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); |
| 1236 if (it != opener()->pending_new_windows_.end()) { | 1257 if (it != opener()->pending_new_windows_.end()) { |
| 1237 const NewWindowInfo& new_window_info = it->second; | 1258 params.src = it->second.url.spec(); |
| 1238 if (new_window_info.changed || !has_render_view_) | |
| 1239 params.src = it->second.url.spec(); | |
| 1240 } else { | 1259 } else { |
| 1241 NOTREACHED(); | 1260 NOTREACHED(); |
| 1242 } | 1261 } |
| 1243 | 1262 |
| 1244 // Once a new guest is attached to the DOM of the embedder page, then the | 1263 // Once a new guest is attached to the DOM of the embedder page, then the |
| 1245 // lifetime of the new guest is no longer managed by the opener guest. | 1264 // lifetime of the new guest is no longer managed by the opener guest. |
| 1246 opener()->pending_new_windows_.erase(this); | 1265 opener()->pending_new_windows_.erase(this); |
| 1247 | 1266 |
| 1248 // The guest's frame name takes precedence over the BrowserPlugin's name. | 1267 // The guest's frame name takes precedence over the BrowserPlugin's name. |
| 1249 // The guest's frame name is assigned in | 1268 // The guest's frame name is assigned in |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 pending_lock_request_ = false; | 1443 pending_lock_request_ = false; |
| 1425 if (succeeded) | 1444 if (succeeded) |
| 1426 mouse_locked_ = true; | 1445 mouse_locked_ = true; |
| 1427 } | 1446 } |
| 1428 | 1447 |
| 1429 void BrowserPluginGuest::OnNavigateGuest( | 1448 void BrowserPluginGuest::OnNavigateGuest( |
| 1430 int instance_id, | 1449 int instance_id, |
| 1431 const std::string& src) { | 1450 const std::string& src) { |
| 1432 GURL url = delegate_ ? delegate_->ResolveURL(src) : GURL(src); | 1451 GURL url = delegate_ ? delegate_->ResolveURL(src) : GURL(src); |
| 1433 | 1452 |
| 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 | 1453 // As guests do not swap processes on navigation, only navigations to |
| 1456 // normal web URLs are supported. No protocol handlers are installed for | 1454 // normal web URLs are supported. No protocol handlers are installed for |
| 1457 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 1455 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 1458 // can be granted to the guest process. | 1456 // can be granted to the guest process. |
| 1459 LoadURLWithParams(validated_url, Referrer(), PAGE_TRANSITION_AUTO_TOPLEVEL, | 1457 LoadURLWithParams(url, Referrer(), PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 1460 GetWebContents()); | 1458 GetWebContents()); |
| 1461 } | 1459 } |
| 1462 | 1460 |
| 1463 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { | 1461 void BrowserPluginGuest::OnPluginDestroyed(int instance_id) { |
| 1464 Destroy(); | 1462 Destroy(); |
| 1465 } | 1463 } |
| 1466 | 1464 |
| 1467 void BrowserPluginGuest::OnResizeGuest( | 1465 void BrowserPluginGuest::OnResizeGuest( |
| 1468 int instance_id, | 1466 int instance_id, |
| 1469 const BrowserPluginHostMsg_ResizeGuest_Params& params) { | 1467 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, | 1850 request_info.Set(browser_plugin::kRequestMethod, |
| 1853 base::Value::CreateStringValue(request_method)); | 1851 base::Value::CreateStringValue(request_method)); |
| 1854 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1852 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1855 | 1853 |
| 1856 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1854 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1857 new DownloadRequest(callback), | 1855 new DownloadRequest(callback), |
| 1858 request_info); | 1856 request_info); |
| 1859 } | 1857 } |
| 1860 | 1858 |
| 1861 } // namespace content | 1859 } // namespace content |
| OLD | NEW |