| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 int render_process_id = render_view_host->GetProcess()->GetID(); | 305 int render_process_id = render_view_host->GetProcess()->GetID(); |
| 306 GlobalRequestID global_id(render_process_id, url_request_id); | 306 GlobalRequestID global_id(render_process_id, url_request_id); |
| 307 net::URLRequest* url_request = | 307 net::URLRequest* url_request = |
| 308 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 308 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
| 309 if (url_request) | 309 if (url_request) |
| 310 return url_request->url().possibly_invalid_spec(); | 310 return url_request->url().possibly_invalid_spec(); |
| 311 return ""; | 311 return ""; |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool SupportsScheme(const GURL& url) { |
| 315 // javascript: URLs are not supported. |
| 316 if (url.SchemeIs(kJavaScriptScheme)) |
| 317 return false; |
| 318 |
| 319 ChildProcessSecurityPolicyImpl* policy = |
| 320 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 321 if (policy->IsWebSafeScheme(url.scheme()) || |
| 322 policy->IsPseudoScheme(url.scheme())) { |
| 323 return true; |
| 324 } |
| 325 |
| 326 return false; |
| 327 } |
| 328 |
| 314 } // namespace | 329 } // namespace |
| 315 | 330 |
| 316 class BrowserPluginGuest::EmbedderWebContentsObserver | 331 class BrowserPluginGuest::EmbedderWebContentsObserver |
| 317 : public WebContentsObserver { | 332 : public WebContentsObserver { |
| 318 public: | 333 public: |
| 319 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) | 334 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) |
| 320 : WebContentsObserver(guest->embedder_web_contents()), | 335 : WebContentsObserver(guest->embedder_web_contents()), |
| 321 browser_plugin_guest_(guest) { | 336 browser_plugin_guest_(guest) { |
| 322 } | 337 } |
| 323 | 338 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // Clean up unattached new windows opened by this guest. | 410 // Clean up unattached new windows opened by this guest. |
| 396 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 411 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
| 397 it != pending_new_windows.end(); ++it) { | 412 it != pending_new_windows.end(); ++it) { |
| 398 it->first->Destroy(); | 413 it->first->Destroy(); |
| 399 } | 414 } |
| 400 // All pending windows should be removed from the set after Destroy() is | 415 // All pending windows should be removed from the set after Destroy() is |
| 401 // called on all of them. | 416 // called on all of them. |
| 402 DCHECK(pending_new_windows_.empty()); | 417 DCHECK(pending_new_windows_.empty()); |
| 403 } | 418 } |
| 404 | 419 |
| 420 void BrowserPluginGuest::ReportLoadAbort(const GURL& url, |
| 421 bool is_top_level, |
| 422 int reason) { |
| 423 if (!delegate_) |
| 424 return; |
| 425 |
| 426 std::string error_type; |
| 427 base::RemoveChars(net::ErrorToString(reason), "net::", |
| 428 &error_type); |
| 429 delegate_->LoadAbort(is_top_level, url, error_type); |
| 430 } |
| 431 |
| 405 void BrowserPluginGuest::LoadURLWithParams(const GURL& url, | 432 void BrowserPluginGuest::LoadURLWithParams(const GURL& url, |
| 406 const Referrer& referrer, | 433 const Referrer& referrer, |
| 407 PageTransition transition_type, | 434 PageTransition transition_type, |
| 408 WebContents* web_contents) { | 435 WebContents* web_contents) { |
| 436 // If the URL is invalid, then there's nothing to do here except abort. |
| 437 if (!url.is_valid()) { |
| 438 ReportLoadAbort(url, true /* is_top_level */, net::ERR_INVALID_URL); |
| 439 return; |
| 440 } |
| 441 |
| 409 // Do not allow navigating a guest to schemes other than known safe schemes. | 442 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 410 // This will block the embedder trying to load unwanted schemes, e.g. | 443 // This will block the embedder trying to load unwanted schemes, e.g. |
| 411 // chrome://settings. | 444 // chrome://settings. |
| 412 bool scheme_is_blocked = | 445 if (!SupportsScheme(url)) { |
| 413 (!ChildProcessSecurityPolicyImpl::GetInstance()->IsWebSafeScheme( | 446 ReportLoadAbort(url, true /* is_top_level */, |
| 414 url.scheme()) && | 447 net::ERR_DISALLOWED_URL_SCHEME); |
| 415 !ChildProcessSecurityPolicyImpl::GetInstance()->IsPseudoScheme( | |
| 416 url.scheme())) || | |
| 417 url.SchemeIs(kJavaScriptScheme); | |
| 418 bool can_commit = | |
| 419 GetContentClient()->browser()->CanCommitURL( | |
| 420 GetWebContents()->GetRenderProcessHost(), url); | |
| 421 if (scheme_is_blocked || !url.is_valid() || !can_commit) { | |
| 422 if (delegate_) { | |
| 423 // TODO(fsamuel): Need better error reporting here. | |
| 424 std::string error_type; | |
| 425 base::RemoveChars(net::ErrorToString(net::ERR_ABORTED), "net::", | |
| 426 &error_type); | |
| 427 delegate_->LoadAbort(true /* is_top_level */, url, error_type); | |
| 428 } | |
| 429 return; | 448 return; |
| 430 } | 449 } |
| 431 | 450 |
| 451 if (!GetContentClient()->browser()->CanCommitURL( |
| 452 GetWebContents()->GetRenderProcessHost(), url)) { |
| 453 ReportLoadAbort(url, true /* is_top_level */, net::ERR_ACCESS_DENIED); |
| 454 return; |
| 455 } |
| 456 |
| 432 GURL validated_url(url); | 457 GURL validated_url(url); |
| 433 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 458 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 434 | 459 |
| 435 NavigationController::LoadURLParams load_url_params(validated_url); | 460 NavigationController::LoadURLParams load_url_params(validated_url); |
| 436 load_url_params.referrer = referrer; | 461 load_url_params.referrer = referrer; |
| 437 load_url_params.transition_type = transition_type; | 462 load_url_params.transition_type = transition_type; |
| 438 load_url_params.extra_headers = std::string(); | 463 load_url_params.extra_headers = std::string(); |
| 439 if (delegate_ && delegate_->IsOverridingUserAgent()) { | 464 if (delegate_ && delegate_->IsOverridingUserAgent()) { |
| 440 load_url_params.override_user_agent = | 465 load_url_params.override_user_agent = |
| 441 NavigationController::UA_OVERRIDE_TRUE; | 466 NavigationController::UA_OVERRIDE_TRUE; |
| (...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 base::Value::CreateStringValue(request_method)); | 1908 base::Value::CreateStringValue(request_method)); |
| 1884 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1909 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1885 | 1910 |
| 1886 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1911 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1887 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), | 1912 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), |
| 1888 callback), | 1913 callback), |
| 1889 request_info); | 1914 request_info); |
| 1890 } | 1915 } |
| 1891 | 1916 |
| 1892 } // namespace content | 1917 } // namespace content |
| OLD | NEW |