1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
#define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
#include <string>
#include "base/memory/scoped_ptr.h"
class GURL;
namespace net {
class HttpResponseHeaders;
class URLRequest;
}
namespace android_webview {
class AwWebResourceResponse;
// This class provides a means of calling Java methods on an instance that has
// a 1:1 relationship with a WebContents instance directly from the IO thread.
//
// Specifically this is used to associate URLRequests with the WebContents that
// the URLRequest is made for.
//
// The native class is intended to be a short-lived handle that pins the
// Java-side instance. It is preferable to use the static getter methods to
// obtain a new instance of the class rather than holding on to one for
// prolonged periods of time (see note for more details).
//
// Note: The native AwContentsIoThreadClient instance has a Global ref to
// the Java object. By keeping the native AwContentsIoThreadClient
// instance alive you're also prolonging the lifetime of the Java instance, so
// don't keep a AwContentsIoThreadClient if you don't need to.
class AwContentsIoThreadClient {
public:
// Corresponds to WebSettings cache mode constants.
enum CacheMode {
LOAD_DEFAULT = -1,
LOAD_NORMAL = 0,
LOAD_CACHE_ELSE_NETWORK = 1,
LOAD_NO_CACHE = 2,
LOAD_CACHE_ONLY = 3,
};
virtual ~AwContentsIoThreadClient() {}
// Returns whether this is a new pop up that is still waiting for association
// with the java counter part.
virtual bool PendingAssociation() const = 0;
// Retrieve CacheMode setting value of this AwContents.
// This method is called on the IO thread only.
virtual CacheMode GetCacheMode() const = 0;
// This will attempt to fetch the AwContentsIoThreadClient for the given
// |render_process_id|, |render_frame_id| pair.
// This method can be called from any thread.
// An empty scoped_ptr is a valid return value.
static scoped_ptr<AwContentsIoThreadClient> FromID(int render_process_id,
int render_frame_id);
// Called on the IO thread when a subframe is created.
static void SubFrameCreated(int render_process_id,
int parent_render_frame_id,
int child_render_frame_id);
// This method is called on the IO thread only.
virtual scoped_ptr<AwWebResourceResponse> ShouldInterceptRequest(
const net::URLRequest* request) = 0;
// Retrieve the AllowContentAccess setting value of this AwContents.
// This method is called on the IO thread only.
virtual bool ShouldBlockContentUrls() const = 0;
// Retrieve the AllowFileAccess setting value of this AwContents.
// This method is called on the IO thread only.
virtual bool ShouldBlockFileUrls() const = 0;
// Retrieve the BlockNetworkLoads setting value of this AwContents.
// This method is called on the IO thread only.
virtual bool ShouldBlockNetworkLoads() const = 0;
// Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
virtual bool ShouldAcceptThirdPartyCookies() const = 0;
// Called when ResourceDispathcerHost detects a download request.
// The download is already cancelled when this is called, since
// relevant for DownloadListener is already extracted.
virtual void NewDownload(const GURL& url,
const std::string& user_agent,
const std::string& content_disposition,
const std::string& mime_type,
int64 content_length) = 0;
// Called when a new login request is detected. See the documentation for
// WebViewClient.onReceivedLoginRequest for arguments. Note that |account|
// may be empty.
virtual void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) = 0;
// Called when a resource loading error has occured (e.g. an I/O error,
// host name lookup failure etc.)
virtual void OnReceivedError(const net::URLRequest* request) = 0;
// Called when a response from the server is received with status code >= 400.
virtual void OnReceivedHttpError(
const net::URLRequest* request,
const net::HttpResponseHeaders* response_headers) = 0;
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
|