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_
10 #include "base/memory/scoped_ptr.h"
18 namespace android_webview
{
20 class AwWebResourceResponse
;
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.
25 // Specifically this is used to associate URLRequests with the WebContents that
26 // the URLRequest is made for.
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).
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
{
39 // Corresponds to WebSettings cache mode constants.
43 LOAD_CACHE_ELSE_NETWORK
= 1,
48 virtual ~AwContentsIoThreadClient() {}
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;
54 // Retrieve CacheMode setting value of this AwContents.
55 // This method is called on the IO thread only.
56 virtual CacheMode
GetCacheMode() const = 0;
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
,
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
);
70 // This method is called on the IO thread only.
71 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|
102 virtual void NewLoginRequest(const std::string
& realm
,
103 const std::string
& account
,
104 const std::string
& args
) = 0;
107 } // namespace android_webview
109 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_