 Chromium Code Reviews
 Chromium Code Reviews Issue 2900563002:
  Network service: Safe browsing check for sub-resources from renderer.  (Closed)
    
  
    Issue 2900563002:
  Network service: Safe browsing check for sub-resources from renderer.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/renderer/chrome_content_renderer_client.h" | 5 #include "chrome/renderer/chrome_content_renderer_client.h" | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #include "chrome/renderer/net_benchmarking_extension.h" | 50 #include "chrome/renderer/net_benchmarking_extension.h" | 
| 51 #include "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h" | 51 #include "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h" | 
| 52 #include "chrome/renderer/pepper/pepper_helper.h" | 52 #include "chrome/renderer/pepper/pepper_helper.h" | 
| 53 #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" | 53 #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" | 
| 54 #include "chrome/renderer/plugins/plugin_preroller.h" | 54 #include "chrome/renderer/plugins/plugin_preroller.h" | 
| 55 #include "chrome/renderer/plugins/plugin_uma.h" | 55 #include "chrome/renderer/plugins/plugin_uma.h" | 
| 56 #include "chrome/renderer/prerender/prerender_dispatcher.h" | 56 #include "chrome/renderer/prerender/prerender_dispatcher.h" | 
| 57 #include "chrome/renderer/prerender/prerender_helper.h" | 57 #include "chrome/renderer/prerender/prerender_helper.h" | 
| 58 #include "chrome/renderer/prerender/prerenderer_client.h" | 58 #include "chrome/renderer/prerender/prerenderer_client.h" | 
| 59 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 59 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 
| 60 #include "chrome/renderer/safe_browsing/safe_browsing_url_loader_throttle.h" | |
| 60 #include "chrome/renderer/searchbox/search_bouncer.h" | 61 #include "chrome/renderer/searchbox/search_bouncer.h" | 
| 61 #include "chrome/renderer/searchbox/searchbox.h" | 62 #include "chrome/renderer/searchbox/searchbox.h" | 
| 62 #include "chrome/renderer/searchbox/searchbox_extension.h" | 63 #include "chrome/renderer/searchbox/searchbox_extension.h" | 
| 63 #include "chrome/renderer/tts_dispatcher.h" | 64 #include "chrome/renderer/tts_dispatcher.h" | 
| 64 #include "chrome/renderer/worker_content_settings_client_proxy.h" | 65 #include "chrome/renderer/worker_content_settings_client_proxy.h" | 
| 65 #include "components/autofill/content/renderer/autofill_agent.h" | 66 #include "components/autofill/content/renderer/autofill_agent.h" | 
| 66 #include "components/autofill/content/renderer/password_autofill_agent.h" | 67 #include "components/autofill/content/renderer/password_autofill_agent.h" | 
| 67 #include "components/autofill/content/renderer/password_generation_agent.h" | 68 #include "components/autofill/content/renderer/password_generation_agent.h" | 
| 68 #include "components/content_settings/core/common/content_settings_pattern.h" | 69 #include "components/content_settings/core/common/content_settings_pattern.h" | 
| 69 #include "components/contextual_search/renderer/overlay_js_render_frame_observer .h" | 70 #include "components/contextual_search/renderer/overlay_js_render_frame_observer .h" | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 99 #include "extensions/features/features.h" | 100 #include "extensions/features/features.h" | 
| 100 #include "ipc/ipc_sync_channel.h" | 101 #include "ipc/ipc_sync_channel.h" | 
| 101 #include "media/base/media_switches.h" | 102 #include "media/base/media_switches.h" | 
| 102 #include "media/media_features.h" | 103 #include "media/media_features.h" | 
| 103 #include "net/base/net_errors.h" | 104 #include "net/base/net_errors.h" | 
| 104 #include "ppapi/c/private/ppb_pdf.h" | 105 #include "ppapi/c/private/ppb_pdf.h" | 
| 105 #include "ppapi/features/features.h" | 106 #include "ppapi/features/features.h" | 
| 106 #include "ppapi/shared_impl/ppapi_switches.h" | 107 #include "ppapi/shared_impl/ppapi_switches.h" | 
| 107 #include "printing/features/features.h" | 108 #include "printing/features/features.h" | 
| 108 #include "services/service_manager/public/cpp/connector.h" | 109 #include "services/service_manager/public/cpp/connector.h" | 
| 110 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 109 #include "third_party/WebKit/public/platform/URLConversion.h" | 111 #include "third_party/WebKit/public/platform/URLConversion.h" | 
| 110 #include "third_party/WebKit/public/platform/WebCache.h" | 112 #include "third_party/WebKit/public/platform/WebCache.h" | 
| 111 #include "third_party/WebKit/public/platform/WebCachePolicy.h" | 113 #include "third_party/WebKit/public/platform/WebCachePolicy.h" | 
| 112 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 114 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 
| 113 #include "third_party/WebKit/public/platform/WebURL.h" | 115 #include "third_party/WebKit/public/platform/WebURL.h" | 
| 114 #include "third_party/WebKit/public/platform/WebURLError.h" | 116 #include "third_party/WebKit/public/platform/WebURLError.h" | 
| 115 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 117 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 
| 116 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 118 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 
| 117 #include "third_party/WebKit/public/web/WebDataSource.h" | 119 #include "third_party/WebKit/public/web/WebDataSource.h" | 
| 118 #include "third_party/WebKit/public/web/WebDocument.h" | 120 #include "third_party/WebKit/public/web/WebDocument.h" | 
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // |module_event_sink|: it is owned by a ChromeContentRendererClient, which is | 339 // |module_event_sink|: it is owned by a ChromeContentRendererClient, which is | 
| 338 // a leaked singleton in the process. | 340 // a leaked singleton in the process. | 
| 339 io_task_runner->PostTask( | 341 io_task_runner->PostTask( | 
| 340 FROM_HERE, base::Bind(&HandleModuleEventOnIOThread, | 342 FROM_HERE, base::Bind(&HandleModuleEventOnIOThread, | 
| 341 base::Unretained(module_event_sink), event)); | 343 base::Unretained(module_event_sink), event)); | 
| 342 } | 344 } | 
| 343 #endif | 345 #endif | 
| 344 | 346 | 
| 345 } // namespace | 347 } // namespace | 
| 346 | 348 | 
| 349 ChromeContentRendererClient::FrameData::FrameData() = default; | |
| 350 ChromeContentRendererClient::FrameData::~FrameData() = default; | |
| 351 | |
| 347 ChromeContentRendererClient::ChromeContentRendererClient() | 352 ChromeContentRendererClient::ChromeContentRendererClient() | 
| 348 : main_entry_time_(base::TimeTicks::Now()) { | 353 : main_entry_time_(base::TimeTicks::Now()) { | 
| 349 #if BUILDFLAG(ENABLE_EXTENSIONS) | 354 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 350 extensions::ExtensionsClient::Set( | 355 extensions::ExtensionsClient::Set( | 
| 351 extensions::ChromeExtensionsClient::GetInstance()); | 356 extensions::ChromeExtensionsClient::GetInstance()); | 
| 352 extensions::ExtensionsRendererClient::Set( | 357 extensions::ExtensionsRendererClient::Set( | 
| 353 ChromeExtensionsRendererClient::GetInstance()); | 358 ChromeExtensionsRendererClient::GetInstance()); | 
| 354 #endif | 359 #endif | 
| 355 #if BUILDFLAG(ENABLE_PLUGINS) | 360 #if BUILDFLAG(ENABLE_PLUGINS) | 
| 356 for (size_t i = 0; i < arraysize(kPredefinedAllowedCameraDeviceOrigins); ++i) | 361 for (size_t i = 0; i < arraysize(kPredefinedAllowedCameraDeviceOrigins); ++i) | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 } | 492 } | 
| 488 | 493 | 
| 489 #if defined(OS_CHROMEOS) | 494 #if defined(OS_CHROMEOS) | 
| 490 leak_detector_remote_client_.reset(new LeakDetectorRemoteClient()); | 495 leak_detector_remote_client_.reset(new LeakDetectorRemoteClient()); | 
| 491 thread->AddObserver(leak_detector_remote_client_.get()); | 496 thread->AddObserver(leak_detector_remote_client_.get()); | 
| 492 #endif | 497 #endif | 
| 493 } | 498 } | 
| 494 | 499 | 
| 495 void ChromeContentRendererClient::RenderFrameCreated( | 500 void ChromeContentRendererClient::RenderFrameCreated( | 
| 496 content::RenderFrame* render_frame) { | 501 content::RenderFrame* render_frame) { | 
| 497 new ChromeRenderFrameObserver(render_frame); | 502 new ChromeRenderFrameObserver(this, render_frame); | 
| 498 | 503 | 
| 499 bool should_whitelist_for_content_settings = | 504 bool should_whitelist_for_content_settings = | 
| 500 base::CommandLine::ForCurrentProcess()->HasSwitch( | 505 base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 501 switches::kInstantProcess); | 506 switches::kInstantProcess); | 
| 502 extensions::Dispatcher* ext_dispatcher = NULL; | 507 extensions::Dispatcher* ext_dispatcher = NULL; | 
| 503 #if BUILDFLAG(ENABLE_EXTENSIONS) | 508 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 504 ext_dispatcher = | 509 ext_dispatcher = | 
| 505 ChromeExtensionsRendererClient::GetInstance()->extension_dispatcher(); | 510 ChromeExtensionsRendererClient::GetInstance()->extension_dispatcher(); | 
| 506 #endif | 511 #endif | 
| 507 ContentSettingsObserver* content_settings = new ContentSettingsObserver( | 512 ContentSettingsObserver* content_settings = new ContentSettingsObserver( | 
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 return true; | 1192 return true; | 
| 1188 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 1193 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 
| 1189 | 1194 | 
| 1190 return false; | 1195 return false; | 
| 1191 } | 1196 } | 
| 1192 | 1197 | 
| 1193 bool ChromeContentRendererClient::WillSendRequest( | 1198 bool ChromeContentRendererClient::WillSendRequest( | 
| 1194 WebLocalFrame* frame, | 1199 WebLocalFrame* frame, | 
| 1195 ui::PageTransition transition_type, | 1200 ui::PageTransition transition_type, | 
| 1196 const blink::WebURL& url, | 1201 const blink::WebURL& url, | 
| 1197 GURL* new_url) { | 1202 GURL* new_url, | 
| 1203 std::vector<std::unique_ptr<content::URLLoaderThrottle>>* throttles) { | |
| 1198 // Check whether the request should be allowed. If not allowed, we reset the | 1204 // Check whether the request should be allowed. If not allowed, we reset the | 
| 1199 // URL to something invalid to prevent the request and cause an error. | 1205 // URL to something invalid to prevent the request and cause an error. | 
| 1200 #if BUILDFLAG(ENABLE_EXTENSIONS) | 1206 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 1201 if (ChromeExtensionsRendererClient::GetInstance()->WillSendRequest( | 1207 if (ChromeExtensionsRendererClient::GetInstance()->WillSendRequest( | 
| 1202 frame, transition_type, url, new_url)) { | 1208 frame, transition_type, url, new_url)) { | 
| 1203 return true; | 1209 return true; | 
| 1204 } | 1210 } | 
| 1205 #endif | 1211 #endif | 
| 1206 | 1212 | 
| 1213 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1214 switches::kEnableNetworkService)) { | |
| 1215 RenderFrame* render_frame = content::RenderFrame::FromWebFrame(frame); | |
| 1216 auto& frame_data = frame_data_map_[render_frame]; | |
| 1217 if (!frame_data.safe_browsing) { | |
| 1218 render_frame->GetRemoteInterfaces()->GetInterface( | |
| 1219 &frame_data.safe_browsing); | |
| 1220 } | |
| 1221 | |
| 1222 // TODO(yzshen): Is it safe to assume that all URL requests will be aborted | |
| 1223 // before the render frame goes away? Because that is when | |
| 1224 // |frame_data.safe_browsing| goes away. | |
| 
kinuko
2017/05/25 11:30:57
This is actually not true (or not going to be true
 
yzshen1
2017/05/26 20:43:52
Since URL loads may not always associated with ren
 | |
| 1225 throttles->push_back( | |
| 1226 base::MakeUnique<safe_browsing::SafeBrowsingURLLoaderThrottle>( | |
| 1227 frame_data.safe_browsing.get())); | |
| 1228 } | |
| 1229 | |
| 1207 if (!url.ProtocolIs(chrome::kChromeSearchScheme)) | 1230 if (!url.ProtocolIs(chrome::kChromeSearchScheme)) | 
| 1208 return false; | 1231 return false; | 
| 1209 | 1232 | 
| 1210 SearchBox* search_box = | 1233 SearchBox* search_box = | 
| 1211 SearchBox::Get(content::RenderFrame::FromWebFrame(frame->LocalRoot())); | 1234 SearchBox::Get(content::RenderFrame::FromWebFrame(frame->LocalRoot())); | 
| 1212 if (search_box) { | 1235 if (search_box) { | 
| 1213 // Note: this GURL copy could be avoided if host() were added to WebURL. | 1236 // Note: this GURL copy could be avoided if host() were added to WebURL. | 
| 1214 GURL gurl(url); | 1237 GURL gurl(url); | 
| 1215 SearchBox::ImageSourceType type = SearchBox::NONE; | 1238 SearchBox::ImageSourceType type = SearchBox::NONE; | 
| 1216 if (gurl.host_piece() == chrome::kChromeUIFaviconHost) | 1239 if (gurl.host_piece() == chrome::kChromeUIFaviconHost) | 
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 | 1594 | 
| 1572 RecordYouTubeRewriteUMA(result); | 1595 RecordYouTubeRewriteUMA(result); | 
| 1573 return corrected_url.ReplaceComponents(r); | 1596 return corrected_url.ReplaceComponents(r); | 
| 1574 } | 1597 } | 
| 1575 | 1598 | 
| 1576 std::unique_ptr<base::TaskScheduler::InitParams> | 1599 std::unique_ptr<base::TaskScheduler::InitParams> | 
| 1577 ChromeContentRendererClient::GetTaskSchedulerInitParams() { | 1600 ChromeContentRendererClient::GetTaskSchedulerInitParams() { | 
| 1578 return task_scheduler_util:: | 1601 return task_scheduler_util:: | 
| 1579 GetRendererTaskSchedulerInitParamsFromCommandLine(); | 1602 GetRendererTaskSchedulerInitParamsFromCommandLine(); | 
| 1580 } | 1603 } | 
| 1604 | |
| 1605 void ChromeContentRendererClient::OnRenderFrameDestruct( | |
| 1606 content::RenderFrame* frame) { | |
| 1607 frame_data_map_.erase(frame); | |
| 1608 } | |
| OLD | NEW |