Index: content/browser/renderer_host/ime_adapter_android.cc |
=================================================================== |
--- content/browser/renderer_host/ime_adapter_android.cc (revision 255719) |
+++ content/browser/renderer_host/ime_adapter_android.cc (working copy) |
@@ -11,9 +11,14 @@ |
#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_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/view_messages.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/native_web_keyboard_event.h" |
#include "jni/ImeAdapter_jni.h" |
#include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
@@ -240,27 +245,21 @@ |
} |
void ImeAdapterAndroid::Cut(JNIEnv* env, jobject) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
- if (!rwhi) |
- return; |
- |
- rwhi->Cut(); |
+ RenderFrameHost* rfh = GetFocusedFrame(); |
+ if (rfh) |
+ rfh->Cut(); |
} |
void ImeAdapterAndroid::Copy(JNIEnv* env, jobject) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
- if (!rwhi) |
- return; |
- |
- rwhi->Copy(); |
+ RenderFrameHost* rfh = GetFocusedFrame(); |
+ if (rfh) |
+ rfh->Copy(); |
} |
void ImeAdapterAndroid::Paste(JNIEnv* env, jobject) { |
- RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
- if (!rwhi) |
- return; |
- |
- rwhi->Paste(); |
+ RenderFrameHost* rfh = GetFocusedFrame(); |
+ if (rfh) |
+ rfh->Paste(); |
} |
void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, jobject) { |
@@ -268,6 +267,7 @@ |
} |
RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(rwhva_); |
RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); |
if (!rwh) |
@@ -276,4 +276,21 @@ |
return RenderWidgetHostImpl::From(rwh); |
} |
+RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { |
+ RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
+ if (!rwh) |
+ return NULL; |
+ if (!rwh->IsRenderView()) |
+ return NULL; |
+ RenderViewHost* rvh = RenderViewHost::From(rwh); |
+ RenderFrameHostImpl* rfh = |
+ static_cast<RenderFrameHostImpl*>(rvh->GetMainFrame()); |
+ FrameTreeNode* focused_frame = |
+ rfh->frame_tree_node()->frame_tree()->GetFocusedFrame(); |
+ if (!focused_frame) |
+ return NULL; |
+ |
+ return focused_frame->current_frame_host(); |
+} |
+ |
} // namespace content |