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
|
// Copyright (c) 2010 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.
#include "chrome/browser/renderer_host/sync_resource_handler.h"
#include "base/logging.h"
#include "chrome/browser/debugger/devtools_netlog_observer.h"
#include "chrome/browser/net/load_timing_observer.h"
#include "chrome/browser/renderer_host/global_request_id.h"
#include "chrome/common/render_messages.h"
#include "net/base/io_buffer.h"
#include "net/http/http_response_headers.h"
SyncResourceHandler::SyncResourceHandler(
ResourceDispatcherHost::Receiver* receiver,
int process_id,
const GURL& url,
IPC::Message* result_message,
ResourceDispatcherHost* resource_dispatcher_host)
: read_buffer_(new net::IOBuffer(kReadBufSize)),
receiver_(receiver),
process_id_(process_id),
result_message_(result_message),
rdh_(resource_dispatcher_host) {
result_.final_url = url;
}
SyncResourceHandler::~SyncResourceHandler() {
}
bool SyncResourceHandler::OnUploadProgress(int request_id,
uint64 position,
uint64 size) {
return true;
}
bool SyncResourceHandler::OnRequestRedirected(int request_id,
const GURL& new_url,
ResourceResponse* response,
bool* defer) {
URLRequest* request = rdh_->GetURLRequest(
GlobalRequestID(process_id_, request_id));
LoadTimingObserver::PopulateTimingInfo(request, response);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);
// TODO(darin): It would be much better if this could live in WebCore, but
// doing so requires API changes at all levels. Similar code exists in
// WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
if (new_url.GetOrigin() != result_.final_url.GetOrigin()) {
LOG(ERROR) << "Cross origin redirect denied";
return false;
}
result_.final_url = new_url;
return true;
}
bool SyncResourceHandler::OnResponseStarted(int request_id,
ResourceResponse* response) {
URLRequest* request = rdh_->GetURLRequest(
GlobalRequestID(process_id_, request_id));
LoadTimingObserver::PopulateTimingInfo(request, response);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);
// We don't care about copying the status here.
result_.headers = response->response_head.headers;
result_.mime_type = response->response_head.mime_type;
result_.charset = response->response_head.charset;
result_.download_file_path = response->response_head.download_file_path;
result_.request_time = response->response_head.request_time;
result_.response_time = response->response_head.response_time;
result_.connection_id = response->response_head.connection_id;
result_.connection_reused = response->response_head.connection_reused;
result_.load_timing = response->response_head.load_timing;
result_.devtools_info = response->response_head.devtools_info;
return true;
}
bool SyncResourceHandler::OnWillStart(int request_id,
const GURL& url,
bool* defer) {
return true;
}
bool SyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
int* buf_size, int min_size) {
DCHECK(min_size == -1);
*buf = read_buffer_.get();
*buf_size = kReadBufSize;
return true;
}
bool SyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) {
if (!*bytes_read)
return true;
result_.data.append(read_buffer_->data(), *bytes_read);
return true;
}
bool SyncResourceHandler::OnResponseCompleted(
int request_id,
const URLRequestStatus& status,
const std::string& security_info) {
result_.status = status;
ViewHostMsg_SyncLoad::WriteReplyParams(result_message_, result_);
receiver_->Send(result_message_);
result_message_ = NULL;
return true;
}
void SyncResourceHandler::OnRequestClosed() {
if (!result_message_)
return;
result_message_->set_reply_error();
receiver_->Send(result_message_);
receiver_ = NULL; // URLRequest is gone, and perhaps also the receiver.
}
|