OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
16 #include "base/debug/asan_invalid_access.h" | 16 #include "base/debug/asan_invalid_access.h" |
17 #include "base/debug/crash_logging.h" | 17 #include "base/debug/crash_logging.h" |
18 #include "base/debug/dump_without_crashing.h" | 18 #include "base/debug/dump_without_crashing.h" |
| 19 #include "base/feature_list.h" |
19 #include "base/files/file.h" | 20 #include "base/files/file.h" |
20 #include "base/i18n/char_iterator.h" | 21 #include "base/i18n/char_iterator.h" |
21 #include "base/logging.h" | 22 #include "base/logging.h" |
22 #include "base/macros.h" | 23 #include "base/macros.h" |
23 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
24 #include "base/memory/shared_memory.h" | 25 #include "base/memory/shared_memory.h" |
25 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
26 #include "base/metrics/field_trial.h" | 27 #include "base/metrics/field_trial.h" |
27 #include "base/metrics/field_trial_params.h" | 28 #include "base/metrics/field_trial_params.h" |
28 #include "base/metrics/histogram_macros.h" | 29 #include "base/metrics/histogram_macros.h" |
29 #include "base/process/process.h" | 30 #include "base/process/process.h" |
30 #include "base/stl_util.h" | 31 #include "base/stl_util.h" |
31 #include "base/strings/string16.h" | 32 #include "base/strings/string16.h" |
32 #include "base/strings/utf_string_conversions.h" | 33 #include "base/strings/utf_string_conversions.h" |
33 #include "base/task_runner_util.h" | 34 #include "base/task_runner_util.h" |
34 #include "base/threading/thread_task_runner_handle.h" | 35 #include "base/threading/thread_task_runner_handle.h" |
35 #include "base/time/time.h" | 36 #include "base/time/time.h" |
36 #include "base/trace_event/trace_event.h" | 37 #include "base/trace_event/trace_event.h" |
37 #include "build/build_config.h" | 38 #include "build/build_config.h" |
38 #include "cc/base/switches.h" | 39 #include "cc/base/switches.h" |
| 40 #include "components/mime_util/mime_util.h" |
39 #include "content/child/appcache/appcache_dispatcher.h" | 41 #include "content/child/appcache/appcache_dispatcher.h" |
40 #include "content/child/feature_policy/feature_policy_platform.h" | 42 #include "content/child/feature_policy/feature_policy_platform.h" |
41 #include "content/child/quota_dispatcher.h" | 43 #include "content/child/quota_dispatcher.h" |
42 #include "content/child/request_extra_data.h" | 44 #include "content/child/request_extra_data.h" |
43 #include "content/child/service_worker/service_worker_handle_reference.h" | 45 #include "content/child/service_worker/service_worker_handle_reference.h" |
44 #include "content/child/service_worker/service_worker_network_provider.h" | 46 #include "content/child/service_worker/service_worker_network_provider.h" |
45 #include "content/child/service_worker/service_worker_provider_context.h" | 47 #include "content/child/service_worker/service_worker_provider_context.h" |
46 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 48 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
47 #include "content/child/v8_value_converter_impl.h" | 49 #include "content/child/v8_value_converter_impl.h" |
48 #include "content/child/web_url_loader_impl.h" | 50 #include "content/child/web_url_loader_impl.h" |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 592 |
591 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: | 593 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: |
592 return WebFrameLoadType::kReloadBypassingCache; | 594 return WebFrameLoadType::kReloadBypassingCache; |
593 | 595 |
594 default: | 596 default: |
595 NOTREACHED(); | 597 NOTREACHED(); |
596 return WebFrameLoadType::kStandard; | 598 return WebFrameLoadType::kStandard; |
597 } | 599 } |
598 } | 600 } |
599 | 601 |
| 602 bool IsDataURLMimeTypeSupported(const GURL& url) { |
| 603 std::string utf8_mime_type; |
| 604 std::string utf8_charset; |
| 605 if (net::DataURL::Parse(url, &utf8_mime_type, &utf8_charset, nullptr)) { |
| 606 return mime_util::IsSupportedMimeType(utf8_mime_type); |
| 607 } |
| 608 return false; |
| 609 } |
| 610 |
600 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = | 611 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = |
601 nullptr; | 612 nullptr; |
602 | 613 |
603 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { | 614 WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) { |
604 DCHECK(!path.IsAbsolute()); | 615 DCHECK(!path.IsAbsolute()); |
605 return WebString::FromUTF8( | 616 return WebString::FromUTF8( |
606 std::string("./") + | 617 std::string("./") + |
607 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); | 618 path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe()); |
608 } | 619 } |
609 | 620 |
(...skipping 4729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5339 // A content initiated navigation may have originated from a link-click, | 5350 // A content initiated navigation may have originated from a link-click, |
5340 // script, drag-n-drop operation, etc. | 5351 // script, drag-n-drop operation, etc. |
5341 // info.extraData is only non-null if this is a redirect. Use the extraData | 5352 // info.extraData is only non-null if this is a redirect. Use the extraData |
5342 // initiation information for redirects, and check pending_navigation_params_ | 5353 // initiation information for redirects, and check pending_navigation_params_ |
5343 // otherwise. | 5354 // otherwise. |
5344 bool is_content_initiated = | 5355 bool is_content_initiated = |
5345 info.extra_data ? static_cast<DocumentState*>(info.extra_data) | 5356 info.extra_data ? static_cast<DocumentState*>(info.extra_data) |
5346 ->navigation_state() | 5357 ->navigation_state() |
5347 ->IsContentInitiated() | 5358 ->IsContentInitiated() |
5348 : !IsBrowserInitiated(pending_navigation_params_.get()); | 5359 : !IsBrowserInitiated(pending_navigation_params_.get()); |
| 5360 const bool is_top_level = IsTopLevelNavigation(frame_); |
5349 | 5361 |
5350 // Webkit is asking whether to navigate to a new URL. | 5362 // Webkit is asking whether to navigate to a new URL. |
5351 // This is fine normally, except if we're showing UI from one security | 5363 // This is fine normally, except if we're showing UI from one security |
5352 // context and they're trying to navigate to a different context. | 5364 // context and they're trying to navigate to a different context. |
5353 const GURL& url = info.url_request.Url(); | 5365 const GURL& url = info.url_request.Url(); |
5354 | 5366 |
| 5367 // Block renderer-initiated loads of data URLs in the top frame. If the mime |
| 5368 // type of the data URL is supported, the URL will eventually be rendered, so |
| 5369 // block it here. Otherwise, the load might be handled by a plugin or end up |
| 5370 // as a download, so allow it to let the embedder figure out what to do with |
| 5371 // it. |
| 5372 if (is_content_initiated && is_top_level && url.SchemeIs(url::kDataScheme) && |
| 5373 url.spec() != kUnreachableWebDataURL && IsDataURLMimeTypeSupported(url) && |
| 5374 !base::FeatureList::IsEnabled( |
| 5375 features::kAllowContentInitiatedDataUrlNavigations)) { |
| 5376 LOG(ERROR) << ">> BLOCKING!!!! " << url; |
| 5377 if (info.extra_data) { |
| 5378 LOG(ERROR) << ">> NavigationState.IsContentInitiated : " |
| 5379 << static_cast<DocumentState*>(info.extra_data) |
| 5380 ->navigation_state() |
| 5381 ->IsContentInitiated(); |
| 5382 } else { |
| 5383 LOG(ERROR) << ">> IsBrowserInitiated(pending_navigation_params_.get(): " |
| 5384 << IsBrowserInitiated(pending_navigation_params_.get()); |
| 5385 } |
| 5386 AddMessageToConsole( |
| 5387 CONSOLE_MESSAGE_LEVEL_ERROR, |
| 5388 "Not allowed to top-level navigate to resource: " + url.spec()); |
| 5389 return blink::kWebNavigationPolicyIgnore; |
| 5390 } |
| 5391 |
5355 // With PlzNavigate, the redirect list is available for the first url. So | 5392 // With PlzNavigate, the redirect list is available for the first url. So |
5356 // maintain the old behavior of not classifying the first URL in the chain as | 5393 // maintain the old behavior of not classifying the first URL in the chain as |
5357 // a redirect. | 5394 // a redirect. |
5358 bool is_redirect = | 5395 bool is_redirect = |
5359 info.extra_data || | 5396 info.extra_data || |
5360 (pending_navigation_params_ && | 5397 (pending_navigation_params_ && |
5361 !pending_navigation_params_->request_params.redirects.empty() && | 5398 !pending_navigation_params_->request_params.redirects.empty() && |
5362 (!IsBrowserSideNavigationEnabled() || | 5399 (!IsBrowserSideNavigationEnabled() || |
5363 url != pending_navigation_params_->request_params.redirects[0])); | 5400 url != pending_navigation_params_->request_params.redirects[0])); |
5364 | 5401 |
(...skipping 11 matching lines...) Expand all Loading... |
5376 Send(new FrameHostMsg_NavigationHandledByEmbedder(routing_id_)); | 5413 Send(new FrameHostMsg_NavigationHandledByEmbedder(routing_id_)); |
5377 } | 5414 } |
5378 return blink::kWebNavigationPolicyIgnore; | 5415 return blink::kWebNavigationPolicyIgnore; |
5379 } | 5416 } |
5380 #endif | 5417 #endif |
5381 | 5418 |
5382 Referrer referrer( | 5419 Referrer referrer( |
5383 RenderViewImpl::GetReferrerFromRequest(frame_, info.url_request)); | 5420 RenderViewImpl::GetReferrerFromRequest(frame_, info.url_request)); |
5384 | 5421 |
5385 // If the browser is interested, then give it a chance to look at the request. | 5422 // If the browser is interested, then give it a chance to look at the request. |
5386 if (is_content_initiated && IsTopLevelNavigation(frame_) && | 5423 if (is_content_initiated && is_top_level && |
5387 render_view_->renderer_preferences_ | 5424 render_view_->renderer_preferences_ |
5388 .browser_handles_all_top_level_requests) { | 5425 .browser_handles_all_top_level_requests) { |
5389 OpenURL(url, IsHttpPost(info.url_request), | 5426 OpenURL(url, IsHttpPost(info.url_request), |
5390 GetRequestBodyForWebURLRequest(info.url_request), | 5427 GetRequestBodyForWebURLRequest(info.url_request), |
5391 GetWebURLRequestHeaders(info.url_request), referrer, | 5428 GetWebURLRequestHeaders(info.url_request), referrer, |
5392 info.default_policy, info.replaces_current_history_item, false); | 5429 info.default_policy, info.replaces_current_history_item, false); |
5393 return blink::kWebNavigationPolicyIgnore; // Suppress the load here. | 5430 return blink::kWebNavigationPolicyIgnore; // Suppress the load here. |
5394 } | 5431 } |
5395 | 5432 |
5396 // Back/forward navigations in newly created subframes should be sent to the | 5433 // Back/forward navigations in newly created subframes should be sent to the |
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6991 policy(info.default_policy), | 7028 policy(info.default_policy), |
6992 replaces_current_history_item(info.replaces_current_history_item), | 7029 replaces_current_history_item(info.replaces_current_history_item), |
6993 history_navigation_in_new_child_frame( | 7030 history_navigation_in_new_child_frame( |
6994 info.is_history_navigation_in_new_child_frame), | 7031 info.is_history_navigation_in_new_child_frame), |
6995 client_redirect(info.is_client_redirect), | 7032 client_redirect(info.is_client_redirect), |
6996 cache_disabled(info.is_cache_disabled), | 7033 cache_disabled(info.is_cache_disabled), |
6997 form(info.form), | 7034 form(info.form), |
6998 source_location(info.source_location) {} | 7035 source_location(info.source_location) {} |
6999 | 7036 |
7000 } // namespace content | 7037 } // namespace content |
OLD | NEW |