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

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

Issue 572013002: Removing ContentViewCore dependencies from direct WebContents functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch and addressed review comments. Created 6 years, 2 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.app.Activity; 8 import android.app.Activity;
9 import android.app.SearchManager; 9 import android.app.SearchManager;
10 import android.content.ClipboardManager; 10 import android.content.ClipboardManager;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 import org.chromium.content.browser.input.PastePopupMenu.PastePopupMenuDelegate; 68 import org.chromium.content.browser.input.PastePopupMenu.PastePopupMenuDelegate;
69 import org.chromium.content.browser.input.PopupTouchHandleDrawable; 69 import org.chromium.content.browser.input.PopupTouchHandleDrawable;
70 import org.chromium.content.browser.input.PopupTouchHandleDrawable.PopupTouchHan dleDrawableDelegate; 70 import org.chromium.content.browser.input.PopupTouchHandleDrawable.PopupTouchHan dleDrawableDelegate;
71 import org.chromium.content.browser.input.SelectPopup; 71 import org.chromium.content.browser.input.SelectPopup;
72 import org.chromium.content.browser.input.SelectPopupDialog; 72 import org.chromium.content.browser.input.SelectPopupDialog;
73 import org.chromium.content.browser.input.SelectPopupDropdown; 73 import org.chromium.content.browser.input.SelectPopupDropdown;
74 import org.chromium.content.browser.input.SelectPopupItem; 74 import org.chromium.content.browser.input.SelectPopupItem;
75 import org.chromium.content.browser.input.SelectionEventType; 75 import org.chromium.content.browser.input.SelectionEventType;
76 import org.chromium.content.common.ContentSwitches; 76 import org.chromium.content.common.ContentSwitches;
77 import org.chromium.content_public.browser.GestureStateListener; 77 import org.chromium.content_public.browser.GestureStateListener;
78 import org.chromium.content_public.browser.JavaScriptCallback;
79 import org.chromium.content_public.browser.WebContents; 78 import org.chromium.content_public.browser.WebContents;
80 import org.chromium.ui.base.DeviceFormFactor; 79 import org.chromium.ui.base.DeviceFormFactor;
81 import org.chromium.ui.base.ViewAndroid; 80 import org.chromium.ui.base.ViewAndroid;
82 import org.chromium.ui.base.ViewAndroidDelegate; 81 import org.chromium.ui.base.ViewAndroidDelegate;
83 import org.chromium.ui.base.WindowAndroid; 82 import org.chromium.ui.base.WindowAndroid;
84 import org.chromium.ui.gfx.DeviceDisplayInfo; 83 import org.chromium.ui.gfx.DeviceDisplayInfo;
85 84
86 import java.lang.annotation.Annotation; 85 import java.lang.annotation.Annotation;
87 import java.lang.reflect.Field; 86 import java.lang.reflect.Field;
88 import java.util.ArrayList; 87 import java.util.ArrayList;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 // If OSK is newly shown, delay the form foc us until 569 // If OSK is newly shown, delay the form foc us until
571 // the onSizeChanged (in order to adjust rel ative to the 570 // the onSizeChanged (in order to adjust rel ative to the
572 // new size). 571 // new size).
573 // TODO(jdduke): We should not assume that o nSizeChanged will 572 // TODO(jdduke): We should not assume that o nSizeChanged will
574 // always be called, crbug.com/294908. 573 // always be called, crbug.com/294908.
575 getContainerView().getWindowVisibleDisplayFr ame( 574 getContainerView().getWindowVisibleDisplayFr ame(
576 mFocusPreOSKViewportRect); 575 mFocusPreOSKViewportRect);
577 } else if (hasFocus() && resultCode == 576 } else if (hasFocus() && resultCode ==
578 InputMethodManager.RESULT_UNCHANGED_SHOW N) { 577 InputMethodManager.RESULT_UNCHANGED_SHOW N) {
579 // If the OSK was already there, focus the f orm immediately. 578 // If the OSK was already there, focus the f orm immediately.
580 scrollFocusedEditableNodeIntoView(); 579 assert mWebContents != null;
580 mWebContents.scrollFocusedEditableNodeIntoVi ew();
581 } 581 }
582 } 582 }
583 }; 583 };
584 } 584 }
585 } 585 }
586 ); 586 );
587 } 587 }
588 588
589 /** 589 /**
590 * 590 *
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 846 }
847 return mContentViewClient; 847 return mContentViewClient;
848 } 848 }
849 849
850 @CalledByNative 850 @CalledByNative
851 private void onBackgroundColorChanged(int color) { 851 private void onBackgroundColorChanged(int color) {
852 getContentViewClient().onBackgroundColorChanged(color); 852 getContentViewClient().onBackgroundColorChanged(color);
853 } 853 }
854 854
855 /** 855 /**
856 * Shows an interstitial page driven by the passed in delegate.
857 *
858 * @param url The URL being blocked by the interstitial.
859 * @param delegate The delegate handling the interstitial.
860 */
861 @VisibleForTesting
862 public void showInterstitialPage(
863 String url, InterstitialPageDelegateAndroid delegate) {
864 assert mWebContents != null;
865 mWebContents.showInterstitialPage(url, delegate.getNative());
866 }
867
868 /**
869 * @return Whether the page is currently showing an interstitial, such as a bad HTTPS page.
870 */
871 public boolean isShowingInterstitialPage() {
872 assert mWebContents != null;
873 return mWebContents.isShowingInterstitialPage();
874 }
875
876 /**
877 * @return Viewport width in physical pixels as set from onSizeChanged. 856 * @return Viewport width in physical pixels as set from onSizeChanged.
878 */ 857 */
879 @CalledByNative 858 @CalledByNative
880 public int getViewportWidthPix() { return mViewportWidthPix; } 859 public int getViewportWidthPix() {
860 return mViewportWidthPix;
861 }
881 862
882 /** 863 /**
883 * @return Viewport height in physical pixels as set from onSizeChanged. 864 * @return Viewport height in physical pixels as set from onSizeChanged.
884 */ 865 */
885 @CalledByNative 866 @CalledByNative
886 public int getViewportHeightPix() { return mViewportHeightPix; } 867 public int getViewportHeightPix() {
868 return mViewportHeightPix;
869 }
887 870
888 /** 871 /**
889 * @return Width of underlying physical surface. 872 * @return Width of underlying physical surface.
890 */ 873 */
891 @CalledByNative 874 @CalledByNative
892 public int getPhysicalBackingWidthPix() { return mPhysicalBackingWidthPix; } 875 public int getPhysicalBackingWidthPix() {
876 return mPhysicalBackingWidthPix;
877 }
893 878
894 /** 879 /**
895 * @return Height of underlying physical surface. 880 * @return Height of underlying physical surface.
896 */ 881 */
897 @CalledByNative 882 @CalledByNative
898 public int getPhysicalBackingHeightPix() { return mPhysicalBackingHeightPix; } 883 public int getPhysicalBackingHeightPix() {
884 return mPhysicalBackingHeightPix;
885 }
899 886
900 /* TODO(aelias): Remove these when downstream callers disappear. */ 887 /* TODO(aelias): Remove these when downstream callers disappear. */
901 @VisibleForTesting 888 @VisibleForTesting
902 public int getViewportSizeOffsetWidthPix() { return 0; } 889 public int getViewportSizeOffsetWidthPix() {
890 return 0;
891 }
892
903 @VisibleForTesting 893 @VisibleForTesting
904 public int getViewportSizeOffsetHeightPix() { return getTopControlsLayoutHei ghtPix(); } 894 public int getViewportSizeOffsetHeightPix() {
895 return getTopControlsLayoutHeightPix();
896 }
905 897
906 /** 898 /**
907 * @return The amount that the viewport size given to Blink is shrunk by the URL-bar.. 899 * @return The amount that the viewport size given to Blink is shrunk by the URL-bar..
908 */ 900 */
909 @CalledByNative 901 @CalledByNative
910 public int getTopControlsLayoutHeightPix() { return mTopControlsLayoutHeight Pix; } 902 public int getTopControlsLayoutHeightPix() {
903 return mTopControlsLayoutHeightPix;
904 }
911 905
912 /** 906 /**
913 * @see android.webkit.WebView#getContentHeight() 907 * @see android.webkit.WebView#getContentHeight()
914 */ 908 */
915 public float getContentHeightCss() { 909 public float getContentHeightCss() {
916 return mRenderCoordinates.getContentHeightCss(); 910 return mRenderCoordinates.getContentHeightCss();
917 } 911 }
918 912
919 /** 913 /**
920 * @see android.webkit.WebView#getContentWidth() 914 * @see android.webkit.WebView#getContentWidth()
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 computeVerticalScrollOffset(), 1172 computeVerticalScrollOffset(),
1179 computeVerticalScrollExtent()); 1173 computeVerticalScrollExtent());
1180 break; 1174 break;
1181 default: 1175 default:
1182 break; 1176 break;
1183 } 1177 }
1184 } 1178 }
1185 } 1179 }
1186 1180
1187 /** 1181 /**
1188 * Inserts the provided markup sandboxed into the frame.
1189 */
1190 public void setupTransitionView(String markup) {
1191 assert mWebContents != null;
1192 mWebContents.setupTransitionView(markup);
1193 }
1194
1195 /**
1196 * Hides transition elements specified by the selector, and activates any
1197 * exiting-transition stylesheets.
1198 */
1199 public void beginExitTransition(String cssSelector) {
1200 assert mWebContents != null;
1201 mWebContents.beginExitTransition(cssSelector);
1202 }
1203
1204 /**
1205 * Requests the renderer insert a link to the specified stylesheet in the
1206 * main frame's document.
1207 */
1208 public void addStyleSheetByURL(String url) {
1209 assert mWebContents != null;
1210 mWebContents.addStyleSheetByURL(url);
1211 }
1212
1213 /**
1214 * Injects the passed Javascript code in the current page and evaluates it.
1215 * If a result is required, pass in a callback.
1216 * Used in automation tests.
1217 *
1218 * @param script The Javascript to execute.
1219 * @param callback The callback to be fired off when a result is ready. The script's
1220 * result will be json encoded and passed as the parameter, and the call
1221 * will be made on the main thread.
1222 * If no result is required, pass null.
1223 */
1224 public void evaluateJavaScript(String script, JavaScriptCallback callback) {
1225 assert mWebContents != null;
1226 mWebContents.evaluateJavaScript(script, callback);
1227 }
1228
1229 /**
1230 * Post a message to a frame. 1182 * Post a message to a frame.
1231 * TODO(sgurun) also add support for transferring a message channel port. 1183 * TODO(sgurun) also add support for transferring a message channel port.
1232 * 1184 *
1233 * @param frameName The name of the frame. If the name is null the message i s posted 1185 * @param frameName The name of the frame. If the name is null the message i s posted
1234 * to the main frame. 1186 * to the main frame.
1235 * @param message The message 1187 * @param message The message
1236 * @param sourceOrigin The source origin 1188 * @param sourceOrigin The source origin
1237 * @param targetOrigin The target origin 1189 * @param targetOrigin The target origin
1238 */ 1190 */
1239 public void postMessageToFrame(String frameName, String message, 1191 public void postMessageToFrame(String frameName, String message,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 mPopupZoomer.hide(false); 1400 mPopupZoomer.hide(false);
1449 1401
1450 // Execute a delayed form focus operation because the OSK was brought 1402 // Execute a delayed form focus operation because the OSK was brought
1451 // up earlier. 1403 // up earlier.
1452 if (!mFocusPreOSKViewportRect.isEmpty()) { 1404 if (!mFocusPreOSKViewportRect.isEmpty()) {
1453 Rect rect = new Rect(); 1405 Rect rect = new Rect();
1454 getContainerView().getWindowVisibleDisplayFrame(rect); 1406 getContainerView().getWindowVisibleDisplayFrame(rect);
1455 if (!rect.equals(mFocusPreOSKViewportRect)) { 1407 if (!rect.equals(mFocusPreOSKViewportRect)) {
1456 // Only assume the OSK triggered the onSizeChanged if width was preserved. 1408 // Only assume the OSK triggered the onSizeChanged if width was preserved.
1457 if (rect.width() == mFocusPreOSKViewportRect.width()) { 1409 if (rect.width() == mFocusPreOSKViewportRect.width()) {
1458 scrollFocusedEditableNodeIntoView(); 1410 assert mWebContents != null;
1411 mWebContents.scrollFocusedEditableNodeIntoView();
1459 } 1412 }
1460 cancelRequestToScrollFocusedEditableNodeIntoView(); 1413 cancelRequestToScrollFocusedEditableNodeIntoView();
1461 } 1414 }
1462 } 1415 }
1463 } 1416 }
1464 1417
1465 private void cancelRequestToScrollFocusedEditableNodeIntoView() { 1418 private void cancelRequestToScrollFocusedEditableNodeIntoView() {
1466 // Zero-ing the rect will prevent |updateAfterSizeChanged()| from 1419 // Zero-ing the rect will prevent |updateAfterSizeChanged()| from
1467 // issuing the delayed form focus event. 1420 // issuing the delayed form focus event.
1468 mFocusPreOSKViewportRect.setEmpty(); 1421 mFocusPreOSKViewportRect.setEmpty();
1469 } 1422 }
1470 1423
1471 private void scrollFocusedEditableNodeIntoView() {
1472 assert mWebContents != null;
1473 mWebContents.scrollFocusedEditableNodeIntoView();
1474 }
1475
1476 /**
1477 * Selects the word around the caret, if any.
1478 * The caller can check if selection actually occurred by listening to OnSel ectionChanged.
1479 */
1480 public void selectWordAroundCaret() {
1481 assert mWebContents != null;
1482 mWebContents.selectWordAroundCaret();
1483 }
1484
1485 /** 1424 /**
1486 * @see View#onWindowFocusChanged(boolean) 1425 * @see View#onWindowFocusChanged(boolean)
1487 */ 1426 */
1488 public void onWindowFocusChanged(boolean hasWindowFocus) { 1427 public void onWindowFocusChanged(boolean hasWindowFocus) {
1489 if (!hasWindowFocus) resetGestureDetection(); 1428 if (!hasWindowFocus) resetGestureDetection();
1490 } 1429 }
1491 1430
1492 public void onFocusChanged(boolean gainFocus) { 1431 public void onFocusChanged(boolean gainFocus) {
1493 if (gainFocus) { 1432 if (gainFocus) {
1494 restoreSelectionPopupsIfNecessary(); 1433 restoreSelectionPopupsIfNecessary();
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 2465
2527 /** 2466 /**
2528 * Return the current scale of the ContentView. 2467 * Return the current scale of the ContentView.
2529 * @return The current page scale factor. 2468 * @return The current page scale factor.
2530 */ 2469 */
2531 @VisibleForTesting 2470 @VisibleForTesting
2532 public float getScale() { 2471 public float getScale() {
2533 return mRenderCoordinates.getPageScaleFactor(); 2472 return mRenderCoordinates.getPageScaleFactor();
2534 } 2473 }
2535 2474
2536 /**
2537 * If the view is ready to draw contents to the screen. In hardware mode,
2538 * the initialization of the surface texture may not occur until after the
2539 * view has been added to the layout. This method will return {@code true}
2540 * once the texture is actually ready.
2541 */
2542 public boolean isReady() {
2543 assert mWebContents != null;
2544 return mWebContents.isReady();
2545 }
2546
2547 @CalledByNative 2475 @CalledByNative
2548 private void startContentIntent(String contentUrl) { 2476 private void startContentIntent(String contentUrl) {
2549 getContentViewClient().onStartContentIntent(getContext(), contentUrl); 2477 getContentViewClient().onStartContentIntent(getContext(), contentUrl);
2550 } 2478 }
2551 2479
2552 @Override 2480 @Override
2553 public void onAccessibilityStateChanged(boolean enabled) { 2481 public void onAccessibilityStateChanged(boolean enabled) {
2554 setAccessibilityState(enabled); 2482 setAccessibilityState(enabled);
2555 } 2483 }
2556 2484
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 * Sets whether or not we should set accessibility focus on page load. 2695 * Sets whether or not we should set accessibility focus on page load.
2768 * This only applies if an accessibility service like TalkBack is running. 2696 * This only applies if an accessibility service like TalkBack is running.
2769 * This is desirable behavior for a browser window, but not for an embedded 2697 * This is desirable behavior for a browser window, but not for an embedded
2770 * WebView. 2698 * WebView.
2771 */ 2699 */
2772 public void setShouldSetAccessibilityFocusOnPageLoad(boolean on) { 2700 public void setShouldSetAccessibilityFocusOnPageLoad(boolean on) {
2773 mShouldSetAccessibilityFocusOnPageLoad = on; 2701 mShouldSetAccessibilityFocusOnPageLoad = on;
2774 } 2702 }
2775 2703
2776 /** 2704 /**
2777 * Inform WebKit that Fullscreen mode has been exited by the user.
2778 */
2779 public void exitFullscreen() {
2780 assert mWebContents != null;
2781 mWebContents.exitFullscreen();
2782 }
2783
2784 /**
2785 * Changes whether hiding the top controls is enabled.
2786 *
2787 * @param enableHiding Whether hiding the top controls should be enabled or not.
2788 * @param enableShowing Whether showing the top controls should be enabled o r not.
2789 * @param animate Whether the transition should be animated or not.
2790 */
2791 public void updateTopControlsState(boolean enableHiding, boolean enableShowi ng,
2792 boolean animate) {
2793 assert mWebContents != null;
2794 mWebContents.updateTopControlsState(
2795 enableHiding, enableShowing, animate);
2796 }
2797
2798 /**
2799 * @return The cached copy of render positions and scales. 2705 * @return The cached copy of render positions and scales.
2800 */ 2706 */
2801 public RenderCoordinates getRenderCoordinates() { 2707 public RenderCoordinates getRenderCoordinates() {
2802 return mRenderCoordinates; 2708 return mRenderCoordinates;
2803 } 2709 }
2804 2710
2805 @CalledByNative 2711 @CalledByNative
2806 private static Rect createRect(int x, int y, int right, int bottom) { 2712 private static Rect createRect(int x, int y, int right, int bottom) {
2807 return new Rect(x, y, right, bottom); 2713 return new Rect(x, y, right, bottom);
2808 } 2714 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 if (mPotentiallyActiveFlingCount <= 0) return; 2812 if (mPotentiallyActiveFlingCount <= 0) return;
2907 mPotentiallyActiveFlingCount--; 2813 mPotentiallyActiveFlingCount--;
2908 updateGestureStateListener(GestureEventType.FLING_END); 2814 updateGestureStateListener(GestureEventType.FLING_END);
2909 } 2815 }
2910 2816
2911 @Override 2817 @Override
2912 public void onScreenOrientationChanged(int orientation) { 2818 public void onScreenOrientationChanged(int orientation) {
2913 sendOrientationChangeEvent(orientation); 2819 sendOrientationChangeEvent(orientation);
2914 } 2820 }
2915 2821
2916 public void resumeResponseDeferredAtStart() {
2917 assert mWebContents != null;
2918 mWebContents.resumeResponseDeferredAtStart();
2919 }
2920
2921 /** 2822 /**
2922 * Set whether the ContentViewCore requires the WebContents to be fullscreen in order to lock 2823 * Set whether the ContentViewCore requires the WebContents to be fullscreen in order to lock
2923 * the screen orientation. 2824 * the screen orientation.
2924 */ 2825 */
2925 public void setFullscreenRequiredForOrientationLock(boolean value) { 2826 public void setFullscreenRequiredForOrientationLock(boolean value) {
2926 mFullscreenRequiredForOrientationLock = value; 2827 mFullscreenRequiredForOrientationLock = value;
2927 } 2828 }
2928 2829
2929 @CalledByNative 2830 @CalledByNative
2930 private boolean isFullscreenRequiredForOrientationLock() { 2831 private boolean isFullscreenRequiredForOrientationLock() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 private native void nativeWasResized(long nativeContentViewCoreImpl); 2931 private native void nativeWasResized(long nativeContentViewCoreImpl);
3031 2932
3032 private native void nativeSetAccessibilityEnabled( 2933 private native void nativeSetAccessibilityEnabled(
3033 long nativeContentViewCoreImpl, boolean enabled); 2934 long nativeContentViewCoreImpl, boolean enabled);
3034 2935
3035 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l, 2936 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l,
3036 int x, int y, int w, int h); 2937 int x, int y, int w, int h);
3037 2938
3038 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 2939 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
3039 } 2940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698