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

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 2411293002: Fix cross-renderer resource loads for <webview> with PlzNavigate. (Closed)
Patch Set: fix Created 4 years, 2 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 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 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 16 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
17 #include "components/guest_view/browser/guest_view_event.h" 17 #include "components/guest_view/browser/guest_view_event.h"
18 #include "components/guest_view/browser/guest_view_manager.h" 18 #include "components/guest_view/browser/guest_view_manager.h"
19 #include "components/guest_view/common/guest_view_constants.h" 19 #include "components/guest_view/common/guest_view_constants.h"
20 #include "components/web_cache/browser/web_cache_manager.h" 20 #include "components/web_cache/browser/web_cache_manager.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/child_process_security_policy.h" 23 #include "content/public/browser/child_process_security_policy.h"
24 #include "content/public/browser/native_web_keyboard_event.h" 24 #include "content/public/browser/native_web_keyboard_event.h"
25 #include "content/public/browser/navigation_entry.h" 25 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/navigation_handle.h"
26 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/render_widget_host.h" 33 #include "content/public/browser/render_widget_host.h"
33 #include "content/public/browser/render_widget_host_view.h" 34 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/resource_request_details.h" 35 #include "content/public/browser/resource_request_details.h"
35 #include "content/public/browser/site_instance.h" 36 #include "content/public/browser/site_instance.h"
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 void WebViewGuest::LoadProgressChanged(WebContents* source, double progress) { 594 void WebViewGuest::LoadProgressChanged(WebContents* source, double progress) {
594 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 595 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
595 args->SetString(guest_view::kUrl, web_contents()->GetURL().spec()); 596 args->SetString(guest_view::kUrl, web_contents()->GetURL().spec());
596 args->SetDouble(webview::kProgress, progress); 597 args->SetDouble(webview::kProgress, progress);
597 DispatchEventToView(base::MakeUnique<GuestViewEvent>( 598 DispatchEventToView(base::MakeUnique<GuestViewEvent>(
598 webview::kEventLoadProgress, std::move(args))); 599 webview::kEventLoadProgress, std::move(args)));
599 } 600 }
600 601
601 void WebViewGuest::LoadAbort(bool is_top_level, 602 void WebViewGuest::LoadAbort(bool is_top_level,
602 const GURL& url, 603 const GURL& url,
603 int error_code, 604 int error_code) {
604 const std::string& error_type) {
605 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 605 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
606 args->SetBoolean(guest_view::kIsTopLevel, is_top_level); 606 args->SetBoolean(guest_view::kIsTopLevel, is_top_level);
607 args->SetString(guest_view::kUrl, url.possibly_invalid_spec()); 607 args->SetString(guest_view::kUrl, url.possibly_invalid_spec());
608 args->SetInteger(guest_view::kCode, error_code); 608 args->SetInteger(guest_view::kCode, error_code);
609 args->SetString(guest_view::kReason, error_type); 609 args->SetString(guest_view::kReason, net::ErrorToShortString(error_code));
610 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadAbort, 610 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadAbort,
611 std::move(args))); 611 std::move(args)));
612 } 612 }
613 613
614 void WebViewGuest::SetContextMenuPosition(const gfx::Point& position) { 614 void WebViewGuest::SetContextMenuPosition(const gfx::Point& position) {
615 if (web_view_guest_delegate_) 615 if (web_view_guest_delegate_)
616 web_view_guest_delegate_->SetContextMenuPosition(position); 616 web_view_guest_delegate_->SetContextMenuPosition(position);
617 } 617 }
618 618
619 void WebViewGuest::CreateNewGuestWebViewWindow( 619 void WebViewGuest::CreateNewGuestWebViewWindow(
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 pending_zoom_factor_(0.0), 799 pending_zoom_factor_(0.0),
800 did_set_explicit_zoom_(false), 800 did_set_explicit_zoom_(false),
801 weak_ptr_factory_(this) { 801 weak_ptr_factory_(this) {
802 web_view_guest_delegate_.reset( 802 web_view_guest_delegate_.reset(
803 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 803 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
804 } 804 }
805 805
806 WebViewGuest::~WebViewGuest() { 806 WebViewGuest::~WebViewGuest() {
807 } 807 }
808 808
809 void WebViewGuest::DidCommitProvisionalLoadForFrame( 809 void WebViewGuest::DidFinishNavigation(
810 content::RenderFrameHost* render_frame_host, 810 content::NavigationHandle* navigation_handle) {
811 const GURL& url, 811 if (navigation_handle->IsErrorPage() || !navigation_handle->HasCommitted()) {
812 ui::PageTransition transition_type) { 812 // Suppress loadabort for "mailto" URLs.
813 if (!render_frame_host->GetParent()) { 813 // Also during destruction, owner_web_contents() is null so there's no point
814 // trying to send the event.
815 if (!navigation_handle->GetURL().SchemeIs(url::kMailToScheme) &&
816 owner_web_contents()) {
817 int error_code = navigation_handle->IsErrorPage()
818 ? navigation_handle->GetNetErrorCode()
819 : net::ERR_BLOCKED_BY_CLIENT;
Fady Samuel 2016/10/13 15:33:01 This would happen if the load is blocked by the we
jam 2016/10/13 16:30:06 Right. the error code ERR_BLOCKED_BY_CLIENT keeps
820 LoadAbort(navigation_handle->IsInMainFrame(), navigation_handle->GetURL(),
821 error_code);
822 }
823 return;
824 }
825
826 if (navigation_handle->IsInMainFrame()) {
814 // For LoadDataWithBaseURL loads, |url| contains the data URL, but the 827 // For LoadDataWithBaseURL loads, |url| contains the data URL, but the
815 // virtual URL is needed in that case. So use WebContents::GetURL instead. 828 // virtual URL is needed in that case. So use WebContents::GetURL instead.
816 src_ = web_contents()->GetURL(); 829 src_ = web_contents()->GetURL();
817 // Handle a pending zoom if one exists. 830 // Handle a pending zoom if one exists.
818 if (pending_zoom_factor_) { 831 if (pending_zoom_factor_) {
819 SetZoom(pending_zoom_factor_); 832 SetZoom(pending_zoom_factor_);
820 pending_zoom_factor_ = 0.0; 833 pending_zoom_factor_ = 0.0;
821 } 834 }
822 } 835 }
823 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 836 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
824 args->SetString(guest_view::kUrl, src_.spec()); 837 args->SetString(guest_view::kUrl, src_.spec());
825 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent()); 838 args->SetBoolean(guest_view::kIsTopLevel, navigation_handle->IsInMainFrame());
826 args->SetString(webview::kInternalBaseURLForDataURL, 839 args->SetString(webview::kInternalBaseURLForDataURL,
827 web_contents() 840 web_contents()
828 ->GetController() 841 ->GetController()
829 .GetLastCommittedEntry() 842 .GetLastCommittedEntry()
830 ->GetBaseURLForDataURL() 843 ->GetBaseURLForDataURL()
831 .spec()); 844 .spec());
832 args->SetInteger(webview::kInternalCurrentEntryIndex, 845 args->SetInteger(webview::kInternalCurrentEntryIndex,
833 web_contents()->GetController().GetCurrentEntryIndex()); 846 web_contents()->GetController().GetCurrentEntryIndex());
834 args->SetInteger(webview::kInternalEntryCount, 847 args->SetInteger(webview::kInternalEntryCount,
835 web_contents()->GetController().GetEntryCount()); 848 web_contents()->GetController().GetEntryCount());
836 args->SetInteger(webview::kInternalProcessId, 849 args->SetInteger(webview::kInternalProcessId,
837 web_contents()->GetRenderProcessHost()->GetID()); 850 web_contents()->GetRenderProcessHost()->GetID());
838 DispatchEventToView(base::MakeUnique<GuestViewEvent>( 851 DispatchEventToView(base::MakeUnique<GuestViewEvent>(
839 webview::kEventLoadCommit, std::move(args))); 852 webview::kEventLoadCommit, std::move(args)));
840 853
841 find_helper_.CancelAllFindSessions(); 854 find_helper_.CancelAllFindSessions();
842 } 855 }
843 856
844 void WebViewGuest::DidFailProvisionalLoad( 857 void WebViewGuest::DidStartNavigation(
845 content::RenderFrameHost* render_frame_host, 858 content::NavigationHandle* navigation_handle) {
846 const GURL& validated_url,
847 int error_code,
848 const base::string16& error_description,
849 bool was_ignored_by_handler) {
850 // Suppress loadabort for "mailto" URLs.
851 if (validated_url.SchemeIs(url::kMailToScheme))
852 return;
853
854 LoadAbort(!render_frame_host->GetParent(), validated_url, error_code,
855 net::ErrorToShortString(error_code));
856 }
857
858 void WebViewGuest::DidStartProvisionalLoadForFrame(
859 content::RenderFrameHost* render_frame_host,
860 const GURL& validated_url,
861 bool is_error_page,
862 bool is_iframe_srcdoc) {
863 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 859 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
864 args->SetString(guest_view::kUrl, validated_url.spec()); 860 args->SetString(guest_view::kUrl, navigation_handle->GetURL().spec());
865 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent()); 861 args->SetBoolean(guest_view::kIsTopLevel, navigation_handle->IsInMainFrame());
866 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStart, 862 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStart,
867 std::move(args))); 863 std::move(args)));
868 } 864 }
869 865
870 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { 866 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
871 // Cancel all find sessions in progress. 867 // Cancel all find sessions in progress.
872 find_helper_.CancelAllFindSessions(); 868 find_helper_.CancelAllFindSessions();
873 869
874 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 870 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
875 args->SetInteger(webview::kProcessId, 871 args->SetInteger(webview::kProcessId,
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 const WebContents* web_contents) const { 1370 const WebContents* web_contents) const {
1375 return is_guest_fullscreen_; 1371 return is_guest_fullscreen_;
1376 } 1372 }
1377 1373
1378 void WebViewGuest::LoadURLWithParams( 1374 void WebViewGuest::LoadURLWithParams(
1379 const GURL& url, 1375 const GURL& url,
1380 const content::Referrer& referrer, 1376 const content::Referrer& referrer,
1381 ui::PageTransition transition_type, 1377 ui::PageTransition transition_type,
1382 bool force_navigation) { 1378 bool force_navigation) {
1383 if (!url.is_valid()) { 1379 if (!url.is_valid()) {
1384 LoadAbort(true /* is_top_level */, url, net::ERR_INVALID_URL, 1380 LoadAbort(true /* is_top_level */, url, net::ERR_INVALID_URL);
1385 net::ErrorToShortString(net::ERR_INVALID_URL));
1386 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); 1381 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */);
1387 return; 1382 return;
1388 } 1383 }
1389 1384
1390 bool scheme_is_blocked = 1385 bool scheme_is_blocked =
1391 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( 1386 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
1392 url.scheme()) && 1387 url.scheme()) &&
1393 !url.SchemeIs(url::kAboutScheme)) || 1388 !url.SchemeIs(url::kAboutScheme)) ||
1394 url.SchemeIs(url::kJavaScriptScheme); 1389 url.SchemeIs(url::kJavaScriptScheme);
1395 1390
1396 // Do not allow navigating a guest to schemes other than known safe schemes. 1391 // Do not allow navigating a guest to schemes other than known safe schemes.
1397 // This will block the embedder trying to load unwanted schemes, e.g. 1392 // This will block the embedder trying to load unwanted schemes, e.g.
1398 // chrome://. 1393 // chrome://.
1399 if (scheme_is_blocked) { 1394 if (scheme_is_blocked) {
1400 LoadAbort(true /* is_top_level */, url, net::ERR_DISALLOWED_URL_SCHEME, 1395 LoadAbort(true /* is_top_level */, url, net::ERR_DISALLOWED_URL_SCHEME);
1401 net::ErrorToShortString(net::ERR_DISALLOWED_URL_SCHEME));
1402 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); 1396 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */);
1403 return; 1397 return;
1404 } 1398 }
1405 1399
1406 if (!force_navigation && (src_ == url)) 1400 if (!force_navigation && (src_ == url))
1407 return; 1401 return;
1408 1402
1409 GURL validated_url(url); 1403 GURL validated_url(url);
1410 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); 1404 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url);
1411 // As guests do not swap processes on navigation, only navigations to 1405 // As guests do not swap processes on navigation, only navigations to
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1512 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1519 DispatchEventToView(base::MakeUnique<GuestViewEvent>( 1513 DispatchEventToView(base::MakeUnique<GuestViewEvent>(
1520 webview::kEventExitFullscreen, std::move(args))); 1514 webview::kEventExitFullscreen, std::move(args)));
1521 } 1515 }
1522 // Since we changed fullscreen state, sending a Resize message ensures that 1516 // Since we changed fullscreen state, sending a Resize message ensures that
1523 // renderer/ sees the change. 1517 // renderer/ sees the change.
1524 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); 1518 web_contents()->GetRenderViewHost()->GetWidget()->WasResized();
1525 } 1519 }
1526 1520
1527 } // namespace extensions 1521 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698