Index: content/browser/renderer_host/ime_adapter_android.cc |
diff --git a/content/browser/renderer_host/ime_adapter_android.cc b/content/browser/renderer_host/ime_adapter_android.cc |
index 3a7d18b94da7ce41b8a4981e98e7d87b3eda70cc..9f9479aaf08e8ae5288132fdd62b85e9cdc20185 100644 |
--- a/content/browser/renderer_host/ime_adapter_android.cc |
+++ b/content/browser/renderer_host/ime_adapter_android.cc |
@@ -14,11 +14,8 @@ |
#include "base/android/scoped_java_ref.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
-#include "content/browser/frame_host/frame_tree.h" |
-#include "content/browser/frame_host/frame_tree_node.h" |
#include "content/browser/frame_host/render_frame_host_impl.h" |
#include "content/browser/renderer_host/render_view_host_delegate.h" |
-#include "content/browser/renderer_host/render_view_host_impl.h" |
#include "content/browser/renderer_host/render_widget_host_impl.h" |
#include "content/browser/renderer_host/render_widget_host_view_android.h" |
#include "content/common/input_messages.h" |
@@ -110,6 +107,7 @@ void AppendUnderlineSpan(JNIEnv*, |
ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
: rwhva_(rwhva) { |
+ DCHECK(rwhva_); |
} |
ImeAdapterAndroid::~ImeAdapterAndroid() { |
@@ -142,7 +140,7 @@ void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
const JavaParamRef<jobject>& text, |
const JavaParamRef<jstring>& text_str, |
int relative_cursor_pos) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
if (!rwhi) |
return; |
@@ -172,7 +170,7 @@ void ImeAdapterAndroid::CommitText(JNIEnv* env, |
const JavaParamRef<jobject>& text, |
const JavaParamRef<jstring>& text_str, |
int relative_cursor_pos) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
if (!rwhi) |
return; |
@@ -195,7 +193,7 @@ void ImeAdapterAndroid::CommitText(JNIEnv* env, |
void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, |
const JavaParamRef<jobject>&) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
if (!rwhi) |
return; |
@@ -288,7 +286,7 @@ void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, |
bool ImeAdapterAndroid::RequestTextInputStateUpdate( |
JNIEnv* env, |
const JavaParamRef<jobject>&) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
if (!rwhi) |
return false; |
rwhi->Send(new InputMsg_RequestTextInputStateUpdate(rwhi->GetRoutingID())); |
@@ -300,7 +298,7 @@ void ImeAdapterAndroid::RequestCursorUpdate( |
const base::android::JavaParamRef<jobject>& obj, |
bool immediate_request, |
bool monitor_request) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
if (!rwhi) |
return; |
rwhi->Send(new InputMsg_RequestCompositionUpdate( |
@@ -312,36 +310,34 @@ void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, |
java_ime_adapter_.reset(); |
} |
-RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { |
+RenderWidgetHostImpl* ImeAdapterAndroid::GetFocusedWidget() { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- DCHECK(rwhva_); |
- RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); |
- if (!rwh) |
- return nullptr; |
- |
- return RenderWidgetHostImpl::From(rwh); |
+ return rwhva_->GetFocusedWidget(); |
} |
RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { |
- RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
- if (!rwh) |
- return nullptr; |
- RenderViewHost* rvh = RenderViewHost::From(rwh); |
- if (!rvh) |
- return nullptr; |
- FrameTreeNode* focused_frame = |
- rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); |
- if (!focused_frame) |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ // We get the focused frame from the WebContents of the page. Although |
+ // |rwhva_->GetFocusedWidget()| does a similar thing, but, there is no direct |
Charlie Reis
2017/01/29 18:08:14
nit: Drop "but," (since you already lead with "Alt
EhsanK
2017/01/31 15:53:14
Done. Thanks!
|
+ // way to get a RenderFrameHost from its RWH. |
+ RenderWidgetHostImpl* rwh = |
+ RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
+ if (!rwh || !rwh->delegate()) |
Charlie Reis
2017/01/29 18:08:14
I think you might need a null check on the GetAsWe
EhsanK
2017/01/31 15:53:14
Acknowledged.
|
return nullptr; |
- return focused_frame->current_frame_host(); |
+ return rwh->delegate()->GetAsWebContents()->GetFocusedFrame(); |
Charlie Reis
2017/01/29 18:08:14
Thanks-- much better to go through WebContents tha
EhsanK
2017/01/31 15:53:14
Acknowledged.
|
} |
WebContents* ImeAdapterAndroid::GetWebContents() { |
- RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
- if (!rwh) |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
EhsanK
2017/01/31 15:53:14
This method was not actually used given that:
1-
Charlie Reis
2017/01/31 17:01:28
Great!
|
+ // WebContents is the delegate for any RWH on the page. Therefore, we simply |
+ // use the page's RWHV to get to the WebContents. |
+ RenderWidgetHostImpl* rwh = |
+ RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
+ if (!rwh || !rwh->delegate()) |
return nullptr; |
- return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
+ |
+ return rwh->delegate()->GetAsWebContents(); |
} |
std::vector<blink::WebCompositionUnderline> |