forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchrome_content_renderer_client.cc
1474 lines (1309 loc) · 56.2 KB
/
chrome_content_renderer_client.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 "chrome/renderer/chrome_content_renderer_client.h"
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/debug/crash_logging.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/pepper_permission_util.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/secure_origin_whitelist.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
#include "chrome/grit/renderer_resources.h"
#include "chrome/renderer/app_categorizer.h"
#include "chrome/renderer/banners/app_banner_client.h"
#include "chrome/renderer/benchmarking_extension.h"
#include "chrome/renderer/chrome_render_frame_observer.h"
#include "chrome/renderer/chrome_render_thread_observer.h"
#include "chrome/renderer/chrome_render_view_observer.h"
#include "chrome/renderer/content_settings_observer.h"
#include "chrome/renderer/loadtimes_extension_bindings.h"
#include "chrome/renderer/media/chrome_key_systems.h"
#include "chrome/renderer/net/net_error_helper.h"
#include "chrome/renderer/net_benchmarking_extension.h"
#include "chrome/renderer/page_load_histograms.h"
#include "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h"
#include "chrome/renderer/pepper/pepper_helper.h"
#include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h"
#include "chrome/renderer/plugins/plugin_preroller.h"
#include "chrome/renderer/plugins/plugin_uma.h"
#include "chrome/renderer/prerender/prerender_dispatcher.h"
#include "chrome/renderer/prerender/prerender_helper.h"
#include "chrome/renderer/prerender/prerenderer_client.h"
#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
#include "chrome/renderer/safe_browsing/threat_dom_details.h"
#include "chrome/renderer/searchbox/search_bouncer.h"
#include "chrome/renderer/searchbox/searchbox.h"
#include "chrome/renderer/searchbox/searchbox_extension.h"
#include "chrome/renderer/tts_dispatcher.h"
#include "chrome/renderer/worker_content_settings_client_proxy.h"
#include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/password_autofill_agent.h"
#include "components/autofill/content/renderer/password_generation_agent.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/contextual_search/renderer/overlay_js_render_frame_observer.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/dom_distiller/content/renderer/distillability_agent.h"
#include "components/dom_distiller/content/renderer/distiller_js_render_frame_observer.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/error_page/common/localized_error.h"
#include "components/network_hints/renderer/prescient_networking_dispatcher.h"
#include "components/password_manager/content/renderer/credential_manager_client.h"
#include "components/pdf/renderer/pepper_pdf_host.h"
#include "components/plugins/renderer/mobile_youtube_plugin.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "components/startup_metric_utils/common/startup_metric.mojom.h"
#include "components/subresource_filter/content/renderer/ruleset_dealer.h"
#include "components/subresource_filter/content/renderer/subresource_filter_agent.h"
#include "components/version_info/version_info.h"
#include "components/visitedlink/renderer/visitedlink_slave.h"
#include "components/web_cache/renderer/web_cache_impl.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/plugin_instance_throttler.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_visitor.h"
#include "extensions/common/constants.h"
#include "ipc/ipc_sync_channel.h"
#include "net/base/net_errors.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/shared_impl/ppapi_switches.h"
#include "services/shell/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/platform/URLConversion.h"
#include "third_party/WebKit/public/platform/WebCachePolicy.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.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/web/WebCache.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebPluginParams.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/jstemplate_builder.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
#if !defined(DISABLE_NACL)
#include "components/nacl/common/nacl_constants.h"
#include "components/nacl/renderer/nacl_helper.h"
#endif
#if defined(ENABLE_EXTENSIONS)
#include "chrome/common/extensions/chrome_extensions_client.h"
#include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/switches.h"
#include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/renderer_extension_registry.h"
#endif
#if defined(ENABLE_PLUGINS)
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
#include "chrome/renderer/plugins/power_saver_info.h"
#endif
#if defined(ENABLE_PRINTING)
#include "chrome/common/chrome_content_client.h"
#include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
#include "components/printing/renderer/print_web_view_helper.h"
#include "printing/print_settings.h"
#endif
#if defined(ENABLE_PRINT_PREVIEW)
#include "chrome/renderer/pepper/chrome_pdf_print_client.h"
#endif
#if defined(ENABLE_SPELLCHECK)
#include "components/spellcheck/renderer/spellcheck.h"
#include "components/spellcheck/renderer/spellcheck_provider.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "chrome/renderer/media/webrtc_logging_message_filter.h"
#endif
using autofill::AutofillAgent;
using autofill::PasswordAutofillAgent;
using autofill::PasswordGenerationAgent;
using base::ASCIIToUTF16;
using base::UserMetricsAction;
using blink::WebCache;
using blink::WebCachePolicy;
using blink::WebConsoleMessage;
using blink::WebDataSource;
using blink::WebDocument;
using blink::WebFrame;
using blink::WebLocalFrame;
using blink::WebPlugin;
using blink::WebPluginParams;
using blink::WebSecurityOrigin;
using blink::WebSecurityPolicy;
using blink::WebString;
using blink::WebURL;
using blink::WebURLError;
using blink::WebURLRequest;
using blink::WebURLResponse;
using blink::WebVector;
using content::PluginInstanceThrottler;
using content::RenderFrame;
using content::RenderThread;
using content::WebPluginInfo;
using extensions::Extension;
namespace internal {
const char kFlashYouTubeRewriteUMA[] = "Plugin.Flash.YouTubeRewrite";
} // namespace internal
namespace {
void RecordYouTubeRewriteUMA(internal::YouTubeRewriteStatus status) {
UMA_HISTOGRAM_ENUMERATION(internal::kFlashYouTubeRewriteUMA, status,
internal::NUM_PLUGIN_ERROR);
}
// Whitelist PPAPI for Android Runtime for Chromium. (See crbug.com/383937)
#if defined(ENABLE_PLUGINS)
const char* const kPredefinedAllowedCameraDeviceOrigins[] = {
"6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F",
"4EB74897CB187C7633357C2FE832E0AD6A44883A"
};
const char* const kPredefinedAllowedCompositorOrigins[] = {
"6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F",
"4EB74897CB187C7633357C2FE832E0AD6A44883A"
};
#endif
#if defined(ENABLE_PLUGINS)
void AppendParams(const std::vector<base::string16>& additional_names,
const std::vector<base::string16>& additional_values,
WebVector<WebString>* existing_names,
WebVector<WebString>* existing_values) {
DCHECK(additional_names.size() == additional_values.size());
DCHECK(existing_names->size() == existing_values->size());
size_t existing_size = existing_names->size();
size_t total_size = existing_size + additional_names.size();
WebVector<WebString> names(total_size);
WebVector<WebString> values(total_size);
for (size_t i = 0; i < existing_size; ++i) {
names[i] = (*existing_names)[i];
values[i] = (*existing_values)[i];
}
for (size_t i = 0; i < additional_names.size(); ++i) {
names[existing_size + i] = additional_names[i];
values[existing_size + i] = additional_values[i];
}
existing_names->swap(names);
existing_values->swap(values);
}
// For certain sandboxed Pepper plugins, use the JavaScript Content Settings.
bool ShouldUseJavaScriptSettingForPlugin(const WebPluginInfo& plugin) {
if (plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS &&
plugin.type != WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS) {
return false;
}
#if !defined(DISABLE_NACL)
// Treat Native Client invocations like JavaScript.
if (plugin.name == ASCIIToUTF16(nacl::kNaClPluginName))
return true;
#endif
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
// Treat CDM invocations like JavaScript.
if (plugin.name == ASCIIToUTF16(kWidevineCdmDisplayName)) {
DCHECK(plugin.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS);
return true;
}
#endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
return false;
}
#endif // defined(ENABLE_PLUGINS)
#if defined(ENABLE_SPELLCHECK)
class SpellCheckReplacer : public content::RenderViewVisitor {
public:
explicit SpellCheckReplacer(SpellCheck* spellcheck)
: spellcheck_(spellcheck) {}
bool Visit(content::RenderView* render_view) override;
private:
SpellCheck* spellcheck_; // New shared spellcheck for all views. Weak Ptr.
DISALLOW_COPY_AND_ASSIGN(SpellCheckReplacer);
};
bool SpellCheckReplacer::Visit(content::RenderView* render_view) {
SpellCheckProvider* provider = SpellCheckProvider::Get(render_view);
DCHECK(provider);
provider->set_spellcheck(spellcheck_);
return true;
}
#endif
#if defined(ENABLE_EXTENSIONS)
bool IsStandaloneExtensionProcess() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
extensions::switches::kExtensionProcess);
}
#endif
// Defers media player loading in background pages until they're visible.
// TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135
class MediaLoadDeferrer : public content::RenderFrameObserver {
public:
MediaLoadDeferrer(content::RenderFrame* render_frame,
const base::Closure& continue_loading_cb)
: content::RenderFrameObserver(render_frame),
continue_loading_cb_(continue_loading_cb) {}
~MediaLoadDeferrer() override {}
private:
// content::RenderFrameObserver implementation:
void WasShown() override {
continue_loading_cb_.Run();
delete this;
}
void OnDestruct() override { delete this; }
const base::Closure continue_loading_cb_;
DISALLOW_COPY_AND_ASSIGN(MediaLoadDeferrer);
};
} // namespace
ChromeContentRendererClient::ChromeContentRendererClient()
: main_entry_time_(base::TimeTicks::Now()) {
#if defined(ENABLE_EXTENSIONS)
extensions::ExtensionsClient::Set(
extensions::ChromeExtensionsClient::GetInstance());
extensions::ExtensionsRendererClient::Set(
ChromeExtensionsRendererClient::GetInstance());
#endif
#if defined(ENABLE_PLUGINS)
for (size_t i = 0; i < arraysize(kPredefinedAllowedCameraDeviceOrigins); ++i)
allowed_camera_device_origins_.insert(
kPredefinedAllowedCameraDeviceOrigins[i]);
for (size_t i = 0; i < arraysize(kPredefinedAllowedCompositorOrigins); ++i)
allowed_compositor_origins_.insert(kPredefinedAllowedCompositorOrigins[i]);
#endif
#if defined(ENABLE_PRINTING)
printing::SetAgent(GetUserAgent());
#endif
}
ChromeContentRendererClient::~ChromeContentRendererClient() {
}
void ChromeContentRendererClient::RenderThreadStarted() {
RenderThread* thread = RenderThread::Get();
{
startup_metric_utils::mojom::StartupMetricHostPtr startup_metric_host;
thread->GetRemoteInterfaces()->GetInterface(&startup_metric_host);
startup_metric_host->RecordRendererMainEntryTime(main_entry_time_);
}
chrome_observer_.reset(new ChromeRenderThreadObserver());
web_cache_impl_.reset(new web_cache::WebCacheImpl());
#if defined(ENABLE_EXTENSIONS)
ChromeExtensionsRendererClient::GetInstance()->RenderThreadStarted();
#endif
prescient_networking_dispatcher_.reset(
new network_hints::PrescientNetworkingDispatcher());
#if defined(ENABLE_SPELLCHECK)
// ChromeRenderViewTest::SetUp() creates a Spellcheck and injects it using
// SetSpellcheck(). Don't overwrite it.
if (!spellcheck_) {
spellcheck_.reset(new SpellCheck());
thread->AddObserver(spellcheck_.get());
}
#endif
visited_link_slave_.reset(new visitedlink::VisitedLinkSlave());
#if defined(FULL_SAFE_BROWSING)
phishing_classifier_.reset(safe_browsing::PhishingClassifierFilter::Create());
#endif
prerender_dispatcher_.reset(new prerender::PrerenderDispatcher());
subresource_filter_ruleset_dealer_.reset(
new subresource_filter::RulesetDealer());
#if defined(ENABLE_WEBRTC)
webrtc_logging_message_filter_ =
new WebRtcLoggingMessageFilter(thread->GetIOTaskRunner());
#endif
thread->AddObserver(chrome_observer_.get());
#if defined(FULL_SAFE_BROWSING)
thread->AddObserver(phishing_classifier_.get());
#endif
thread->AddObserver(visited_link_slave_.get());
thread->AddObserver(prerender_dispatcher_.get());
thread->AddObserver(subresource_filter_ruleset_dealer_.get());
thread->AddObserver(SearchBouncer::GetInstance());
#if defined(ENABLE_WEBRTC)
thread->AddFilter(webrtc_logging_message_filter_.get());
#endif
thread->RegisterExtension(extensions_v8::LoadTimesExtension::Get());
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableBenchmarking))
thread->RegisterExtension(extensions_v8::BenchmarkingExtension::Get());
if (command_line->HasSwitch(switches::kEnableNetBenchmarking))
thread->RegisterExtension(extensions_v8::NetBenchmarkingExtension::Get());
if (command_line->HasSwitch(switches::kInstantProcess))
thread->RegisterExtension(extensions_v8::SearchBoxExtension::Get());
// chrome-search: and chrome-distiller: pages should not be accessible by
// normal content, and should also be unable to script anything but themselves
// (to help limit the damage that a corrupt page could cause).
WebString chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme));
// The Instant process can only display the content but not read it. Other
// processes can't display it or read it.
if (!command_line->HasSwitch(switches::kInstantProcess))
WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme);
WebString dom_distiller_scheme(
ASCIIToUTF16(dom_distiller::kDomDistillerScheme));
// TODO(nyquist): Add test to ensure this happens when the flag is set.
WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dom_distiller_scheme);
#if defined(OS_CHROMEOS)
WebSecurityPolicy::registerURLSchemeAsLocal(
WebString::fromUTF8(content::kExternalFileScheme));
#endif
#if defined(OS_ANDROID)
WebSecurityPolicy::registerURLSchemeAsAllowedForReferrer(
WebString::fromUTF8(chrome::kAndroidAppScheme));
#endif
// chrome-search: pages should not be accessible by bookmarklets
// or javascript: URLs typed in the omnibox.
WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
chrome_search_scheme);
// chrome-search: resources shouldn't trigger insecure content warnings. Note
// that chrome-extension: and chrome-extension-resource: schemes are taken
// care of in extensions::Dispatcher.
WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme);
#if defined(ENABLE_PRINT_PREVIEW)
pdf_print_client_.reset(new ChromePDFPrintClient());
pdf::PepperPDFHost::SetPrintClient(pdf_print_client_.get());
#endif
std::set<GURL> origins;
GetSecureOriginWhitelist(&origins);
for (const GURL& origin : origins) {
WebSecurityPolicy::addOriginTrustworthyWhiteList(
WebSecurityOrigin::create(origin));
}
std::set<std::string> schemes;
GetSchemesBypassingSecureContextCheckWhitelist(&schemes);
for (const std::string& scheme : schemes) {
WebSecurityPolicy::addSchemeToBypassSecureContextWhitelist(
WebString::fromUTF8(scheme));
}
#if defined(OS_CHROMEOS)
leak_detector_remote_client_.reset(new LeakDetectorRemoteClient());
thread->AddObserver(leak_detector_remote_client_.get());
#endif
}
void ChromeContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
new ChromeRenderFrameObserver(render_frame);
bool should_whitelist_for_content_settings =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kInstantProcess);
extensions::Dispatcher* ext_dispatcher = NULL;
#if defined(ENABLE_EXTENSIONS)
ext_dispatcher =
ChromeExtensionsRendererClient::GetInstance()->extension_dispatcher();
#endif
ContentSettingsObserver* content_settings = new ContentSettingsObserver(
render_frame, ext_dispatcher, should_whitelist_for_content_settings);
if (chrome_observer_.get()) {
content_settings->SetContentSettingRules(
chrome_observer_->content_setting_rules());
}
#if defined(ENABLE_EXTENSIONS)
ChromeExtensionsRendererClient::GetInstance()->RenderFrameCreated(
render_frame);
#endif
#if defined(ENABLE_PLUGINS)
new PepperHelper(render_frame);
#endif
#if !defined(DISABLE_NACL)
new nacl::NaClHelper(render_frame);
#endif
#if defined(FULL_SAFE_BROWSING)
safe_browsing::ThreatDOMDetails::Create(render_frame);
#endif
new NetErrorHelper(render_frame);
if (render_frame->IsMainFrame()) {
// Only attach MainRenderFrameObserver to the main frame, since
// we only want to log page load metrics for the main frame.
new page_load_metrics::MetricsRenderFrameObserver(render_frame);
} else {
// Avoid any race conditions from having the browser tell subframes that
// they're prerendering.
if (prerender::PrerenderHelper::IsPrerendering(
render_frame->GetRenderView()->GetMainRenderFrame())) {
new prerender::PrerenderHelper(render_frame);
}
}
// Set up a mojo service to test if this page is a distiller page.
new dom_distiller::DistillerJsRenderFrameObserver(
render_frame, chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL);
// Create DistillabilityAgent to send distillability updates to
// DistillabilityDriver in the browser process.
new dom_distiller::DistillabilityAgent(render_frame);
// Set up a mojo service to test if this page is a contextual search page.
new contextual_search::OverlayJsRenderFrameObserver(render_frame);
PasswordAutofillAgent* password_autofill_agent =
new PasswordAutofillAgent(render_frame);
PasswordGenerationAgent* password_generation_agent =
new PasswordGenerationAgent(render_frame, password_autofill_agent);
new AutofillAgent(render_frame, password_autofill_agent,
password_generation_agent);
// There is no render thread, thus no RulesetDealer in ChromeRenderViewTests.
if (subresource_filter_ruleset_dealer_) {
new subresource_filter::SubresourceFilterAgent(
render_frame, subresource_filter_ruleset_dealer_.get());
}
}
void ChromeContentRendererClient::RenderViewCreated(
content::RenderView* render_view) {
#if defined(ENABLE_EXTENSIONS)
ChromeExtensionsRendererClient::GetInstance()->RenderViewCreated(render_view);
#endif
new PageLoadHistograms(render_view);
#if defined(ENABLE_PRINTING)
new printing::PrintWebViewHelper(
render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>(
new ChromePrintWebViewHelperDelegate()));
#endif
#if defined(ENABLE_SPELLCHECK)
new SpellCheckProvider(render_view, spellcheck_.get());
#endif
new prerender::PrerendererClient(render_view);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kInstantProcess))
new SearchBox(render_view);
new ChromeRenderViewObserver(render_view, web_cache_impl_.get());
new password_manager::CredentialManagerClient(render_view);
}
SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() {
return const_cast<SkBitmap*>(ResourceBundle::GetSharedInstance().
GetImageNamed(IDR_SAD_PLUGIN).ToSkBitmap());
}
SkBitmap* ChromeContentRendererClient::GetSadWebViewBitmap() {
return const_cast<SkBitmap*>(ResourceBundle::GetSharedInstance().
GetImageNamed(IDR_SAD_WEBVIEW).ToSkBitmap());
}
bool ChromeContentRendererClient::OverrideCreatePlugin(
content::RenderFrame* render_frame,
WebLocalFrame* frame,
const WebPluginParams& params,
WebPlugin** plugin) {
std::string orig_mime_type = params.mimeType.utf8();
#if defined(ENABLE_EXTENSIONS)
if (!ChromeExtensionsRendererClient::GetInstance()->OverrideCreatePlugin(
render_frame, params)) {
return false;
}
#endif
GURL url(params.url);
#if defined(ENABLE_PLUGINS)
ChromeViewHostMsg_GetPluginInfo_Output output;
WebString top_origin = frame->top()->getSecurityOrigin().toString();
render_frame->Send(new ChromeViewHostMsg_GetPluginInfo(
render_frame->GetRoutingID(), url, blink::WebStringToGURL(top_origin),
orig_mime_type, &output));
*plugin = CreatePlugin(render_frame, frame, params, output);
#else // !defined(ENABLE_PLUGINS)
#if defined(OS_ANDROID)
if (plugins::MobileYouTubePlugin::IsYouTubeURL(url, orig_mime_type)) {
base::StringPiece template_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_MOBILE_YOUTUBE_PLUGIN_HTML));
*plugin = (new plugins::MobileYouTubePlugin(render_frame, frame, params,
template_html))->plugin();
return true;
}
#endif // defined(OS_ANDROID)
PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url);
*plugin = NonLoadablePluginPlaceholder::CreateNotSupportedPlugin(
render_frame, frame, params)->plugin();
#endif // defined(ENABLE_PLUGINS)
return true;
}
WebPlugin* ChromeContentRendererClient::CreatePluginReplacement(
content::RenderFrame* render_frame,
const base::FilePath& plugin_path) {
return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame,
plugin_path)->plugin();
}
void ChromeContentRendererClient::DeferMediaLoad(
content::RenderFrame* render_frame,
bool has_played_media_before,
const base::Closure& closure) {
// Don't allow autoplay/autoload of media resources in a RenderFrame that is
// hidden and has never played any media before. We want to allow future
// loads even when hidden to allow playlist-like functionality.
//
// NOTE: This is also used to defer media loading for prerender.
// NOTE: Switch can be used to allow autoplay, unless frame is prerendered.
//
// TODO(dalecurtis): Include an idle check too. http://crbug.com/509135
if ((render_frame->IsHidden() && !has_played_media_before &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGestureRequirementForMediaPlayback)) ||
prerender::PrerenderHelper::IsPrerendering(render_frame)) {
new MediaLoadDeferrer(render_frame, closure);
return;
}
closure.Run();
}
#if defined(ENABLE_PLUGINS)
WebPlugin* ChromeContentRendererClient::CreatePlugin(
content::RenderFrame* render_frame,
WebLocalFrame* frame,
const WebPluginParams& original_params,
const ChromeViewHostMsg_GetPluginInfo_Output& output) {
const WebPluginInfo& info = output.plugin;
const std::string& actual_mime_type = output.actual_mime_type;
const base::string16& group_name = output.group_name;
const std::string& identifier = output.group_identifier;
ChromeViewHostMsg_GetPluginInfo_Status status = output.status;
GURL url(original_params.url);
std::string orig_mime_type = original_params.mimeType.utf8();
ChromePluginPlaceholder* placeholder = NULL;
// If the browser plugin is to be enabled, this should be handled by the
// renderer, so the code won't reach here due to the early exit in
// OverrideCreatePlugin.
if (status == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound ||
orig_mime_type == content::kBrowserPluginMimeType) {
PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url);
placeholder = ChromePluginPlaceholder::CreateLoadableMissingPlugin(
render_frame, frame, original_params);
} else {
// TODO(bauerb): This should be in content/.
WebPluginParams params(original_params);
for (size_t i = 0; i < info.mime_types.size(); ++i) {
if (info.mime_types[i].mime_type == actual_mime_type) {
AppendParams(info.mime_types[i].additional_param_names,
info.mime_types[i].additional_param_values,
¶ms.attributeNames, ¶ms.attributeValues);
break;
}
}
if (params.mimeType.isNull() && (actual_mime_type.size() > 0)) {
// Webkit might say that mime type is null while we already know the
// actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case
// we should use what we know since WebpluginDelegateProxy does some
// specific initializations based on this information.
params.mimeType = WebString::fromUTF8(actual_mime_type.c_str());
}
ContentSettingsObserver* observer =
ContentSettingsObserver::Get(render_frame);
const ContentSettingsType content_type =
ShouldUseJavaScriptSettingForPlugin(info)
? CONTENT_SETTINGS_TYPE_JAVASCRIPT
: CONTENT_SETTINGS_TYPE_PLUGINS;
if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized ||
status == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked) &&
observer->IsPluginTemporarilyAllowed(identifier)) {
status = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed;
}
auto create_blocked_plugin = [&render_frame, &frame, ¶ms, &info,
&identifier, &group_name](
int template_id, const base::string16& message) {
return ChromePluginPlaceholder::CreateBlockedPlugin(
render_frame, frame, params, info, identifier, group_name,
template_id, message, PowerSaverInfo());
};
switch (status) {
case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
NOTREACHED();
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed:
case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
#if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
const bool is_nacl_plugin =
info.name == ASCIIToUTF16(nacl::kNaClPluginName);
const bool is_nacl_mime_type =
actual_mime_type == nacl::kNaClPluginMimeType;
const bool is_pnacl_mime_type =
actual_mime_type == nacl::kPnaclPluginMimeType;
if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) {
bool is_nacl_unrestricted = false;
if (is_nacl_mime_type) {
is_nacl_unrestricted =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaCl);
} else if (is_pnacl_mime_type) {
is_nacl_unrestricted = true;
}
GURL manifest_url;
GURL app_url;
if (is_nacl_mime_type || is_pnacl_mime_type) {
// Normal NaCl/PNaCl embed. The app URL is the page URL.
manifest_url = url;
app_url = frame->top()->document().url();
} else {
// NaCl is being invoked as a content handler. Look up the NaCl
// module using the MIME type. The app URL is the manifest URL.
manifest_url = GetNaClContentHandlerURL(actual_mime_type, info);
app_url = manifest_url;
}
const Extension* extension =
extensions::RendererExtensionRegistry::Get()
->GetExtensionOrAppByURL(manifest_url);
if (!IsNaClAllowed(manifest_url,
app_url,
is_nacl_unrestricted,
extension,
¶ms)) {
WebString error_message;
if (is_nacl_mime_type) {
error_message =
"Only unpacked extensions and apps installed from the Chrome "
"Web Store can load NaCl modules without enabling Native "
"Client in about:flags.";
} else if (is_pnacl_mime_type) {
error_message =
"Portable Native Client must not be disabled in about:flags.";
}
frame->addMessageToConsole(
WebConsoleMessage(WebConsoleMessage::LevelError,
error_message));
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
#if defined(OS_CHROMEOS)
l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED));
#else
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name));
#endif
break;
}
}
#endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
// Delay loading plugins if prerendering.
// TODO(mmenke): In the case of prerendering, feed into
// ChromeContentRendererClient::CreatePlugin instead, to
// reduce the chance of future regressions.
bool is_prerendering =
prerender::PrerenderHelper::IsPrerendering(render_frame);
bool power_saver_setting_on =
status ==
ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
PowerSaverInfo power_saver_info =
PowerSaverInfo::Get(render_frame, power_saver_setting_on, params,
info, frame->document().url());
// Prevent small plugins from loading by using a placeholder until
// we can determine the unobscured size of the object.
bool blocked_for_tinyness =
ChromePluginPlaceholder::IsSmallContentFilterEnabled() &&
power_saver_info.power_saver_enabled;
if (power_saver_info.blocked_for_background_tab || is_prerendering ||
!power_saver_info.poster_attribute.empty() ||
blocked_for_tinyness) {
placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
render_frame, frame, params, info, identifier, group_name,
power_saver_info.poster_attribute.empty()
? IDR_BLOCKED_PLUGIN_HTML
: IDR_PLUGIN_POSTER_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
power_saver_info);
placeholder->set_blocked_for_prerendering(is_prerendering);
placeholder->set_blocked_for_tinyness(blocked_for_tinyness);
placeholder->AllowLoading();
break;
}
std::unique_ptr<content::PluginInstanceThrottler> throttler;
if (power_saver_info.power_saver_enabled) {
throttler =
PluginInstanceThrottler::Create(RenderFrame::RECORD_DECISION);
// PluginPreroller manages its own lifetime.
new PluginPreroller(
render_frame, frame, params, info, identifier, group_name,
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
throttler.get());
}
return render_frame->CreatePlugin(frame, info, params,
std::move(throttler));
}
case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled: {
PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type,
url);
placeholder = create_blocked_plugin(
IDR_DISABLED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED, group_name));
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked: {
#if defined(ENABLE_PLUGIN_INSTALLATION)
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED, group_name));
placeholder->AllowLoading();
render_frame->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin(
render_frame->GetRoutingID(), placeholder->CreateRoutingId(),
identifier));
#else
NOTREACHED();
#endif
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed: {
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED, group_name));
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized: {
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, group_name));
placeholder->AllowLoading();
render_frame->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin(
render_frame->GetRoutingID(), group_name, identifier));
observer->DidBlockContentType(content_type, group_name);
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked: {
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name));
placeholder->AllowLoading();
RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked"));
observer->DidBlockContentType(content_type, group_name);
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy: {
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED_BY_POLICY,
group_name));
RenderThread::Get()->RecordAction(
UserMetricsAction("Plugin_BlockedByPolicy"));
observer->DidBlockContentType(content_type, group_name);
break;
}
case ChromeViewHostMsg_GetPluginInfo_Status::kComponentUpdateRequired: {
placeholder = create_blocked_plugin(
IDR_BLOCKED_PLUGIN_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED, group_name));
placeholder->AllowLoading();
render_frame->Send(new ChromeViewHostMsg_BlockedComponentUpdatedPlugin(
render_frame->GetRoutingID(), placeholder->CreateRoutingId(),
identifier));
break;
}
}
}
placeholder->SetStatus(status);
return placeholder->plugin();
}
#endif // defined(ENABLE_PLUGINS)
// For NaCl content handling plugins, the NaCl manifest is stored in an
// additonal 'nacl' param associated with the MIME type.
// static
GURL ChromeContentRendererClient::GetNaClContentHandlerURL(
const std::string& actual_mime_type,
const content::WebPluginInfo& plugin) {
// Look for the manifest URL among the MIME type's additonal parameters.
const char kNaClPluginManifestAttribute[] = "nacl";
base::string16 nacl_attr = ASCIIToUTF16(kNaClPluginManifestAttribute);
for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
if (plugin.mime_types[i].mime_type == actual_mime_type) {
const content::WebPluginMimeType& content_type = plugin.mime_types[i];
for (size_t i = 0; i < content_type.additional_param_names.size(); ++i) {
if (content_type.additional_param_names[i] == nacl_attr)
return GURL(content_type.additional_param_values[i]);
}
break;
}
}
return GURL();
}
#if !defined(DISABLE_NACL)
// static
bool ChromeContentRendererClient::IsNaClAllowed(
const GURL& manifest_url,
const GURL& app_url,
bool is_nacl_unrestricted,
const Extension* extension,
WebPluginParams* params) {
// Temporarily allow these whitelisted apps and WebUIs to use NaCl.
bool is_whitelisted_web_ui =
app_url.spec() == chrome::kChromeUIAppListStartPageURL;
bool is_invoked_by_webstore_installed_extension = false;
bool is_extension_unrestricted = false;
bool is_extension_force_installed = false;
#if defined(ENABLE_EXTENSIONS)
bool is_extension_from_webstore = extension && extension->from_webstore();
bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension");
bool is_invoked_by_hosted_app = extension &&
extension->is_hosted_app() &&
extension->web_extent().MatchesURL(app_url);
is_invoked_by_webstore_installed_extension = is_extension_from_webstore &&
(is_invoked_by_extension || is_invoked_by_hosted_app);
// Allow built-in extensions and developer mode extensions.
is_extension_unrestricted = extension &&
(extensions::Manifest::IsUnpackedLocation(extension->location()) ||
extensions::Manifest::IsComponentLocation(extension->location()));
// Allow extensions force installed by admin policy.
is_extension_force_installed = extension &&
extensions::Manifest::IsPolicyLocation(extension->location());
#endif // defined(ENABLE_EXTENSIONS)
// Allow NaCl under any of the following circumstances:
// 1) An app or URL is explictly whitelisted above.
// 2) An extension is loaded unpacked or built-in (component) to Chrome.
// 3) An extension is force installed by policy.
// 4) An extension is installed from the webstore, and invoked in that
// context (hosted app URL or chrome-extension:// scheme).
// 5) --enable-nacl is set.
bool is_nacl_allowed_by_location =
is_whitelisted_web_ui ||
AppCategorizer::IsWhitelistedApp(manifest_url, app_url) ||
is_extension_unrestricted ||
is_extension_force_installed ||
is_invoked_by_webstore_installed_extension;
bool is_nacl_allowed = is_nacl_allowed_by_location || is_nacl_unrestricted;
if (is_nacl_allowed) {
// Make sure that PPAPI 'dev' interfaces are only available for unpacked
// and component extensions. Also allow dev interfaces when --enable-nacl
// is set, but do not allow --enable-nacl to provide dev interfaces to
// webstore installed and other normally allowed URLs.
WebString dev_attribute = WebString::fromUTF8("@dev");
if (is_extension_unrestricted ||
(is_nacl_unrestricted && !is_nacl_allowed_by_location)) {
// Add the special '@dev' attribute.
std::vector<base::string16> param_names;
std::vector<base::string16> param_values;
param_names.push_back(dev_attribute);
param_values.push_back(WebString());
AppendParams(
param_names,
param_values,
¶ms->attributeNames,
¶ms->attributeValues);
} else {
// If the params somehow contain '@dev', remove it.
size_t attribute_count = params->attributeNames.size();
for (size_t i = 0; i < attribute_count; ++i) {
if (params->attributeNames[i].equals(dev_attribute))
params->attributeNames[i] = WebString();
}
}
}
return is_nacl_allowed;
}
#endif // defined(DISABLE_NACL)
bool ChromeContentRendererClient::HasErrorPage(int http_status_code,
std::string* error_domain) {