| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 // If it's not an error page, the request was blocked by the webrequest |
| 818 // API. |
| 819 int error_code = navigation_handle->IsErrorPage() |
| 820 ? navigation_handle->GetNetErrorCode() |
| 821 : net::ERR_BLOCKED_BY_CLIENT; |
| 822 LoadAbort(navigation_handle->IsInMainFrame(), navigation_handle->GetURL(), |
| 823 error_code); |
| 824 } |
| 825 return; |
| 826 } |
| 827 |
| 828 if (navigation_handle->IsInMainFrame()) { |
| 814 // For LoadDataWithBaseURL loads, |url| contains the data URL, but the | 829 // For LoadDataWithBaseURL loads, |url| contains the data URL, but the |
| 815 // virtual URL is needed in that case. So use WebContents::GetURL instead. | 830 // virtual URL is needed in that case. So use WebContents::GetURL instead. |
| 816 src_ = web_contents()->GetURL(); | 831 src_ = web_contents()->GetURL(); |
| 817 // Handle a pending zoom if one exists. | 832 // Handle a pending zoom if one exists. |
| 818 if (pending_zoom_factor_) { | 833 if (pending_zoom_factor_) { |
| 819 SetZoom(pending_zoom_factor_); | 834 SetZoom(pending_zoom_factor_); |
| 820 pending_zoom_factor_ = 0.0; | 835 pending_zoom_factor_ = 0.0; |
| 821 } | 836 } |
| 822 } | 837 } |
| 823 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 838 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 824 args->SetString(guest_view::kUrl, src_.spec()); | 839 args->SetString(guest_view::kUrl, src_.spec()); |
| 825 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent()); | 840 args->SetBoolean(guest_view::kIsTopLevel, navigation_handle->IsInMainFrame()); |
| 826 args->SetString(webview::kInternalBaseURLForDataURL, | 841 args->SetString(webview::kInternalBaseURLForDataURL, |
| 827 web_contents() | 842 web_contents() |
| 828 ->GetController() | 843 ->GetController() |
| 829 .GetLastCommittedEntry() | 844 .GetLastCommittedEntry() |
| 830 ->GetBaseURLForDataURL() | 845 ->GetBaseURLForDataURL() |
| 831 .spec()); | 846 .spec()); |
| 832 args->SetInteger(webview::kInternalCurrentEntryIndex, | 847 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 833 web_contents()->GetController().GetCurrentEntryIndex()); | 848 web_contents()->GetController().GetCurrentEntryIndex()); |
| 834 args->SetInteger(webview::kInternalEntryCount, | 849 args->SetInteger(webview::kInternalEntryCount, |
| 835 web_contents()->GetController().GetEntryCount()); | 850 web_contents()->GetController().GetEntryCount()); |
| 836 args->SetInteger(webview::kInternalProcessId, | 851 args->SetInteger(webview::kInternalProcessId, |
| 837 web_contents()->GetRenderProcessHost()->GetID()); | 852 web_contents()->GetRenderProcessHost()->GetID()); |
| 838 DispatchEventToView(base::MakeUnique<GuestViewEvent>( | 853 DispatchEventToView(base::MakeUnique<GuestViewEvent>( |
| 839 webview::kEventLoadCommit, std::move(args))); | 854 webview::kEventLoadCommit, std::move(args))); |
| 840 | 855 |
| 841 find_helper_.CancelAllFindSessions(); | 856 find_helper_.CancelAllFindSessions(); |
| 842 } | 857 } |
| 843 | 858 |
| 844 void WebViewGuest::DidFailProvisionalLoad( | 859 void WebViewGuest::DidStartNavigation( |
| 845 content::RenderFrameHost* render_frame_host, | 860 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()); | 861 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 864 args->SetString(guest_view::kUrl, validated_url.spec()); | 862 args->SetString(guest_view::kUrl, navigation_handle->GetURL().spec()); |
| 865 args->SetBoolean(guest_view::kIsTopLevel, !render_frame_host->GetParent()); | 863 args->SetBoolean(guest_view::kIsTopLevel, navigation_handle->IsInMainFrame()); |
| 866 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStart, | 864 DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventLoadStart, |
| 867 std::move(args))); | 865 std::move(args))); |
| 868 } | 866 } |
| 869 | 867 |
| 870 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { | 868 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { |
| 871 // Cancel all find sessions in progress. | 869 // Cancel all find sessions in progress. |
| 872 find_helper_.CancelAllFindSessions(); | 870 find_helper_.CancelAllFindSessions(); |
| 873 | 871 |
| 874 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 872 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 875 args->SetInteger(webview::kProcessId, | 873 args->SetInteger(webview::kProcessId, |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 const WebContents* web_contents) const { | 1372 const WebContents* web_contents) const { |
| 1375 return is_guest_fullscreen_; | 1373 return is_guest_fullscreen_; |
| 1376 } | 1374 } |
| 1377 | 1375 |
| 1378 void WebViewGuest::LoadURLWithParams( | 1376 void WebViewGuest::LoadURLWithParams( |
| 1379 const GURL& url, | 1377 const GURL& url, |
| 1380 const content::Referrer& referrer, | 1378 const content::Referrer& referrer, |
| 1381 ui::PageTransition transition_type, | 1379 ui::PageTransition transition_type, |
| 1382 bool force_navigation) { | 1380 bool force_navigation) { |
| 1383 if (!url.is_valid()) { | 1381 if (!url.is_valid()) { |
| 1384 LoadAbort(true /* is_top_level */, url, net::ERR_INVALID_URL, | 1382 LoadAbort(true /* is_top_level */, url, net::ERR_INVALID_URL); |
| 1385 net::ErrorToShortString(net::ERR_INVALID_URL)); | |
| 1386 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); | 1383 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
| 1387 return; | 1384 return; |
| 1388 } | 1385 } |
| 1389 | 1386 |
| 1390 bool scheme_is_blocked = | 1387 bool scheme_is_blocked = |
| 1391 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1388 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
| 1392 url.scheme()) && | 1389 url.scheme()) && |
| 1393 !url.SchemeIs(url::kAboutScheme)) || | 1390 !url.SchemeIs(url::kAboutScheme)) || |
| 1394 url.SchemeIs(url::kJavaScriptScheme); | 1391 url.SchemeIs(url::kJavaScriptScheme); |
| 1395 | 1392 |
| 1396 // Do not allow navigating a guest to schemes other than known safe schemes. | 1393 // 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. | 1394 // This will block the embedder trying to load unwanted schemes, e.g. |
| 1398 // chrome://. | 1395 // chrome://. |
| 1399 if (scheme_is_blocked) { | 1396 if (scheme_is_blocked) { |
| 1400 LoadAbort(true /* is_top_level */, url, net::ERR_DISALLOWED_URL_SCHEME, | 1397 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 */); | 1398 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
| 1403 return; | 1399 return; |
| 1404 } | 1400 } |
| 1405 | 1401 |
| 1406 if (!force_navigation && (src_ == url)) | 1402 if (!force_navigation && (src_ == url)) |
| 1407 return; | 1403 return; |
| 1408 | 1404 |
| 1409 GURL validated_url(url); | 1405 GURL validated_url(url); |
| 1410 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1406 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 1411 // As guests do not swap processes on navigation, only navigations to | 1407 // As guests do not swap processes on navigation, only navigations to |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1514 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1519 DispatchEventToView(base::MakeUnique<GuestViewEvent>( | 1515 DispatchEventToView(base::MakeUnique<GuestViewEvent>( |
| 1520 webview::kEventExitFullscreen, std::move(args))); | 1516 webview::kEventExitFullscreen, std::move(args))); |
| 1521 } | 1517 } |
| 1522 // Since we changed fullscreen state, sending a Resize message ensures that | 1518 // Since we changed fullscreen state, sending a Resize message ensures that |
| 1523 // renderer/ sees the change. | 1519 // renderer/ sees the change. |
| 1524 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1520 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
| 1525 } | 1521 } |
| 1526 | 1522 |
| 1527 } // namespace extensions | 1523 } // namespace extensions |
| OLD | NEW |