1 // Copyright (c) 2009 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/url_request/url_request.h"
11
12 // static
Factory(URLRequest * request,const std::string & scheme)13 URLRequestJob* URLRequestDataJob::Factory(URLRequest* request,
14 const std::string& scheme) {
15 return new URLRequestDataJob(request);
16 }
17
URLRequestDataJob(URLRequest * request)18 URLRequestDataJob::URLRequestDataJob(URLRequest* request)
19 : URLRequestSimpleJob(request) {
20 }
21
22
GetData(std::string * mime_type,std::string * charset,std::string * data) const23 bool URLRequestDataJob::GetData(std::string* mime_type,
24 std::string* charset,
25 std::string* data) const {
26 // Check if data URL is valid. If not, don't bother to try to extract data.
27 // Otherwise, parse the data from the data URL.
28 const GURL& url = request_->url();
29 if (!url.is_valid())
30 return false;
31 return net::DataURL::Parse(url, mime_type, charset, data);
32 }
33
34