Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 130183004: <webview>: Add better loadabort reason messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reupload Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // Clean up unattached new windows opened by this guest. 395 // Clean up unattached new windows opened by this guest.
396 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); 396 for (PendingWindowMap::const_iterator it = pending_new_windows.begin();
397 it != pending_new_windows.end(); ++it) { 397 it != pending_new_windows.end(); ++it) {
398 it->first->Destroy(); 398 it->first->Destroy();
399 } 399 }
400 // All pending windows should be removed from the set after Destroy() is 400 // All pending windows should be removed from the set after Destroy() is
401 // called on all of them. 401 // called on all of them.
402 DCHECK(pending_new_windows_.empty()); 402 DCHECK(pending_new_windows_.empty());
403 } 403 }
404 404
405 // static
406 bool BrowserPluginGuest::SupportsScheme(const GURL& url) {
407 // javascript: URLs are not supported.
408 if (url.SchemeIs(kJavaScriptScheme))
409 return false;
410
411 ChildProcessSecurityPolicyImpl* policy =
412 ChildProcessSecurityPolicyImpl::GetInstance();
413 if (policy->IsWebSafeScheme(url.scheme()) ||
414 policy->IsPseudoScheme(url.scheme())) {
415 return true;
416 }
417
418 return false;
419 }
420
421 void BrowserPluginGuest::ReportLoadAbort(const GURL& url,
422 bool is_top_level,
423 int reason) {
424 if (!delegate_)
425 return;
426
427 std::string error_type;
428 base::RemoveChars(net::ErrorToString(reason), "net::",
429 &error_type);
430 delegate_->LoadAbort(is_top_level, url, error_type);
431 }
432
405 void BrowserPluginGuest::LoadURLWithParams(const GURL& url, 433 void BrowserPluginGuest::LoadURLWithParams(const GURL& url,
406 const Referrer& referrer, 434 const Referrer& referrer,
407 PageTransition transition_type, 435 PageTransition transition_type,
408 WebContents* web_contents) { 436 WebContents* web_contents) {
437 // If the URL is invalid, then there's nothing to do here except abort.
438 if (!url.is_valid()) {
439 ReportLoadAbort(url, true /* is_top_level */, net::ERR_INVALID_URL);
440 return;
441 }
442
409 // Do not allow navigating a guest to schemes other than known safe schemes. 443 // 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. 444 // This will block the embedder trying to load unwanted schemes, e.g.
411 // chrome://settings. 445 // chrome://settings.
412 bool scheme_is_blocked = 446 if (!SupportsScheme(url)) {
413 (!ChildProcessSecurityPolicyImpl::GetInstance()->IsWebSafeScheme( 447 ReportLoadAbort(url, true /* is_top_level */,
414 url.scheme()) && 448 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; 449 return;
430 } 450 }
431 451
452 if (!GetContentClient()->browser()->CanCommitURL(
453 GetWebContents()->GetRenderProcessHost(), url)) {
454 ReportLoadAbort(url, true /* is_top_level */, net::ERR_ACCESS_DENIED);
455 return;
456 }
457
432 GURL validated_url(url); 458 GURL validated_url(url);
433 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url); 459 GetWebContents()->GetRenderProcessHost()->FilterURL(false, &validated_url);
434 460
435 NavigationController::LoadURLParams load_url_params(validated_url); 461 NavigationController::LoadURLParams load_url_params(validated_url);
436 load_url_params.referrer = referrer; 462 load_url_params.referrer = referrer;
437 load_url_params.transition_type = transition_type; 463 load_url_params.transition_type = transition_type;
438 load_url_params.extra_headers = std::string(); 464 load_url_params.extra_headers = std::string();
439 if (delegate_ && delegate_->IsOverridingUserAgent()) { 465 if (delegate_ && delegate_->IsOverridingUserAgent()) {
440 load_url_params.override_user_agent = 466 load_url_params.override_user_agent =
441 NavigationController::UA_OVERRIDE_TRUE; 467 NavigationController::UA_OVERRIDE_TRUE;
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 base::Value::CreateStringValue(request_method)); 1909 base::Value::CreateStringValue(request_method));
1884 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); 1910 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url));
1885 1911
1886 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, 1912 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD,
1887 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), 1913 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(),
1888 callback), 1914 callback),
1889 request_info); 1915 request_info);
1890 } 1916 }
1891 1917
1892 } // namespace content 1918 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698