Upstream version 11.40.277.0
[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 AwWebResourceResponse;
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_frame_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_frame_id);
64
65   // Called on the IO thread when a subframe is created.
66   static void SubFrameCreated(int render_process_id,
67                               int parent_render_frame_id,
68                               int child_render_frame_id);
69
70   // This method is called on the IO thread only.
71   virtual scoped_ptr<AwWebResourceResponse> ShouldInterceptRequest(
72       const GURL& location,
73       const net::URLRequest* request) = 0;
74
75   // Retrieve the AllowContentAccess setting value of this AwContents.
76   // This method is called on the IO thread only.
77   virtual bool ShouldBlockContentUrls() const = 0;
78
79   // Retrieve the AllowFileAccess setting value of this AwContents.
80   // This method is called on the IO thread only.
81   virtual bool ShouldBlockFileUrls() const = 0;
82
83   // Retrieve the BlockNetworkLoads setting value of this AwContents.
84   // This method is called on the IO thread only.
85   virtual bool ShouldBlockNetworkLoads() const = 0;
86
87   // Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
88   virtual bool ShouldAcceptThirdPartyCookies() const = 0;
89
90   // Called when ResourceDispathcerHost detects a download request.
91   // The download is already cancelled when this is called, since
92   // relevant for DownloadListener is already extracted.
93   virtual void NewDownload(const GURL& url,
94                            const std::string& user_agent,
95                            const std::string& content_disposition,
96                            const std::string& mime_type,
97                            int64 content_length) = 0;
98
99   // Called when a new login request is detected. See the documentation for
100   // WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
101   // may be empty.
102   virtual void NewLoginRequest(const std::string& realm,
103                                const std::string& account,
104                                const std::string& args) = 0;
105 };
106
107 } // namespace android_webview
108
109 #endif  // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_