Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 2752113005: Let ImeAdapterAndroid have the same lifecycle as its Java peer (Closed)
Patch Set: comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.assist.AssistStructure.ViewNode; 9 import android.app.assist.AssistStructure.ViewNode;
10 import android.content.ClipData; 10 import android.content.ClipData;
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 assert windowNativePointer != 0; 568 assert windowNativePointer != 0;
569 569
570 final float dipScale = windowAndroid.getDisplay().getDipScale(); 570 final float dipScale = windowAndroid.getDisplay().getDipScale();
571 571
572 mRenderCoordinates.reset(); 572 mRenderCoordinates.reset();
573 mRenderCoordinates.setDeviceScaleFactor(dipScale, windowAndroid.getConte xt()); 573 mRenderCoordinates.setDeviceScaleFactor(dipScale, windowAndroid.getConte xt());
574 574
575 mJoystickScrollProvider = 575 mJoystickScrollProvider =
576 new JoystickScrollProvider(webContents, getContainerView(), wind owAndroid); 576 new JoystickScrollProvider(webContents, getContainerView(), wind owAndroid);
577 577
578 mImeAdapter = createImeAdapter();
578 mNativeContentViewCore = nativeInit(webContents, mViewAndroidDelegate, w indowNativePointer, 579 mNativeContentViewCore = nativeInit(webContents, mViewAndroidDelegate, w indowNativePointer,
579 dipScale, mRetainedJavaScriptObjects); 580 mImeAdapter.getNativePointer(), dipScale, mRetainedJavaScriptObj ects);
580 mWebContents = nativeGetWebContentsAndroid(mNativeContentViewCore); 581 mWebContents = nativeGetWebContentsAndroid(mNativeContentViewCore);
581 582
582 setContainerViewInternals(internalDispatcher); 583 setContainerViewInternals(internalDispatcher);
583 584
584 initPopupZoomer(mContext); 585 initPopupZoomer(mContext);
585 mImeAdapter = createImeAdapter();
586 attachImeAdapter();
587 586
588 mSelectionPopupController = new SelectionPopupController(mContext, windo wAndroid, 587 mSelectionPopupController = new SelectionPopupController(mContext, windo wAndroid,
589 webContents, viewDelegate.getContainerView(), mRenderCoordinates , mImeAdapter); 588 webContents, viewDelegate.getContainerView(), mRenderCoordinates );
590 mSelectionPopupController.setCallback(ActionModeCallbackHelper.EMPTY_CAL LBACK); 589 mSelectionPopupController.setCallback(ActionModeCallbackHelper.EMPTY_CAL LBACK);
591 mSelectionPopupController.setContainerView(getContainerView()); 590 mSelectionPopupController.setContainerView(getContainerView());
592 591
593 mWebContentsObserver = new ContentViewWebContentsObserver(this); 592 mWebContentsObserver = new ContentViewWebContentsObserver(this);
594 593
595 mShouldRequestUnbufferedDispatch = Build.VERSION.SDK_INT >= Build.VERSIO N_CODES.LOLLIPOP 594 mShouldRequestUnbufferedDispatch = Build.VERSION.SDK_INT >= Build.VERSIO N_CODES.LOLLIPOP
596 && ContentFeatureList.isEnabled(ContentFeatureList.REQUEST_UNBUF FERED_DISPATCH); 595 && ContentFeatureList.isEnabled(ContentFeatureList.REQUEST_UNBUF FERED_DISPATCH);
597 } 596 }
598 597
599 /** 598 /**
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 mSelectionPopupController.setContainerView(containerView); 681 mSelectionPopupController.setContainerView(containerView);
683 } 682 }
684 } finally { 683 } finally {
685 TraceEvent.end("ContentViewCore.setContainerView"); 684 TraceEvent.end("ContentViewCore.setContainerView");
686 } 685 }
687 } 686 }
688 687
689 @CalledByNative 688 @CalledByNative
690 private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) { 689 private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) {
691 assert nativeContentViewCore == mNativeContentViewCore; 690 assert nativeContentViewCore == mNativeContentViewCore;
691 mImeAdapter.destroy();
boliu 2017/03/23 04:17:01 that still doesn't work for webview with gc. by th
boliu 2017/03/23 19:02:02 The other option is to have ime adapter lifetime b
Jinsuk Kim 2017/03/23 23:10:24 I can get the native CVC to own IAA and call Java
Jinsuk Kim 2017/03/24 02:34:23 Done.
692 mNativeContentViewCore = 0; 692 mNativeContentViewCore = 0;
693 } 693 }
694 694
695 /** 695 /**
696 * Set the Container view Internals. 696 * Set the Container view Internals.
697 * @param internalDispatcher Handles dispatching all hidden or super methods to the 697 * @param internalDispatcher Handles dispatching all hidden or super methods to the
698 * containerView. 698 * containerView.
699 */ 699 */
700 public void setContainerViewInternals(InternalAccessDelegate internalDispatc her) { 700 public void setContainerViewInternals(InternalAccessDelegate internalDispatc her) {
701 mContainerViewInternals = internalDispatcher; 701 mContainerViewInternals = internalDispatcher;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w. 777 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w.
778 */ 778 */
779 public void destroy() { 779 public void destroy() {
780 removeDisplayAndroidObserver(); 780 removeDisplayAndroidObserver();
781 if (mNativeContentViewCore != 0) { 781 if (mNativeContentViewCore != 0) {
782 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); 782 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore);
783 } 783 }
784 mWebContentsObserver.destroy(); 784 mWebContentsObserver.destroy();
785 mWebContentsObserver = null; 785 mWebContentsObserver = null;
786 mImeAdapter.resetAndHideKeyboard(); 786 mImeAdapter.resetAndHideKeyboard();
787
787 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not 788 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not
788 // currently a real Null Object. 789 // currently a real Null Object.
789 // 790 //
790 // Instead of deleting the client we use the Null Object pattern to avoi d null checks 791 // Instead of deleting the client we use the Null Object pattern to avoi d null checks
791 // in this class. 792 // in this class.
792 mContentViewClient = new ContentViewClient(); 793 mContentViewClient = new ContentViewClient();
793 mWebContents = null; 794 mWebContents = null;
794 mNativeContentViewCore = 0; 795 mNativeContentViewCore = 0;
795 mJavaScriptInterfaces.clear(); 796 mJavaScriptInterfaces.clear();
796 mRetainedJavaScriptObjects.clear(); 797 mRetainedJavaScriptObjects.clear();
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 } 1746 }
1746 1747
1747 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker, 1748 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker,
1748 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop, 1749 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop,
1749 insertionMarkerBottom); 1750 insertionMarkerBottom);
1750 1751
1751 TraceEvent.end("ContentViewCore:updateFrameInfo"); 1752 TraceEvent.end("ContentViewCore:updateFrameInfo");
1752 } 1753 }
1753 1754
1754 @CalledByNative 1755 @CalledByNative
1755 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e, 1756 private void updateImeAdapter(int textInputType, int textInputFlags, int tex tInputMode,
1756 int textInputFlags, int textInputMode, String text, int selectionSta rt, 1757 String text, int selectionStart, int selectionEnd, int compositionSt art,
1757 int selectionEnd, int compositionStart, int compositionEnd, boolean showImeIfNeeded, 1758 int compositionEnd, boolean showImeIfNeeded, boolean replyToRequest) {
1758 boolean replyToRequest) {
1759 try { 1759 try {
1760 TraceEvent.begin("ContentViewCore.updateImeAdapter"); 1760 TraceEvent.begin("ContentViewCore.updateImeAdapter");
1761 boolean focusedNodeEditable = (textInputType != TextInputType.NONE); 1761 boolean focusedNodeEditable = (textInputType != TextInputType.NONE);
1762 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD); 1762 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD);
1763 1763
1764 mImeAdapter.attach(nativeImeAdapterAndroid);
1765 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded, 1764 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded,
1766 text, selectionStart, selectionEnd, compositionStart, compos itionEnd, 1765 text, selectionStart, selectionEnd, compositionStart, compos itionEnd,
1767 replyToRequest); 1766 replyToRequest);
1768 1767
1769 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble()); 1768 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble());
1770 mSelectionPopupController.updateSelectionState(focusedNodeEditable, 1769 mSelectionPopupController.updateSelectionState(focusedNodeEditable,
1771 focusedNodeIsPassword); 1770 focusedNodeIsPassword);
1772 if (editableToggled) { 1771 if (editableToggled) {
1773 mJoystickScrollProvider.setEnabled(!focusedNodeEditable); 1772 mJoystickScrollProvider.setEnabled(!focusedNodeEditable);
1774 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable); 1773 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable);
1775 } 1774 }
1776 } finally { 1775 } finally {
1777 TraceEvent.end("ContentViewCore.updateImeAdapter"); 1776 TraceEvent.end("ContentViewCore.updateImeAdapter");
1778 } 1777 }
1779 } 1778 }
1780 1779
1781 @CalledByNative
1782 private void forceUpdateImeAdapter(long nativeImeAdapterAndroid) {
1783 mImeAdapter.attach(nativeImeAdapterAndroid);
1784 }
1785
1786 /** 1780 /**
1787 * Called (from native) when the <select> popup needs to be shown. 1781 * Called (from native) when the <select> popup needs to be shown.
1788 * @param anchorView View anchored for popup. 1782 * @param anchorView View anchored for popup.
1789 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup. 1783 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup.
1790 * @param items Items to show. 1784 * @param items Items to show.
1791 * @param enabled POPUP_ITEM_TYPEs for items. 1785 * @param enabled POPUP_ITEM_TYPEs for items.
1792 * @param multiple Whether the popup menu should support multi-select . 1786 * @param multiple Whether the popup menu should support multi-select .
1793 * @param selectedIndices Indices of selected items. 1787 * @param selectedIndices Indices of selected items.
1794 */ 1788 */
1795 @SuppressWarnings("unused") 1789 @SuppressWarnings("unused")
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 } 1884 }
1891 1885
1892 private boolean canPaste() { 1886 private boolean canPaste() {
1893 return ((ClipboardManager) mContext.getSystemService( 1887 return ((ClipboardManager) mContext.getSystemService(
1894 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); 1888 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
1895 } 1889 }
1896 1890
1897 @SuppressWarnings("unused") 1891 @SuppressWarnings("unused")
1898 @CalledByNative 1892 @CalledByNative
1899 private void onRenderProcessChange() { 1893 private void onRenderProcessChange() {
1900 attachImeAdapter();
1901 // Immediately sync closed caption settings to the new render process. 1894 // Immediately sync closed caption settings to the new render process.
1902 mSystemCaptioningBridge.syncToListener(this); 1895 mSystemCaptioningBridge.syncToListener(this);
1903 } 1896 }
1904 1897
1905 /** 1898 /**
1906 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI.
1907 */
1908 public void attachImeAdapter() {
1909 if (mImeAdapter != null && mNativeContentViewCore != 0) {
1910 mImeAdapter.attach(nativeGetNativeImeAdapter(mNativeContentViewCore) );
1911 }
1912 }
1913
1914 /**
1915 * @see View#hasFocus() 1899 * @see View#hasFocus()
1916 */ 1900 */
1917 @CalledByNative 1901 @CalledByNative
1918 private boolean hasFocus() { 1902 private boolean hasFocus() {
1919 // If the container view is not focusable, we consider it always focused from 1903 // If the container view is not focusable, we consider it always focused from
1920 // Chromium's point of view. 1904 // Chromium's point of view.
1921 if (!mContainerView.isFocusable()) return true; 1905 if (!mContainerView.isFocusable()) return true;
1922 return mContainerView.hasFocus(); 1906 return mContainerView.hasFocus();
1923 } 1907 }
1924 1908
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 @VisibleForTesting 2567 @VisibleForTesting
2584 public ResultReceiver getNewShowKeyboardReceiver() { 2568 public ResultReceiver getNewShowKeyboardReceiver() {
2585 if (mShowKeyboardResultReceiver == null) { 2569 if (mShowKeyboardResultReceiver == null) {
2586 // Note: the returned object will get leaked by Android framework. 2570 // Note: the returned object will get leaked by Android framework.
2587 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler()); 2571 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler());
2588 } 2572 }
2589 return mShowKeyboardResultReceiver; 2573 return mShowKeyboardResultReceiver;
2590 } 2574 }
2591 2575
2592 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate, 2576 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate,
2593 long windowAndroidPtr, float dipScale, HashSet<Object> retainedObjec tSet); 2577 long windowAndroidPtr, long imeAdapterPtr, float dipScale,
2578 HashSet<Object> retainedObjectSet);
2594 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents); 2579 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents);
2595 2580
2596 private native void nativeUpdateWindowAndroid( 2581 private native void nativeUpdateWindowAndroid(
2597 long nativeContentViewCoreImpl, long windowAndroidPtr); 2582 long nativeContentViewCoreImpl, long windowAndroidPtr);
2598 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl); 2583 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl);
2599 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl); 2584 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl);
2600 2585
2601 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl); 2586 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl);
2602 2587
2603 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused); 2588 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 2633
2649 private native void nativeSetDoubleTapSupportEnabled( 2634 private native void nativeSetDoubleTapSupportEnabled(
2650 long nativeContentViewCoreImpl, boolean enabled); 2635 long nativeContentViewCoreImpl, boolean enabled);
2651 2636
2652 private native void nativeSetMultiTouchZoomSupportEnabled( 2637 private native void nativeSetMultiTouchZoomSupportEnabled(
2653 long nativeContentViewCoreImpl, boolean enabled); 2638 long nativeContentViewCoreImpl, boolean enabled);
2654 2639
2655 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l, 2640 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l,
2656 long nativeSelectPopupSourceFrame, int[] indices); 2641 long nativeSelectPopupSourceFrame, int[] indices);
2657 2642
2658
2659 private native long nativeGetNativeImeAdapter(long nativeContentViewCoreImpl );
2660
2661 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl); 2643 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl);
2662 2644
2663 private native void nativeSetAllowJavascriptInterfacesInspection( 2645 private native void nativeSetAllowJavascriptInterfacesInspection(
2664 long nativeContentViewCoreImpl, boolean allow); 2646 long nativeContentViewCoreImpl, boolean allow);
2665 2647
2666 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object, 2648 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object,
2667 String name, Class requiredAnnotation); 2649 String name, Class requiredAnnotation);
2668 2650
2669 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl, 2651 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl,
2670 String name); 2652 String name);
2671 2653
2672 private native void nativeWasResized(long nativeContentViewCoreImpl); 2654 private native void nativeWasResized(long nativeContentViewCoreImpl);
2673 2655
2674 private native void nativeSetAccessibilityEnabled( 2656 private native void nativeSetAccessibilityEnabled(
2675 long nativeContentViewCoreImpl, boolean enabled); 2657 long nativeContentViewCoreImpl, boolean enabled);
2676 2658
2677 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l, 2659 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l,
2678 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily, 2660 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily,
2679 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor, 2661 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor,
2680 String textTrackTextShadow, String textTrackTextSize); 2662 String textTrackTextShadow, String textTrackTextSize);
2681 2663
2682 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 2664 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
2683 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); 2665 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl);
2684 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, 2666 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y,
2685 int screenX, int screenY, String[] mimeTypes, String content); 2667 int screenX, int screenY, String[] mimeTypes, String content);
2686 } 2668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698