forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_view_impl.cc
6756 lines (5833 loc) · 247 KB
/
render_view_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 (c) 2012 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_view_impl.h"
#include <algorithm>
#include <cmath>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/debug/trace_event.h"
#include "base/files/file_path.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "content/child/appcache_dispatcher.h"
#include "content/child/child_thread.h"
#include "content/child/fileapi/file_system_dispatcher.h"
#include "content/child/fileapi/webfilesystem_callback_adapters.h"
#include "content/child/npapi/webplugin_delegate_impl.h"
#include "content/child/quota_dispatcher.h"
#include "content/child/request_extra_data.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/clipboard_messages.h"
#include "content/common/database_messages.h"
#include "content/common/drag_messages.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/common/input_messages.h"
#include "content/common/java_bridge_messages.h"
#include "content/common/pepper_messages.h"
#include "content/common/pepper_plugin_registry.h"
#include "content/common/socket_stream_handle_data.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_client.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/drop_data.h"
#include "content/public/common/favicon_url.h"
#include "content/public/common/file_chooser_params.h"
#include "content/public/common/ssl_status.h"
#include "content/public/common/three_d_api_types.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.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/history_item_serialization.h"
#include "content/public/renderer/navigation_state.h"
#include "content/public/renderer/password_form_conversion_utils.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/renderer/render_view_visitor.h"
#include "content/renderer/accessibility/renderer_accessibility.h"
#include "content/renderer/accessibility/renderer_accessibility_complete.h"
#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
#include "content/renderer/browser_plugin/browser_plugin.h"
#include "content/renderer/browser_plugin/browser_plugin_manager.h"
#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
#include "content/renderer/context_menu_params_builder.h"
#include "content/renderer/device_orientation_dispatcher.h"
#include "content/renderer/devtools/devtools_agent.h"
#include "content/renderer/disambiguation_popup_helper.h"
#include "content/renderer/dom_automation_controller.h"
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
#include "content/renderer/drop_data_builder.h"
#include "content/renderer/external_popup_menu.h"
#include "content/renderer/fetchers/alt_error_page_resource_fetcher.h"
#include "content/renderer/geolocation_dispatcher.h"
#include "content/renderer/gpu/input_handler_manager.h"
#include "content/renderer/gpu/render_widget_compositor.h"
#include "content/renderer/idle_user_detector.h"
#include "content/renderer/image_loading_helper.h"
#include "content/renderer/ime_event_guard.h"
#include "content/renderer/input_tag_speech_dispatcher.h"
#include "content/renderer/internal_document_state_data.h"
#include "content/renderer/java/java_bridge_dispatcher.h"
#include "content/renderer/load_progress_tracker.h"
#include "content/renderer/media/audio_device_factory.h"
#include "content/renderer/media/audio_renderer_mixer_manager.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/media_stream_impl.h"
#include "content/renderer/media/render_media_log.h"
#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
#include "content/renderer/media/rtc_peer_connection_handler.h"
#include "content/renderer/media/video_capture_impl_manager.h"
#include "content/renderer/media/webmediaplayer_impl.h"
#include "content/renderer/media/webmediaplayer_ms.h"
#include "content/renderer/media/webmediaplayer_params.h"
#include "content/renderer/mhtml_generator.h"
#include "content/renderer/notification_provider.h"
#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_process.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl_params.h"
#include "content/renderer/render_view_mouse_lock_dispatcher.h"
#include "content/renderer/render_widget_fullscreen_pepper.h"
#include "content/renderer/renderer_date_time_picker.h"
#include "content/renderer/renderer_webapplicationcachehost_impl.h"
#include "content/renderer/renderer_webcolorchooser_impl.h"
#include "content/renderer/savable_resources.h"
#include "content/renderer/speech_recognition_dispatcher.h"
#include "content/renderer/stats_collection_controller.h"
#include "content/renderer/stats_collection_observer.h"
#include "content/renderer/text_input_client_observer.h"
#include "content/renderer/v8_value_converter_impl.h"
#include "content/renderer/web_ui_extension.h"
#include "content/renderer/web_ui_extension_data.h"
#include "content/renderer/webplugin_delegate_proxy.h"
#include "content/renderer/webplugin_impl.h"
#include "content/renderer/websharedworker_proxy.h"
#include "media/audio/audio_output_device.h"
#include "media/base/audio_renderer_mixer_input.h"
#include "media/base/filter_collection.h"
#include "media/base/media_switches.h"
#include "media/filters/audio_renderer_impl.h"
#include "media/filters/gpu_video_decoder.h"
#include "net/base/data_url.h"
#include "net/base/escape.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/WebCString.h"
#include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebFileSystemType.h"
#include "third_party/WebKit/public/platform/WebHTTPBody.h"
#include "third_party/WebKit/public/platform/WebImage.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
#include "third_party/WebKit/public/platform/WebPoint.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/platform/WebSocketStreamHandle.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/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebAccessibilityObject.h"
#include "third_party/WebKit/public/web/WebColorName.h"
#include "third_party/WebKit/public/web/WebDOMEvent.h"
#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebFileChooserParams.h"
#include "third_party/WebKit/public/web/WebFileSystemCallbacks.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebFormControlElement.h"
#include "third_party/WebKit/public/web/WebFormElement.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebHelperPlugin.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebPageSerializer.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
#include "third_party/WebKit/public/web/WebPluginAction.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/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/WebSerializedScriptValue.h"
#include "third_party/WebKit/public/web/WebSettings.h"
#include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebUserMediaClient.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "v8/include/v8.h"
#include "webkit/child/weburlresponse_extradata_impl.h"
#include "webkit/common/dom_storage/dom_storage_types.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/renderer/appcache/web_application_cache_host_impl.h"
#include "webkit/renderer/webpreferences_renderer.h"
#if defined(OS_ANDROID)
#include <cpu-features.h>
#include "content/common/android/device_telephony_info.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/renderer/android/address_detector.h"
#include "content/renderer/android/content_detector.h"
#include "content/renderer/android/email_detector.h"
#include "content/renderer/android/phone_number_detector.h"
#include "content/renderer/media/android/renderer_media_player_manager.h"
#include "content/renderer/media/android/stream_texture_factory_android.h"
#include "content/renderer/media/android/webmediaplayer_android.h"
#include "content/renderer/media/android/webmediaplayer_proxy_android.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h"
#include "third_party/WebKit/public/platform/WebFloatRect.h"
#include "third_party/WebKit/public/web/WebHitTestResult.h"
#include "ui/gfx/rect_f.h"
#if defined(GOOGLE_TV)
#include "content/renderer/media/rtc_video_decoder_bridge_tv.h"
#include "content/renderer/media/rtc_video_decoder_factory_tv.h"
#endif
#elif defined(OS_WIN)
// TODO(port): these files are currently Windows only because they concern:
// * theming
#include "ui/native_theme/native_theme_win.h"
#elif defined(USE_X11)
#include "ui/native_theme/native_theme.h"
#elif defined(OS_MACOSX)
#include "skia/ext/skia_utils_mac.h"
#endif
using WebKit::WebAccessibilityNotification;
using WebKit::WebAccessibilityObject;
using WebKit::WebApplicationCacheHost;
using WebKit::WebApplicationCacheHostClient;
using WebKit::WebCString;
using WebKit::WebColor;
using WebKit::WebColorName;
using WebKit::WebConsoleMessage;
using WebKit::WebContextMenuData;
using WebKit::WebCookieJar;
using WebKit::WebData;
using WebKit::WebDataSource;
using WebKit::WebDocument;
using WebKit::WebDOMEvent;
using WebKit::WebDOMMessageEvent;
using WebKit::WebDragData;
using WebKit::WebDragOperation;
using WebKit::WebDragOperationsMask;
using WebKit::WebEditingAction;
using WebKit::WebElement;
using WebKit::WebExternalPopupMenu;
using WebKit::WebExternalPopupMenuClient;
using WebKit::WebFileChooserCompletion;
using WebKit::WebFileSystem;
using WebKit::WebFileSystemCallbacks;
using WebKit::WebFindOptions;
using WebKit::WebFormControlElement;
using WebKit::WebFormElement;
using WebKit::WebFrame;
using WebKit::WebGestureEvent;
using WebKit::WebHistoryItem;
using WebKit::WebHTTPBody;
using WebKit::WebIconURL;
using WebKit::WebImage;
using WebKit::WebInputElement;
using WebKit::WebInputEvent;
using WebKit::WebMediaPlayer;
using WebKit::WebMediaPlayerAction;
using WebKit::WebMediaPlayerClient;
using WebKit::WebMouseEvent;
using WebKit::WebNavigationPolicy;
using WebKit::WebNavigationType;
using WebKit::WebNode;
using WebKit::WebPageSerializer;
using WebKit::WebPageSerializerClient;
using WebKit::WebPeerConnection00Handler;
using WebKit::WebPeerConnection00HandlerClient;
using WebKit::WebPeerConnectionHandler;
using WebKit::WebPeerConnectionHandlerClient;
using WebKit::WebPluginAction;
using WebKit::WebPluginContainer;
using WebKit::WebPluginDocument;
using WebKit::WebPluginParams;
using WebKit::WebPoint;
using WebKit::WebPopupMenuInfo;
using WebKit::WebRange;
using WebKit::WebRect;
using WebKit::WebReferrerPolicy;
using WebKit::WebScriptSource;
using WebKit::WebSearchableFormData;
using WebKit::WebSecurityOrigin;
using WebKit::WebSecurityPolicy;
using WebKit::WebSerializedScriptValue;
using WebKit::WebSettings;
using WebKit::WebSharedWorker;
using WebKit::WebSize;
using WebKit::WebSocketStreamHandle;
using WebKit::WebStorageNamespace;
using WebKit::WebStorageQuotaCallbacks;
using WebKit::WebStorageQuotaError;
using WebKit::WebStorageQuotaType;
using WebKit::WebString;
using WebKit::WebTextAffinity;
using WebKit::WebTextDirection;
using WebKit::WebTouchEvent;
using WebKit::WebURL;
using WebKit::WebURLError;
using WebKit::WebURLRequest;
using WebKit::WebURLResponse;
using WebKit::WebUserGestureIndicator;
using WebKit::WebVector;
using WebKit::WebView;
using WebKit::WebWidget;
using WebKit::WebWindowFeatures;
using appcache::WebApplicationCacheHostImpl;
using base::Time;
using base::TimeDelta;
using webkit_glue::WebURLResponseExtraDataImpl;
#if defined(OS_ANDROID)
using WebKit::WebContentDetectionResult;
using WebKit::WebFloatPoint;
using WebKit::WebFloatRect;
using WebKit::WebHitTestResult;
#endif
namespace content {
//-----------------------------------------------------------------------------
typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
LAZY_INSTANCE_INITIALIZER;
// Time, in seconds, we delay before sending content state changes (such as form
// state and scroll position) to the browser. We delay sending changes to avoid
// spamming the browser.
// To avoid having tab/session restore require sending a message to get the
// current content state during tab closing we use a shorter timeout for the
// foreground renderer. This means there is a small window of time from which
// content state is modified and not sent to session restore, but this is
// better than having to wake up all renderers during shutdown.
static const int kDelaySecondsForContentStateSyncHidden = 5;
static const int kDelaySecondsForContentStateSync = 1;
static const size_t kExtraCharsBeforeAndAfterSelection = 100;
// The maximum number of popups that can be spawned from one page.
static const int kMaximumNumberOfUnacknowledgedPopups = 25;
static const float kScalingIncrement = 0.1f;
static const float kScalingIncrementForGesture = 0.01f;
#if defined(OS_ANDROID)
// Delay between tapping in content and launching the associated android intent.
// Used to allow users see what has been recognized as content.
static const size_t kContentIntentDelayMilliseconds = 700;
#endif
static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
NULL;
static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
// Replace any occurrences of swappedout:// with about:blank.
const WebURL& blank_url = GURL(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);
}
}
// If |data_source| is non-null and has an InternalDocumentStateData associated
// with it, the AltErrorPageResourceFetcher is reset.
static void StopAltErrorPageFetcher(WebDataSource* data_source) {
if (data_source) {
InternalDocumentStateData* internal_data =
InternalDocumentStateData::FromDataSource(data_source);
if (internal_data)
internal_data->set_alt_error_page_fetcher(NULL);
}
}
static bool IsReload(const ViewMsg_Navigate_Params& params) {
return
params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
params.navigation_type ==
ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
}
static WebReferrerPolicy GetReferrerPolicyFromRequest(
WebFrame* frame,
const WebURLRequest& request) {
return request.extraData() ?
static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
frame->document().referrerPolicy();
}
static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
const WebURLResponse& response) {
return static_cast<WebURLResponseExtraDataImpl*>(
response.extraData());
}
NOINLINE static 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)
NOINLINE static 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.
static const char kCrashDomain[] = "crash";
static const char kHeapOverflow[] = "/heap-overflow";
static const char kHeapUnderflow[] = "/heap-underflow";
static const char kUseAfterFree[] = "/use-after-free";
static const int kArraySize = 5;
if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1))
return;
if (!url.has_path())
return;
scoped_ptr<int[]> array(new int[kArraySize]);
std::string crash_type(url.path());
int dummy = 0;
if (crash_type == kHeapOverflow) {
dummy = array[kArraySize];
} else if (crash_type == kHeapUnderflow ) {
dummy = array[-1];
} else if (crash_type == kUseAfterFree) {
int* dangling = array.get();
array.reset();
dummy = dangling[kArraySize / 2];
}
// Make sure the assignments to the dummy value aren't optimized away.
base::debug::Alias(&dummy);
}
#endif // ADDRESS_SANITIZER
static void MaybeHandleDebugURL(const GURL& url) {
if (!url.SchemeIs(chrome::kChromeUIScheme))
return;
if (url == GURL(kChromeUICrashURL)) {
CrashIntentionally();
} 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)
MaybeTriggerAsanError(url);
#endif // ADDRESS_SANITIZER
}
// Returns false unless this is a top-level navigation.
static bool IsTopLevelNavigation(WebFrame* frame) {
return frame->parent() == NULL;
}
// Returns false unless this is a top-level navigation that crosses origins.
static bool IsNonLocalTopLevelNavigation(const GURL& url,
WebFrame* frame,
WebNavigationType type) {
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(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
return false;
// Not interested in reloads/form submits/resubmits/back forward navigations.
if (type != WebKit::WebNavigationTypeReload &&
type != WebKit::WebNavigationTypeFormSubmitted &&
type != WebKit::WebNavigationTypeFormResubmitted &&
type != WebKit::WebNavigationTypeBackForward) {
// 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.
WebKit::WebFrame* opener = frame->opener();
if (!opener) {
return true;
}
if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
return true;
}
return false;
}
static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(frame->mainWorldScriptContext());
v8::Date::DateTimeConfigurationChangeNotification();
WebKit::WebFrame* child = frame->firstChild();
for (; child; child = child->nextSibling())
NotifyTimezoneChange(child);
}
static WindowOpenDisposition NavigationPolicyToDisposition(
WebNavigationPolicy policy) {
switch (policy) {
case WebKit::WebNavigationPolicyIgnore:
return IGNORE_ACTION;
case WebKit::WebNavigationPolicyDownload:
return SAVE_TO_DISK;
case WebKit::WebNavigationPolicyCurrentTab:
return CURRENT_TAB;
case WebKit::WebNavigationPolicyNewBackgroundTab:
return NEW_BACKGROUND_TAB;
case WebKit::WebNavigationPolicyNewForegroundTab:
return NEW_FOREGROUND_TAB;
case WebKit::WebNavigationPolicyNewWindow:
return NEW_WINDOW;
case WebKit::WebNavigationPolicyNewPopup:
return NEW_POPUP;
default:
NOTREACHED() << "Unexpected WebNavigationPolicy";
return IGNORE_ACTION;
}
}
// Returns true if the device scale is high enough that losing subpixel
// antialiasing won't have a noticeable effect on text quality.
static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
#if defined(OS_ANDROID)
// On Android, we never have subpixel antialiasing.
return true;
#else
return device_scale_factor > 1.5f;
#endif
}
static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
// Compositing for fixed-position elements is dependent on
// device_scale_factor if no flag is set. http://crbug.com/172738
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
return false;
if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseAcceleratedCompositingForOverflowScroll(
float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseTransitionCompositing(float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
return false;
if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
return true;
// TODO(ajuma): Re-enable this by default for high-DPI once the problem
// of excessive layer promotion caused by overlap has been addressed.
// http://crbug.com/178119.
return false;
}
static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
return false;
if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) {
switch (type) {
case WebKit::WebIconURL::TypeFavicon:
return FaviconURL::FAVICON;
case WebKit::WebIconURL::TypeTouch:
return FaviconURL::TOUCH_ICON;
case WebKit::WebIconURL::TypeTouchPrecomposed:
return FaviconURL::TOUCH_PRECOMPOSED_ICON;
case WebKit::WebIconURL::TypeInvalid:
return FaviconURL::INVALID_ICON;
}
return FaviconURL::INVALID_ICON;
}
///////////////////////////////////////////////////////////////////////////////
struct RenderViewImpl::PendingFileChooser {
PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
: params(p),
completion(c) {
}
FileChooserParams params;
WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
};
namespace {
class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
public:
explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
: webwidget_(webwidget) {}
virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
if (succeeded)
webwidget_->didAcquirePointerLock();
else
webwidget_->didNotAcquirePointerLock();
}
virtual void OnMouseLockLost() OVERRIDE {
webwidget_->didLosePointerLock();
}
virtual bool HandleMouseLockedInputEvent(
const WebKit::WebMouseEvent &event) OVERRIDE {
// The WebWidget handles mouse lock in WebKit's handleInputEvent().
return false;
}
private:
WebKit::WebWidget* webwidget_;
};
int64 ExtractPostId(const WebHistoryItem& item) {
if (item.isNull())
return -1;
if (item.httpBody().isNull())
return -1;
return item.httpBody().identifier();
}
bool TouchEnabled() {
// Based on the definition of chrome::kEnableTouchIcon.
#if defined(OS_ANDROID)
return true;
#else
return false;
#endif
}
WebDragData DropDataToWebDragData(const DropData& drop_data) {
std::vector<WebDragData::Item> item_list;
// These fields are currently unused when dragging into WebKit.
DCHECK(drop_data.download_metadata.empty());
DCHECK(drop_data.file_contents.empty());
DCHECK(drop_data.file_description_filename.empty());
if (!drop_data.text.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
item.stringData = drop_data.text.string();
item_list.push_back(item);
}
// TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
// meaningful to write an empty URL to the clipboard?
if (!drop_data.url.is_empty()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
item.stringData = WebString::fromUTF8(drop_data.url.spec());
item.title = drop_data.url_title;
item_list.push_back(item);
}
if (!drop_data.html.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
item.stringData = drop_data.html.string();
item.baseURL = drop_data.html_base_url;
item_list.push_back(item);
}
for (std::vector<DropData::FileInfo>::const_iterator it =
drop_data.filenames.begin();
it != drop_data.filenames.end();
++it) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeFilename;
item.filenameData = it->path;
item.displayNameData = it->display_name;
item_list.push_back(item);
}
for (std::map<base::string16, base::string16>::const_iterator it =
drop_data.custom_data.begin();
it != drop_data.custom_data.end();
++it) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = it->first;
item.stringData = it->second;
item_list.push_back(item);
}
WebDragData result;
result.initialize();
result.setItems(item_list);
result.setFilesystemId(drop_data.filesystem_id);
return result;
}
} // namespace
RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
: RenderWidget(WebKit::WebPopupTypeNone,
params->screen_info,
params->swapped_out),
webkit_preferences_(params->webkit_prefs),
send_content_state_immediately_(false),
enabled_bindings_(0),
send_preferred_size_changes_(false),
is_loading_(false),
navigation_gesture_(NavigationGestureUnknown),
opened_by_user_gesture_(true),
opener_suppressed_(false),
page_id_(-1),
last_page_id_sent_to_browser_(-1),
next_page_id_(params->next_page_id),
history_list_offset_(-1),
history_list_length_(0),
target_url_status_(TARGET_NONE),
selection_text_offset_(0),
selection_range_(ui::Range::InvalidRange()),
#if defined(OS_ANDROID)
top_controls_constraints_(cc::BOTH),
#endif
cached_is_main_frame_pinned_to_left_(false),
cached_is_main_frame_pinned_to_right_(false),
cached_has_main_frame_horizontal_scrollbar_(false),
cached_has_main_frame_vertical_scrollbar_(false),
cookie_jar_(this),
notification_provider_(NULL),
geolocation_dispatcher_(NULL),
input_tag_speech_dispatcher_(NULL),
speech_recognition_dispatcher_(NULL),
device_orientation_dispatcher_(NULL),
media_stream_dispatcher_(NULL),
browser_plugin_manager_(NULL),
media_stream_client_(NULL),
web_user_media_client_(NULL),
devtools_agent_(NULL),
accessibility_mode_(AccessibilityModeOff),
renderer_accessibility_(NULL),
java_bridge_dispatcher_(NULL),
mouse_lock_dispatcher_(NULL),
#if defined(OS_ANDROID)
body_background_color_(SK_ColorWHITE),
expected_content_intent_id_(0),
media_player_proxy_(NULL),
#endif
#if defined(OS_WIN)
focused_plugin_id_(-1),
#endif
enumeration_completion_id_(0),
#if defined(OS_ANDROID)
load_progress_tracker_(new LoadProgressTracker(this)),
#endif
session_storage_namespace_id_(params->session_storage_namespace_id),
decrement_shared_popup_at_destruction_(false),
handling_select_range_(false),
next_snapshot_id_(0),
allow_partial_swap_(params->allow_partial_swap),
context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
}
void RenderViewImpl::Initialize(RenderViewImplParams* params) {
RenderFrameImpl* main_frame = RenderFrameImpl::Create(
this, params->main_frame_routing_id);
main_render_frame_.reset(main_frame);
#if defined(ENABLE_PLUGINS)
pepper_helper_.reset(new PepperPluginDelegateImpl(this));
#else
pepper_helper_.reset(new RenderViewPepperHelper());
#endif
routing_id_ = params->routing_id;
surface_id_ = params->surface_id;
if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
opener_id_ = params->opener_id;
// Ensure we start with a valid next_page_id_ from the browser.
DCHECK_GE(next_page_id_, 0);
#if defined(ENABLE_NOTIFICATIONS)
notification_provider_ = new NotificationProvider(this);
#else
notification_provider_ = NULL;
#endif
webwidget_ = WebView::create(this);
webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kStatsCollectionController))
stats_collection_observer_.reset(new StatsCollectionObserver(this));
#if defined(OS_ANDROID)
content::DeviceTelephonyInfo device_info;
const std::string region_code =
command_line.HasSwitch(switches::kNetworkCountryIso)
? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
: device_info.GetNetworkCountryIso();
content_detectors_.push_back(linked_ptr<ContentDetector>(
new AddressDetector()));
content_detectors_.push_back(linked_ptr<ContentDetector>(
new PhoneNumberDetector(region_code)));
content_detectors_.push_back(linked_ptr<ContentDetector>(
new EmailDetector()));
#endif
if (params->counter) {
shared_popup_counter_ = params->counter;
// Only count this if it isn't swapped out upon creation.
if (!params->swapped_out)
shared_popup_counter_->data++;
decrement_shared_popup_at_destruction_ = true;
} else {
shared_popup_counter_ = new SharedRenderViewCounter(0);
decrement_shared_popup_at_destruction_ = false;
}
RenderThread::Get()->AddRoute(routing_id_, this);
// Take a reference on behalf of the RenderThread. This will be balanced
// when we receive ViewMsg_ClosePage.
AddRef();
// If this is a popup, we must wait for the CreatingNew_ACK message before
// completing initialization. Otherwise, we can finish it now.
if (opener_id_ == MSG_ROUTING_NONE) {
did_show_ = true;
CompleteInit();
}
g_view_map.Get().insert(std::make_pair(webview(), this));
g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
webview()->setDeviceScaleFactor(device_scale_factor_);
webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
ShouldUseFixedPositionCompositing(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
ShouldUseTransitionCompositing(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
webkit_glue::ApplyWebPreferences(webkit_preferences_, webview());
webview()->initializeMainFrame(main_render_frame_.get());
if (switches::IsTouchDragDropEnabled())
webview()->settings()->setTouchDragDropEnabled(true);
if (switches::IsTouchEditingEnabled())
webview()->settings()->setTouchEditingEnabled(true);
if (!params->frame_name.empty())
webview()->mainFrame()->setName(params->frame_name);
OnSetRendererPrefs(params->renderer_prefs);
#if defined(ENABLE_WEBRTC)
if (!media_stream_dispatcher_)
media_stream_dispatcher_ = new MediaStreamDispatcher(this);
#endif
new MHTMLGenerator(this);
#if defined(OS_MACOSX)
new TextInputClientObserver(this);
#endif // defined(OS_MACOSX)
#if defined(OS_ANDROID)
media_player_manager_.reset(new RendererMediaPlayerManager());
#endif
// The next group of objects all implement RenderViewObserver, so are deleted
// along with the RenderView automatically.
devtools_agent_ = new DevToolsAgent(this);
mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
new ImageLoadingHelper(this);
// Create renderer_accessibility_ if needed.
OnSetAccessibilityMode(params->accessibility_mode);
new IdleUserDetector(this);
if (command_line.HasSwitch(switches::kDomAutomationController))
enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
if (command_line.HasSwitch(switches::kStatsCollectionController))
enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
ProcessViewLayoutFlags(command_line);
GetContentClient()->renderer()->RenderViewCreated(this);
// If we have an opener_id but we weren't created by a renderer, then
// it's the browser asking us to set our opener to another RenderView.
if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
if (opener_view)
webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
}
// If we are initially swapped out, navigate to kSwappedOutURL.
// This ensures we are in a unique origin that others cannot script.
if (is_swapped_out_)
NavigateToSwappedOutURL(webview()->mainFrame());
}
RenderViewImpl::~RenderViewImpl() {
history_page_ids_.clear();
if (decrement_shared_popup_at_destruction_)
shared_popup_counter_->data--;
base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
// If file chooser is still waiting for answer, dispatch empty answer.
while (!file_chooser_completions_.empty()) {
if (file_chooser_completions_.front()->completion) {
file_chooser_completions_.front()->completion->didChooseFile(
WebVector<WebString>());
}
file_chooser_completions_.pop_front();
}
#if defined(OS_ANDROID)
// The date/time picker client is both a scoped_ptr member of this class and
// a RenderViewObserver. Reset it to prevent double deletion.
date_time_picker_client_.reset();
#endif
#ifndef NDEBUG
// Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
ViewMap* views = g_view_map.Pointer();
for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)