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

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: s/isValid/mIsConnected/ 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 , mImeAdapter);
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);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 @VisibleForTesting 763 @VisibleForTesting
765 public void setPopupZoomerForTest(PopupZoomer popupZoomer) { 764 public void setPopupZoomerForTest(PopupZoomer popupZoomer) {
766 mPopupZoomer = popupZoomer; 765 mPopupZoomer = popupZoomer;
767 } 766 }
768 767
769 /** 768 /**
770 * Destroy the internal state of the ContentView. This method may only be 769 * Destroy the internal state of the ContentView. This method may only be
771 * called after the ContentView has been removed from the view system. No 770 * called after the ContentView has been removed from the view system. No
772 * other methods may be called on this ContentView after this method has 771 * other methods may be called on this ContentView after this method has
773 * been called. 772 * been called.
774 * Warning: destroy() is not guranteed to be called in Android WebView. 773 * Warning: destroy() is not guranteed to be called in Android WebView.
boliu 2017/03/22 16:55:02 this will leak on webview
Jinsuk Kim 2017/03/23 01:17:49 Moved it to |onNativeContentViewCoreDestroyed()|
775 * Any object that relies solely on destroy() being called to be cleaned up 774 * Any object that relies solely on destroy() being called to be cleaned up
776 * will leak in Android WebView. If appropriate, consider clean up in 775 * will leak in Android WebView. If appropriate, consider clean up in
777 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w. 776 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w.
778 */ 777 */
779 public void destroy() { 778 public void destroy() {
780 removeDisplayAndroidObserver(); 779 removeDisplayAndroidObserver();
781 if (mNativeContentViewCore != 0) { 780 if (mNativeContentViewCore != 0) {
782 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); 781 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore);
783 } 782 }
784 mWebContentsObserver.destroy(); 783 mWebContentsObserver.destroy();
785 mWebContentsObserver = null; 784 mWebContentsObserver = null;
786 mImeAdapter.resetAndHideKeyboard(); 785 mImeAdapter.destroy();
786
787 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not 787 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not
788 // currently a real Null Object. 788 // currently a real Null Object.
789 // 789 //
790 // Instead of deleting the client we use the Null Object pattern to avoi d null checks 790 // Instead of deleting the client we use the Null Object pattern to avoi d null checks
791 // in this class. 791 // in this class.
792 mContentViewClient = new ContentViewClient(); 792 mContentViewClient = new ContentViewClient();
793 mWebContents = null; 793 mWebContents = null;
794 mNativeContentViewCore = 0; 794 mNativeContentViewCore = 0;
795 mJavaScriptInterfaces.clear(); 795 mJavaScriptInterfaces.clear();
796 mRetainedJavaScriptObjects.clear(); 796 mRetainedJavaScriptObjects.clear();
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 } 1745 }
1746 1746
1747 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker, 1747 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker,
1748 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop, 1748 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop,
1749 insertionMarkerBottom); 1749 insertionMarkerBottom);
1750 1750
1751 TraceEvent.end("ContentViewCore:updateFrameInfo"); 1751 TraceEvent.end("ContentViewCore:updateFrameInfo");
1752 } 1752 }
1753 1753
1754 @CalledByNative 1754 @CalledByNative
1755 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e, 1755 private void updateImeAdapter(int textInputType, int textInputFlags, int tex tInputMode,
1756 int textInputFlags, int textInputMode, String text, int selectionSta rt, 1756 String text, int selectionStart, int selectionEnd, int compositionSt art,
1757 int selectionEnd, int compositionStart, int compositionEnd, boolean showImeIfNeeded, 1757 int compositionEnd, boolean showImeIfNeeded, boolean replyToRequest) {
1758 boolean replyToRequest) {
1759 try { 1758 try {
1760 TraceEvent.begin("ContentViewCore.updateImeAdapter"); 1759 TraceEvent.begin("ContentViewCore.updateImeAdapter");
1761 boolean focusedNodeEditable = (textInputType != TextInputType.NONE); 1760 boolean focusedNodeEditable = (textInputType != TextInputType.NONE);
1762 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD); 1761 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD);
1763 1762
1764 mImeAdapter.attach(nativeImeAdapterAndroid);
1765 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded, 1763 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded,
1766 text, selectionStart, selectionEnd, compositionStart, compos itionEnd, 1764 text, selectionStart, selectionEnd, compositionStart, compos itionEnd,
1767 replyToRequest); 1765 replyToRequest);
1768 1766
1769 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble()); 1767 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble());
1770 mSelectionPopupController.updateSelectionState(focusedNodeEditable, 1768 mSelectionPopupController.updateSelectionState(focusedNodeEditable,
1771 focusedNodeIsPassword); 1769 focusedNodeIsPassword);
1772 if (editableToggled) { 1770 if (editableToggled) {
1773 mJoystickScrollProvider.setEnabled(!focusedNodeEditable); 1771 mJoystickScrollProvider.setEnabled(!focusedNodeEditable);
1774 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable); 1772 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable);
1775 } 1773 }
1776 } finally { 1774 } finally {
1777 TraceEvent.end("ContentViewCore.updateImeAdapter"); 1775 TraceEvent.end("ContentViewCore.updateImeAdapter");
1778 } 1776 }
1779 } 1777 }
1780 1778
1781 @CalledByNative
1782 private void forceUpdateImeAdapter(long nativeImeAdapterAndroid) {
1783 mImeAdapter.attach(nativeImeAdapterAndroid);
1784 }
1785
1786 /** 1779 /**
1787 * Called (from native) when the <select> popup needs to be shown. 1780 * Called (from native) when the <select> popup needs to be shown.
1788 * @param anchorView View anchored for popup. 1781 * @param anchorView View anchored for popup.
1789 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup. 1782 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup.
1790 * @param items Items to show. 1783 * @param items Items to show.
1791 * @param enabled POPUP_ITEM_TYPEs for items. 1784 * @param enabled POPUP_ITEM_TYPEs for items.
1792 * @param multiple Whether the popup menu should support multi-select . 1785 * @param multiple Whether the popup menu should support multi-select .
1793 * @param selectedIndices Indices of selected items. 1786 * @param selectedIndices Indices of selected items.
1794 */ 1787 */
1795 @SuppressWarnings("unused") 1788 @SuppressWarnings("unused")
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 } 1883 }
1891 1884
1892 private boolean canPaste() { 1885 private boolean canPaste() {
1893 return ((ClipboardManager) mContext.getSystemService( 1886 return ((ClipboardManager) mContext.getSystemService(
1894 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); 1887 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
1895 } 1888 }
1896 1889
1897 @SuppressWarnings("unused") 1890 @SuppressWarnings("unused")
1898 @CalledByNative 1891 @CalledByNative
1899 private void onRenderProcessChange() { 1892 private void onRenderProcessChange() {
1900 attachImeAdapter();
1901 // Immediately sync closed caption settings to the new render process. 1893 // Immediately sync closed caption settings to the new render process.
1902 mSystemCaptioningBridge.syncToListener(this); 1894 mSystemCaptioningBridge.syncToListener(this);
1903 } 1895 }
1904 1896
1905 /** 1897 /**
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() 1898 * @see View#hasFocus()
1916 */ 1899 */
1917 @CalledByNative 1900 @CalledByNative
1918 private boolean hasFocus() { 1901 private boolean hasFocus() {
1919 // If the container view is not focusable, we consider it always focused from 1902 // If the container view is not focusable, we consider it always focused from
1920 // Chromium's point of view. 1903 // Chromium's point of view.
1921 if (!mContainerView.isFocusable()) return true; 1904 if (!mContainerView.isFocusable()) return true;
1922 return mContainerView.hasFocus(); 1905 return mContainerView.hasFocus();
1923 } 1906 }
1924 1907
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 @VisibleForTesting 2566 @VisibleForTesting
2584 public ResultReceiver getNewShowKeyboardReceiver() { 2567 public ResultReceiver getNewShowKeyboardReceiver() {
2585 if (mShowKeyboardResultReceiver == null) { 2568 if (mShowKeyboardResultReceiver == null) {
2586 // Note: the returned object will get leaked by Android framework. 2569 // Note: the returned object will get leaked by Android framework.
2587 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler()); 2570 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler());
2588 } 2571 }
2589 return mShowKeyboardResultReceiver; 2572 return mShowKeyboardResultReceiver;
2590 } 2573 }
2591 2574
2592 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate, 2575 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate,
2593 long windowAndroidPtr, float dipScale, HashSet<Object> retainedObjec tSet); 2576 long windowAndroidPtr, long imeAdapterPtr, float dipScale,
2577 HashSet<Object> retainedObjectSet);
2594 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents); 2578 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents);
2595 2579
2596 private native void nativeUpdateWindowAndroid( 2580 private native void nativeUpdateWindowAndroid(
2597 long nativeContentViewCoreImpl, long windowAndroidPtr); 2581 long nativeContentViewCoreImpl, long windowAndroidPtr);
2598 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl); 2582 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl);
2599 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl); 2583 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl);
2600 2584
2601 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl); 2585 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl);
2602 2586
2603 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused); 2587 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 2632
2649 private native void nativeSetDoubleTapSupportEnabled( 2633 private native void nativeSetDoubleTapSupportEnabled(
2650 long nativeContentViewCoreImpl, boolean enabled); 2634 long nativeContentViewCoreImpl, boolean enabled);
2651 2635
2652 private native void nativeSetMultiTouchZoomSupportEnabled( 2636 private native void nativeSetMultiTouchZoomSupportEnabled(
2653 long nativeContentViewCoreImpl, boolean enabled); 2637 long nativeContentViewCoreImpl, boolean enabled);
2654 2638
2655 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l, 2639 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l,
2656 long nativeSelectPopupSourceFrame, int[] indices); 2640 long nativeSelectPopupSourceFrame, int[] indices);
2657 2641
2658
2659 private native long nativeGetNativeImeAdapter(long nativeContentViewCoreImpl );
2660
2661 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl); 2642 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl);
2662 2643
2663 private native void nativeSetAllowJavascriptInterfacesInspection( 2644 private native void nativeSetAllowJavascriptInterfacesInspection(
2664 long nativeContentViewCoreImpl, boolean allow); 2645 long nativeContentViewCoreImpl, boolean allow);
2665 2646
2666 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object, 2647 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object,
2667 String name, Class requiredAnnotation); 2648 String name, Class requiredAnnotation);
2668 2649
2669 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl, 2650 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl,
2670 String name); 2651 String name);
2671 2652
2672 private native void nativeWasResized(long nativeContentViewCoreImpl); 2653 private native void nativeWasResized(long nativeContentViewCoreImpl);
2673 2654
2674 private native void nativeSetAccessibilityEnabled( 2655 private native void nativeSetAccessibilityEnabled(
2675 long nativeContentViewCoreImpl, boolean enabled); 2656 long nativeContentViewCoreImpl, boolean enabled);
2676 2657
2677 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l, 2658 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l,
2678 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily, 2659 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily,
2679 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor, 2660 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor,
2680 String textTrackTextShadow, String textTrackTextSize); 2661 String textTrackTextShadow, String textTrackTextSize);
2681 2662
2682 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 2663 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
2683 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); 2664 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl);
2684 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, 2665 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y,
2685 int screenX, int screenY, String[] mimeTypes, String content); 2666 int screenX, int screenY, String[] mimeTypes, String content);
2686 } 2667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698