summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_data_job.cc
blob: 3d9dacef3d26ba8bb8f68940421c18d7eea36825 (plain)
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
// 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.

// Simple implementation of a data: protocol handler.

#include "net/url_request/url_request_data_job.h"

#include "net/base/data_url.h"
#include "net/url_request/url_request.h"

// static
URLRequestJob* URLRequestDataJob::Factory(net::URLRequest* request,
                                          const std::string& scheme) {
  return new URLRequestDataJob(request);
}

URLRequestDataJob::URLRequestDataJob(net::URLRequest* request)
    : URLRequestSimpleJob(request) {
}

bool URLRequestDataJob::GetData(std::string* mime_type,
                                std::string* charset,
                                std::string* data) const {
  // Check if data URL is valid. If not, don't bother to try to extract data.
  // Otherwise, parse the data from the data URL.
  const GURL& url = request_->url();
  if (!url.is_valid())
    return false;
  return net::DataURL::Parse(url, mime_type, charset, data);
}

URLRequestDataJob::~URLRequestDataJob() {
}