1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_
#include <deque>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h"
#include "webkit/plugins/ppapi/callbacks.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource.h"
struct PPB_URLLoader;
struct PPB_URLLoaderTrusted;
namespace WebKit {
class WebFrame;
class WebURL;
}
namespace webkit {
namespace ppapi {
class PluginInstance;
class PPB_URLRequestInfo_Impl;
class PPB_URLResponseInfo_Impl;
class PPB_URLLoader_Impl : public Resource, public WebKit::WebURLLoaderClient {
public:
PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader);
virtual ~PPB_URLLoader_Impl();
// Returns a pointer to the interface implementing PPB_URLLoader that is
// exposed to the plugin.
static const PPB_URLLoader* GetInterface();
// Returns a pointer to the interface implementing PPB_URLLoaderTrusted that
// is exposed to the plugin.
static const PPB_URLLoaderTrusted* GetTrustedInterface();
// Resource overrides.
virtual PPB_URLLoader_Impl* AsPPB_URLLoader_Impl();
virtual void LastPluginRefWasDeleted(bool instance_destroyed);
// PPB_URLLoader implementation.
int32_t Open(PPB_URLRequestInfo_Impl* request,
PP_CompletionCallback callback);
int32_t FollowRedirect(PP_CompletionCallback callback);
bool GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent);
bool GetDownloadProgress(int64_t* bytes_received,
int64_t* total_bytes_to_be_received);
int32_t ReadResponseBody(void* buffer, int32_t bytes_to_read,
PP_CompletionCallback callback);
int32_t FinishStreamingToFile(PP_CompletionCallback callback);
void Close();
// PPB_URLLoaderTrusted implementation.
void GrantUniversalAccess();
void SetStatusCallback(PP_URLLoaderTrusted_StatusCallback cb);
// WebKit::WebURLLoaderClient implementation.
virtual void willSendRequest(WebKit::WebURLLoader* loader,
WebKit::WebURLRequest& new_request,
const WebKit::WebURLResponse& redir_response);
virtual void didSendData(WebKit::WebURLLoader* loader,
unsigned long long bytes_sent,
unsigned long long total_bytes_to_be_sent);
virtual void didReceiveResponse(WebKit::WebURLLoader* loader,
const WebKit::WebURLResponse& response);
virtual void didDownloadData(WebKit::WebURLLoader* loader,
int data_length);
virtual void didReceiveData(WebKit::WebURLLoader* loader,
const char* data,
int data_length,
int encoded_data_length);
virtual void didFinishLoading(WebKit::WebURLLoader* loader,
double finish_time);
virtual void didFail(WebKit::WebURLLoader* loader,
const WebKit::WebURLError& error);
PPB_URLResponseInfo_Impl* response_info() const { return response_info_; }
// Returns the number of bytes currently available for synchronous reading
// in the loader.
int32_t buffer_size() const { return buffer_.size(); }
private:
// Check that |callback| is valid (only non-blocking operation is supported)
// and that no callback is already pending. Returns |PP_OK| if okay, else
// |PP_ERROR_...| to be returned to the plugin.
int32_t ValidateCallback(PP_CompletionCallback callback);
// Sets up |callback| as the pending callback. This should only be called once
// it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
void RegisterCallback(PP_CompletionCallback callback);
void RunCallback(int32_t result);
size_t FillUserBuffer();
// Converts a WebURLResponse to a URLResponseInfo and saves it.
void SaveResponse(const WebKit::WebURLResponse& response);
// Calls the status_callback_ (if any) with the current upload and download
// progress. Call this function if you update any of these values to
// synchronize an out-of-process plugin's state.
void UpdateStatus();
// Returns true if the plugin has requested we record download or upload
// progress. When false, we don't need to update the counters. We go out of
// our way not to allow access to this information unless it's requested,
// even when it would be easier just to return it and not check, so that
// plugins don't depend on access without setting the flag.
bool RecordDownloadProgress() const;
bool RecordUploadProgress() const;
// If true, then the plugin instance is a full-frame plugin and we're just
// wrapping the main document's loader (i.e. loader_ is null).
bool main_document_loader_;
scoped_ptr<WebKit::WebURLLoader> loader_;
scoped_refptr<PPB_URLRequestInfo_Impl> request_info_;
scoped_refptr<PPB_URLResponseInfo_Impl> response_info_;
scoped_refptr<TrackedCompletionCallback> pending_callback_;
std::deque<char> buffer_;
int64_t bytes_sent_;
int64_t total_bytes_to_be_sent_;
int64_t bytes_received_;
int64_t total_bytes_to_be_received_;
char* user_buffer_;
size_t user_buffer_size_;
int32_t done_status_;
bool has_universal_access_;
PP_URLLoaderTrusted_StatusCallback status_callback_;
DISALLOW_COPY_AND_ASSIGN(PPB_URLLoader_Impl);
};
} // namespace ppapi
} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_URL_LOADER_IMPL_H_
|