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" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (!rvh) | 121 if (!rvh) |
122 return NULL; | 122 return NULL; |
123 content::WebContents* web_contents = | 123 content::WebContents* web_contents = |
124 content::WebContents::FromRenderViewHost(rvh); | 124 content::WebContents::FromRenderViewHost(rvh); |
125 if (!web_contents) | 125 if (!web_contents) |
126 return NULL; | 126 return NULL; |
127 | 127 |
128 return prerender::PrerenderContents::FromWebContents(web_contents); | 128 return prerender::PrerenderContents::FromWebContents(web_contents); |
129 } | 129 } |
130 | 130 |
| 131 prerender::PrerenderManager* GetPrerenderManager(int render_process_id, |
| 132 int render_view_id) { |
| 133 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 134 |
| 135 content::RenderViewHost* render_view_host = |
| 136 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 137 if (!render_view_host) |
| 138 return NULL; |
| 139 |
| 140 content::WebContents* web_contents = |
| 141 content::WebContents::FromRenderViewHost(render_view_host); |
| 142 if (!web_contents) |
| 143 return NULL; |
| 144 |
| 145 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 146 if (!browser_context) |
| 147 return NULL; |
| 148 |
| 149 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 150 if (!profile) |
| 151 return NULL; |
| 152 |
| 153 return prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 154 } |
| 155 |
131 void UpdatePrerenderNetworkBytesCallback(int render_process_id, | 156 void UpdatePrerenderNetworkBytesCallback(int render_process_id, |
132 int render_view_id, | 157 int render_view_id, |
133 int64 bytes) { | 158 int64 bytes) { |
134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
135 | 160 |
136 prerender::PrerenderContents* prerender_contents = | 161 prerender::PrerenderContents* prerender_contents = |
137 FindPrerenderContents(render_process_id, render_view_id); | 162 FindPrerenderContents(render_process_id, render_view_id); |
138 | 163 |
139 if (!prerender_contents) | 164 if (prerender_contents) |
140 return; | 165 prerender_contents->AddNetworkBytes(bytes); |
141 prerender_contents->AddNetworkBytes(bytes); | 166 |
142 prerender_contents->prerender_manager()->AddProfileNetworkBytesIfEnabled( | 167 prerender::PrerenderManager* prerender_manager = |
143 bytes); | 168 GetPrerenderManager(render_process_id, render_view_id); |
| 169 if (prerender_manager) |
| 170 prerender_manager->AddProfileNetworkBytesIfEnabled(bytes); |
144 } | 171 } |
145 | 172 |
146 #if !defined(OS_ANDROID) | 173 #if !defined(OS_ANDROID) |
147 // Goes through the extension's file browser handlers and checks if there is one | 174 // Goes through the extension's file browser handlers and checks if there is one |
148 // that can handle the |mime_type|. | 175 // that can handle the |mime_type|. |
149 // |extension| must not be NULL. | 176 // |extension| must not be NULL. |
150 bool ExtensionCanHandleMimeType(const Extension* extension, | 177 bool ExtensionCanHandleMimeType(const Extension* extension, |
151 const std::string& mime_type) { | 178 const std::string& mime_type) { |
152 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 179 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
153 if (!handler) | 180 if (!handler) |
(...skipping 12 matching lines...) Expand all Loading... |
166 content::RenderViewHost* render_view_host = | 193 content::RenderViewHost* render_view_host = |
167 content::RenderViewHost::FromID(render_process_id, render_view_id); | 194 content::RenderViewHost::FromID(render_process_id, render_view_id); |
168 if (!render_view_host) | 195 if (!render_view_host) |
169 return; | 196 return; |
170 | 197 |
171 content::WebContents* web_contents = | 198 content::WebContents* web_contents = |
172 content::WebContents::FromRenderViewHost(render_view_host); | 199 content::WebContents::FromRenderViewHost(render_view_host); |
173 if (!web_contents) | 200 if (!web_contents) |
174 return; | 201 return; |
175 | 202 |
176 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); | 203 Profile* profile = |
177 if (!browser_context) | 204 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
178 return; | |
179 | |
180 Profile* profile = Profile::FromBrowserContext(browser_context); | |
181 if (!profile) | |
182 return; | |
183 | 205 |
184 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 206 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
185 if (!streams_private) | 207 if (!streams_private) |
186 return; | 208 return; |
187 streams_private->ExecuteMimeTypeHandler( | 209 streams_private->ExecuteMimeTypeHandler( |
188 extension_id, web_contents, stream.Pass(), expected_content_size); | 210 extension_id, web_contents, stream.Pass(), expected_content_size); |
189 } | 211 } |
190 | 212 |
191 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { | 213 void LaunchURL(const GURL& url, int render_process_id, int render_view_id) { |
192 // If there is no longer a WebContents, the request may have raced with tab | 214 // If there is no longer a WebContents, the request may have raced with tab |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 url_request->GetTotalReceivedBytes())); | 688 url_request->GetTotalReceivedBytes())); |
667 } | 689 } |
668 } | 690 } |
669 | 691 |
670 // static | 692 // static |
671 void ChromeResourceDispatcherHostDelegate:: | 693 void ChromeResourceDispatcherHostDelegate:: |
672 SetExternalProtocolHandlerDelegateForTesting( | 694 SetExternalProtocolHandlerDelegateForTesting( |
673 ExternalProtocolHandler::Delegate* delegate) { | 695 ExternalProtocolHandler::Delegate* delegate) { |
674 g_external_protocol_handler_delegate = delegate; | 696 g_external_protocol_handler_delegate = delegate; |
675 } | 697 } |
OLD | NEW |