forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_frame_impl.cc
6247 lines (5451 loc) · 244 KB
/
render_frame_impl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/render_frame_impl.h"
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/debug/asan_invalid_access.h"
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/files/file.h"
#include "base/i18n/char_iterator.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/process/process.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event_argument.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "components/scheduler/renderer/renderer_scheduler.h"
#include "content/child/appcache/appcache_dispatcher.h"
#include "content/child/permissions/permission_dispatcher.h"
#include "content/child/quota_dispatcher.h"
#include "content/child/request_extra_data.h"
#include "content/child/service_worker/service_worker_handle_reference.h"
#include "content/child/service_worker/service_worker_network_provider.h"
#include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/service_worker/web_service_worker_provider_impl.h"
#include "content/child/v8_value_converter_impl.h"
#include "content/child/web_url_loader_impl.h"
#include "content/child/web_url_request_util.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/child/websocket_bridge.h"
#include "content/child/weburlresponse_extradata_impl.h"
#include "content/common/accessibility_messages.h"
#include "content/common/clipboard_messages.h"
#include "content/common/content_security_policy_header.h"
#include "content/common/frame_messages.h"
#include "content/common/frame_replication_state.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/common/input_messages.h"
#include "content/common/navigation_params.h"
#include "content/common/page_messages.h"
#include "content/common/savable_subframe.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/common/site_isolation_policy.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/swapped_out_messages.h"
#include "content/common/view_messages.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/file_chooser_file_info.h"
#include "content/public/common/file_chooser_params.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/page_state.h"
#include "content/public/common/resource_response.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "content/public/renderer/browser_plugin_delegate.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/context_menu_client.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/navigation_state.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/accessibility/renderer_accessibility.h"
#include "content/renderer/bluetooth/web_bluetooth_impl.h"
#include "content/renderer/browser_plugin/browser_plugin.h"
#include "content/renderer/browser_plugin/browser_plugin_manager.h"
#include "content/renderer/child_frame_compositing_helper.h"
#include "content/renderer/context_menu_params_builder.h"
#include "content/renderer/devtools/devtools_agent.h"
#include "content/renderer/dom_automation_controller.h"
#include "content/renderer/effective_connection_type_helper.h"
#include "content/renderer/external_popup_menu.h"
#include "content/renderer/gpu/gpu_benchmarking_extension.h"
#include "content/renderer/history_controller.h"
#include "content/renderer/history_serialization.h"
#include "content/renderer/image_downloader/image_downloader_impl.h"
#include "content/renderer/ime_event_guard.h"
#include "content/renderer/input/input_handler_manager.h"
#include "content/renderer/internal_document_state_data.h"
#include "content/renderer/manifest/manifest_manager.h"
#include "content/renderer/media/audio_device_factory.h"
#include "content/renderer/media/media_permission_dispatcher.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/media_stream_renderer_factory_impl.h"
#include "content/renderer/media/midi_dispatcher.h"
#include "content/renderer/media/render_media_log.h"
#include "content/renderer/media/renderer_webmediaplayer_delegate.h"
#include "content/renderer/media/user_media_client_impl.h"
#include "content/renderer/media/web_media_element_source_utils.h"
#include "content/renderer/media/webmediaplayer_ms.h"
#include "content/renderer/mojo/service_registry_js_wrapper.h"
#include "content/renderer/mojo_bindings_controller.h"
#include "content/renderer/navigation_state_impl.h"
#include "content/renderer/notification_permission_dispatcher.h"
#include "content/renderer/pepper/plugin_instance_throttler_impl.h"
#include "content/renderer/presentation/presentation_dispatcher.h"
#include "content/renderer/push_messaging/push_messaging_dispatcher.h"
#include "content/renderer/render_frame_proxy.h"
#include "content/renderer/render_process.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "content/renderer/render_widget_fullscreen_pepper.h"
#include "content/renderer/renderer_webapplicationcachehost_impl.h"
#include "content/renderer/renderer_webcolorchooser_impl.h"
#include "content/renderer/savable_resources.h"
#include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
#include "content/renderer/shared_worker_repository.h"
#include "content/renderer/skia_benchmarking_extension.h"
#include "content/renderer/stats_collection_controller.h"
#include "content/renderer/web_frame_utils.h"
#include "content/renderer/web_ui_extension.h"
#include "content/renderer/websharedworker_proxy.h"
#include "crypto/sha2.h"
#include "gin/modules/module_registry.h"
#include "media/audio/audio_output_device.h"
#include "media/base/audio_renderer_mixer_input.h"
#include "media/base/cdm_factory.h"
#include "media/base/decoder_factory.h"
#include "media/base/media.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/blink/url_index.h"
#include "media/blink/webencryptedmediaclient_impl.h"
#include "media/blink/webmediaplayer_impl.h"
#include "media/renderers/gpu_video_accelerator_factories.h"
#include "mojo/common/url_type_converters.h"
#include "mojo/edk/js/core.h"
#include "mojo/edk/js/support.h"
#include "net/base/data_url.h"
#include "net/base/net_errors.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_util.h"
#include "storage/common/data_element.h"
#include "third_party/WebKit/public/platform/FilePathConversion.h"
#include "third_party/WebKit/public/platform/URLConversion.h"
#include "third_party/WebKit/public/platform/WebCachePolicy.h"
#include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebMediaPlayer.h"
#include "third_party/WebKit/public/platform/WebMediaPlayerSource.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebColorSuggestion.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebFrameSerializer.h"
#include "third_party/WebKit/public/web/WebFrameSerializerCacheControlPolicy.h"
#include "third_party/WebKit/public/web/WebFrameWidget.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebPluginDocument.h"
#include "third_party/WebKit/public/web/WebPluginParams.h"
#include "third_party/WebKit/public/web/WebRange.h"
#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSearchableFormData.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
#include "third_party/WebKit/public/web/WebSettings.h"
#include "third_party/WebKit/public/web/WebSurroundingText.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWidget.h"
#include "url/url_constants.h"
#include "url/url_util.h"
#if defined(ENABLE_PLUGINS)
#include "content/renderer/pepper/pepper_browser_connection.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/pepper_plugin_registry.h"
#include "content/renderer/pepper/pepper_webplugin_impl.h"
#include "content/renderer/pepper/plugin_module.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "content/renderer/media/rtc_peer_connection_handler.h"
#endif
#if defined(OS_ANDROID)
#include <cpu-features.h>
#include "content/renderer/java/gin_java_bridge_dispatcher.h"
#include "content/renderer/media/android/renderer_media_player_manager.h"
#include "content/renderer/media/android/renderer_media_session_manager.h"
#include "content/renderer/media/android/renderer_surface_view_manager.h"
#include "content/renderer/media/android/stream_texture_factory.h"
#include "content/renderer/media/android/webmediaplayer_android.h"
#include "content/renderer/media/android/webmediasession_android.h"
#include "media/base/android/media_codec_util.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h"
#endif
#if defined(ENABLE_PEPPER_CDMS)
#include "content/renderer/media/cdm/pepper_cdm_wrapper_impl.h"
#include "content/renderer/media/cdm/render_cdm_factory.h"
#elif defined(ENABLE_BROWSER_CDMS)
#include "content/renderer/media/cdm/render_cdm_factory.h"
#include "content/renderer/media/cdm/renderer_cdm_manager.h"
#endif
#if defined(ENABLE_MOJO_MEDIA)
#include "content/renderer/media/media_interface_provider.h"
#endif
#if defined(ENABLE_MOJO_CDM)
#include "media/mojo/clients/mojo_cdm_factory.h" // nogncheck
#endif
#if defined(ENABLE_MOJO_RENDERER)
#include "media/mojo/clients/mojo_renderer_factory.h" // nogncheck
#else
#include "media/renderers/default_renderer_factory.h"
#endif
#if defined(ENABLE_MOJO_AUDIO_DECODER) || defined(ENABLE_MOJO_VIDEO_DECODER)
#include "media/mojo/clients/mojo_decoder_factory.h" // nogncheck
#endif
using blink::WebCachePolicy;
using blink::WebContentDecryptionModule;
using blink::WebContextMenuData;
using blink::WebCString;
using blink::WebData;
using blink::WebDataSource;
using blink::WebDocument;
using blink::WebDOMEvent;
using blink::WebDOMMessageEvent;
using blink::WebElement;
using blink::WebExternalPopupMenu;
using blink::WebExternalPopupMenuClient;
using blink::WebFindOptions;
using blink::WebFrame;
using blink::WebFrameLoadType;
using blink::WebFrameSerializer;
using blink::WebFrameSerializerClient;
using blink::WebHistoryItem;
using blink::WebHTTPBody;
using blink::WebLocalFrame;
using blink::WebMediaPlayer;
using blink::WebMediaPlayerClient;
using blink::WebMediaPlayerEncryptedMediaClient;
using blink::WebMediaSession;
using blink::WebNavigationPolicy;
using blink::WebNavigationType;
using blink::WebNode;
using blink::WebPluginDocument;
using blink::WebPluginParams;
using blink::WebPopupMenuInfo;
using blink::WebRange;
using blink::WebRect;
using blink::WebReferrerPolicy;
using blink::WebScriptSource;
using blink::WebSearchableFormData;
using blink::WebSecurityOrigin;
using blink::WebSecurityPolicy;
using blink::WebSerializedScriptValue;
using blink::WebServiceWorkerProvider;
using blink::WebSettings;
using blink::WebStorageQuotaCallbacks;
using blink::WebString;
using blink::WebURL;
using blink::WebURLError;
using blink::WebURLRequest;
using blink::WebURLResponse;
using blink::WebUserGestureIndicator;
using blink::WebVector;
using blink::WebView;
using base::Time;
using base::TimeDelta;
#if defined(OS_ANDROID)
using blink::WebFloatPoint;
using blink::WebFloatRect;
#endif
#define STATIC_ASSERT_ENUM(a, b) \
static_assert(static_cast<int>(a) == static_cast<int>(b), \
"mismatching enums: " #a)
namespace content {
namespace {
const size_t kExtraCharsBeforeAndAfterSelection = 100;
typedef std::map<int, RenderFrameImpl*> RoutingIDFrameMap;
static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map =
LAZY_INSTANCE_INITIALIZER;
typedef std::map<blink::WebFrame*, RenderFrameImpl*> FrameMap;
base::LazyInstance<FrameMap> g_frame_map = LAZY_INSTANCE_INITIALIZER;
int64_t ExtractPostId(const WebHistoryItem& item) {
if (item.isNull() || item.httpBody().isNull())
return -1;
return item.httpBody().identifier();
}
WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
const WebURLResponse& response) {
return static_cast<WebURLResponseExtraDataImpl*>(response.getExtraData());
}
void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
WebVector<WebURL> urls;
ds->redirectChain(urls);
result->reserve(urls.size());
for (size_t i = 0; i < urls.size(); ++i) {
result->push_back(urls[i]);
}
}
// Gets URL that should override the default getter for this data source
// (if any), storing it in |output|. Returns true if there is an override URL.
bool MaybeGetOverriddenURL(WebDataSource* ds, GURL* output) {
DocumentState* document_state = DocumentState::FromDataSource(ds);
// If load was from a data URL, then the saved data URL, not the history
// URL, should be the URL of the data source.
if (document_state->was_load_data_with_base_url_request()) {
*output = document_state->data_url();
return true;
}
// WebDataSource has unreachable URL means that the frame is loaded through
// blink::WebFrame::loadData(), and the base URL will be in the redirect
// chain. However, we never visited the baseURL. So in this case, we should
// use the unreachable URL as the original URL.
if (ds->hasUnreachableURL()) {
*output = ds->unreachableURL();
return true;
}
return false;
}
// Returns the original request url. If there is no redirect, the original
// url is the same as ds->request()->url(). If the WebDataSource belongs to a
// frame was loaded by loadData, the original url will be ds->unreachableURL()
GURL GetOriginalRequestURL(WebDataSource* ds) {
GURL overriden_url;
if (MaybeGetOverriddenURL(ds, &overriden_url))
return overriden_url;
std::vector<GURL> redirects;
GetRedirectChain(ds, &redirects);
if (!redirects.empty())
return redirects.at(0);
return ds->originalRequest().url();
}
bool IsBrowserInitiated(NavigationParams* pending) {
// A navigation resulting from loading a javascript URL should not be treated
// as a browser initiated event. Instead, we want it to look as if the page
// initiated any load resulting from JS execution.
return pending &&
!pending->common_params.url.SchemeIs(url::kJavaScriptScheme);
}
NOINLINE void CrashIntentionally() {
// NOTE(shess): Crash directly rather than using NOTREACHED() so
// that the signature is easier to triage in crash reports.
//
// Linker's ICF feature may merge this function with other functions with the
// same definition and it may confuse the crash report processing system.
static int static_variable_to_make_this_function_unique = 0;
base::debug::Alias(&static_variable_to_make_this_function_unique);
volatile int* zero = nullptr;
*zero = 0;
}
NOINLINE void BadCastCrashIntentionally() {
class A {
virtual void f() {}
};
class B {
virtual void f() {}
};
A a;
(void)(B*)&a;
}
#if defined(ADDRESS_SANITIZER) || defined(SYZYASAN)
NOINLINE void MaybeTriggerAsanError(const GURL& url) {
// NOTE(rogerm): We intentionally perform an invalid heap access here in
// order to trigger an Address Sanitizer (ASAN) error report.
const char kCrashDomain[] = "crash";
const char kHeapOverflow[] = "/heap-overflow";
const char kHeapUnderflow[] = "/heap-underflow";
const char kUseAfterFree[] = "/use-after-free";
#if defined(SYZYASAN)
const char kCorruptHeapBlock[] = "/corrupt-heap-block";
const char kCorruptHeap[] = "/corrupt-heap";
#endif
if (!url.DomainIs(kCrashDomain))
return;
if (!url.has_path())
return;
std::string crash_type(url.path());
if (crash_type == kHeapOverflow) {
LOG(ERROR)
<< "Intentionally causing ASAN heap overflow"
<< " because user navigated to " << url.spec();
base::debug::AsanHeapOverflow();
} else if (crash_type == kHeapUnderflow) {
LOG(ERROR)
<< "Intentionally causing ASAN heap underflow"
<< " because user navigated to " << url.spec();
base::debug::AsanHeapUnderflow();
} else if (crash_type == kUseAfterFree) {
LOG(ERROR)
<< "Intentionally causing ASAN heap use-after-free"
<< " because user navigated to " << url.spec();
base::debug::AsanHeapUseAfterFree();
#if defined(SYZYASAN)
} else if (crash_type == kCorruptHeapBlock) {
LOG(ERROR)
<< "Intentionally causing ASAN corrupt heap block"
<< " because user navigated to " << url.spec();
base::debug::AsanCorruptHeapBlock();
} else if (crash_type == kCorruptHeap) {
LOG(ERROR)
<< "Intentionally causing ASAN corrupt heap"
<< " because user navigated to " << url.spec();
base::debug::AsanCorruptHeap();
#endif
}
}
#endif // ADDRESS_SANITIZER || SYZYASAN
void MaybeHandleDebugURL(const GURL& url) {
if (!url.SchemeIs(kChromeUIScheme))
return;
if (url == GURL(kChromeUIBadCastCrashURL)) {
LOG(ERROR)
<< "Intentionally crashing (with bad cast)"
<< " because user navigated to " << url.spec();
BadCastCrashIntentionally();
} else if (url == GURL(kChromeUICrashURL)) {
LOG(ERROR) << "Intentionally crashing (with null pointer dereference)"
<< " because user navigated to " << url.spec();
CrashIntentionally();
} else if (url == GURL(kChromeUIDumpURL)) {
// This URL will only correctly create a crash dump file if content is
// hosted in a process that has correctly called
// base::debug::SetDumpWithoutCrashingFunction. Refer to the documentation
// of base::debug::DumpWithoutCrashing for more details.
base::debug::DumpWithoutCrashing();
} else if (url == GURL(kChromeUIKillURL)) {
LOG(ERROR) << "Intentionally issuing kill signal to current process"
<< " because user navigated to " << url.spec();
base::Process::Current().Terminate(1, false);
} else if (url == GURL(kChromeUIHangURL)) {
LOG(ERROR) << "Intentionally hanging ourselves with sleep infinite loop"
<< " because user navigated to " << url.spec();
for (;;) {
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
}
} else if (url == GURL(kChromeUIShorthangURL)) {
LOG(ERROR) << "Intentionally sleeping renderer for 20 seconds"
<< " because user navigated to " << url.spec();
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
}
#if defined(ADDRESS_SANITIZER) || defined(SYZYASAN)
MaybeTriggerAsanError(url);
#endif // ADDRESS_SANITIZER || SYZYASAN
}
// Returns false unless this is a top-level navigation.
bool IsTopLevelNavigation(WebFrame* frame) {
return frame->parent() == NULL;
}
WebURLRequest CreateURLRequestForNavigation(
const CommonNavigationParams& common_params,
std::unique_ptr<StreamOverrideParameters> stream_override,
bool is_view_source_mode_enabled) {
WebURLRequest request(common_params.url);
if (is_view_source_mode_enabled)
request.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
if (common_params.referrer.url.is_valid()) {
WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
common_params.referrer.policy,
common_params.url,
WebString::fromUTF8(common_params.referrer.url.spec()));
if (!web_referrer.isEmpty())
request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
}
request.setHTTPMethod(WebString::fromUTF8(common_params.method));
RequestExtraData* extra_data = new RequestExtraData();
extra_data->set_stream_override(std::move(stream_override));
extra_data->set_lofi_state(common_params.lofi_state);
request.setExtraData(extra_data);
// Set the ui timestamp for this navigation. Currently the timestamp here is
// only non empty when the navigation was triggered by an Android intent. The
// timestamp is converted to a double version supported by blink. It will be
// passed back to the browser in the DidCommitProvisionalLoad and the
// DocumentLoadComplete IPCs.
base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks();
request.setUiStartTime(ui_timestamp.InSecondsF());
request.setInputPerfMetricReportPolicy(
static_cast<WebURLRequest::InputToLoadPerfMetricReportPolicy>(
common_params.report_type));
return request;
}
// Sanitizes the navigation_start timestamp for browser-initiated navigations,
// where the browser possibly has a better notion of start time than the
// renderer. In the case of cross-process navigations, this carries over the
// time of finishing the onbeforeunload handler of the previous page.
// TimeTicks is sometimes not monotonic across processes, and because
// |browser_navigation_start| is likely before this process existed,
// InterProcessTimeTicksConverter won't help. The timestamp is sanitized by
// clamping it to renderer_navigation_start, initialized earlier in the call
// stack.
base::TimeTicks SanitizeNavigationTiming(
blink::WebFrameLoadType load_type,
const base::TimeTicks& browser_navigation_start,
const base::TimeTicks& renderer_navigation_start) {
if (load_type != blink::WebFrameLoadType::Standard)
return base::TimeTicks();
DCHECK(!browser_navigation_start.is_null());
base::TimeTicks navigation_start =
std::min(browser_navigation_start, renderer_navigation_start);
base::TimeDelta difference =
renderer_navigation_start - browser_navigation_start;
if (difference > base::TimeDelta()) {
UMA_HISTOGRAM_TIMES("Navigation.Start.RendererBrowserDifference.Positive",
difference);
} else {
UMA_HISTOGRAM_TIMES("Navigation.Start.RendererBrowserDifference.Negative",
-difference);
}
return navigation_start;
}
// PlzNavigate
CommonNavigationParams MakeCommonNavigationParams(
blink::WebURLRequest* request,
bool should_replace_current_entry) {
Referrer referrer(
GURL(request->httpHeaderField(WebString::fromUTF8("Referer")).latin1()),
request->referrerPolicy());
// Set the ui timestamp for this navigation. Currently the timestamp here is
// only non empty when the navigation was triggered by an Android intent, or
// by the user clicking on a link. The timestamp is converted from a double
// version supported by blink. It will be passed back to the renderer in the
// CommitNavigation IPC, and then back to the browser again in the
// DidCommitProvisionalLoad and the DocumentLoadComplete IPCs.
base::TimeTicks ui_timestamp =
base::TimeTicks() + base::TimeDelta::FromSecondsD(request->uiStartTime());
FrameMsg_UILoadMetricsReportType::Value report_type =
static_cast<FrameMsg_UILoadMetricsReportType::Value>(
request->inputPerfMetricReportPolicy());
const RequestExtraData* extra_data =
static_cast<RequestExtraData*>(request->getExtraData());
DCHECK(extra_data);
return CommonNavigationParams(
request->url(), referrer, extra_data->transition_type(),
FrameMsg_Navigate_Type::NORMAL, true, should_replace_current_entry,
ui_timestamp, report_type, GURL(), GURL(), extra_data->lofi_state(),
base::TimeTicks::Now(), request->httpMethod().latin1(),
GetRequestBodyForWebURLRequest(*request));
}
media::Context3D GetSharedMainThreadContext3D(
scoped_refptr<ContextProviderCommandBuffer> provider) {
if (!provider)
return media::Context3D();
return media::Context3D(provider->ContextGL(), provider->GrContext());
}
bool IsReload(FrameMsg_Navigate_Type::Value navigation_type) {
switch (navigation_type) {
case FrameMsg_Navigate_Type::RELOAD:
case FrameMsg_Navigate_Type::RELOAD_MAIN_RESOURCE:
case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
return true;
case FrameMsg_Navigate_Type::RESTORE:
case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
case FrameMsg_Navigate_Type::NORMAL:
return false;
}
NOTREACHED();
return false;
}
WebFrameLoadType ReloadFrameLoadTypeFor(
FrameMsg_Navigate_Type::Value navigation_type) {
switch (navigation_type) {
case FrameMsg_Navigate_Type::RELOAD:
case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
return WebFrameLoadType::Reload;
case FrameMsg_Navigate_Type::RELOAD_MAIN_RESOURCE:
return WebFrameLoadType::ReloadMainResource;
case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE:
return WebFrameLoadType::ReloadBypassingCache;
case FrameMsg_Navigate_Type::RESTORE:
case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
case FrameMsg_Navigate_Type::NORMAL:
NOTREACHED();
return WebFrameLoadType::Standard;
}
NOTREACHED();
return WebFrameLoadType::Standard;
}
RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
nullptr;
void OnGotInstanceID(shell::mojom::ConnectResult result,
const std::string& user_id,
uint32_t instance_id) {}
WebString ConvertRelativePathToHtmlAttribute(const base::FilePath& path) {
DCHECK(!path.IsAbsolute());
return WebString::fromUTF8(
std::string("./") +
path.NormalizePathSeparatorsTo(FILE_PATH_LITERAL('/')).AsUTF8Unsafe());
}
// Implementation of WebFrameSerializer::LinkRewritingDelegate that responds
// based on the payload of FrameMsg_GetSerializedHtmlWithLocalLinks.
class LinkRewritingDelegate : public WebFrameSerializer::LinkRewritingDelegate {
public:
LinkRewritingDelegate(
const std::map<GURL, base::FilePath>& url_to_local_path,
const std::map<int, base::FilePath>& frame_routing_id_to_local_path)
: url_to_local_path_(url_to_local_path),
frame_routing_id_to_local_path_(frame_routing_id_to_local_path) {}
bool rewriteFrameSource(WebFrame* frame, WebString* rewritten_link) override {
int routing_id = GetRoutingIdForFrameOrProxy(frame);
auto it = frame_routing_id_to_local_path_.find(routing_id);
if (it == frame_routing_id_to_local_path_.end())
return false; // This can happen because of https://crbug.com/541354.
const base::FilePath& local_path = it->second;
*rewritten_link = ConvertRelativePathToHtmlAttribute(local_path);
return true;
}
bool rewriteLink(const WebURL& url, WebString* rewritten_link) override {
auto it = url_to_local_path_.find(url);
if (it == url_to_local_path_.end())
return false;
const base::FilePath& local_path = it->second;
*rewritten_link = ConvertRelativePathToHtmlAttribute(local_path);
return true;
}
private:
const std::map<GURL, base::FilePath>& url_to_local_path_;
const std::map<int, base::FilePath>& frame_routing_id_to_local_path_;
};
// Implementation of WebFrameSerializer::MHTMLPartsGenerationDelegate that
// 1. Bases shouldSkipResource and getContentID responses on contents of
// FrameMsg_SerializeAsMHTML_Params.
// 2. Stores digests of urls of serialized resources (i.e. urls reported via
// shouldSkipResource) into |digests_of_uris_of_serialized_resources| passed
// to the constructor.
class MHTMLPartsGenerationDelegate
: public WebFrameSerializer::MHTMLPartsGenerationDelegate {
public:
MHTMLPartsGenerationDelegate(
const FrameMsg_SerializeAsMHTML_Params& params,
std::set<std::string>* digests_of_uris_of_serialized_resources)
: params_(params),
digests_of_uris_of_serialized_resources_(
digests_of_uris_of_serialized_resources) {
DCHECK(digests_of_uris_of_serialized_resources_);
}
bool shouldSkipResource(const WebURL& url) override {
std::string digest =
crypto::SHA256HashString(params_.salt + GURL(url).spec());
// Skip if the |url| already covered by serialization of an *earlier* frame.
if (ContainsKey(params_.digests_of_uris_to_skip, digest))
return true;
// Let's record |url| as being serialized for the *current* frame.
auto pair = digests_of_uris_of_serialized_resources_->insert(digest);
bool insertion_took_place = pair.second;
DCHECK(insertion_took_place); // Blink should dedupe within a frame.
return false;
}
WebString getContentID(WebFrame* frame) override {
int routing_id = GetRoutingIdForFrameOrProxy(frame);
auto it = params_.frame_routing_id_to_content_id.find(routing_id);
if (it == params_.frame_routing_id_to_content_id.end())
return WebString();
const std::string& content_id = it->second;
return WebString::fromUTF8(content_id);
}
blink::WebFrameSerializerCacheControlPolicy cacheControlPolicy() override {
return params_.mhtml_cache_control_policy;
}
bool useBinaryEncoding() override { return params_.mhtml_binary_encoding; }
private:
const FrameMsg_SerializeAsMHTML_Params& params_;
std::set<std::string>* digests_of_uris_of_serialized_resources_;
DISALLOW_COPY_AND_ASSIGN(MHTMLPartsGenerationDelegate);
};
// Returns true if a subresource certificate error (described by |url|
// and |security_info|) is "interesting" to the browser process. The
// browser process is interested in certificate errors that differ from
// certificate errors encountered while loading the main frame's main
// resource. In other words, it would be confusing to mark a page as
// having displayed/run insecure content when the whole page has already
// been marked as insecure for the same reason, so subresources with the
// same certificate errors as the main resource are not sent to the
// browser process.
bool IsContentWithCertificateErrorsRelevantToUI(
blink::WebFrame* frame,
const blink::WebURL& url,
const blink::WebCString& security_info) {
blink::WebFrame* main_frame = frame->top();
// If the main frame is remote, then it must be cross-site and
// therefore this subresource's certificate errors are potentially
// interesting to the browser (not redundant with the main frame's
// main resource).
if (main_frame->isWebRemoteFrame())
return true;
WebDataSource* main_ds = main_frame->toWebLocalFrame()->dataSource();
content::SSLStatus ssl_status;
content::SSLStatus main_resource_ssl_status;
CHECK(DeserializeSecurityInfo(security_info, &ssl_status));
CHECK(DeserializeSecurityInfo(main_ds->response().securityInfo(),
&main_resource_ssl_status));
// Do not send subresource certificate errors if they are the same
// as errors that occured during the main page load. This compares
// most, but not all, fields of SSLStatus. For example, this check
// does not compare |content_status| because the navigation entry
// might have mixed content but also have the exact same SSL
// connection properties as the subresource, thereby making the
// subresource errors duplicative.
return (!url::Origin(GURL(url)).IsSameOriginWith(
url::Origin(GURL(main_ds->request().url()))) ||
main_resource_ssl_status.security_style !=
ssl_status.security_style ||
main_resource_ssl_status.cert_id != ssl_status.cert_id ||
main_resource_ssl_status.cert_status != ssl_status.cert_status ||
main_resource_ssl_status.security_bits != ssl_status.security_bits ||
main_resource_ssl_status.connection_status !=
ssl_status.connection_status);
}
#if defined(OS_ANDROID)
// Returns true if WMPI should be used for playback, false otherwise.
//
// Note that HLS and MP4 detection are pre-redirect and path-based. It is
// possible to load such a URL and find different content.
bool UseWebMediaPlayerImpl(const GURL& url) {
// WMPI does not support HLS.
if (media::MediaCodecUtil::IsHLSURL(url))
return false;
// Don't use WMPI if the container likely contains a codec we can't decode in
// software and platform decoders are not available.
if (base::EndsWith(url.path(), ".mp4",
base::CompareCase::INSENSITIVE_ASCII) &&
!media::HasPlatformDecoderSupport()) {
return false;
}
// Indicates if the Android MediaPlayer should be used instead of WMPI.
if (GetContentClient()->renderer()->ShouldUseMediaPlayerForURL(url))
return false;
// Otherwise enable WMPI if indicated via experiment or command line.
return media::IsUnifiedMediaPipelineEnabled();
}
#endif // defined(OS_ANDROID)
#if defined(ENABLE_MOJO_CDM)
// Returns whether mojo CDM should be used at runtime. Note that even when mojo
// CDM is enabled at compile time (ENABLE_MOJO_CDM is defined), there are cases
// where we want to choose other CDM types. For example, on Android when we use
// WebMediaPlayerAndroid, we still want to use ProxyMediaKeys. In the future,
// when we experiment mojo CDM on desktop, we will choose between mojo CDM and
// pepper CDM at runtime.
// TODO(xhwang): Remove this when we use mojo CDM for all remote CDM cases by
// default.
bool UseMojoCdm() {
#if defined(OS_ANDROID)
return media::IsUnifiedMediaPipelineEnabled();
#else
return true;
#endif
}
#endif // defined(ENABLE_MOJO_CDM)
} // namespace
struct RenderFrameImpl::PendingFileChooser {
PendingFileChooser(const FileChooserParams& p,
blink::WebFileChooserCompletion* c)
: params(p), completion(c) {}
FileChooserParams params;
blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
};
// static
RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view,
int32_t routing_id) {
DCHECK(routing_id != MSG_ROUTING_NONE);
CreateParams params(render_view, routing_id);
if (g_create_render_frame_impl)
return g_create_render_frame_impl(params);
else
return new RenderFrameImpl(params);
}
// static
RenderFrame* RenderFrame::FromRoutingID(int routing_id) {
return RenderFrameImpl::FromRoutingID(routing_id);
}
// static
RenderFrameImpl* RenderFrameImpl::FromRoutingID(int routing_id) {
RoutingIDFrameMap::iterator iter =
g_routing_id_frame_map.Get().find(routing_id);
if (iter != g_routing_id_frame_map.Get().end())
return iter->second;
return NULL;
}
// static
RenderFrameImpl* RenderFrameImpl::CreateMainFrame(
RenderViewImpl* render_view,
int32_t routing_id,
int32_t widget_routing_id,
bool hidden,
const blink::WebScreenInfo& screen_info,
CompositorDependencies* compositor_deps,
blink::WebFrame* opener) {
// A main frame RenderFrame must have a RenderWidget.
DCHECK_NE(MSG_ROUTING_NONE, widget_routing_id);
RenderFrameImpl* render_frame =
RenderFrameImpl::Create(render_view, routing_id);
render_frame->InitializeBlameContext(nullptr);
WebLocalFrame* web_frame = WebLocalFrame::create(
blink::WebTreeScopeType::Document, render_frame, opener);
render_frame->BindToWebFrame(web_frame);
render_view->webview()->setMainFrame(web_frame);
render_frame->render_widget_ = RenderWidget::CreateForFrame(
widget_routing_id, hidden, screen_info, compositor_deps, web_frame);
// TODO(kenrb): Observing shouldn't be necessary when we sort out
// WasShown and WasHidden, separating page-level visibility from
// frame-level visibility.
// TODO(avi): This DCHECK is to track cleanup for https://crbug.com/545684
DCHECK_EQ(render_view->GetWidget(), render_frame->render_widget_)
<< "Main frame is no longer reusing the RenderView as its widget! "
<< "Does the RenderFrame need to register itself with the RenderWidget?";
return render_frame;
}
// static
void RenderFrameImpl::CreateFrame(
int routing_id,
int proxy_routing_id,
int opener_routing_id,
int parent_routing_id,
int previous_sibling_routing_id,
const FrameReplicationState& replicated_state,
CompositorDependencies* compositor_deps,
const FrameMsg_NewFrame_WidgetParams& widget_params,
const blink::WebFrameOwnerProperties& frame_owner_properties) {
blink::WebLocalFrame* web_frame;
RenderFrameImpl* render_frame;
if (proxy_routing_id == MSG_ROUTING_NONE) {
RenderFrameProxy* parent_proxy =
RenderFrameProxy::FromRoutingID(parent_routing_id);
// If the browser is sending a valid parent routing id, it should already
// be created and registered.
CHECK(parent_proxy);
blink::WebRemoteFrame* parent_web_frame = parent_proxy->web_frame();
blink::WebFrame* previous_sibling_web_frame = nullptr;
RenderFrameProxy* previous_sibling_proxy =
RenderFrameProxy::FromRoutingID(previous_sibling_routing_id);
if (previous_sibling_proxy)
previous_sibling_web_frame = previous_sibling_proxy->web_frame();
// Create the RenderFrame and WebLocalFrame, linking the two.
render_frame =
RenderFrameImpl::Create(parent_proxy->render_view(), routing_id);
render_frame->InitializeBlameContext(FromRoutingID(parent_routing_id));
web_frame = parent_web_frame->createLocalChild(
replicated_state.scope, WebString::fromUTF8(replicated_state.name),
WebString::fromUTF8(replicated_state.unique_name),
replicated_state.sandbox_flags, render_frame,
previous_sibling_web_frame, frame_owner_properties,
ResolveOpener(opener_routing_id, nullptr));
// The RenderFrame is created and inserted into the frame tree in the above
// call to createLocalChild.
render_frame->in_frame_tree_ = true;
} else {
RenderFrameProxy* proxy =
RenderFrameProxy::FromRoutingID(proxy_routing_id);
// The remote frame could've been detached while the remote-to-local
// navigation was being initiated in the browser process. Drop the
// navigation and don't create the frame in that case. See
// https://crbug.com/526304.
if (!proxy)
return;
render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id);
render_frame->InitializeBlameContext(nullptr);
render_frame->proxy_routing_id_ = proxy_routing_id;
web_frame = blink::WebLocalFrame::createProvisional(
render_frame, proxy->web_frame(), replicated_state.sandbox_flags);
}
render_frame->BindToWebFrame(web_frame);
CHECK(parent_routing_id != MSG_ROUTING_NONE || !web_frame->parent());
if (widget_params.routing_id != MSG_ROUTING_NONE) {
CHECK(!web_frame->parent() ||
SiteIsolationPolicy::AreCrossProcessFramesPossible());
render_frame->render_widget_ = RenderWidget::CreateForFrame(
widget_params.routing_id, widget_params.hidden,
render_frame->render_view_->screen_info(), compositor_deps, web_frame);
// TODO(avi): The main frame re-uses the RenderViewImpl as its widget, so
// avoid double-registering the frame as an observer.
// https://crbug.com/545684
if (web_frame->parent()) {
// TODO(kenrb): Observing shouldn't be necessary when we sort out
// WasShown and WasHidden, separating page-level visibility from
// frame-level visibility.
render_frame->render_widget_->RegisterRenderFrame(render_frame);
}
}
render_frame->Initialize();