forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_frame_impl.cc
4340 lines (3786 loc) · 166 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 "base/auto_reset.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/debug/asan_invalid_access.h"
#include "base/debug/dump_without_crashing.h"
#include "base/i18n/char_iterator.h"
#include "base/metrics/histogram.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "content/child/appcache/appcache_dispatcher.h"
#include "content/child/plugin_messages.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/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/clipboard_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/frame_replication_state.h"
#include "content/common/input_messages.h"
#include "content/common/service_worker/service_worker_types.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/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/context_menu_params.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/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/dom_utils.h"
#include "content/renderer/external_popup_menu.h"
#include "content/renderer/geolocation_dispatcher.h"
#include "content/renderer/history_controller.h"
#include "content/renderer/history_serialization.h"
#include "content/renderer/image_loading_helper.h"
#include "content/renderer/ime_event_guard.h"
#include "content/renderer/internal_document_state_data.h"
#include "content/renderer/manifest/manifest_manager.h"
#include "content/renderer/media/audio_renderer_mixer_manager.h"
#include "content/renderer/media/crypto/render_cdm_factory.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/media_stream_renderer_factory.h"
#include "content/renderer/media/midi_dispatcher.h"
#include "content/renderer/media/render_media_log.h"
#include "content/renderer/media/user_media_client_impl.h"
#include "content/renderer/media/webmediaplayer_ms.h"
#include "content/renderer/mojo/service_registry_js_wrapper.h"
#include "content/renderer/notification_permission_dispatcher.h"
#include "content/renderer/npapi/plugin_channel_host.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/screen_orientation/screen_orientation_dispatcher.h"
#include "content/renderer/shared_worker_repository.h"
#include "content/renderer/v8_value_converter_impl.h"
#include "content/renderer/websharedworker_proxy.h"
#include "gin/modules/module_registry.h"
#include "media/base/audio_renderer_mixer_input.h"
#include "media/base/media_log.h"
#include "media/blink/webcontentdecryptionmodule_impl.h"
#include "media/blink/webencryptedmediaclient_impl.h"
#include "media/blink/webmediaplayer_impl.h"
#include "media/blink/webmediaplayer_params.h"
#include "media/filters/default_renderer_factory.h"
#include "media/filters/gpu_video_accelerator_factories.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 "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/WebDocument.h"
#include "third_party/WebKit/public/web/WebGlyphCache.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/WebPluginParams.h"
#include "third_party/WebKit/public/web/WebPluginPlaceholder.h"
#include "third_party/WebKit/public/web/WebRange.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSearchableFormData.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.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"
#if defined(ENABLE_PLUGINS)
#include "content/renderer/npapi/webplugin_impl.h"
#include "content/renderer/pepper/pepper_browser_connection.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.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/common/gpu/client/context_provider_command_buffer.h"
#include "content/renderer/android/synchronous_compositor_factory.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/stream_texture_factory_impl.h"
#include "content/renderer/media/android/webmediaplayer_android.h"
#else
#include "webkit/common/gpu/context_provider_web_context.h"
#endif
#if defined(ENABLE_PEPPER_CDMS)
#include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
#elif defined(ENABLE_BROWSER_CDMS)
#include "content/renderer/media/crypto/renderer_cdm_manager.h"
#endif
using blink::WebContextMenuData;
using blink::WebData;
using blink::WebDataSource;
using blink::WebDocument;
using blink::WebElement;
using blink::WebExternalPopupMenu;
using blink::WebExternalPopupMenuClient;
using blink::WebFrame;
using blink::WebHistoryItem;
using blink::WebHTTPBody;
using blink::WebLocalFrame;
using blink::WebMediaPlayer;
using blink::WebMediaPlayerClient;
using blink::WebNavigationPolicy;
using blink::WebNavigationType;
using blink::WebNode;
using blink::WebPluginParams;
using blink::WebPopupMenuInfo;
using blink::WebRange;
using blink::WebReferrerPolicy;
using blink::WebScriptSource;
using blink::WebSearchableFormData;
using blink::WebSecurityOrigin;
using blink::WebSecurityPolicy;
using blink::WebServiceWorkerProvider;
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;
namespace content {
namespace {
const char kDefaultAcceptHeader[] =
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/"
"*;q=0.8";
const char kAcceptHeader[] = "Accept";
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 ExtractPostId(const WebHistoryItem& item) {
if (item.isNull())
return -1;
if (item.httpBody().isNull())
return -1;
return item.httpBody().identifier();
}
WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
const WebURLResponse& response) {
return static_cast<WebURLResponseExtraDataImpl*>(response.extraData());
}
void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
// Replace any occurrences of swappedout:// with about:blank.
const WebURL& blank_url = GURL(url::kAboutBlankURL);
WebVector<WebURL> urls;
ds->redirectChain(urls);
result->reserve(urls.size());
for (size_t i = 0; i < urls.size(); ++i) {
if (urls[i] != GURL(kSwappedOutURL))
result->push_back(urls[i]);
else
result->push_back(blank_url);
}
}
// 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) {
// 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())
return ds->unreachableURL();
std::vector<GURL> redirects;
GetRedirectChain(ds, &redirects);
if (!redirects.empty())
return redirects.at(0);
return ds->originalRequest().url();
}
NOINLINE void CrashIntentionally() {
// NOTE(shess): Crash directly rather than using NOTREACHED() so
// that the signature is easier to triage in crash reports.
volatile int* zero = NULL;
*zero = 0;
}
#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, sizeof(kCrashDomain) - 1))
return;
if (!url.has_path())
return;
std::string crash_type(url.path());
if (crash_type == kHeapOverflow) {
base::debug::AsanHeapOverflow();
} else if (crash_type == kHeapUnderflow ) {
base::debug::AsanHeapUnderflow();
} else if (crash_type == kUseAfterFree) {
base::debug::AsanHeapUseAfterFree();
#if defined(SYZYASAN)
} else if (crash_type == kCorruptHeapBlock) {
base::debug::AsanCorruptHeapBlock();
} else if (crash_type == kCorruptHeap) {
base::debug::AsanCorruptHeap();
#endif
}
}
#endif // ADDRESS_SANITIZER || SYZYASAN
void MaybeHandleDebugURL(const GURL& url) {
if (!url.SchemeIs(kChromeUIScheme))
return;
if (url == GURL(kChromeUICrashURL)) {
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)) {
base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
} else if (url == GURL(kChromeUIHangURL)) {
for (;;) {
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
}
} else if (url == GURL(kChromeUIShorthangURL)) {
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;
}
// Returns false unless this is a top-level navigation that crosses origins.
bool IsNonLocalTopLevelNavigation(const GURL& url,
WebFrame* frame,
WebNavigationType type,
bool is_form_post) {
if (!IsTopLevelNavigation(frame))
return false;
// Navigations initiated within Webkit are not sent out to the external host
// in the following cases.
// 1. The url scheme is not http/https
// 2. The origin of the url and the opener is the same in which case the
// opener relationship is maintained.
// 3. Reloads/form submits/back forward navigations
if (!url.SchemeIs(url::kHttpScheme) && !url.SchemeIs(url::kHttpsScheme))
return false;
if (type != blink::WebNavigationTypeReload &&
type != blink::WebNavigationTypeBackForward && !is_form_post) {
// The opener relationship between the new window and the parent allows the
// new window to script the parent and vice versa. This is not allowed if
// the origins of the two domains are different. This can be treated as a
// top level navigation and routed back to the host.
blink::WebFrame* opener = frame->opener();
if (!opener)
return true;
if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
return true;
}
return false;
}
WebURLRequest CreateURLRequestForNavigation(
const CommonNavigationParams& common_params,
const RequestNavigationParams& request_params,
scoped_ptr<StreamOverrideParameters> stream_override,
bool is_view_source_mode_enabled) {
WebURLRequest request(common_params.url);
if (is_view_source_mode_enabled)
request.setCachePolicy(WebURLRequest::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);
}
if (!request_params.extra_headers.empty()) {
for (net::HttpUtil::HeadersIterator i(request_params.extra_headers.begin(),
request_params.extra_headers.end(),
"\n");
i.GetNext();) {
request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
WebString::fromUTF8(i.values()));
}
}
if (request_params.is_post) {
request.setHTTPMethod(WebString::fromUTF8("POST"));
// Set post data.
WebHTTPBody http_body;
http_body.initialize();
const char* data = NULL;
if (request_params.browser_initiated_post_data.size()) {
data = reinterpret_cast<const char*>(
&request_params.browser_initiated_post_data.front());
}
http_body.appendData(
WebData(data, request_params.browser_initiated_post_data.size()));
request.setHTTPBody(http_body);
}
RequestExtraData* extra_data = new RequestExtraData();
extra_data->set_stream_override(stream_override.Pass());
request.setExtraData(extra_data);
return request;
}
void UpdateFrameNavigationTiming(WebFrame* frame,
base::TimeTicks browser_navigation_start,
base::TimeTicks renderer_navigation_start) {
// The browser provides the navigation_start time to bootstrap the
// Navigation Timing information for the browser-initiated navigations. In
// case of cross-process navigations, this carries over the time of
// finishing the onbeforeunload handler of the previous page.
DCHECK(!browser_navigation_start.is_null());
if (frame->provisionalDataSource()) {
// |browser_navigation_start| is likely before this process existed, so we
// can't use InterProcessTimeTicksConverter. We need at least to ensure
// that the browser-side navigation start we set is not later than the one
// on the renderer side.
base::TimeTicks navigation_start = std::min(
browser_navigation_start, renderer_navigation_start);
double navigation_start_seconds =
(navigation_start - base::TimeTicks()).InSecondsF();
frame->provisionalDataSource()->setNavigationStartTime(
navigation_start_seconds);
// TODO(clamy): We need to provide additional timing values for the
// Navigation Timing API to work with browser-side navigations.
}
}
// PlzNavigate
FrameHostMsg_BeginNavigation_Params MakeBeginNavigationParams(
blink::WebURLRequest* request) {
FrameHostMsg_BeginNavigation_Params params;
params.method = request->httpMethod().latin1();
params.headers = GetWebURLRequestHeaders(*request);
params.load_flags = GetLoadFlagsForWebURLRequest(*request);
params.request_body = GetRequestBodyForWebURLRequest(*request);
params.has_user_gesture = request->hasUserGesture();
return params;
}
// PlzNavigate
CommonNavigationParams MakeCommonNavigationParams(
blink::WebURLRequest* request) {
const RequestExtraData kEmptyData;
const RequestExtraData* extra_data =
static_cast<RequestExtraData*>(request->extraData());
if (!extra_data)
extra_data = &kEmptyData;
CommonNavigationParams params;
params.url = request->url();
params.referrer = Referrer(
GURL(request->httpHeaderField(WebString::fromUTF8("Referer")).latin1()),
request->referrerPolicy());
params.transition = extra_data->transition_type();
return params;
}
#if !defined(OS_ANDROID)
media::Context3D GetSharedMainThreadContext3D() {
cc::ContextProvider* provider =
RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
if (!provider)
return media::Context3D();
return media::Context3D(provider->ContextGL(), provider->GrContext());
}
#endif
RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
nullptr;
} // namespace
// static
RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view,
int32 routing_id) {
DCHECK(routing_id != MSG_ROUTING_NONE);
if (g_create_render_frame_impl)
return g_create_render_frame_impl(render_view, routing_id);
else
return new RenderFrameImpl(render_view, routing_id);
}
// static
RenderFrameImpl* RenderFrameImpl::FromRoutingID(int32 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
void RenderFrameImpl::CreateFrame(int routing_id,
int parent_routing_id,
int proxy_routing_id) {
// TODO(nasko): For now, this message is only sent for subframes, as the
// top level frame is created when the RenderView is created through the
// ViewMsg_New IPC.
CHECK_NE(MSG_ROUTING_NONE, parent_routing_id);
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();
// Create the RenderFrame and WebLocalFrame, linking the two.
render_frame =
RenderFrameImpl::Create(parent_proxy->render_view(), routing_id);
web_frame = parent_web_frame->createLocalChild("", render_frame);
} else {
RenderFrameProxy* proxy =
RenderFrameProxy::FromRoutingID(proxy_routing_id);
CHECK(proxy);
render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id);
web_frame = blink::WebLocalFrame::create(render_frame);
render_frame->proxy_routing_id_ = proxy_routing_id;
web_frame->initializeToReplaceRemoteFrame(proxy->web_frame());
}
render_frame->SetWebFrame(web_frame);
render_frame->Initialize();
}
// static
RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) {
return RenderFrameImpl::FromWebFrame(web_frame);
}
// static
RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) {
FrameMap::iterator iter = g_frame_map.Get().find(web_frame);
if (iter != g_frame_map.Get().end())
return iter->second;
return NULL;
}
// static
void RenderFrameImpl::InstallCreateHook(
CreateRenderFrameImplFunction create_render_frame_impl) {
CHECK(!g_create_render_frame_impl);
g_create_render_frame_impl = create_render_frame_impl;
}
// RenderFrameImpl ----------------------------------------------------------
RenderFrameImpl::RenderFrameImpl(RenderViewImpl* render_view, int routing_id)
: frame_(NULL),
render_view_(render_view->AsWeakPtr()),
routing_id_(routing_id),
is_swapped_out_(false),
render_frame_proxy_(NULL),
is_detaching_(false),
proxy_routing_id_(MSG_ROUTING_NONE),
#if defined(ENABLE_PLUGINS)
plugin_power_saver_helper_(NULL),
#endif
cookie_jar_(this),
selection_text_offset_(0),
selection_range_(gfx::Range::InvalidRange()),
handling_select_range_(false),
notification_permission_dispatcher_(NULL),
web_user_media_client_(NULL),
web_encrypted_media_client_(NULL),
midi_dispatcher_(NULL),
#if defined(OS_ANDROID)
media_player_manager_(NULL),
#endif
#if defined(ENABLE_BROWSER_CDMS)
cdm_manager_(NULL),
#endif
#if defined(VIDEO_HOLE)
contains_media_player_(false),
#endif
geolocation_dispatcher_(NULL),
push_messaging_dispatcher_(NULL),
screen_orientation_dispatcher_(NULL),
manifest_manager_(NULL),
accessibility_mode_(AccessibilityModeOff),
renderer_accessibility_(NULL),
weak_factory_(this) {
std::pair<RoutingIDFrameMap::iterator, bool> result =
g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this));
CHECK(result.second) << "Inserting a duplicate item.";
RenderThread::Get()->AddRoute(routing_id_, this);
render_view_->RegisterRenderFrame(this);
// Everything below subclasses RenderFrameObserver and is automatically
// deleted when the RenderFrame gets deleted.
#if defined(OS_ANDROID)
new GinJavaBridgeDispatcher(this);
#endif
#if defined(ENABLE_PLUGINS)
plugin_power_saver_helper_ = new PluginPowerSaverHelper(this);
#endif
manifest_manager_ = new ManifestManager(this);
}
RenderFrameImpl::~RenderFrameImpl() {
FOR_EACH_OBSERVER(RenderFrameObserver, observers_, RenderFrameGone());
FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnDestruct());
#if defined(VIDEO_HOLE)
if (contains_media_player_)
render_view_->UnregisterVideoHoleFrame(this);
#endif
if (render_frame_proxy_)
delete render_frame_proxy_;
render_view_->UnregisterRenderFrame(this);
g_routing_id_frame_map.Get().erase(routing_id_);
RenderThread::Get()->RemoveRoute(routing_id_);
}
void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) {
DCHECK(!frame_);
std::pair<FrameMap::iterator, bool> result = g_frame_map.Get().insert(
std::make_pair(web_frame, this));
CHECK(result.second) << "Inserting a duplicate item.";
frame_ = web_frame;
}
void RenderFrameImpl::Initialize() {
#if defined(ENABLE_PLUGINS)
new PepperBrowserConnection(this);
#endif
new SharedWorkerRepository(this);
if (!frame_->parent())
new ImageLoadingHelper(this);
// We delay calling this until we have the WebFrame so that any observer or
// embedder can call GetWebFrame on any RenderFrame.
GetContentClient()->renderer()->RenderFrameCreated(this);
}
RenderWidget* RenderFrameImpl::GetRenderWidget() {
return render_view_.get();
}
#if defined(ENABLE_PLUGINS)
void RenderFrameImpl::PepperPluginCreated(RendererPpapiHost* host) {
FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
DidCreatePepperPlugin(host));
if (host->GetPluginName() == kFlashPluginName) {
RenderThread::Get()->RecordAction(
base::UserMetricsAction("FrameLoadWithFlash"));
}
}
void RenderFrameImpl::PepperDidChangeCursor(
PepperPluginInstanceImpl* instance,
const blink::WebCursorInfo& cursor) {
// Update the cursor appearance immediately if the requesting plugin is the
// one which receives the last mouse event. Otherwise, the new cursor won't be
// picked up until the plugin gets the next input event. That is bad if, e.g.,
// the plugin would like to set an invisible cursor when there isn't any user
// input for a while.
if (instance == render_view_->pepper_last_mouse_event_target())
GetRenderWidget()->didChangeCursor(cursor);
}
void RenderFrameImpl::PepperDidReceiveMouseEvent(
PepperPluginInstanceImpl* instance) {
render_view_->set_pepper_last_mouse_event_target(instance);
}
void RenderFrameImpl::PepperTextInputTypeChanged(
PepperPluginInstanceImpl* instance) {
if (instance != render_view_->focused_pepper_plugin())
return;
GetRenderWidget()->UpdateTextInputType();
if (renderer_accessibility())
renderer_accessibility()->FocusedNodeChanged(WebNode());
}
void RenderFrameImpl::PepperCaretPositionChanged(
PepperPluginInstanceImpl* instance) {
if (instance != render_view_->focused_pepper_plugin())
return;
GetRenderWidget()->UpdateSelectionBounds();
}
void RenderFrameImpl::PepperCancelComposition(
PepperPluginInstanceImpl* instance) {
if (instance != render_view_->focused_pepper_plugin())
return;
Send(new InputHostMsg_ImeCancelComposition(render_view_->GetRoutingID()));;
#if defined(OS_MACOSX) || defined(USE_AURA)
GetRenderWidget()->UpdateCompositionInfo(true);
#endif
}
void RenderFrameImpl::PepperSelectionChanged(
PepperPluginInstanceImpl* instance) {
if (instance != render_view_->focused_pepper_plugin())
return;
SyncSelectionIfRequired();
}
RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer(
PepperPluginInstanceImpl* plugin) {
GURL active_url;
if (render_view_->webview() && render_view_->webview()->mainFrame())
active_url = GURL(render_view_->webview()->mainFrame()->document().url());
RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
GetRenderWidget()->routing_id(), GetRenderWidget()->compositor_deps(),
plugin, active_url, GetRenderWidget()->screenInfo());
widget->show(blink::WebNavigationPolicyIgnore);
return widget;
}
bool RenderFrameImpl::IsPepperAcceptingCompositionEvents() const {
if (!render_view_->focused_pepper_plugin())
return false;
return render_view_->focused_pepper_plugin()->
IsPluginAcceptingCompositionEvents();
}
void RenderFrameImpl::PluginCrashed(const base::FilePath& plugin_path,
base::ProcessId plugin_pid) {
// TODO(jam): dispatch this IPC in RenderFrameHost and switch to use
// routing_id_ as a result.
Send(new FrameHostMsg_PluginCrashed(routing_id_, plugin_path, plugin_pid));
}
void RenderFrameImpl::SimulateImeSetComposition(
const base::string16& text,
const std::vector<blink::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end) {
render_view_->OnImeSetComposition(
text, underlines, selection_start, selection_end);
}
void RenderFrameImpl::SimulateImeConfirmComposition(
const base::string16& text,
const gfx::Range& replacement_range) {
render_view_->OnImeConfirmComposition(text, replacement_range, false);
}
void RenderFrameImpl::OnImeSetComposition(
const base::string16& text,
const std::vector<blink::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end) {
// When a PPAPI plugin has focus, we bypass WebKit.
if (!IsPepperAcceptingCompositionEvents()) {
pepper_composition_text_ = text;
} else {
// TODO(kinaba) currently all composition events are sent directly to
// plugins. Use DOM event mechanism after WebKit is made aware about
// plugins that support composition.
// The code below mimics the behavior of WebCore::Editor::setComposition.
// Empty -> nonempty: composition started.
if (pepper_composition_text_.empty() && !text.empty()) {
render_view_->focused_pepper_plugin()->HandleCompositionStart(
base::string16());
}
// Nonempty -> empty: composition canceled.
if (!pepper_composition_text_.empty() && text.empty()) {
render_view_->focused_pepper_plugin()->HandleCompositionEnd(
base::string16());
}
pepper_composition_text_ = text;
// Nonempty: composition is ongoing.
if (!pepper_composition_text_.empty()) {
render_view_->focused_pepper_plugin()->HandleCompositionUpdate(
pepper_composition_text_, underlines, selection_start,
selection_end);
}
}
}
void RenderFrameImpl::OnImeConfirmComposition(
const base::string16& text,
const gfx::Range& replacement_range,
bool keep_selection) {
// When a PPAPI plugin has focus, we bypass WebKit.
// Here, text.empty() has a special meaning. It means to commit the last
// update of composition text (see
// RenderWidgetHost::ImeConfirmComposition()).
const base::string16& last_text = text.empty() ? pepper_composition_text_
: text;
// last_text is empty only when both text and pepper_composition_text_ is.
// Ignore it.
if (last_text.empty())
return;
if (!IsPepperAcceptingCompositionEvents()) {
base::i18n::UTF16CharIterator iterator(&last_text);
int32 i = 0;
while (iterator.Advance()) {
blink::WebKeyboardEvent char_event;
char_event.type = blink::WebInputEvent::Char;
char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
char_event.modifiers = 0;
char_event.windowsKeyCode = last_text[i];
char_event.nativeKeyCode = last_text[i];
const int32 char_start = i;
for (; i < iterator.array_pos(); ++i) {
char_event.text[i - char_start] = last_text[i];
char_event.unmodifiedText[i - char_start] = last_text[i];
}
if (GetRenderWidget()->webwidget())
GetRenderWidget()->webwidget()->handleInputEvent(char_event);
}
} else {
// Mimics the order of events sent by WebKit.
// See WebCore::Editor::setComposition() for the corresponding code.
render_view_->focused_pepper_plugin()->HandleCompositionEnd(last_text);
render_view_->focused_pepper_plugin()->HandleTextInput(last_text);
}
pepper_composition_text_.clear();
}
#endif // defined(ENABLE_PLUGINS)
MediaStreamDispatcher* RenderFrameImpl::GetMediaStreamDispatcher() {
if (!web_user_media_client_)
InitializeUserMediaClient();
return web_user_media_client_ ?
web_user_media_client_->media_stream_dispatcher() : NULL;
}
bool RenderFrameImpl::Send(IPC::Message* message) {
if (is_detaching_) {
delete message;
return false;
}
if (is_swapped_out_) {
if (!SwappedOutMessages::CanSendWhileSwappedOut(message)) {
delete message;
return false;
}
}
return RenderThread::Get()->Send(message);
}
#if defined(OS_MACOSX) || defined(OS_ANDROID)
void RenderFrameImpl::DidHideExternalPopupMenu() {
// We need to clear external_popup_menu_ as soon as ExternalPopupMenu::close
// is called. Otherwise, createExternalPopupMenu() for new popup will fail.
external_popup_menu_.reset();
}
#endif
bool RenderFrameImpl::OnMessageReceived(const IPC::Message& msg) {
// TODO(kenrb): document() should not be null, but as a transitional step
// we have RenderFrameProxy 'wrapping' a RenderFrameImpl, passing messages
// to this method. This happens for a top-level remote frame, where a
// document-less RenderFrame is replaced by a RenderFrameProxy but kept
// around and is still able to receive messages.
if (!frame_->document().isNull())
GetContentClient()->SetActiveURL(frame_->document().url());
ObserverListBase<RenderFrameObserver>::Iterator it(observers_);
RenderFrameObserver* observer;
while ((observer = it.GetNext()) != NULL) {
if (observer->OnMessageReceived(msg))
return true;
}
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg)
IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate)
IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload)
IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut)
IPC_MESSAGE_HANDLER(FrameMsg_Stop, OnStop)
IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed)
IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction,
OnCustomContextMenuAction)
IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo)
IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo)
IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
IPC_MESSAGE_HANDLER(InputMsg_MoveRangeSelectionExtent,
OnMoveRangeSelectionExtent)
IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace)
IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling)
IPC_MESSAGE_HANDLER(InputMsg_ExtendSelectionAndDelete,
OnExtendSelectionAndDelete)
IPC_MESSAGE_HANDLER(InputMsg_SetCompositionFromExistingText,
OnSetCompositionFromExistingText)
IPC_MESSAGE_HANDLER(InputMsg_ExecuteNoValueEditCommand,
OnExecuteNoValueEditCommand)
IPC_MESSAGE_HANDLER(FrameMsg_CSSInsertRequest, OnCSSInsertRequest)
IPC_MESSAGE_HANDLER(FrameMsg_JavaScriptExecuteRequest,
OnJavaScriptExecuteRequest)
IPC_MESSAGE_HANDLER(FrameMsg_JavaScriptExecuteRequestForTests,
OnJavaScriptExecuteRequestForTests)
IPC_MESSAGE_HANDLER(FrameMsg_SetEditableSelectionOffsets,
OnSetEditableSelectionOffsets)
IPC_MESSAGE_HANDLER(FrameMsg_SetupTransitionView, OnSetupTransitionView)
IPC_MESSAGE_HANDLER(FrameMsg_BeginExitTransition, OnBeginExitTransition)
IPC_MESSAGE_HANDLER(FrameMsg_RevertExitTransition, OnRevertExitTransition)
IPC_MESSAGE_HANDLER(FrameMsg_HideTransitionElements,
OnHideTransitionElements)
IPC_MESSAGE_HANDLER(FrameMsg_ShowTransitionElements,
OnShowTransitionElements)
IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload)
IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest,
OnTextSurroundingSelectionRequest)
IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL,
OnAddStyleSheetByURL)
IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode,
OnSetAccessibilityMode)
IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener)
IPC_MESSAGE_HANDLER(FrameMsg_RequestNavigation, OnRequestNavigation)
IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation)
#if defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
#elif defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
#endif
IPC_END_MESSAGE_MAP()
return handled;
}
void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) {
TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate",
"id", routing_id_,
"url", params.common_params.url.possibly_invalid_spec());
bool is_reload =
RenderViewImpl::IsReload(params.common_params.navigation_type);
bool is_history_navigation = params.commit_params.page_state.IsValid();
WebURLRequest::CachePolicy cache_policy =
WebURLRequest::UseProtocolCachePolicy;
if (!RenderFrameImpl::PrepareRenderViewForNavigation(
params.common_params.url, true, is_history_navigation,
params.current_history_list_offset, &is_reload, &cache_policy)) {
Send(new FrameHostMsg_DidDropNavigation(routing_id_));
return;
}
render_view_->history_list_offset_ = params.current_history_list_offset;
render_view_->history_list_length_ = params.current_history_list_length;
if (params.should_clear_history_list) {
CHECK_EQ(-1, render_view_->history_list_offset_);
CHECK_EQ(0, render_view_->history_list_length_);
}
GetContentClient()->SetActiveURL(params.common_params.url);
WebFrame* frame = frame_;
if (!params.frame_to_navigate.empty()) {
// TODO(nasko): Move this lookup to the browser process.
frame = render_view_->webview()->findFrameByName(
WebString::fromUTF8(params.frame_to_navigate));
CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
}
if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) {
// We cannot reload if we do not have any history state. This happens, for