Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_IO_THREAD_CLIENT_H_ | |
| 6 #define ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_IO_THREAD_CLIENT_H_ | |
| 7 | |
| 8 #include "base/android/scoped_java_ref.h" | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 | |
| 12 class GURL; | |
| 13 class InterceptedRequestData; | |
| 14 class JavaDelegateMapMaintainer; | |
| 15 | |
| 16 namespace content { | |
| 17 class WebContents; | |
| 18 } | |
| 19 | |
| 20 namespace net { | |
| 21 class URLRequest; | |
| 22 } | |
| 23 | |
| 24 namespace android_webview { | |
| 25 | |
| 26 // This lets us implement URLRequest intercepting in a way that lets the | |
| 27 // embedder associate URLRequests with the WebContents that the URLRequest | |
| 28 // is made for. | |
|
joth
2012/09/13 20:09:12
nit: maybe generalize the comment to describe this
mkosiba (inactive)
2012/09/17 17:48:22
everybody would love me (puppy eyes), yes!
| |
| 29 // | |
| 30 // The native class is intended to be a short-lived handle that pins the | |
| 31 // Java-side instance. It is preferable to use the static getter methods to | |
| 32 // obtain a new instance of the class rather than holding on to one for | |
| 33 // prolonged periods of time (see note for more details). | |
| 34 // | |
| 35 // Note: The native AwContentsIoThreadClient instance has a Global ref to | |
| 36 // the Java object. By keeping the native AwContentsIoThreadClient | |
| 37 // instance alive you're also prolonging the lifetime of the Java instance, so | |
| 38 // don't keep a AwContentsIoThreadClient if you don't need to. | |
| 39 class AwContentsIoThreadClient { | |
| 40 public: | |
| 41 // This will attempt to fetch the AwContentsIoThreadClient for the given | |
| 42 // |render_process_id|, |render_view_id| pair. | |
| 43 // This method can be called from any thread. | |
| 44 // An empty scoped_ptr is a valid return value. | |
| 45 static AwContentsIoThreadClient FromID(int render_process_id, | |
| 46 int render_view_id); | |
| 47 | |
| 48 // Associates the |jclient| instance (which must implement the | |
| 49 // AwContentsIoThreadClient Java interface) with the |web_contents|. | |
| 50 // This should be called at most once per |web_contents|. | |
| 51 static void Associate(content::WebContents* web_contents, | |
| 52 const base::android::JavaRef<jobject>& jclient); | |
| 53 | |
| 54 // JNI registration method. | |
| 55 static bool RegisterAwContentsIoThreadClient(JNIEnv* env); | |
| 56 | |
| 57 AwContentsIoThreadClient(const AwContentsIoThreadClient& orig); | |
| 58 ~AwContentsIoThreadClient(); | |
| 59 void operator=(const AwContentsIoThreadClient& rhs); | |
| 60 | |
| 61 // This method is called on the IO thread only. | |
| 62 scoped_ptr<InterceptedRequestData> ShouldInterceptRequest( | |
| 63 const net::URLRequest* request); | |
| 64 | |
| 65 private: | |
| 66 AwContentsIoThreadClient(); | |
| 67 AwContentsIoThreadClient(const base::android::JavaRef<jobject>& jclient); | |
| 68 | |
| 69 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
| 70 }; | |
| 71 | |
| 72 } // namespace android_webview | |
| 73 | |
| 74 #endif // ANDROID_WEBVIEW_NATIVE_AW_CONTENTS_IO_THREAD_CLIENT_H_ | |
| OLD | NEW |