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 InterceptedRequestData
;
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_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
,
65 // This method is called on the IO thread only.
66 virtual scoped_ptr
<InterceptedRequestData
> ShouldInterceptRequest(
68 const net::URLRequest
* request
) = 0;
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;
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;
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;
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;
91 // Called when a new login request is detected. See the documentation for
92 // WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
94 virtual void NewLoginRequest(const std::string
& realm
,
95 const std::string
& account
,
96 const std::string
& args
) = 0;
99 } // namespace android_webview
101 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_