| 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/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/download/download_request_limiter.h" | 13 #include "chrome/browser/download/download_request_limiter.h" |
| 14 #include "chrome/browser/download/download_resource_throttle.h" | 14 #include "chrome/browser/download/download_resource_throttle.h" |
| 15 #include "chrome/browser/download/download_util.h" | 15 #include "chrome/browser/download/download_util.h" |
| 16 #include "chrome/browser/extensions/user_script_listener.h" | 16 #include "chrome/browser/extensions/user_script_listener.h" |
| 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 17 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 18 #include "chrome/browser/google/google_util.h" | 18 #include "chrome/browser/google/google_util.h" |
| 19 #include "chrome/browser/instant/instant_loader.h" | 19 #include "chrome/browser/instant/instant_loader.h" |
| 20 #include "chrome/browser/net/load_timing_observer.h" | 20 #include "chrome/browser/net/load_timing_observer.h" |
| 21 #include "chrome/browser/prerender/prerender_manager.h" | 21 #include "chrome/browser/prerender/prerender_manager.h" |
| 22 #include "chrome/browser/prerender/prerender_manager_factory.h" | |
| 23 #include "chrome/browser/prerender/prerender_tracker.h" | 22 #include "chrome/browser/prerender/prerender_tracker.h" |
| 24 #include "chrome/browser/profiles/profile_io_data.h" | 23 #include "chrome/browser/profiles/profile_io_data.h" |
| 25 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" | 24 #include "chrome/browser/renderer_host/chrome_url_request_user_data.h" |
| 26 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" | 25 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h" |
| 27 #include "chrome/browser/renderer_host/transfer_navigation_resource_throttle.h" | 26 #include "chrome/browser/renderer_host/transfer_navigation_resource_throttle.h" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 29 #include "chrome/browser/ui/auto_login_prompter.h" | 28 #include "chrome/browser/ui/auto_login_prompter.h" |
| 30 #include "chrome/browser/ui/login/login_prompt.h" | 29 #include "chrome/browser/ui/login/login_prompt.h" |
| 31 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 30 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 32 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 33 #include "chrome/common/extensions/user_script.h" | 32 #include "chrome/common/extensions/user_script.h" |
| 34 #include "chrome/common/metrics/experiments_helper.h" | 33 #include "chrome/common/metrics/experiments_helper.h" |
| 35 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" | 34 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" |
| 36 #include "chrome/common/render_messages.h" | 35 #include "chrome/common/render_messages.h" |
| 37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/render_view_host_delegate.h" | |
| 41 #include "content/public/browser/render_widget_host_view.h" | |
| 42 #include "content/public/browser/resource_context.h" | 39 #include "content/public/browser/resource_context.h" |
| 43 #include "content/public/browser/resource_dispatcher_host.h" | 40 #include "content/public/browser/resource_dispatcher_host.h" |
| 44 #include "content/public/browser/resource_request_info.h" | 41 #include "content/public/browser/resource_request_info.h" |
| 45 #include "content/public/browser/web_contents.h" | |
| 46 #include "content/public/browser/web_contents_view.h" | |
| 47 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 48 #include "net/base/ssl_config_service.h" | 43 #include "net/base/ssl_config_service.h" |
| 49 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
| 50 #include "ui/gfx/size.h" | |
| 51 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | 45 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
| 52 | 46 |
| 53 // TODO(oshima): Enable this for other platforms. | 47 // TODO(oshima): Enable this for other platforms. |
| 54 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 55 #include "chrome/browser/renderer_host/offline_resource_throttle.h" | 49 #include "chrome/browser/renderer_host/offline_resource_throttle.h" |
| 56 #endif | 50 #endif |
| 57 | 51 |
| 58 using content::BrowserThread; | 52 using content::BrowserThread; |
| 59 using content::RenderViewHost; | 53 using content::RenderViewHost; |
| 60 using content::ResourceDispatcherHostLoginDelegate; | 54 using content::ResourceDispatcherHostLoginDelegate; |
| 61 using content::ResourceRequestInfo; | 55 using content::ResourceRequestInfo; |
| 62 | 56 |
| 63 namespace { | 57 namespace { |
| 64 | 58 |
| 65 // TODO(gavinp): Remove this after https://bugs.webkit.org/show_bug.cgi?id=85005 | |
| 66 // lands in WebKit. | |
| 67 void AddPrerenderOnUI( | |
| 68 int render_process_id, int render_view_id, | |
| 69 const GURL& url, const content::Referrer& referrer) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 71 prerender::PrerenderManager* prerender_manager = | |
| 72 prerender::FindPrerenderManagerUsingRenderProcessId(render_process_id); | |
| 73 if (!prerender_manager) | |
| 74 return; | |
| 75 | |
| 76 RenderViewHost* render_view_host = | |
| 77 RenderViewHost::FromID(render_process_id, render_view_id); | |
| 78 if (!render_view_host) | |
| 79 return; | |
| 80 gfx::Rect tab_bounds; | |
| 81 if (content::WebContents* source_wc = | |
| 82 render_view_host->GetDelegate()->GetAsWebContents()) | |
| 83 source_wc->GetView()->GetContainerBounds(&tab_bounds); | |
| 84 gfx::Size view_size = tab_bounds.size(); | |
| 85 if (view_size.IsEmpty()) | |
| 86 view_size = prerender_manager->config().default_tab_bounds.size(); | |
| 87 prerender_manager->AddPrerenderFromLinkRelPrerender( | |
| 88 render_process_id, render_view_id, url, referrer, view_size); | |
| 89 } | |
| 90 | |
| 91 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { | 59 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { |
| 92 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | 60 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, |
| 93 render_view_id); | 61 render_view_id); |
| 94 if (!rvh) | 62 if (!rvh) |
| 95 return; | 63 return; |
| 96 | 64 |
| 97 content::NotificationService::current()->Notify( | 65 content::NotificationService::current()->Notify( |
| 98 chrome::NOTIFICATION_DOWNLOAD_INITIATED, | 66 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
| 99 content::Source<RenderViewHost>(rvh), | 67 content::Source<RenderViewHost>(rvh), |
| 100 content::NotificationService::NoDetails()); | 68 content::NotificationService::NoDetails()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 if (resource_type == ResourceType::PREFETCH) { | 97 if (resource_type == ResourceType::PREFETCH) { |
| 130 // All PREFETCH requests should be GETs, but be defensive about it. | 98 // All PREFETCH requests should be GETs, but be defensive about it. |
| 131 if (method != "GET") | 99 if (method != "GET") |
| 132 return false; | 100 return false; |
| 133 | 101 |
| 134 // If prefetch is disabled, kill the request. | 102 // If prefetch is disabled, kill the request. |
| 135 if (!prerender::PrerenderManager::IsPrefetchEnabled()) | 103 if (!prerender::PrerenderManager::IsPrefetchEnabled()) |
| 136 return false; | 104 return false; |
| 137 } | 105 } |
| 138 | 106 |
| 139 // Handle a PRERENDER motivated request. Very similar to rel=prefetch, these | |
| 140 // rel=prerender requests instead launch an early render of the entire page. | |
| 141 if (resource_type == ResourceType::PRERENDER) { | |
| 142 if (prerender::PrerenderManager::IsPrerenderingPossible()) { | |
| 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 144 base::Bind(&AddPrerenderOnUI, child_id, route_id, url, referrer)); | |
| 145 } | |
| 146 // Prerendering or not, this request should be aborted. | |
| 147 return false; | |
| 148 } | |
| 149 | |
| 150 // Abort any prerenders that spawn requests that use invalid HTTP methods. | 107 // Abort any prerenders that spawn requests that use invalid HTTP methods. |
| 151 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && | 108 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && |
| 152 !prerender::PrerenderManager::IsValidHttpMethod(method)) { | 109 !prerender::PrerenderManager::IsValidHttpMethod(method)) { |
| 153 prerender_tracker_->TryCancelOnIOThread( | 110 prerender_tracker_->TryCancelOnIOThread( |
| 154 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD); | 111 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD); |
| 155 return false; | 112 return false; |
| 156 } | 113 } |
| 157 | 114 |
| 158 return true; | 115 return true; |
| 159 } | 116 } |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 if (base::Base64Encode(serialized, &hashed)) { | 412 if (base::Base64Encode(serialized, &hashed)) { |
| 456 // If successful, swap the header value with the new one. | 413 // If successful, swap the header value with the new one. |
| 457 // Note that the list of IDs and the header could be temporarily out of sync | 414 // Note that the list of IDs and the header could be temporarily out of sync |
| 458 // if IDs are added as we are recreating the header, but we're OK with those | 415 // if IDs are added as we are recreating the header, but we're OK with those |
| 459 // descrepancies. | 416 // descrepancies. |
| 460 variation_ids_header_ = hashed; | 417 variation_ids_header_ = hashed; |
| 461 } else { | 418 } else { |
| 462 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized; | 419 DVLOG(1) << "Failed to base64 encode Variation IDs value: " << serialized; |
| 463 } | 420 } |
| 464 } | 421 } |
| OLD | NEW |