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

Side by Side Diff: webkit/plugins/ppapi/url_response_info_util.cc

Issue 10993031: Refactor the URLResponseInfo to use new design (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « webkit/plugins/ppapi/url_response_info_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/url_response_info_util.h"
6
7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPHeade rVisitor.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h"
12 #include "webkit/base/file_path_string_conversions.h"
13 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
14 #include "webkit/glue/webkit_glue.h"
15
16 using WebKit::WebHTTPHeaderVisitor;
17 using WebKit::WebString;
18 using WebKit::WebURLResponse;
19
20 namespace webkit {
21 namespace ppapi {
22
23 namespace {
24
25 class HeaderFlattener : public WebHTTPHeaderVisitor {
26 public:
27 const std::string& buffer() const { return buffer_; }
28
29 virtual void visitHeader(const WebString& name, const WebString& value) {
30 if (!buffer_.empty())
31 buffer_.append("\n");
32 buffer_.append(name.utf8());
33 buffer_.append(": ");
34 buffer_.append(value.utf8());
35 }
36
37 private:
38 std::string buffer_;
39 };
40
41 bool IsRedirect(int32_t status) {
42 return status >= 300 && status <= 399;
43 }
44
45 } // namespace
46
47 ::ppapi::URLResponseInfoData DataFromWebURLResponse(
48 PP_Instance pp_instance,
49 const WebURLResponse& response) {
50 ::ppapi::URLResponseInfoData data;
51
52 data.url = response.url().spec();
53 data.status_code = response.httpStatusCode();
54 data.status_text = response.httpStatusText().utf8();
55 if (IsRedirect(data.status_code)) {
56 data.redirect_url = response.httpHeaderField(
57 WebString::fromUTF8("Location")).utf8();
58 }
59
60 HeaderFlattener flattener;
61 response.visitHTTPHeaderFields(&flattener);
62 data.headers = flattener.buffer();
63
64 WebString file_path = response.downloadFilePath();
65 if (!file_path.isEmpty()) {
66 scoped_refptr<PPB_FileRef_Impl> file_ref(
67 PPB_FileRef_Impl::CreateExternal(
68 pp_instance,
69 webkit_base::WebStringToFilePath(file_path),
70 std::string()));
71 data.body_as_file_ref = file_ref->GetCreateInfo();
72 file_ref->GetReference(); // The returned data has one ref for the plugin.
73 }
74 return data;
75 }
76
77 } // namespace ppapi
78 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/url_response_info_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698