Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 CONTENT_BROWSER_ANDROID_CONTEXT_SELECTION_CLIENT_H_ | |
| 6 #define CONTENT_BROWSER_ANDROID_CONTEXT_SELECTION_CLIENT_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include "base/android/jni_weak_ref.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class WebContents; | |
| 18 | |
| 19 // The native portion of Java ContextSelectionClient. | |
| 20 // This class performs one operation: retrieves the selected text together with | |
| 21 // its surrounding context from WebContents. This surrounding text is obtained | |
| 22 // asynchronously from the current focused frame and passed back to Java layer. | |
| 23 class ContextSelectionClient { | |
| 24 public: | |
| 25 ContextSelectionClient(JNIEnv* env, | |
| 26 const base::android::JavaRef<jobject>& obj, | |
| 27 WebContents* web_contents); | |
| 28 | |
| 29 // Sends asynchronius request to retrieve the text. | |
| 30 void RequestSurroundingText(JNIEnv* env, | |
| 31 const base::android::JavaParamRef<jobject>& obj, | |
| 32 int num_extra_characters, | |
| 33 int callback_data); | |
| 34 | |
| 35 // Cancels all pending requests. | |
| 36 void CancelAllRequests(JNIEnv* env, | |
| 37 const base::android::JavaParamRef<jobject>& obj); | |
| 38 | |
| 39 private: | |
| 40 class UserData; | |
|
Ted C
2017/03/30 00:12:39
Ah...I was thinking this didn't need to be an inne
Tima Vaisburd
2017/03/30 01:03:13
Done.
| |
| 41 friend class UserData; | |
| 42 | |
| 43 ~ContextSelectionClient(); | |
| 44 | |
| 45 void OnSurroundingTextReceived(int callback_data, | |
| 46 const base::string16& text, | |
| 47 int start, | |
| 48 int end); | |
| 49 | |
| 50 // A weak reference to the Java ContentSelectionClient object. | |
| 51 JavaObjectWeakGlobalRef java_ref_; | |
| 52 | |
| 53 // WebContents is used to find the relevant RenderFrameHost that can send | |
| 54 // the request for the text. | |
| 55 WebContents* web_contents_; | |
| 56 | |
| 57 base::WeakPtrFactory<ContextSelectionClient> weak_ptr_factory_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(ContextSelectionClient); | |
| 60 }; | |
| 61 | |
| 62 bool RegisterContextSelectionClient(JNIEnv* env); | |
| 63 | |
| 64 } // namespace content | |
| 65 | |
| 66 #endif // CONTENT_BROWSER_ANDROID_CONTEXT_SELECTION_CLIENT_H_ | |
| OLD | NEW |