[Android] Redirect obsolete chrome:// URLs to NTP.
[chromium-blink-merge.git] / android_webview / browser / aw_contents_io_thread_client.h
blobe24097616d771ba25fc444f5e79941eebffd7811
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.
5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
12 class GURL;
14 namespace net {
15 class HttpResponseHeaders;
16 class URLRequest;
19 namespace android_webview {
21 class AwWebResourceResponse;
23 // This class provides a means of calling Java methods on an instance that has
24 // a 1:1 relationship with a WebContents instance directly from the IO thread.
26 // Specifically this is used to associate URLRequests with the WebContents that
27 // the URLRequest is made for.
29 // The native class is intended to be a short-lived handle that pins the
30 // Java-side instance. It is preferable to use the static getter methods to
31 // obtain a new instance of the class rather than holding on to one for
32 // prolonged periods of time (see note for more details).
34 // Note: The native AwContentsIoThreadClient instance has a Global ref to
35 // the Java object. By keeping the native AwContentsIoThreadClient
36 // instance alive you're also prolonging the lifetime of the Java instance, so
37 // don't keep a AwContentsIoThreadClient if you don't need to.
38 class AwContentsIoThreadClient {
39 public:
40 // Corresponds to WebSettings cache mode constants.
41 enum CacheMode {
42 LOAD_DEFAULT = -1,
43 LOAD_NORMAL = 0,
44 LOAD_CACHE_ELSE_NETWORK = 1,
45 LOAD_NO_CACHE = 2,
46 LOAD_CACHE_ONLY = 3,
49 virtual ~AwContentsIoThreadClient() {}
51 // Returns whether this is a new pop up that is still waiting for association
52 // with the java counter part.
53 virtual bool PendingAssociation() const = 0;
55 // Retrieve CacheMode setting value of this AwContents.
56 // This method is called on the IO thread only.
57 virtual CacheMode GetCacheMode() const = 0;
59 // This will attempt to fetch the AwContentsIoThreadClient for the given
60 // |render_process_id|, |render_frame_id| pair.
61 // This method can be called from any thread.
62 // An empty scoped_ptr is a valid return value.
63 static scoped_ptr<AwContentsIoThreadClient> FromID(int render_process_id,
64 int render_frame_id);
66 // Called on the IO thread when a subframe is created.
67 static void SubFrameCreated(int render_process_id,
68 int parent_render_frame_id,
69 int child_render_frame_id);
71 // This method is called on the IO thread only.
72 virtual scoped_ptr<AwWebResourceResponse> ShouldInterceptRequest(
73 const net::URLRequest* request) = 0;
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;
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;
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;
87 // Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
88 virtual bool ShouldAcceptThirdPartyCookies() const = 0;
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;
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;
106 // Called when a resource loading error has occured (e.g. an I/O error,
107 // host name lookup failure etc.)
108 virtual void OnReceivedError(const net::URLRequest* request) = 0;
110 // Called when a response from the server is received with status code >= 400.
111 virtual void OnReceivedHttpError(
112 const net::URLRequest* request,
113 const net::HttpResponseHeaders* response_headers) = 0;
116 } // namespace android_webview
118 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_