- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / browser / aw_contents_io_thread_client.h
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 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11
12 class GURL;
13
14 namespace net {
15 class URLRequest;
16 }
17
18 namespace android_webview {
19
20 class InterceptedRequestData;
21
22 // This class provides a means of calling Java methods on an instance that has
23 // a 1:1 relationship with a WebContents instance directly from the IO thread.
24 //
25 // Specifically this is used to associate URLRequests with the WebContents that
26 // the URLRequest is made for.
27 //
28 // The native class is intended to be a short-lived handle that pins the
29 // Java-side instance. It is preferable to use the static getter methods to
30 // obtain a new instance of the class rather than holding on to one for
31 // prolonged periods of time (see note for more details).
32 //
33 // Note: The native AwContentsIoThreadClient instance has a Global ref to
34 // the Java object. By keeping the native AwContentsIoThreadClient
35 // instance alive you're also prolonging the lifetime of the Java instance, so
36 // don't keep a AwContentsIoThreadClient if you don't need to.
37 class AwContentsIoThreadClient {
38  public:
39   // Corresponds to WebSettings cache mode constants.
40   enum CacheMode {
41     LOAD_DEFAULT = -1,
42     LOAD_NORMAL = 0,
43     LOAD_CACHE_ELSE_NETWORK = 1,
44     LOAD_NO_CACHE = 2,
45     LOAD_CACHE_ONLY = 3,
46   };
47
48   virtual ~AwContentsIoThreadClient() {}
49
50   // Returns whether this is a new pop up that is still waiting for association
51   // with the java counter part.
52   virtual bool PendingAssociation() const = 0;
53
54   // Retrieve CacheMode setting value of this AwContents.
55   // This method is called on the IO thread only.
56   virtual CacheMode GetCacheMode() const = 0;
57
58   // This will attempt to fetch the AwContentsIoThreadClient for the given
59   // |render_process_id|, |render_view_id| pair.
60   // This method can be called from any thread.
61   // An empty scoped_ptr is a valid return value.
62   static scoped_ptr<AwContentsIoThreadClient> FromID(int render_process_id,
63                                                      int render_view_id);
64
65   // This method is called on the IO thread only.
66   virtual scoped_ptr<InterceptedRequestData> ShouldInterceptRequest(
67       const GURL& location,
68       const net::URLRequest* request) = 0;
69
70   // Retrieve the AllowContentAccess setting value of this AwContents.
71   // This method is called on the IO thread only.
72   virtual bool ShouldBlockContentUrls() const = 0;
73
74   // Retrieve the AllowFileAccess setting value of this AwContents.
75   // This method is called on the IO thread only.
76   virtual bool ShouldBlockFileUrls() const = 0;
77
78   // Retrieve the BlockNetworkLoads setting value of this AwContents.
79   // This method is called on the IO thread only.
80   virtual bool ShouldBlockNetworkLoads() const = 0;
81
82   // Called when ResourceDispathcerHost detects a download request.
83   // The download is already cancelled when this is called, since
84   // relevant for DownloadListener is already extracted.
85   virtual void NewDownload(const GURL& url,
86                            const std::string& user_agent,
87                            const std::string& content_disposition,
88                            const std::string& mime_type,
89                            int64 content_length) = 0;
90
91   // Called when a new login request is detected. See the documentation for
92   // WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
93   // may be empty.
94   virtual void NewLoginRequest(const std::string& realm,
95                                const std::string& account,
96                                const std::string& args) = 0;
97 };
98
99 } // namespace android_webview
100
101 #endif  // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_