forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrender_frame_impl.h
1492 lines (1311 loc) · 66.7 KB
/
render_frame_impl.h
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.
#ifndef CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
#define CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/containers/id_map.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/optional.h"
#include "base/process/process_handle.h"
#include "base/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "base/values.h"
#include "build/build_config.h"
#include "cc/input/browser_controls_state.h"
#include "content/common/buildflags.h"
#include "content/common/download/mhtml_file_writer.mojom.h"
#include "content/common/frame.mojom.h"
#include "content/common/frame_replication_state.mojom-forward.h"
#include "content/common/navigation_params.mojom.h"
#include "content/common/render_accessibility.mojom.h"
#include "content/common/renderer.mojom.h"
#include "content/common/web_ui.mojom.h"
#include "content/public/common/referrer.h"
#include "content/public/common/stop_find_action.h"
#include "content/public/common/widget_type.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_media_playback_options.h"
#include "content/public/renderer/websocket_handshake_throttle_provider.h"
#include "content/renderer/content_security_policy_util.h"
#include "content/renderer/frame_blame_context.h"
#include "content/renderer/media/media_factory.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_platform_file.h"
#include "media/base/routing_token_callback.h"
#include "media/base/speech_recognition_client.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom-forward.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/mojom/interface_provider.mojom.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/common/feature_policy/document_policy.h"
#include "third_party/blink/public/common/feature_policy/feature_policy.h"
#include "third_party/blink/public/common/loader/loading_behavior_flag.h"
#include "third_party/blink/public/common/loader/previews_state.h"
#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/common/unique_name/unique_name_helper.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom.h"
#include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
#include "third_party/blink/public/mojom/commit_result/commit_result.mojom.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
#include "third_party/blink/public/mojom/frame/frame.mojom.h"
#include "third_party/blink/public/mojom/frame/frame_owner_element_type.mojom.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/policy_container.mojom-shared.h"
#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-forward.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
#include "third_party/blink/public/mojom/loader/resource_load_info_notifier.mojom.h"
#include "third_party/blink/public/mojom/media/renderer_audio_input_stream_factory.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "third_party/blink/public/mojom/use_counter/css_property_id.mojom.h"
#include "third_party/blink/public/platform/child_url_loader_factory_bundle.h"
#include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/web/web_ax_object.h"
#include "third_party/blink/public/web/web_document_loader.h"
#include "third_party/blink/public/web/web_frame_load_type.h"
#include "third_party/blink/public/web/web_frame_serializer_client.h"
#include "third_party/blink/public/web/web_history_commit_type.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_meaningful_layout.h"
#include "third_party/blink/public/web/web_script_execution_callback.h"
#include "ui/accessibility/ax_event.h"
#include "ui/accessibility/ax_mode.h"
#include "ui/gfx/range/range.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(ENABLE_PLUGINS)
#include "content/common/pepper_plugin.mojom.h"
#endif
namespace blink {
namespace scheduler {
class WebAgentGroupScheduler;
} // namespace scheduler
class WeakWrapperResourceLoadInfoNotifier;
class WebComputedAXTree;
class WebContentDecryptionModule;
class WebElement;
class WebFrameRequestBlocker;
class WebLocalFrame;
class WebMediaStreamDeviceObserver;
class WebSecurityOrigin;
class WebString;
class WebURL;
struct FramePolicy;
} // namespace blink
namespace gfx {
class Point;
class Range;
} // namespace gfx
namespace media {
class MediaPermission;
}
namespace url {
class Origin;
}
namespace content {
class AgentSchedulingGroup;
class BlinkInterfaceRegistryImpl;
class CompositorDependencies;
class DocumentState;
class MediaPermissionDispatcher;
class NavigationClient;
class PepperPluginInstanceImpl;
class RendererPpapiHost;
class RenderAccessibilityManager;
class RenderFrameObserver;
class RenderViewImpl;
class CONTENT_EXPORT RenderFrameImpl
: public RenderFrame,
public blink::mojom::ResourceLoadInfoNotifier,
blink::mojom::AutoplayConfigurationClient,
public mojom::Frame,
mojom::FrameBindingsControl,
mojom::MhtmlFileWriter,
public blink::WebLocalFrameClient,
service_manager::mojom::InterfaceProvider {
public:
// Creates a new RenderFrame as the main frame of |render_view|.
static RenderFrameImpl* CreateMainFrame(
AgentSchedulingGroup& agent_scheduling_group,
RenderViewImpl* render_view,
CompositorDependencies* compositor_deps,
blink::WebFrame* opener,
bool is_for_nested_main_frame,
mojom::FrameReplicationStatePtr replication_state,
const base::UnguessableToken& devtools_frame_token,
mojom::CreateLocalMainFrameParamsPtr params);
// Creates a new RenderFrame with |routing_id|. If |previous_routing_id| is
// MSG_ROUTING_NONE, it creates the Blink WebLocalFrame and inserts it into
// the frame tree after the frame identified by |previous_sibling_routing_id|,
// or as the first child if |previous_sibling_routing_id| is MSG_ROUTING_NONE.
// Otherwise, the frame is semi-orphaned until it commits, at which point it
// replaces the previous object identified by |previous_routing_id|. The
// previous object can either be a RenderFrame or a RenderFrameProxy.
// The frame's opener is set to the frame identified by |opener_routing_id|.
// The frame is created as a child of the RenderFrame identified by
// |parent_routing_id| or as the top-level frame if
// the latter is MSG_ROUTING_NONE.
// |devtools_frame_token| is passed from the browser and corresponds to the
// owner FrameTreeNode. It can only be used for tagging requests and calls
// for context frame attribution. It should never be passed back to the
// browser as a frame identifier in the control flows calls.
// The |widget_params| is not null if the frame is to be a local root, which
// means it will own a RenderWidget, in which case the |widget_params| hold
// the routing id and initialization properties for the RenderWidget.
//
// Note: This is called only when RenderFrame is being created in response
// to IPC message from the browser process. All other frame creation is driven
// through Blink and Create.
static void CreateFrame(
AgentSchedulingGroup& agent_scheduling_group,
const blink::LocalFrameToken& token,
int routing_id,
mojo::PendingAssociatedReceiver<mojom::Frame> frame_receiver,
mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker,
int previous_routing_id,
const base::Optional<blink::FrameToken>& opener_frame_token,
int parent_routing_id,
int previous_sibling_routing_id,
const base::UnguessableToken& devtools_frame_token,
mojom::FrameReplicationStatePtr replicated_state,
CompositorDependencies* compositor_deps,
mojom::CreateFrameWidgetParamsPtr widget_params,
blink::mojom::FrameOwnerPropertiesPtr frame_owner_properties,
bool has_committed_real_load,
blink::mojom::PolicyContainerPtr policy_container);
// Returns the RenderFrameImpl for the given routing ID.
static RenderFrameImpl* FromRoutingID(int routing_id);
// Just like RenderFrame::FromWebFrame but returns the implementation.
static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
// Constructor parameters are bundled into a struct.
struct CONTENT_EXPORT CreateParams {
CreateParams(AgentSchedulingGroup& agent_scheduling_group,
RenderViewImpl* render_view,
int32_t routing_id,
mojo::PendingAssociatedReceiver<mojom::Frame> frame_receiver,
mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker,
const base::UnguessableToken& devtools_frame_token);
~CreateParams();
CreateParams(CreateParams&&);
CreateParams& operator=(CreateParams&&);
AgentSchedulingGroup* agent_scheduling_group;
RenderViewImpl* render_view;
int32_t routing_id;
mojo::PendingAssociatedReceiver<mojom::Frame> frame_receiver;
mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker;
base::UnguessableToken devtools_frame_token;
};
using CreateRenderFrameImplFunction = RenderFrameImpl* (*)(CreateParams);
// Web tests override the creation of RenderFrames in order to inject a
// partial testing fake.
static void InstallCreateHook(CreateRenderFrameImplFunction create_frame);
// Looks up and returns the WebFrame corresponding to a given frame routing
// ID.
static blink::WebFrame* ResolveWebFrame(int opener_frame_routing_id);
// Possibly set the kOpenerCrossOrigin and kSandboxNoGesture policy in
// |download_policy|.
static void MaybeSetDownloadFramePolicy(
bool is_opener_navigation,
const blink::WebURLRequest& request,
const blink::WebSecurityOrigin& current_origin,
bool has_download_sandbox_flag,
bool blocking_downloads_in_sandbox_enabled,
bool from_ad,
blink::NavigationDownloadPolicy* download_policy);
// Overwrites the given URL to use an HTML5 embed if possible.
blink::WebURL OverrideFlashEmbedWithHTML(const blink::WebURL& url) override;
~RenderFrameImpl() override;
// Returns the unique name of the RenderFrame.
const std::string& unique_name() const { return unique_name_helper_.value(); }
// TODO(jam): this is a temporary getter until all the code is transitioned
// to using RenderFrame instead of RenderView.
RenderViewImpl* render_view() { return render_view_; }
// Returns the blink::WebFrameWidget attached to the local root of this
// frame.
blink::WebFrameWidget* GetLocalRootWebFrameWidget();
// This method must be called after the WebLocalFrame backing this RenderFrame
// has been created and added to the frame tree. It creates all objects that
// depend on the frame being at its proper spot.
//
// Virtual for web tests to inject their own behaviour into the WebLocalFrame.
virtual void Initialize(blink::WebFrame* parent);
// Start/Stop loading notifications.
// TODO(nasko): Those are page-level methods at this time and come from
// WebViewClient. We should move them to be WebLocalFrameClient calls and put
// logic in the browser side to balance starts/stops.
void DidStartLoading() override;
void DidStopLoading() override;
// Returns the object implementing the RenderAccessibility mojo interface and
// serves as a bridge between RenderFrameImpl and RenderAccessibilityImpl.
RenderAccessibilityManager* GetRenderAccessibilityManager() {
return render_accessibility_manager_.get();
}
// Called from RenderAccessibilityManager to let the RenderFrame know when the
// accessibility mode has changed, so that it can notify its observers.
void NotifyAccessibilityModeChange(ui::AXMode new_mode);
// Whether or not the frame is currently swapped into the frame tree. If
// this is false, this is a provisional frame which has not committed yet,
// and which will swap with a proxy when it commits.
//
// TODO(https://crbug.com/578349): Remove this once provisional frames are
// gone, and clean up code that depends on it.
bool in_frame_tree() { return in_frame_tree_; }
#if BUILDFLAG(ENABLE_PLUGINS)
mojom::PepperHost* GetPepperHost();
// Notification that a PPAPI plugin has been created.
void PepperPluginCreated(RendererPpapiHost* host);
// Informs the render view that a PPAPI plugin has changed text input status.
void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
// Cancels current composition.
void PepperCancelComposition(PepperPluginInstanceImpl* instance);
// Informs the render view that a PPAPI plugin has changed selection.
void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
#endif // BUILDFLAG(ENABLE_PLUGINS)
void ScriptedPrint(bool user_initiated);
// IPC::Sender
bool Send(IPC::Message* msg) override;
// IPC::Listener
bool OnMessageReceived(const IPC::Message& msg) override;
void OnAssociatedInterfaceRequest(
const std::string& interface_name,
mojo::ScopedInterfaceEndpointHandle handle) override;
// RenderFrame implementation:
RenderView* GetRenderView() override;
RenderAccessibility* GetRenderAccessibility() override;
std::unique_ptr<AXTreeSnapshotter> CreateAXTreeSnapshotter() override;
int GetRoutingID() override;
blink::WebLocalFrame* GetWebFrame() override;
const blink::web_pref::WebPreferences& GetBlinkPreferences() override;
void ShowVirtualKeyboard() override;
blink::WebPlugin* CreatePlugin(const WebPluginInfo& info,
const blink::WebPluginParams& params) override;
void ExecuteJavaScript(const base::string16& javascript) override;
bool IsMainFrame() override;
bool IsHidden() override;
void BindLocalInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
blink::AssociatedInterfaceRegistry* GetAssociatedInterfaceRegistry() override;
blink::AssociatedInterfaceProvider* GetRemoteAssociatedInterfaces() override;
#if BUILDFLAG(ENABLE_PLUGINS)
void PluginDidStartLoading() override;
void PluginDidStopLoading() override;
#endif
bool IsFTPDirectoryListing() override;
void SetSelectedText(const base::string16& selection_text,
size_t offset,
const gfx::Range& range) override;
void AddMessageToConsole(blink::mojom::ConsoleMessageLevel level,
const std::string& message) override;
blink::PreviewsState GetPreviewsState() override;
bool IsPasting() override;
bool IsBrowserSideNavigationPending() override;
void LoadHTMLStringForTesting(const std::string& html,
const GURL& base_url,
const std::string& text_encoding,
const GURL& unreachable_url,
bool replace_current_item) override;
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
blink::TaskType task_type) override;
int GetEnabledBindings() override;
void SetAccessibilityModeForTest(ui::AXMode new_mode) override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
const RenderFrameMediaPlaybackOptions& GetRenderFrameMediaPlaybackOptions()
override;
void SetRenderFrameMediaPlaybackOptions(
const RenderFrameMediaPlaybackOptions& opts) override;
void SetAllowsCrossBrowsingInstanceFrameLookup() override;
gfx::RectF ElementBoundsInWindow(const blink::WebElement& element) override;
void ConvertViewportToWindow(gfx::Rect* rect) override;
float GetDeviceScaleFactor() override;
// blink::mojom::AutoplayConfigurationClient implementation:
void AddAutoplayFlags(const url::Origin& origin,
const int32_t flags) override;
// blink::mojom::ResourceLoadInfoNotifier implementation:
#if defined(OS_ANDROID)
void NotifyUpdateUserGestureCarryoverInfo() override;
#endif
void NotifyResourceRedirectReceived(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr redirect_response) override;
void NotifyResourceResponseReceived(
int64_t request_id,
const GURL& response_url,
network::mojom::URLResponseHeadPtr head,
network::mojom::RequestDestination request_destination,
int32_t previews_state) override;
void NotifyResourceTransferSizeUpdated(int64_t request_id,
int32_t transfer_size_diff) override;
void NotifyResourceLoadCompleted(
blink::mojom::ResourceLoadInfoPtr resource_load_info,
const ::network::URLLoaderCompletionStatus& status) override;
void NotifyResourceLoadCanceled(int64_t request_id) override;
void Clone(mojo::PendingReceiver<blink::mojom::ResourceLoadInfoNotifier>
pending_resource_load_info_notifier) override;
#if defined(OS_ANDROID)
void ExtractSmartClipData(
const gfx::Rect& rect,
const ExtractSmartClipDataCallback callback) override;
#endif
// mojom::FrameBindingsControl implementation:
void AllowBindings(int32_t enabled_bindings_flags) override;
void EnableMojoJsBindings() override;
void BindWebUI(
mojo::PendingAssociatedReceiver<mojom::WebUI> Receiver,
mojo::PendingAssociatedRemote<mojom::WebUIHost> remote) override;
// These mirror mojom::NavigationClient, called by NavigationClient.
void CommitNavigation(
mojom::CommonNavigationParamsPtr common_params,
mojom::CommitNavigationParamsPtr commit_params,
network::mojom::URLResponseHeadPtr response_head,
mojo::ScopedDataPipeConsumerHandle response_body,
network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
std::unique_ptr<blink::PendingURLLoaderFactoryBundle>
subresource_loader_factories,
base::Optional<std::vector<blink::mojom::TransferrableURLLoaderPtr>>
subresource_overrides,
blink::mojom::ControllerServiceWorkerInfoPtr
controller_service_worker_info,
blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
prefetch_loader_factory,
const base::UnguessableToken& devtools_navigation_token,
blink::mojom::PolicyContainerPtr policy_container,
mojom::NavigationClient::CommitNavigationCallback commit_callback);
void CommitFailedNavigation(
mojom::CommonNavigationParamsPtr common_params,
mojom::CommitNavigationParamsPtr commit_params,
bool has_stale_copy_in_cache,
int error_code,
net::ResolveErrorInfo resolve_error_info,
const base::Optional<std::string>& error_page_content,
std::unique_ptr<blink::PendingURLLoaderFactoryBundle>
subresource_loader_factories,
blink::mojom::PolicyContainerPtr policy_container,
mojom::NavigationClient::CommitFailedNavigationCallback
per_navigation_mojo_interface_callback);
// mojom::MhtmlFileWriter implementation:
void SerializeAsMHTML(const mojom::SerializeAsMHTMLParamsPtr params,
SerializeAsMHTMLCallback callback) override;
// blink::WebLocalFrameClient implementation:
void BindToFrame(blink::WebNavigationControl* frame) override;
blink::WebPlugin* CreatePlugin(const blink::WebPluginParams& params) override;
blink::WebMediaPlayer* CreateMediaPlayer(
const blink::WebMediaPlayerSource& source,
blink::WebMediaPlayerClient* client,
blink::MediaInspectorContext* inspector_context,
blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
blink::WebContentDecryptionModule* initial_cdm,
const blink::WebString& sink_id,
const cc::LayerTreeSettings& settings) override;
std::unique_ptr<blink::WebContentSettingsClient>
CreateWorkerContentSettingsClient() override;
#if !defined(OS_ANDROID)
std::unique_ptr<media::SpeechRecognitionClient> CreateSpeechRecognitionClient(
media::SpeechRecognitionClient::OnReadyCallback callback) override;
#endif
scoped_refptr<blink::WebWorkerFetchContext> CreateWorkerFetchContext()
override;
scoped_refptr<blink::WebWorkerFetchContext>
CreateWorkerFetchContextForPlzDedicatedWorker(
blink::WebDedicatedWorkerHostFactoryClient* factory_client) override;
std::unique_ptr<blink::WebPrescientNetworking> CreatePrescientNetworking()
override;
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
CreateResourceLoadInfoNotifierWrapper() override;
blink::BlameContext* GetFrameBlameContext() override;
std::unique_ptr<blink::WebServiceWorkerProvider> CreateServiceWorkerProvider()
override;
blink::AssociatedInterfaceProvider* GetRemoteNavigationAssociatedInterfaces()
override;
blink::WebLocalFrame* CreateChildFrame(
blink::mojom::TreeScopeType scope,
const blink::WebString& name,
const blink::WebString& fallback_name,
const blink::FramePolicy& frame_policy,
const blink::WebFrameOwnerProperties& frame_owner_properties,
blink::mojom::FrameOwnerElementType frame_owner_element_type,
blink::WebPolicyContainerBindParams policy_container_bind_params)
override;
void InitializeAsChildFrame(blink::WebLocalFrame* parent) override;
std::pair<blink::WebRemoteFrame*, blink::PortalToken> CreatePortal(
blink::CrossVariantMojoAssociatedReceiver<
blink::mojom::PortalInterfaceBase> portal_endpoint,
blink::CrossVariantMojoAssociatedRemote<
blink::mojom::PortalClientInterfaceBase> client_endpoint,
const blink::WebElement& portal_element) override;
blink::WebRemoteFrame* AdoptPortal(
const blink::PortalToken& portal_token,
const blink::WebElement& portal_element) override;
blink::WebFrame* FindFrame(const blink::WebString& name) override;
void WillDetach() override;
void FrameDetached() override;
void DidChangeName(const blink::WebString& name) override;
void DidMatchCSS(
const blink::WebVector<blink::WebString>& newly_matching_selectors,
const blink::WebVector<blink::WebString>& stopped_matching_selectors)
override;
bool ShouldReportDetailedMessageForSourceAndSeverity(
blink::mojom::ConsoleMessageLevel log_level,
const blink::WebString& source) override;
void DidAddMessageToConsole(const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
unsigned source_line,
const blink::WebString& stack_trace) override;
void BeginNavigation(std::unique_ptr<blink::WebNavigationInfo> info) override;
void WillSendSubmitEvent(const blink::WebFormElement& form) override;
void DidCreateDocumentLoader(
blink::WebDocumentLoader* document_loader) override;
bool SwapIn(blink::WebFrame* previous_web_frame) override;
void DidCommitNavigation(
blink::WebHistoryCommitType commit_type,
bool should_reset_browser_interface_broker,
network::mojom::WebSandboxFlags sandbox_flags,
const blink::ParsedFeaturePolicy& feature_policy_header,
const blink::DocumentPolicyFeatureState& document_policy_header) override;
void DidCommitDocumentReplacementNavigation(
blink::WebDocumentLoader* document_loader) override;
void DidClearWindowObject() override;
void DidCreateDocumentElement() override;
void RunScriptsAtDocumentElementAvailable() override;
void DidReceiveTitle(const blink::WebString& title) override;
void DidFinishDocumentLoad() override;
void RunScriptsAtDocumentReady() override;
void RunScriptsAtDocumentIdle() override;
void DidHandleOnloadEvents() override;
void DidFinishLoad() override;
void DidFinishSameDocumentNavigation(blink::WebHistoryCommitType commit_type,
bool content_initiated,
bool is_history_api_navigation) override;
void DidSetPageLifecycleState() override;
void DidUpdateCurrentHistoryItem() override;
base::UnguessableToken GetDevToolsFrameToken() override;
void AbortClientNavigation() override;
void DidChangeSelection(bool is_empty_selection) override;
void FocusedElementChanged(const blink::WebElement& element) override;
void OnMainFrameIntersectionChanged(const gfx::Rect& intersect_rect) override;
void WillSendRequest(blink::WebURLRequest& request,
ForRedirect for_redirect) override;
void OnOverlayPopupAdDetected() override;
void OnLargeStickyAdDetected() override;
void DidLoadResourceFromMemoryCache(
const blink::WebURLRequest& request,
const blink::WebURLResponse& response) override;
void DidChangePerformanceTiming() override;
void DidObserveInputDelay(base::TimeDelta input_delay) override;
void DidChangeCpuTiming(base::TimeDelta time) override;
void DidObserveLoadingBehavior(blink::LoadingBehaviorFlag behavior) override;
void DidObserveNewFeatureUsage(blink::mojom::WebFeature feature) override;
void DidObserveNewCssPropertyUsage(blink::mojom::CSSSampleId css_property,
bool is_animated) override;
void DidObserveLayoutShift(double score, bool after_input_or_scroll) override;
void DidObserveLayoutNg(uint32_t all_block_count,
uint32_t ng_block_count,
uint32_t all_call_count,
uint32_t ng_call_count) override;
void DidObserveLazyLoadBehavior(
blink::WebLocalFrameClient::LazyLoadBehavior lazy_load_behavior) override;
void DidCreateScriptContext(v8::Local<v8::Context> context,
int world_id) override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
int world_id) override;
void DidChangeScrollOffset() override;
blink::WebMediaStreamDeviceObserver* MediaStreamDeviceObserver() override;
bool AllowRTCLegacyTLSProtocols() override;
blink::WebEncryptedMediaClient* EncryptedMediaClient() override;
blink::WebString UserAgentOverride() override;
base::Optional<blink::UserAgentMetadata> UserAgentMetadataOverride() override;
blink::WebString DoNotTrackValue() override;
blink::mojom::RendererAudioInputStreamFactory* GetAudioInputStreamFactory();
bool AllowContentInitiatedDataUrlNavigations(
const blink::WebURL& url) override;
void PostAccessibilityEvent(const ui::AXEvent& event) override;
void MarkWebAXObjectDirty(const blink::WebAXObject& obj,
bool subtree) override;
void CheckIfAudioSinkExistsAndIsAuthorized(
const blink::WebString& sink_id,
blink::WebSetSinkIdCompleteCallback callback) override;
std::unique_ptr<blink::WebURLLoaderFactory> CreateURLLoaderFactory() override;
void OnStopLoading() override;
void DraggableRegionsChanged() override;
blink::BrowserInterfaceBrokerProxy* GetBrowserInterfaceBroker() override;
// Dispatches the current state of selection on the webpage to the browser if
// it has changed.
// TODO(varunjain): delete this method once we figure out how to keep
// selection handles in sync with the webpage.
void SyncSelectionIfRequired() override;
void CreateAudioInputStream(
blink::CrossVariantMojoRemote<
blink::mojom::RendererAudioInputStreamFactoryClientInterfaceBase>
client,
const base::UnguessableToken& session_id,
const media::AudioParameters& params,
bool automatic_gain_control,
uint32_t shared_memory_count) override;
void AssociateInputAndOutputForAec(
const base::UnguessableToken& input_stream_id,
const std::string& output_device_id) override;
void DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) override;
void DidCommitAndDrawCompositorFrame() override;
void WasHidden() override;
void WasShown() override;
void DidChangeMobileFriendliness(const blink::MobileFriendliness&) override;
void SetUpSharedMemoryForSmoothness(
base::ReadOnlySharedMemoryRegion shared_memory) override;
blink::WebURL LastCommittedUrlForUKM() override;
// Binds to the MHTML file generation service in the browser.
void BindMhtmlFileWriter(
mojo::PendingAssociatedReceiver<mojom::MhtmlFileWriter> receiver);
// Binds to the autoplay configuration service in the browser.
void BindAutoplayConfiguration(
mojo::PendingAssociatedReceiver<blink::mojom::AutoplayConfigurationClient>
receiver);
void BindFrameBindingsControl(
mojo::PendingAssociatedReceiver<mojom::FrameBindingsControl> receiver);
void BindNavigationClient(
mojo::PendingAssociatedReceiver<mojom::NavigationClient> receiver);
// Virtual so that a TestRenderFrame can mock out the interface.
virtual mojom::FrameHost* GetFrameHost();
media::MediaPermission* GetMediaPermission();
// Sends the current frame's navigation state to the browser.
void SendUpdateState();
// Creates a MojoBindingsController if Mojo bindings have been enabled for
// this frame. For WebUI, this allows the page to communicate with the browser
// process; for layout tests, this allows the test to mock out services at
// the Mojo IPC layer.
void MaybeEnableMojoBindings();
void NotifyObserversOfFailedProvisionalLoad();
// Plugin-related functions --------------------------------------------------
#if BUILDFLAG(ENABLE_PLUGINS)
PepperPluginInstanceImpl* focused_pepper_plugin() {
return focused_pepper_plugin_;
}
// Indicates that the given instance has been created.
void PepperInstanceCreated(
PepperPluginInstanceImpl* instance,
mojo::PendingAssociatedRemote<mojom::PepperPluginInstance> mojo_instance,
mojo::PendingAssociatedReceiver<mojom::PepperPluginInstanceHost>
mojo_host);
// Indicates that the given instance is being destroyed. This is called from
// the destructor, so it's important that the instance is not dereferenced
// from this call.
void PepperInstanceDeleted(PepperPluginInstanceImpl* instance);
// Notification that the given plugin is focused or unfocused.
void PepperFocusChanged(PepperPluginInstanceImpl* instance, bool focused);
void OnSetPepperVolume(int32_t pp_instance, double volume);
#endif // ENABLE_PLUGINS
const blink::RendererPreferences& GetRendererPreferences() const;
// Called when an ongoing renderer-initiated navigation was dropped by the
// browser.
void OnDroppedNavigation();
void DidStartResponse(const GURL& response_url,
int request_id,
network::mojom::URLResponseHeadPtr response_head,
network::mojom::RequestDestination request_destination,
blink::PreviewsState previews_state);
void DidCompleteResponse(int request_id,
const network::URLLoaderCompletionStatus& status);
void DidCancelResponse(int request_id);
void DidReceiveTransferSizeUpdate(int request_id, int received_data_length);
bool GetCaretBoundsFromFocusedPlugin(gfx::Rect& rect) override;
// Used in tests to install a fake WebURLLoaderFactory via
// RenderViewTest::CreateFakeWebURLLoaderFactory().
void SetWebURLLoaderFactoryOverrideForTest(
std::unique_ptr<blink::WebURLLoaderFactoryForTest> factory);
blink::scheduler::WebAgentGroupScheduler& GetAgentGroupScheduler() override;
url::Origin GetSecurityOriginOfTopFrame();
protected:
explicit RenderFrameImpl(CreateParams params);
bool IsLocalRoot() const;
const RenderFrameImpl* GetLocalRoot() const;
private:
friend class RenderFrameImplTest;
friend class RenderFrameObserver;
friend class TestRenderFrame;
FRIEND_TEST_ALL_PREFIXES(RenderAccessibilityImplTest,
AccessibilityMessagesQueueWhileSwappedOut);
FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest, LocalChildFrameWasShown);
FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest, ZoomLimit);
FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest,
TestOverlayRoutingTokenSendsLater);
FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest,
TestOverlayRoutingTokenSendsNow);
// A wrapper class used as the callback for JavaScript executed
// in an isolated world.
class JavaScriptIsolatedWorldRequest
: public blink::WebScriptExecutionCallback {
public:
JavaScriptIsolatedWorldRequest(
base::WeakPtr<RenderFrameImpl> render_frame_impl,
bool wants_result,
JavaScriptExecuteRequestInIsolatedWorldCallback callback);
void Completed(
const blink::WebVector<v8::Local<v8::Value>>& result) override;
private:
~JavaScriptIsolatedWorldRequest() override;
base::WeakPtr<RenderFrameImpl> render_frame_impl_;
bool wants_result_;
JavaScriptExecuteRequestInIsolatedWorldCallback callback_;
DISALLOW_COPY_AND_ASSIGN(JavaScriptIsolatedWorldRequest);
};
// Similar to base::AutoReset, but skips restoration of the original value if
// |this| is already destroyed.
template <typename T>
class AutoResetMember {
public:
AutoResetMember(RenderFrameImpl* frame,
T RenderFrameImpl::*member,
T new_value)
: weak_frame_(frame->weak_factory_.GetWeakPtr()),
scoped_variable_(&(frame->*member)),
original_value_(*scoped_variable_) {
*scoped_variable_ = new_value;
}
~AutoResetMember() {
if (weak_frame_)
*scoped_variable_ = original_value_;
}
private:
base::WeakPtr<RenderFrameImpl> weak_frame_;
T* scoped_variable_;
T original_value_;
};
class FrameURLLoaderFactory;
// Creates a new RenderFrame. |render_view| is the RenderView object that this
// frame belongs to, and |browser_interface_broker| is the RenderFrameHost's
// BrowserInterfaceBroker through which services are exposed to the
// RenderFrame.
static RenderFrameImpl* Create(
AgentSchedulingGroup& agent_scheduling_group,
RenderViewImpl* render_view,
int32_t routing_id,
mojo::PendingAssociatedReceiver<mojom::Frame> frame_receiver,
mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker,
const base::UnguessableToken& devtools_frame_token);
// Functions to add and remove observers for this object.
void AddObserver(RenderFrameObserver* observer);
void RemoveObserver(RenderFrameObserver* observer);
// Checks whether accessibility support for this frame is currently enabled.
bool IsAccessibilityEnabled() const;
// mojom::Frame implementation:
void CommitSameDocumentNavigation(
mojom::CommonNavigationParamsPtr common_params,
mojom::CommitNavigationParamsPtr commit_params,
CommitSameDocumentNavigationCallback callback) override;
void HandleRendererDebugURL(const GURL& url) override;
void UpdateSubresourceLoaderFactories(
std::unique_ptr<blink::PendingURLLoaderFactoryBundle>
subresource_loader_factories) override;
void BindDevToolsAgent(
mojo::PendingAssociatedRemote<blink::mojom::DevToolsAgentHost> host,
mojo::PendingAssociatedReceiver<blink::mojom::DevToolsAgent> receiver)
override;
void JavaScriptMethodExecuteRequest(
const base::string16& object_name,
const base::string16& method_name,
base::Value arguments,
bool wants_result,
JavaScriptMethodExecuteRequestCallback callback) override;
void JavaScriptExecuteRequest(
const base::string16& javascript,
bool wants_result,
JavaScriptExecuteRequestCallback callback) override;
void JavaScriptExecuteRequestForTests(
const base::string16& javascript,
bool wants_result,
bool has_user_gesture,
int32_t world_id,
JavaScriptExecuteRequestForTestsCallback callback) override;
void JavaScriptExecuteRequestInIsolatedWorld(
const base::string16& javascript,
bool wants_result,
int32_t world_id,
JavaScriptExecuteRequestInIsolatedWorldCallback callback) override;
void SetWantErrorMessageStackTrace() override;
void Unload(int proxy_routing_id,
bool is_loading,
mojom::FrameReplicationStatePtr replicated_frame_state,
const blink::RemoteFrameToken& frame_token) override;
void Delete(mojom::FrameDeleteIntention intent) override;
void BlockRequests() override;
void ResumeBlockedRequests() override;
void GetInterfaceProvider(
mojo::PendingReceiver<service_manager::mojom::InterfaceProvider> receiver)
override;
void GetCanonicalUrlForSharing(
GetCanonicalUrlForSharingCallback callback) override;
void SnapshotAccessibilityTree(
mojom::SnapshotAccessibilityTreeParamsPtr params,
SnapshotAccessibilityTreeCallback callback) override;
void GetSerializedHtmlWithLocalLinks(
const base::flat_map<GURL, base::FilePath>& url_map,
const base::flat_map<blink::FrameToken, base::FilePath>& frame_token_map,
bool save_with_empty_url,
mojo::PendingRemote<mojom::FrameHTMLSerializerHandler> handler_remote)
override;
// IPC message handlers ------------------------------------------------------
//
// The documentation for these functions should be in
// content/common/*_messages.h for the message that the function is handling.
void OnShowContextMenu(const gfx::Point& location);
void OnMoveCaret(const gfx::Point& point);
void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
void OnSelectRange(const gfx::Point& base, const gfx::Point& extent);
void OnSuppressFurtherDialogs();
// Callback scheduled from SerializeAsMHTML for when writing serialized
// MHTML to the handle has been completed in the file thread.
void OnWriteMHTMLComplete(
SerializeAsMHTMLCallback callback,
std::unordered_set<std::string> serialized_resources_uri_digests,
base::TimeDelta main_thread_use_time,
mojom::MhtmlSaveStatus save_status);
// Requests that the browser process navigates to |url|.
void OpenURL(std::unique_ptr<blink::WebNavigationInfo> info);
// Returns a blink::ChildURLLoaderFactoryBundle which can be used to request
// subresources for this frame.
// For frames with committed navigations, this bundle is created with the
// factories provided by the browser at navigation time. For any other frames
// (i.e. frames on the initial about:blank Document), the bundle returned here
// is lazily cloned from the parent or opener's own bundle.
blink::ChildURLLoaderFactoryBundle* GetLoaderFactoryBundle();
// Clones and returns the creator's (parent's or opener's)
// blink::ChildURLLoaderFactoryBundle.
scoped_refptr<blink::ChildURLLoaderFactoryBundle>
GetLoaderFactoryBundleFromCreator();
// Returns a mostly empty bundle, with a fallback that uses a process-wide,
// direct-network factory.
//
// TODO(lukasza): https://crbug.com/1114822: Remove once the fallback is no
// longer needed.
scoped_refptr<blink::ChildURLLoaderFactoryBundle>
GetLoaderFactoryBundleFallback();
scoped_refptr<blink::ChildURLLoaderFactoryBundle> CreateLoaderFactoryBundle(
std::unique_ptr<blink::PendingURLLoaderFactoryBundle> info,
base::Optional<std::vector<blink::mojom::TransferrableURLLoaderPtr>>
subresource_overrides,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
prefetch_loader_factory);
// Update current main frame's encoding and send it to browser window.
// Since we want to let users see the right encoding info from menu
// before finishing loading, we call the UpdateEncoding in
// a) function:DidCommitLoadForFrame. When this function is called,
// that means we have got first data. In here we try to get encoding
// of page if it has been specified in http header.
// b) function:DidReceiveTitle. When this function is called,
// that means we have got specified title. Because in most of webpages,
// title tags will follow meta tags. In here we try to get encoding of
// page if it has been specified in meta tag.
// c) function:DidFinishDocumentLoadForFrame. When this function is
// called, that means we have got whole html page. In here we should
// finally get right encoding of page.
void UpdateEncoding(blink::WebFrame* frame, const std::string& encoding_name);
base::Value GetJavaScriptExecutionResult(v8::Local<v8::Value> result);
void InitializeMediaStreamDeviceObserver();
// Does preparation for the navigation to |url|.
void PrepareRenderViewForNavigation(
const GURL& url,
const mojom::CommitNavigationParams& commit_params);
// Sends a FrameHostMsg_BeginNavigation to the browser
void BeginNavigationInternal(std::unique_ptr<blink::WebNavigationInfo> info,
bool is_history_navigation_in_new_child_frame,
base::TimeTicks renderer_before_unload_start,
base::TimeTicks renderer_before_unload_end);
// TODO(https://crbug.com/778318): When creating a new browsing context, Blink
// always populates it with an initial empty document synchronously, as
// required by the HTML spec. However, for both iframe and window creation,
// there is an additional special case that currently requires completing an
// about:blank navigation synchronously.
//
// 1. Inserting an <iframe> into the active document with no src and no
// srcdoc or with src = "about:blank".
// 2. Opening a new window with no specified URL or with URL = "about:blank".
//
// In both cases, Blink will initialize the new browsing context, and then
// immediately re-navigate to "about:blank". This leads to a number of odd
// situations throughout the navigation stack, and it is spec-incompliant.
//
// For a new <iframe>, the re-navigation to "about:blank" should be a regular
// asynchronous navigation.
//
// For a new window, there should be no navigation at all: the standard states
// that a load event should be dispatched, and nothing else.
//
// See also:
// - https://chromium-review.googlesource.com/c/chromium/src/+/804797
// - https://github.com/whatwg/html/issues/3267
void SynchronouslyCommitAboutBlankForBug778318(
std::unique_ptr<blink::WebNavigationInfo> info);
// Commit navigation with |navigation_params| prepared.
void CommitNavigationWithParams(
mojom::CommonNavigationParamsPtr common_params,
mojom::CommitNavigationParamsPtr commit_params,
std::unique_ptr<blink::PendingURLLoaderFactoryBundle>
subresource_loader_factories,
base::Optional<std::vector<blink::mojom::TransferrableURLLoaderPtr>>
subresource_overrides,
blink::mojom::ControllerServiceWorkerInfoPtr
controller_service_worker_info,
blink::mojom::ServiceWorkerContainerInfoForClientPtr container_info,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
prefetch_loader_factory,
std::unique_ptr<DocumentState> document_state,
std::unique_ptr<blink::WebNavigationParams> navigation_params);
// Decodes a data url for navigation commit.
void DecodeDataURL(const mojom::CommonNavigationParams& common_params,
const mojom::CommitNavigationParams& commit_params,
std::string* mime_type,
std::string* charset,
std::string* data,
GURL* base_url);
// |transition_type| corresponds to the document which triggered this request.