Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / net / xwalk_url_request_job_factory.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_NET_XWALK_URL_REQUEST_JOB_FACTORY_H_
7 #define XWALK_RUNTIME_BROWSER_ANDROID_NET_XWALK_URL_REQUEST_JOB_FACTORY_H_
8
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "net/url_request/url_request_job_factory.h"
13
14 namespace net {
15 class URLRequestJobFactoryImpl;
16 }  // namespace net
17
18 namespace xwalk {
19
20 // Crosswalk uses a custom URLRequestJobFactoryImpl to support
21 // navigation interception and URLRequestJob interception for navigations to
22 // url with unsupported schemes.
23 // This is achieved by returning a URLRequestErrorJob for schemes that would
24 // otherwise be unhandled, which gives the embedder an opportunity to intercept
25 // the request.
26 class XWalkURLRequestJobFactory : public net::URLRequestJobFactory {
27  public:
28   XWalkURLRequestJobFactory();
29   virtual ~XWalkURLRequestJobFactory();
30
31   bool SetProtocolHandler(const std::string& scheme,
32                           ProtocolHandler* protocol_handler);
33
34   // net::URLRequestJobFactory implementation.
35   virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
36       const std::string& scheme,
37       net::URLRequest* request,
38       net::NetworkDelegate* network_delegate) const override;
39
40   net::URLRequestJob* MaybeInterceptRedirect(
41       net::URLRequest* request,
42       net::NetworkDelegate* network_delegate,
43       const GURL& location) const override;
44
45   net::URLRequestJob* MaybeInterceptResponse(
46       net::URLRequest* request,
47       net::NetworkDelegate* network_delegate) const override;
48
49   bool IsHandledProtocol(const std::string& scheme) const override;
50   bool IsHandledURL(const GURL& url) const override;
51   bool IsSafeRedirectTarget(const GURL& location) const override;
52
53  private:
54   // By default calls are forwarded to this factory, to avoid having to
55   // subclass an existing implementation class.
56   scoped_ptr<net::URLRequestJobFactoryImpl> next_factory_;
57
58   DISALLOW_COPY_AND_ASSIGN(XWalkURLRequestJobFactory);
59 };
60
61 }  // namespace xwalk
62
63 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_NET_XWALK_URL_REQUEST_JOB_FACTORY_H_