OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/pepper/url_response_info_util.h" | 5 #include "content/renderer/pepper/url_response_info_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 10 #include "content/public/renderer/renderer_ppapi_host.h" |
11 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | |
12 #include "ipc/ipc_message.h" | |
13 #include "ppapi/proxy/ppapi_messages.h" | |
11 #include "ppapi/shared_impl/url_response_info_data.h" | 14 #include "ppapi/shared_impl/url_response_info_data.h" |
12 #include "third_party/WebKit/public/platform/WebCString.h" | 15 #include "third_party/WebKit/public/platform/WebCString.h" |
13 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 16 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
14 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
15 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
16 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 19 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
17 | 20 |
18 using WebKit::WebHTTPHeaderVisitor; | 21 using WebKit::WebHTTPHeaderVisitor; |
19 using WebKit::WebString; | 22 using WebKit::WebString; |
20 using WebKit::WebURLResponse; | 23 using WebKit::WebURLResponse; |
(...skipping 15 matching lines...) Expand all Loading... | |
36 } | 39 } |
37 | 40 |
38 private: | 41 private: |
39 std::string buffer_; | 42 std::string buffer_; |
40 }; | 43 }; |
41 | 44 |
42 bool IsRedirect(int32_t status) { | 45 bool IsRedirect(int32_t status) { |
43 return status >= 300 && status <= 399; | 46 return status >= 300 && status <= 399; |
44 } | 47 } |
45 | 48 |
49 void DidCreateResourceHost(ppapi::URLResponseInfoData data, | |
yzshen1
2013/08/08 23:16:21
const &, please.
teravest
2013/08/09 02:00:08
Done.
| |
50 const base::FilePath& external_path, | |
51 const DataFromWebURLResponseCallback& callback, | |
52 int pending_resource_id) { | |
53 data.body_as_file_ref = ppapi::MakeExternalFileRefCreateInfo( | |
54 external_path, "", pending_resource_id); | |
dmichael (off chromium)
2013/08/08 21:24:03
nit: s/""/std::string()
| |
55 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, data)); | |
yzshen1
2013/08/08 23:16:21
Why we have to post again? Couldn't we run the cal
teravest
2013/08/09 02:00:08
Changed to run directly.
| |
56 } | |
57 | |
46 } // namespace | 58 } // namespace |
47 | 59 |
48 void DataFromWebURLResponse(PP_Instance pp_instance, | 60 void DataFromWebURLResponse(RendererPpapiHostImpl* host_impl, |
61 PP_Instance pp_instance, | |
49 const WebURLResponse& response, | 62 const WebURLResponse& response, |
50 const DataFromWebURLResponseCallback& callback) { | 63 const DataFromWebURLResponseCallback& callback) { |
51 ppapi::URLResponseInfoData data; | 64 ppapi::URLResponseInfoData data; |
52 | |
53 data.url = response.url().spec(); | 65 data.url = response.url().spec(); |
54 data.status_code = response.httpStatusCode(); | 66 data.status_code = response.httpStatusCode(); |
55 data.status_text = response.httpStatusText().utf8(); | 67 data.status_text = response.httpStatusText().utf8(); |
56 if (IsRedirect(data.status_code)) { | 68 if (IsRedirect(data.status_code)) { |
57 data.redirect_url = response.httpHeaderField( | 69 data.redirect_url = response.httpHeaderField( |
58 WebString::fromUTF8("Location")).utf8(); | 70 WebString::fromUTF8("Location")).utf8(); |
59 } | 71 } |
60 | 72 |
61 HeaderFlattener flattener; | 73 HeaderFlattener flattener; |
62 response.visitHTTPHeaderFields(&flattener); | 74 response.visitHTTPHeaderFields(&flattener); |
63 data.headers = flattener.buffer(); | 75 data.headers = flattener.buffer(); |
64 | 76 |
65 WebString file_path = response.downloadFilePath(); | 77 WebString file_path = response.downloadFilePath(); |
66 if (!file_path.isEmpty()) { | 78 if (!file_path.isEmpty()) { |
67 scoped_refptr<PPB_FileRef_Impl> file_ref( | 79 base::FilePath external_path = base::FilePath::FromUTF16Unsafe(file_path); |
68 PPB_FileRef_Impl::CreateExternal( | 80 host_impl->CreateBrowserResourceHost( |
69 pp_instance, | 81 pp_instance, |
70 base::FilePath::FromUTF16Unsafe(file_path), | 82 PpapiHostMsg_FileRef_CreateExternal(external_path), |
71 std::string())); | 83 base::Bind(&DidCreateResourceHost, data, external_path, callback)); |
72 data.body_as_file_ref = file_ref->GetCreateInfo(); | 84 } else { |
73 file_ref->GetReference(); // The returned data has one ref for the plugin. | 85 base::MessageLoop::current()->PostTask( |
86 FROM_HERE, | |
87 base::Bind(callback, data)); | |
74 } | 88 } |
75 | |
76 // We post data to a callback instead of returning it here because the new | |
77 // implementation for FileRef is asynchronous when creating the resource. | |
78 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, data)); | |
79 } | 89 } |
80 | 90 |
81 } // namespace content | 91 } // namespace content |
OLD | NEW |