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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 if (prerender_contents) | 156 if (prerender_contents) |
157 prerender_contents->AddNetworkBytes(bytes); | 157 prerender_contents->AddNetworkBytes(bytes); |
158 | 158 |
159 prerender::PrerenderManager* prerender_manager = | 159 prerender::PrerenderManager* prerender_manager = |
160 GetPrerenderManager(render_process_id, render_view_id); | 160 GetPrerenderManager(render_process_id, render_view_id); |
161 if (prerender_manager) | 161 if (prerender_manager) |
162 prerender_manager->AddProfileNetworkBytesIfEnabled(bytes); | 162 prerender_manager->AddProfileNetworkBytesIfEnabled(bytes); |
163 } | 163 } |
164 | 164 |
165 #if !defined(OS_ANDROID) | 165 #if defined(ENABLE_EXTENSIONS) |
166 void SendExecuteMimeTypeHandlerEvent(scoped_ptr<content::StreamHandle> stream, | 166 void SendExecuteMimeTypeHandlerEvent(scoped_ptr<content::StreamHandle> stream, |
167 int64 expected_content_size, | 167 int64 expected_content_size, |
168 int render_process_id, | 168 int render_process_id, |
169 int render_view_id, | 169 int render_view_id, |
170 const std::string& extension_id, | 170 const std::string& extension_id, |
171 const std::string& view_id) { | 171 const std::string& view_id) { |
172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
173 | 173 |
174 content::WebContents* web_contents = | 174 content::WebContents* web_contents = |
175 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 175 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
(...skipping 12 matching lines...) Expand all Loading... |
188 Profile* profile = | 188 Profile* profile = |
189 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 189 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
190 | 190 |
191 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); | 191 StreamsPrivateAPI* streams_private = StreamsPrivateAPI::Get(profile); |
192 if (!streams_private) | 192 if (!streams_private) |
193 return; | 193 return; |
194 streams_private->ExecuteMimeTypeHandler( | 194 streams_private->ExecuteMimeTypeHandler( |
195 extension_id, web_contents, stream.Pass(), view_id, | 195 extension_id, web_contents, stream.Pass(), view_id, |
196 expected_content_size); | 196 expected_content_size); |
197 } | 197 } |
| 198 #endif // !defined(ENABLE_EXTENSIONS) |
198 | 199 |
| 200 #if !defined(OS_ANDROID) |
199 void LaunchURL(const GURL& url, int render_process_id, int render_view_id, | 201 void LaunchURL(const GURL& url, int render_process_id, int render_view_id, |
200 bool user_gesture) { | 202 bool user_gesture) { |
201 // If there is no longer a WebContents, the request may have raced with tab | 203 // If there is no longer a WebContents, the request may have raced with tab |
202 // closing. Don't fire the external request. (It may have been a prerender.) | 204 // closing. Don't fire the external request. (It may have been a prerender.) |
203 content::WebContents* web_contents = | 205 content::WebContents* web_contents = |
204 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 206 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
205 if (!web_contents) | 207 if (!web_contents) |
206 return; | 208 return; |
207 | 209 |
208 // Do not launch external requests attached to unswapped prerenders. | 210 // Do not launch external requests attached to unswapped prerenders. |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 #else | 560 #else |
559 return false; | 561 return false; |
560 #endif | 562 #endif |
561 } | 563 } |
562 | 564 |
563 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 565 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
564 net::URLRequest* request, | 566 net::URLRequest* request, |
565 const std::string& mime_type, | 567 const std::string& mime_type, |
566 GURL* origin, | 568 GURL* origin, |
567 std::string* payload) { | 569 std::string* payload) { |
568 #if !defined(OS_ANDROID) | 570 #if defined(ENABLE_EXTENSIONS) |
569 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 571 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
570 ProfileIOData* io_data = | 572 ProfileIOData* io_data = |
571 ProfileIOData::FromResourceContext(info->GetContext()); | 573 ProfileIOData::FromResourceContext(info->GetContext()); |
572 bool profile_is_off_the_record = io_data->IsOffTheRecord(); | 574 bool profile_is_off_the_record = io_data->IsOffTheRecord(); |
573 const scoped_refptr<const extensions::InfoMap> extension_info_map( | 575 const scoped_refptr<const extensions::InfoMap> extension_info_map( |
574 io_data->GetExtensionInfoMap()); | 576 io_data->GetExtensionInfoMap()); |
575 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 577 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
576 // Go through the white-listed extensions and try to use them to intercept | 578 // Go through the white-listed extensions and try to use them to intercept |
577 // the URL request. | 579 // the URL request. |
578 for (size_t i = 0; i < whitelist.size(); ++i) { | 580 for (size_t i = 0; i < whitelist.size(); ++i) { |
(...skipping 22 matching lines...) Expand all Loading... |
601 return true; | 603 return true; |
602 } | 604 } |
603 } | 605 } |
604 #endif | 606 #endif |
605 return false; | 607 return false; |
606 } | 608 } |
607 | 609 |
608 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 610 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
609 net::URLRequest* request, | 611 net::URLRequest* request, |
610 scoped_ptr<content::StreamHandle> stream) { | 612 scoped_ptr<content::StreamHandle> stream) { |
611 #if !defined(OS_ANDROID) | 613 #if defined(ENABLE_EXTENSIONS) |
612 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 614 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
613 std::map<net::URLRequest*, StreamTargetInfo>::iterator ix = | 615 std::map<net::URLRequest*, StreamTargetInfo>::iterator ix = |
614 stream_target_info_.find(request); | 616 stream_target_info_.find(request); |
615 CHECK(ix != stream_target_info_.end()); | 617 CHECK(ix != stream_target_info_.end()); |
616 content::BrowserThread::PostTask( | 618 content::BrowserThread::PostTask( |
617 content::BrowserThread::UI, FROM_HERE, | 619 content::BrowserThread::UI, FROM_HERE, |
618 base::Bind(&SendExecuteMimeTypeHandlerEvent, base::Passed(&stream), | 620 base::Bind(&SendExecuteMimeTypeHandlerEvent, base::Passed(&stream), |
619 request->GetExpectedContentSize(), | 621 request->GetExpectedContentSize(), |
620 info->GetChildID(), info->GetRouteID(), | 622 info->GetChildID(), info->GetRouteID(), |
621 ix->second.extension_id, ix->second.view_id)); | 623 ix->second.extension_id, ix->second.view_id)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 url_request->GetTotalReceivedBytes())); | 733 url_request->GetTotalReceivedBytes())); |
732 } | 734 } |
733 } | 735 } |
734 | 736 |
735 // static | 737 // static |
736 void ChromeResourceDispatcherHostDelegate:: | 738 void ChromeResourceDispatcherHostDelegate:: |
737 SetExternalProtocolHandlerDelegateForTesting( | 739 SetExternalProtocolHandlerDelegateForTesting( |
738 ExternalProtocolHandler::Delegate* delegate) { | 740 ExternalProtocolHandler::Delegate* delegate) { |
739 g_external_protocol_handler_delegate = delegate; | 741 g_external_protocol_handler_delegate = delegate; |
740 } | 742 } |
OLD | NEW |