1 #include "resource_dispatcher_host_delegate_efl.h"
3 #include "content/public/browser/browser_thread.h"
4 #include "content/public/browser/web_contents.h"
5 #include "content/public/browser/resource_request_info.h"
6 #include "net/url_request/url_request.h"
7 #include "net/http/http_response_headers.h"
8 #include "browser/login_delegate_efl.h"
9 #include "browser_context_efl.h"
10 #include "common/web_contents_utils.h"
11 #include "eweb_context.h"
13 using web_contents_utils::WebContentsFromFrameID;
19 void TriggerNewDownloadStartCallbackOnUIThread(
20 int render_process_id, int render_frame_id,
22 const std::string& /*user_agent*/,
23 const std::string& /*content_disposition*/,
24 const std::string& /*mime_type*/,
25 int64 /*content_length*/) {
26 WebContents* web_contents = WebContentsFromFrameID(
27 render_process_id, render_frame_id);
31 BrowserContextEfl* browser_context = static_cast<BrowserContextEfl*>(
32 web_contents->GetBrowserContext());
36 EwkDidStartDownloadCallback* start_download_callback =
37 browser_context->WebContext()->DidStartDownloadCallback();
38 if (!start_download_callback)
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 start_download_callback->TriggerCallback(url.spec());
47 void ResourceDispatcherHostDelegateEfl::RequestBeginning(
48 net::URLRequest* request,
49 ResourceContext* resource_context,
50 AppCacheService* appcache_service,
51 ResourceType::Type resource_type,
54 ScopedVector<ResourceThrottle>* throttles) {
55 BrowserContextEfl::ResourceContextEfl *resource_context_efl =
56 static_cast<BrowserContextEfl::ResourceContextEfl*>(resource_context);
57 if (!resource_context_efl)
60 BrowserContextEfl *browser_context = resource_context_efl->getBrowserContext();
64 EWebContext* eweb_context = browser_context->WebContext();
68 HTTPCustomHeadersEflMap header_map = eweb_context->GetHTTPCustomHeadersEflMap();
69 for (HTTPCustomHeadersEflMap::iterator it = header_map.begin(); it != header_map.end(); ++it)
70 request->SetExtraRequestHeaderByName(it->first, it->second, true);
73 ResourceDispatcherHostLoginDelegate*
74 ResourceDispatcherHostDelegateEfl::CreateLoginDelegate(
75 net::AuthChallengeInfo* auth_info,
76 net::URLRequest* request) {
77 return new LoginDelegateEfl(auth_info, request);
80 void ResourceDispatcherHostDelegateEfl::DownloadStarting(
81 net::URLRequest* request,
82 content::ResourceContext* resource_context,
86 bool is_content_initiated,
88 ScopedVector<content::ResourceThrottle>* throttles) {
89 std::string user_agent;
90 std::string content_disposition;
91 std::string mime_type;
92 int64 content_length = request->GetExpectedContentSize();
94 request->extra_request_headers().GetHeader(
95 net::HttpRequestHeaders::kUserAgent, &user_agent);
97 net::HttpResponseHeaders* response_headers = request->response_headers();
98 if (response_headers) {
99 response_headers->GetNormalizedHeader("content-disposition",
100 &content_disposition);
101 response_headers->GetMimeType(&mime_type);
104 // POST request cannot be repeated in general, so prevent client from
105 // retrying the same request, even if it is with a GET.
106 if ("GET" == request->method()) {
107 TriggerNewDownloadStartCallback(request,
115 void ResourceDispatcherHostDelegateEfl::TriggerNewDownloadStartCallback(
116 net::URLRequest* request,
117 const std::string& user_agent,
118 const std::string& content_disposition,
119 const std::string& mime_type,
120 int64 content_length) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
122 int render_process_id = -1;
123 int render_frame_id = -1;
124 if (!ResourceRequestInfo::GetRenderFrameForRequest(
125 request, &render_process_id, &render_frame_id))
128 if (render_process_id == -1 || render_frame_id == -1)
131 // Since called by IO thread callback trigger needs to
132 // be posted to UI thread so that IO thread is unblocked
133 BrowserThread::PostTask(
134 BrowserThread::UI, FROM_HERE,
135 base::Bind(TriggerNewDownloadStartCallbackOnUIThread,
145 #if !defined(EWK_BRINGUP)
146 bool ResourceDispatcherHostDelegateEfl::ShouldOverrideMimeType(
147 const GURL& url, std::string& mime_type) {
148 return EWebContext::ShouldOverrideMimeForURL(url, mime_type);
152 } // namespace content