| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" |
| 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } |
| 14 | 21 |
| 15 namespace net { | 22 namespace net { |
| 16 class URLRequest; | 23 class URLRequest; |
| 17 } | 24 } |
| 18 | 25 |
| 19 namespace android_webview { | 26 namespace android_webview { |
| 20 | 27 |
| 21 class AwWebResourceResponse; | 28 class AwWebResourceResponse; |
| 22 | 29 |
| 23 // This class provides a means of calling Java methods on an instance that has | 30 // This class provides a means of calling Java methods on an instance that has |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 public: | 46 public: |
| 40 // Corresponds to WebSettings cache mode constants. | 47 // Corresponds to WebSettings cache mode constants. |
| 41 enum CacheMode { | 48 enum CacheMode { |
| 42 LOAD_DEFAULT = -1, | 49 LOAD_DEFAULT = -1, |
| 43 LOAD_NORMAL = 0, | 50 LOAD_NORMAL = 0, |
| 44 LOAD_CACHE_ELSE_NETWORK = 1, | 51 LOAD_CACHE_ELSE_NETWORK = 1, |
| 45 LOAD_NO_CACHE = 2, | 52 LOAD_NO_CACHE = 2, |
| 46 LOAD_CACHE_ONLY = 3, | 53 LOAD_CACHE_ONLY = 3, |
| 47 }; | 54 }; |
| 48 | 55 |
| 49 virtual ~AwContentsIoThreadClient() {} | 56 // Called when AwContents is created before there is a Java client. |
| 57 static void RegisterPendingContents(content::WebContents* web_contents); |
| 58 |
| 59 // Associates the |jclient| instance (which must implement the |
| 60 // AwContentsIoThreadClient Java interface) with the |web_contents|. |
| 61 // This should be called at most once per |web_contents|. |
| 62 static void Associate(content::WebContents* web_contents, |
| 63 const base::android::JavaRef<jobject>& jclient); |
| 64 |
| 65 // Sets the |jclient| java instance to which service worker related |
| 66 // callbacks should be delegated. |
| 67 static void SetServiceWorkerIoThreadClient( |
| 68 const base::android::JavaRef<jobject>& jclient, |
| 69 const base::android::JavaRef<jobject>& browser_context); |
| 70 |
| 71 // Either |pending_associate| is true or |jclient| holds a non-null |
| 72 // Java object. |
| 73 AwContentsIoThreadClient(bool pending_associate, |
| 74 const base::android::JavaRef<jobject>& jclient); |
| 75 ~AwContentsIoThreadClient(); |
| 76 |
| 77 // Implementation of AwContentsIoThreadClient. |
| 50 | 78 |
| 51 // Returns whether this is a new pop up that is still waiting for association | 79 // Returns whether this is a new pop up that is still waiting for association |
| 52 // with the java counter part. | 80 // with the java counter part. |
| 53 virtual bool PendingAssociation() const = 0; | 81 bool PendingAssociation() const; |
| 54 | 82 |
| 55 // Retrieve CacheMode setting value of this AwContents. | 83 // Retrieve CacheMode setting value of this AwContents. |
| 56 // This method is called on the IO thread only. | 84 // This method is called on the IO thread only. |
| 57 virtual CacheMode GetCacheMode() const = 0; | 85 CacheMode GetCacheMode() const; |
| 58 | 86 |
| 59 // This will attempt to fetch the AwContentsIoThreadClient for the given | 87 // This will attempt to fetch the AwContentsIoThreadClient for the given |
| 60 // |render_process_id|, |render_frame_id| pair. | 88 // |render_process_id|, |render_frame_id| pair. |
| 61 // This method can be called from any thread. | 89 // This method can be called from any thread. |
| 62 // An empty scoped_ptr is a valid return value. | 90 // An empty scoped_ptr is a valid return value. |
| 63 static std::unique_ptr<AwContentsIoThreadClient> FromID(int render_process_id, | 91 static std::unique_ptr<AwContentsIoThreadClient> FromID(int render_process_id, |
| 64 int render_frame_id); | 92 int render_frame_id); |
| 65 | 93 |
| 66 // This map is useful when browser side navigations are enabled as | 94 // This map is useful when browser side navigations are enabled as |
| 67 // render_frame_ids will not be valid anymore for some of the navigations. | 95 // render_frame_ids will not be valid anymore for some of the navigations. |
| 68 static std::unique_ptr<AwContentsIoThreadClient> FromID( | 96 static std::unique_ptr<AwContentsIoThreadClient> FromID( |
| 69 int frame_tree_node_id); | 97 int frame_tree_node_id); |
| 70 | 98 |
| 71 // Returns the global thread client for service worker related callbacks. | 99 // Returns the global thread client for service worker related callbacks. |
| 72 // An empty scoped_ptr is a valid return value. | 100 // An empty scoped_ptr is a valid return value. |
| 73 static std::unique_ptr<AwContentsIoThreadClient> | 101 static std::unique_ptr<AwContentsIoThreadClient> |
| 74 GetServiceWorkerIoThreadClient(); | 102 GetServiceWorkerIoThreadClient(); |
| 75 | 103 |
| 76 // Called on the IO thread when a subframe is created. | 104 // Called on the IO thread when a subframe is created. |
| 77 static void SubFrameCreated(int render_process_id, | 105 static void SubFrameCreated(int render_process_id, |
| 78 int parent_render_frame_id, | 106 int parent_render_frame_id, |
| 79 int child_render_frame_id); | 107 int child_render_frame_id); |
| 80 | 108 |
| 81 // This method is called on the IO thread only. | 109 // This method is called on the IO thread only. |
| 82 typedef base::Callback<void(std::unique_ptr<AwWebResourceResponse>)> | 110 typedef base::Callback<void(std::unique_ptr<AwWebResourceResponse>)> |
| 83 ShouldInterceptRequestResultCallback; | 111 ShouldInterceptRequestResultCallback; |
| 84 virtual void ShouldInterceptRequestAsync( | 112 void ShouldInterceptRequestAsync( |
| 85 const net::URLRequest* request, | 113 const net::URLRequest* request, |
| 86 const ShouldInterceptRequestResultCallback callback) = 0; | 114 const ShouldInterceptRequestResultCallback callback); |
| 87 | 115 |
| 88 // Retrieve the AllowContentAccess setting value of this AwContents. | 116 // Retrieve the AllowContentAccess setting value of this AwContents. |
| 89 // This method is called on the IO thread only. | 117 // This method is called on the IO thread only. |
| 90 virtual bool ShouldBlockContentUrls() const = 0; | 118 bool ShouldBlockContentUrls() const; |
| 91 | 119 |
| 92 // Retrieve the AllowFileAccess setting value of this AwContents. | 120 // Retrieve the AllowFileAccess setting value of this AwContents. |
| 93 // This method is called on the IO thread only. | 121 // This method is called on the IO thread only. |
| 94 virtual bool ShouldBlockFileUrls() const = 0; | 122 bool ShouldBlockFileUrls() const; |
| 95 | 123 |
| 96 // Retrieve the BlockNetworkLoads setting value of this AwContents. | 124 // Retrieve the BlockNetworkLoads setting value of this AwContents. |
| 97 // This method is called on the IO thread only. | 125 // This method is called on the IO thread only. |
| 98 virtual bool ShouldBlockNetworkLoads() const = 0; | 126 bool ShouldBlockNetworkLoads() const; |
| 99 | 127 |
| 100 // Retrieve the AcceptThirdPartyCookies setting value of this AwContents. | 128 // Retrieve the AcceptThirdPartyCookies setting value of this AwContents. |
| 101 virtual bool ShouldAcceptThirdPartyCookies() const = 0; | 129 bool ShouldAcceptThirdPartyCookies() const; |
| 102 | 130 |
| 103 // Retrieve the SafeBrowsingEnabled setting value of this AwContents. | 131 // Retrieve the SafeBrowsingEnabled setting value of this AwContents. |
| 104 virtual bool GetSafeBrowsingEnabled() const = 0; | 132 bool GetSafeBrowsingEnabled() const; |
| 133 |
| 134 private: |
| 135 bool pending_association_; |
| 136 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| 137 base::android::ScopedJavaGlobalRef<jobject> bg_thread_client_object_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(AwContentsIoThreadClient); |
| 105 }; | 140 }; |
| 106 | 141 |
| 107 } // namespace android_webview | 142 } // namespace android_webview |
| 108 | 143 |
| 109 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ | 144 #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ |
| OLD | NEW |