blob: fd248c7d07a30ba4536d761bae561ee801a09cd9 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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// Simple implementation of a data: protocol handler.
6
7#include "net/url_request/url_request_data_job.h"
8
9#include "net/base/data_url.h"
10#include "net/base/net_errors.h"
11
12namespace net {
13
14URLRequestDataJob::URLRequestDataJob(
15 URLRequest* request, NetworkDelegate* network_delegate)
16 : URLRequestSimpleJob(request, network_delegate) {
17}
18
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019int URLRequestDataJob::GetData(std::string* mime_type,
20 std::string* charset,
21 std::string* data,
22 const CompletionCallback& callback) const {
23 // Check if data URL is valid. If not, don't bother to try to extract data.
24 // Otherwise, parse the data from the data URL.
25 const GURL& url = request_->url();
26 if (!url.is_valid())
27 return ERR_INVALID_URL;
28 return DataURL::Parse(url, mime_type, charset, data)? OK: ERR_INVALID_URL;
29}
30
31URLRequestDataJob::~URLRequestDataJob() {
32}
33
34} // namespace net