resource_request_details.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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 "content/public/browser/resource_request_details.h"
6
7#include "content/browser/worker_host/worker_service_impl.h"
8#include "content/public/browser/resource_request_info.h"
9#include "net/http/http_response_headers.h"
10#include "net/url_request/url_request.h"
11
12namespace content {
13
14ResourceRequestDetails::ResourceRequestDetails(const net::URLRequest* request,
15                                               int cert_id)
16    : url(request->url()),
17      original_url(request->original_url()),
18      method(request->method()),
19      referrer(request->referrer()),
20      has_upload(request->has_upload()),
21      load_flags(request->load_flags()),
22      status(request->status()),
23      ssl_cert_id(cert_id),
24      ssl_cert_status(request->ssl_info().cert_status),
25      socket_address(request->GetSocketAddress()) {
26  const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
27  resource_type = info->GetResourceType();
28  render_frame_id = info->GetRenderFrameID();
29  http_response_code =
30      request->response_info().headers.get() ?
31          request->response_info().headers.get()->response_code() : -1;
32
33  // If request is from the worker process on behalf of a renderer, use
34  // the renderer process id, since it consumes the notification response
35  // such as ssl state etc.
36  // TODO(atwilson): need to notify all associated renderers in the case
37  // of ssl state change (http://crbug.com/25357). For now, just notify
38  // the first one (works for dedicated workers and shared workers with
39  // a single process).
40  int worker_render_frame_id;
41  if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker(
42          info->GetChildID(), &origin_child_id, &worker_render_frame_id)) {
43    origin_child_id = info->GetChildID();
44  }
45}
46
47ResourceRequestDetails::~ResourceRequestDetails() {}
48
49ResourceRedirectDetails::ResourceRedirectDetails(const net::URLRequest* request,
50                                                 int cert_id,
51                                                 const GURL& new_url)
52    : ResourceRequestDetails(request, cert_id),
53      new_url(new_url) {
54}
55
56ResourceRedirectDetails::~ResourceRedirectDetails() {}
57
58}  // namespace content
59