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

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

Issue 23647008: Revert 221284 "Pepper: Move FileRef to the "new" resource proxy." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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/renderer/pepper/ppb_file_ref_impl.h"
11 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
12 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
13 #include "ipc/ipc_message.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/url_response_info_data.h" 11 #include "ppapi/shared_impl/url_response_info_data.h"
16 #include "third_party/WebKit/public/platform/WebCString.h" 12 #include "third_party/WebKit/public/platform/WebCString.h"
17 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 13 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 15 #include "third_party/WebKit/public/platform/WebURL.h"
20 #include "third_party/WebKit/public/platform/WebURLResponse.h" 16 #include "third_party/WebKit/public/platform/WebURLResponse.h"
21 17
22 using WebKit::WebHTTPHeaderVisitor; 18 using WebKit::WebHTTPHeaderVisitor;
23 using WebKit::WebString; 19 using WebKit::WebString;
24 using WebKit::WebURLResponse; 20 using WebKit::WebURLResponse;
(...skipping 15 matching lines...) Expand all
40 } 36 }
41 37
42 private: 38 private:
43 std::string buffer_; 39 std::string buffer_;
44 }; 40 };
45 41
46 bool IsRedirect(int32_t status) { 42 bool IsRedirect(int32_t status) {
47 return status >= 300 && status <= 399; 43 return status >= 300 && status <= 399;
48 } 44 }
49 45
50 void DidCreateResourceHosts(const ppapi::URLResponseInfoData& in_data,
51 const base::FilePath& external_path,
52 int renderer_pending_host_id,
53 const DataFromWebURLResponseCallback& callback,
54 const std::vector<int>& browser_pending_host_ids) {
55 DCHECK(browser_pending_host_ids.size() == 1);
56 int browser_pending_host_id = 0;
57
58 if (browser_pending_host_ids.size() == 1)
59 browser_pending_host_id = browser_pending_host_ids[0];
60
61 ppapi::URLResponseInfoData data = in_data;
62
63 data.body_as_file_ref = ppapi::MakeExternalFileRefCreateInfo(
64 external_path,
65 std::string(),
66 browser_pending_host_id,
67 renderer_pending_host_id);
68 callback.Run(data);
69 }
70
71 } // namespace 46 } // namespace
72 47
73 void DataFromWebURLResponse(RendererPpapiHostImpl* host_impl, 48 void DataFromWebURLResponse(PP_Instance pp_instance,
74 PP_Instance pp_instance,
75 const WebURLResponse& response, 49 const WebURLResponse& response,
76 const DataFromWebURLResponseCallback& callback) { 50 const DataFromWebURLResponseCallback& callback) {
77 ppapi::URLResponseInfoData data; 51 ppapi::URLResponseInfoData data;
52
78 data.url = response.url().spec(); 53 data.url = response.url().spec();
79 data.status_code = response.httpStatusCode(); 54 data.status_code = response.httpStatusCode();
80 data.status_text = response.httpStatusText().utf8(); 55 data.status_text = response.httpStatusText().utf8();
81 if (IsRedirect(data.status_code)) { 56 if (IsRedirect(data.status_code)) {
82 data.redirect_url = response.httpHeaderField( 57 data.redirect_url = response.httpHeaderField(
83 WebString::fromUTF8("Location")).utf8(); 58 WebString::fromUTF8("Location")).utf8();
84 } 59 }
85 60
86 HeaderFlattener flattener; 61 HeaderFlattener flattener;
87 response.visitHTTPHeaderFields(&flattener); 62 response.visitHTTPHeaderFields(&flattener);
88 data.headers = flattener.buffer(); 63 data.headers = flattener.buffer();
89 64
90 WebString file_path = response.downloadFilePath(); 65 WebString file_path = response.downloadFilePath();
91 if (!file_path.isEmpty()) { 66 if (!file_path.isEmpty()) {
92 base::FilePath external_path = base::FilePath::FromUTF16Unsafe(file_path); 67 scoped_refptr<PPB_FileRef_Impl> file_ref(
93 // TODO(teravest): Write a utility function to create resource hosts in the 68 PPB_FileRef_Impl::CreateExternal(
94 // renderer and browser. 69 pp_instance,
95 PepperFileRefRendererHost* renderer_host = 70 base::FilePath::FromUTF16Unsafe(file_path),
96 new PepperFileRefRendererHost(host_impl, pp_instance, 0, external_path); 71 std::string()));
97 int renderer_pending_host_id = 72 data.body_as_file_ref = file_ref->GetCreateInfo();
98 host_impl->GetPpapiHost()->AddPendingResourceHost( 73 file_ref->GetReference(); // The returned data has one ref for the plugin.
99 scoped_ptr<ppapi::host::ResourceHost>(renderer_host)); 74 }
100 75
101 std::vector<IPC::Message> create_msgs; 76 // We post data to a callback instead of returning it here because the new
102 create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(external_path)); 77 // implementation for FileRef is asynchronous when creating the resource.
103 host_impl->CreateBrowserResourceHosts( 78 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, data));
104 pp_instance,
105 create_msgs,
106 base::Bind(&DidCreateResourceHosts,
107 data,
108 external_path,
109 renderer_pending_host_id,
110 callback));
111 } else {
112 base::MessageLoop::current()->PostTask(
113 FROM_HERE,
114 base::Bind(callback, data));
115 }
116 } 79 }
117 80
118 } // namespace content 81 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/pepper/url_response_info_util.h ('k') | trunk/src/ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698