Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.pm.ActivityInfo; | 9 import android.content.pm.ActivityInfo; |
| 10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat e; | 44 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat e; |
| 45 import org.chromium.content.browser.accessibility.AccessibilityInjector; | 45 import org.chromium.content.browser.accessibility.AccessibilityInjector; |
| 46 import org.chromium.content.browser.input.AdapterInputConnection; | 46 import org.chromium.content.browser.input.AdapterInputConnection; |
| 47 import org.chromium.content.browser.input.HandleView; | 47 import org.chromium.content.browser.input.HandleView; |
| 48 import org.chromium.content.browser.input.ImeAdapter; | 48 import org.chromium.content.browser.input.ImeAdapter; |
| 49 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry; | 49 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry; |
| 50 import org.chromium.content.browser.input.InsertionHandleController; | 50 import org.chromium.content.browser.input.InsertionHandleController; |
| 51 import org.chromium.content.browser.input.SelectPopupDialog; | 51 import org.chromium.content.browser.input.SelectPopupDialog; |
| 52 import org.chromium.content.browser.input.SelectionHandleController; | 52 import org.chromium.content.browser.input.SelectionHandleController; |
| 53 import org.chromium.content.common.TraceEvent; | 53 import org.chromium.content.common.TraceEvent; |
| 54 import org.chromium.ui.gfx.NativeWindow; | 54 import org.chromium.ui.ViewAndroidDelegate; |
| 55 import org.chromium.ui.ViewAndroid; | |
| 56 import org.chromium.ui.gfx.WindowAndroid; | |
| 55 | 57 |
| 56 import java.lang.annotation.Annotation; | 58 import java.lang.annotation.Annotation; |
| 57 import java.util.HashMap; | 59 import java.util.HashMap; |
| 58 import java.util.HashSet; | 60 import java.util.HashSet; |
| 59 import java.util.Map; | 61 import java.util.Map; |
| 60 | 62 |
| 61 /** | 63 /** |
| 62 * Provides a Java-side 'wrapper' around a WebContent (native) instance. | 64 * Provides a Java-side 'wrapper' around a WebContent (native) instance. |
| 63 * Contains all the major functionality necessary to manage the lifecycle of a C ontentView without | 65 * Contains all the major functionality necessary to manage the lifecycle of a C ontentView without |
| 64 * being tied to the view system. | 66 * being tied to the view system. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 private final Rect mFocusPreOSKViewportRect = new Rect(); | 243 private final Rect mFocusPreOSKViewportRect = new Rect(); |
| 242 | 244 |
| 243 private boolean mNeedUpdateOrientationChanged; | 245 private boolean mNeedUpdateOrientationChanged; |
| 244 | 246 |
| 245 // Used to keep track of whether we should try to undo the last zoom-to-text field operation. | 247 // Used to keep track of whether we should try to undo the last zoom-to-text field operation. |
| 246 private boolean mScrolledAndZoomedFocusedEditableNode = false; | 248 private boolean mScrolledAndZoomedFocusedEditableNode = false; |
| 247 | 249 |
| 248 // Whether we use hardware-accelerated drawing. | 250 // Whether we use hardware-accelerated drawing. |
| 249 private boolean mHardwareAccelerated = false; | 251 private boolean mHardwareAccelerated = false; |
| 250 | 252 |
| 253 private ViewAndroid mViewAndroid; | |
| 254 | |
| 251 /** | 255 /** |
| 252 * Constructs a new ContentViewCore. Embedders must call initialize() after constructing | 256 * Constructs a new ContentViewCore. Embedders must call initialize() after constructing |
| 253 * a ContentViewCore and before using it. | 257 * a ContentViewCore and before using it. |
| 254 * | 258 * |
| 255 * @param context The context used to create this. | 259 * @param context The context used to create this. |
| 256 * @param personality The type of ContentViewCore being created. | 260 * @param personality The type of ContentViewCore being created. |
| 257 */ | 261 */ |
| 258 public ContentViewCore(Context context, int personality) { | 262 public ContentViewCore(Context context, int personality) { |
| 259 mContext = context; | 263 mContext = context; |
| 260 | 264 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 | 306 |
| 303 /** | 307 /** |
| 304 * Returns a delegate that can be used to add and remove views from the Cont ainerView. | 308 * Returns a delegate that can be used to add and remove views from the Cont ainerView. |
| 305 * | 309 * |
| 306 * NOTE: Use with care, as not all ContentViewCore users setup their Contain erView in the same | 310 * NOTE: Use with care, as not all ContentViewCore users setup their Contain erView in the same |
| 307 * way. In particular, the Android WebView has limitations on what implement ation details can | 311 * way. In particular, the Android WebView has limitations on what implement ation details can |
| 308 * be provided via a child view, as they are visible in the API and could in troduce | 312 * be provided via a child view, as they are visible in the API and could in troduce |
| 309 * compatibility breaks with existing applications. If in doubt, contact the | 313 * compatibility breaks with existing applications. If in doubt, contact the |
| 310 * android_webview/OWNERS | 314 * android_webview/OWNERS |
| 311 * | 315 * |
| 312 * @return A ContainerViewDelegate that can be used to add and remove views. | 316 * @return A ViewAndroidDelegate that can be used to add and remove views. |
| 313 */ | 317 */ |
| 314 @CalledByNative | 318 @VisibleForTesting |
| 315 public ContainerViewDelegate getContainerViewDelegate() { | 319 public ViewAndroidDelegate getViewAndroidDelegate() { |
| 316 return new ContainerViewDelegate() { | 320 return new ViewAndroidDelegate() { |
| 317 @Override | 321 @Override |
| 318 public void addViewToContainerView(View view) { | 322 public void addViewToContainerView(View view) { |
| 319 mContainerView.addView(view); | 323 mContainerView.addView(view); |
| 320 } | 324 } |
| 321 | 325 |
| 322 @Override | 326 @Override |
| 323 public void removeViewFromContainerView(View view) { | 327 public void removeViewFromContainerView(View view) { |
| 324 mContainerView.removeView(view); | 328 mContainerView.removeView(view); |
| 325 } | 329 } |
| 326 | 330 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 } | 448 } |
| 445 return false; | 449 return false; |
| 446 } | 450 } |
| 447 | 451 |
| 448 /** | 452 /** |
| 449 * | 453 * |
| 450 * @param containerView The view that will act as a container for all views created by this. | 454 * @param containerView The view that will act as a container for all views created by this. |
| 451 * @param internalDispatcher Handles dispatching all hidden or super methods to the | 455 * @param internalDispatcher Handles dispatching all hidden or super methods to the |
| 452 * containerView. | 456 * containerView. |
| 453 * @param nativeWebContents A pointer to the native web contents. | 457 * @param nativeWebContents A pointer to the native web contents. |
| 454 * @param nativeWindow An instance of the NativeWindow. | 458 * @param windowAndroid An instance of the WindowAndroid. |
| 459 * @param shouldCreateViewAndroid Whether ContentViewCore creates a ViewAndr oid object. WebView | |
| 460 * currently does not create ViewAndroid. If that should change, | |
| 461 * ViewAndroid should be rewritten to use Cle anupReference. | |
| 455 * @param isAccessFromFileURLsGrantedByDefault Default WebSettings configura tion. | 462 * @param isAccessFromFileURLsGrantedByDefault Default WebSettings configura tion. |
| 456 */ | 463 */ |
| 457 // Perform important post-construction set up of the ContentViewCore. | 464 // Perform important post-construction set up of the ContentViewCore. |
| 458 // We do not require the containing view in the constructor to allow embedde rs to create a | 465 // We do not require the containing view in the constructor to allow embedde rs to create a |
| 459 // ContentViewCore without having fully created its containing view. The con taining view | 466 // ContentViewCore without having fully created its containing view. The con taining view |
| 460 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what | 467 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what |
| 461 // they do with the ContentViewCore before calling initialize(). | 468 // they do with the ContentViewCore before calling initialize(). |
| 462 // We supply the nativeWebContents pointer here rather than in the construct or to allow us | 469 // We supply the nativeWebContents pointer here rather than in the construct or to allow us |
| 463 // to set the private browsing mode at a later point for the WebView impleme ntation. | 470 // to set the private browsing mode at a later point for the WebView impleme ntation. |
| 464 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for | 471 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for |
| 465 // deleting it after destroying the ContentViewCore. | 472 // deleting it after destroying the ContentViewCore. |
| 466 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher, | 473 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher, |
| 467 int nativeWebContents, NativeWindow nativeWindow, | 474 int nativeWebContents, WindowAndroid windowAndroid, boolean shouldCr eateViewAndroid, |
|
joth
2013/04/18 01:41:17
Seems odd to pass in the window here, along with b
aurimas (slooooooooow)
2013/04/18 02:49:57
Does WebView support JavascriptAppModalDialog or S
| |
| 468 boolean isAccessFromFileURLsGrantedByDefault) { | 475 boolean isAccessFromFileURLsGrantedByDefault) { |
| 469 // Check whether to use hardware acceleration. This is a bit hacky, and | 476 // Check whether to use hardware acceleration. This is a bit hacky, and |
| 470 // only works if the Context is actually an Activity (as it is in the | 477 // only works if the Context is actually an Activity (as it is in the |
| 471 // Chrome application). | 478 // Chrome application). |
| 472 // | 479 // |
| 473 // What we're doing here is checking whether the app has *requested* | 480 // What we're doing here is checking whether the app has *requested* |
| 474 // hardware acceleration by setting the appropriate flags. This does not | 481 // hardware acceleration by setting the appropriate flags. This does not |
| 475 // necessarily mean we're going to *get* hardware acceleration -- that's | 482 // necessarily mean we're going to *get* hardware acceleration -- that's |
| 476 // up to the Android framework. | 483 // up to the Android framework. |
| 477 // | 484 // |
| 478 // TODO(husky): Once the native code has been updated so that the | 485 // TODO(husky): Once the native code has been updated so that the |
| 479 // HW acceleration flag can be set dynamically (Grace is doing this), | 486 // HW acceleration flag can be set dynamically (Grace is doing this), |
| 480 // move this check into onAttachedToWindow(), where we can test for | 487 // move this check into onAttachedToWindow(), where we can test for |
| 481 // HW support directly. | 488 // HW support directly. |
| 482 mHardwareAccelerated = hasHardwareAcceleration(mContext); | 489 mHardwareAccelerated = hasHardwareAcceleration(mContext); |
| 483 | 490 |
| 484 // Input events are delivered at vsync time on JB+. | 491 // Input events are delivered at vsync time on JB+. |
| 485 boolean inputEventsDeliveredAtVSync = | 492 boolean inputEventsDeliveredAtVSync = |
| 486 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN); | 493 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN); |
| 487 | 494 |
| 488 mContainerView = containerView; | 495 mContainerView = containerView; |
| 496 | |
| 497 int viewAndroidNativePointer = 0; | |
| 498 if (shouldCreateViewAndroid) { | |
| 499 mViewAndroid = new ViewAndroid(windowAndroid, getViewAndroidDelegate ()); | |
| 500 viewAndroidNativePointer = mViewAndroid.getNativePointer(); | |
| 501 } | |
| 502 | |
| 489 mNativeContentViewCore = nativeInit(mHardwareAccelerated, inputEventsDel iveredAtVSync, | 503 mNativeContentViewCore = nativeInit(mHardwareAccelerated, inputEventsDel iveredAtVSync, |
| 490 nativeWebContents, nativeWindow.getNativePointer()); | 504 nativeWebContents, viewAndroidNativePointer, windowAndroid.getNa tivePointer()); |
| 491 mContentSettings = new ContentSettings( | 505 mContentSettings = new ContentSettings( |
| 492 this, mNativeContentViewCore, isAccessFromFileURLsGrantedByDefau lt); | 506 this, mNativeContentViewCore, isAccessFromFileURLsGrantedByDefau lt); |
| 493 initializeContainerView(internalDispatcher); | 507 initializeContainerView(internalDispatcher); |
| 494 if (mPersonality == PERSONALITY_VIEW) { | 508 if (mPersonality == PERSONALITY_VIEW) { |
| 495 setAllUserAgentOverridesInHistory(); | 509 setAllUserAgentOverridesInHistory(); |
| 496 } | 510 } |
| 497 | 511 |
| 498 mAccessibilityInjector = AccessibilityInjector.newInstance(this); | 512 mAccessibilityInjector = AccessibilityInjector.newInstance(this); |
| 499 mAccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary(); | 513 mAccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary(); |
| 500 | 514 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 /** | 646 /** |
| 633 * Destroy the internal state of the ContentView. This method may only be | 647 * Destroy the internal state of the ContentView. This method may only be |
| 634 * called after the ContentView has been removed from the view system. No | 648 * called after the ContentView has been removed from the view system. No |
| 635 * other methods may be called on this ContentView after this method has | 649 * other methods may be called on this ContentView after this method has |
| 636 * been called. | 650 * been called. |
| 637 */ | 651 */ |
| 638 public void destroy() { | 652 public void destroy() { |
| 639 if (mNativeContentViewCore != 0) { | 653 if (mNativeContentViewCore != 0) { |
| 640 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); | 654 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); |
| 641 } | 655 } |
| 656 if (mViewAndroid != null) mViewAndroid.destroy(); | |
| 642 mNativeContentViewCore = 0; | 657 mNativeContentViewCore = 0; |
| 643 mContentSettings = null; | 658 mContentSettings = null; |
| 644 mJavaScriptInterfaces.clear(); | 659 mJavaScriptInterfaces.clear(); |
| 645 mRetainedJavaScriptObjects.clear(); | 660 mRetainedJavaScriptObjects.clear(); |
| 646 } | 661 } |
| 647 | 662 |
| 648 /** | 663 /** |
| 649 * Returns true initially, false after destroy() has been called. | 664 * Returns true initially, false after destroy() has been called. |
| 650 * It is illegal to call any other public method after destroy(). | 665 * It is illegal to call any other public method after destroy(). |
| 651 */ | 666 */ |
| (...skipping 1984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2636 nativeDetachExternalVideoSurface(mNativeContentViewCore, playerId); | 2651 nativeDetachExternalVideoSurface(mNativeContentViewCore, playerId); |
| 2637 } | 2652 } |
| 2638 } | 2653 } |
| 2639 | 2654 |
| 2640 @CalledByNative | 2655 @CalledByNative |
| 2641 private void requestExternalVideoSurface(int playerId) { | 2656 private void requestExternalVideoSurface(int playerId) { |
| 2642 getContentViewClient().onExternalVideoSurfaceRequested(playerId); | 2657 getContentViewClient().onExternalVideoSurfaceRequested(playerId); |
| 2643 } | 2658 } |
| 2644 | 2659 |
| 2645 private native int nativeInit(boolean hardwareAccelerated, boolean inputEven tsDeliveredAtVSync, | 2660 private native int nativeInit(boolean hardwareAccelerated, boolean inputEven tsDeliveredAtVSync, |
| 2646 int webContentsPtr, int windowAndroidPtr); | 2661 int webContentsPtr, int viewAndroidPtr, int windowAndroidPtr); |
| 2647 | 2662 |
| 2648 private native void nativeOnJavaContentViewCoreDestroyed(int nativeContentVi ewCoreImpl); | 2663 private native void nativeOnJavaContentViewCoreDestroyed(int nativeContentVi ewCoreImpl); |
| 2649 | 2664 |
| 2650 private native void nativeLoadUrl( | 2665 private native void nativeLoadUrl( |
| 2651 int nativeContentViewCoreImpl, | 2666 int nativeContentViewCoreImpl, |
| 2652 String url, | 2667 String url, |
| 2653 int loadUrlType, | 2668 int loadUrlType, |
| 2654 int transitionType, | 2669 int transitionType, |
| 2655 int uaOverrideOption, | 2670 int uaOverrideOption, |
| 2656 String extraHeaders, | 2671 String extraHeaders, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2805 boolean enableHiding, boolean enableShowing, boolean animate); | 2820 boolean enableHiding, boolean enableShowing, boolean animate); |
| 2806 | 2821 |
| 2807 private native void nativeShowImeIfNeeded(int nativeContentViewCoreImpl); | 2822 private native void nativeShowImeIfNeeded(int nativeContentViewCoreImpl); |
| 2808 | 2823 |
| 2809 private native void nativeAttachExternalVideoSurface( | 2824 private native void nativeAttachExternalVideoSurface( |
| 2810 int nativeContentViewCoreImpl, int playerId, Surface surface); | 2825 int nativeContentViewCoreImpl, int playerId, Surface surface); |
| 2811 | 2826 |
| 2812 private native void nativeDetachExternalVideoSurface( | 2827 private native void nativeDetachExternalVideoSurface( |
| 2813 int nativeContentViewCoreImpl, int playerId); | 2828 int nativeContentViewCoreImpl, int playerId); |
| 2814 } | 2829 } |
| OLD | NEW |