Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: content/renderer/pepper/url_response_info_util.cc

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/renderer/renderer_ppapi_host.h" 10 #include "content/public/renderer/renderer_ppapi_host.h"
(...skipping 25 matching lines...) Expand all
36 buffer_.append("\n"); 36 buffer_.append("\n");
37 buffer_.append(name.utf8()); 37 buffer_.append(name.utf8());
38 buffer_.append(": "); 38 buffer_.append(": ");
39 buffer_.append(value.utf8()); 39 buffer_.append(value.utf8());
40 } 40 }
41 41
42 private: 42 private:
43 std::string buffer_; 43 std::string buffer_;
44 }; 44 };
45 45
46 bool IsRedirect(int32_t status) { 46 bool IsRedirect(int32_t status) { return status >= 300 && status <= 399; }
47 return status >= 300 && status <= 399;
48 }
49 47
50 void DidCreateResourceHosts(const ppapi::URLResponseInfoData& in_data, 48 void DidCreateResourceHosts(const ppapi::URLResponseInfoData& in_data,
51 const base::FilePath& external_path, 49 const base::FilePath& external_path,
52 int renderer_pending_host_id, 50 int renderer_pending_host_id,
53 const DataFromWebURLResponseCallback& callback, 51 const DataFromWebURLResponseCallback& callback,
54 const std::vector<int>& browser_pending_host_ids) { 52 const std::vector<int>& browser_pending_host_ids) {
55 DCHECK_EQ(1U, browser_pending_host_ids.size()); 53 DCHECK_EQ(1U, browser_pending_host_ids.size());
56 int browser_pending_host_id = 0; 54 int browser_pending_host_id = 0;
57 55
58 if (browser_pending_host_ids.size() == 1) 56 if (browser_pending_host_ids.size() == 1)
59 browser_pending_host_id = browser_pending_host_ids[0]; 57 browser_pending_host_id = browser_pending_host_ids[0];
60 58
61 ppapi::URLResponseInfoData data = in_data; 59 ppapi::URLResponseInfoData data = in_data;
62 60
63 data.body_as_file_ref = ppapi::MakeExternalFileRefCreateInfo( 61 data.body_as_file_ref =
64 external_path, 62 ppapi::MakeExternalFileRefCreateInfo(external_path,
65 std::string(), 63 std::string(),
66 browser_pending_host_id, 64 browser_pending_host_id,
67 renderer_pending_host_id); 65 renderer_pending_host_id);
68 callback.Run(data); 66 callback.Run(data);
69 } 67 }
70 68
71 } // namespace 69 } // namespace
72 70
73 void DataFromWebURLResponse(RendererPpapiHostImpl* host_impl, 71 void DataFromWebURLResponse(RendererPpapiHostImpl* host_impl,
74 PP_Instance pp_instance, 72 PP_Instance pp_instance,
75 const WebURLResponse& response, 73 const WebURLResponse& response,
76 const DataFromWebURLResponseCallback& callback) { 74 const DataFromWebURLResponseCallback& callback) {
77 ppapi::URLResponseInfoData data; 75 ppapi::URLResponseInfoData data;
78 data.url = response.url().spec(); 76 data.url = response.url().spec();
79 data.status_code = response.httpStatusCode(); 77 data.status_code = response.httpStatusCode();
80 data.status_text = response.httpStatusText().utf8(); 78 data.status_text = response.httpStatusText().utf8();
81 if (IsRedirect(data.status_code)) { 79 if (IsRedirect(data.status_code)) {
82 data.redirect_url = response.httpHeaderField( 80 data.redirect_url =
83 WebString::fromUTF8("Location")).utf8(); 81 response.httpHeaderField(WebString::fromUTF8("Location")).utf8();
84 } 82 }
85 83
86 HeaderFlattener flattener; 84 HeaderFlattener flattener;
87 response.visitHTTPHeaderFields(&flattener); 85 response.visitHTTPHeaderFields(&flattener);
88 data.headers = flattener.buffer(); 86 data.headers = flattener.buffer();
89 87
90 WebString file_path = response.downloadFilePath(); 88 WebString file_path = response.downloadFilePath();
91 if (!file_path.isEmpty()) { 89 if (!file_path.isEmpty()) {
92 base::FilePath external_path = base::FilePath::FromUTF16Unsafe(file_path); 90 base::FilePath external_path = base::FilePath::FromUTF16Unsafe(file_path);
93 // TODO(teravest): Write a utility function to create resource hosts in the 91 // TODO(teravest): Write a utility function to create resource hosts in the
94 // renderer and browser. 92 // renderer and browser.
95 PepperFileRefRendererHost* renderer_host = 93 PepperFileRefRendererHost* renderer_host =
96 new PepperFileRefRendererHost(host_impl, pp_instance, 0, external_path); 94 new PepperFileRefRendererHost(host_impl, pp_instance, 0, external_path);
97 int renderer_pending_host_id = 95 int renderer_pending_host_id =
98 host_impl->GetPpapiHost()->AddPendingResourceHost( 96 host_impl->GetPpapiHost()->AddPendingResourceHost(
99 scoped_ptr<ppapi::host::ResourceHost>(renderer_host)); 97 scoped_ptr<ppapi::host::ResourceHost>(renderer_host));
100 98
101 std::vector<IPC::Message> create_msgs; 99 std::vector<IPC::Message> create_msgs;
102 create_msgs.push_back(PpapiHostMsg_FileRef_CreateForRawFS(external_path)); 100 create_msgs.push_back(PpapiHostMsg_FileRef_CreateForRawFS(external_path));
103 host_impl->CreateBrowserResourceHosts( 101 host_impl->CreateBrowserResourceHosts(pp_instance,
104 pp_instance, 102 create_msgs,
105 create_msgs, 103 base::Bind(&DidCreateResourceHosts,
106 base::Bind(&DidCreateResourceHosts, 104 data,
107 data, 105 external_path,
108 external_path, 106 renderer_pending_host_id,
109 renderer_pending_host_id, 107 callback));
110 callback));
111 } else { 108 } else {
112 base::MessageLoop::current()->PostTask( 109 base::MessageLoop::current()->PostTask(FROM_HERE,
113 FROM_HERE, 110 base::Bind(callback, data));
114 base::Bind(callback, data));
115 } 111 }
116 } 112 }
117 113
118 } // namespace content 114 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/url_request_info_util.cc ('k') | content/renderer/pepper/v8_var_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698