Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.webcontents; | 5 package org.chromium.content.browser.webcontents; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
| 10 import android.os.Bundle; | 10 import android.os.Bundle; |
| 11 import android.os.Handler; | 11 import android.os.Handler; |
| 12 import android.os.Message; | 12 import android.os.Message; |
| 13 import android.os.Parcel; | 13 import android.os.Parcel; |
| 14 import android.os.ParcelUuid; | 14 import android.os.ParcelUuid; |
| 15 import android.os.Parcelable; | 15 import android.os.Parcelable; |
| 16 | 16 |
| 17 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
| 18 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
| 19 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
| 20 import org.chromium.base.annotations.JNINamespace; | 20 import org.chromium.base.annotations.JNINamespace; |
| 21 import org.chromium.content.browser.AppWebMessagePort; | 21 import org.chromium.content.browser.AppWebMessagePort; |
| 22 import org.chromium.content.browser.MediaSessionImpl; | 22 import org.chromium.content.browser.MediaSessionImpl; |
| 23 import org.chromium.content.browser.framehost.RenderFrameHostDelegate; | |
| 24 import org.chromium.content.browser.framehost.RenderFrameHostImpl; | |
| 23 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; | 25 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; |
| 24 import org.chromium.content_public.browser.AccessibilitySnapshotNode; | 26 import org.chromium.content_public.browser.AccessibilitySnapshotNode; |
| 25 import org.chromium.content_public.browser.ContentBitmapCallback; | 27 import org.chromium.content_public.browser.ContentBitmapCallback; |
| 26 import org.chromium.content_public.browser.ImageDownloadCallback; | 28 import org.chromium.content_public.browser.ImageDownloadCallback; |
| 27 import org.chromium.content_public.browser.JavaScriptCallback; | 29 import org.chromium.content_public.browser.JavaScriptCallback; |
| 28 import org.chromium.content_public.browser.MessagePort; | 30 import org.chromium.content_public.browser.MessagePort; |
| 29 import org.chromium.content_public.browser.NavigationController; | 31 import org.chromium.content_public.browser.NavigationController; |
| 32 import org.chromium.content_public.browser.RenderFrameHost; | |
| 30 import org.chromium.content_public.browser.SmartClipCallback; | 33 import org.chromium.content_public.browser.SmartClipCallback; |
| 31 import org.chromium.content_public.browser.WebContents; | 34 import org.chromium.content_public.browser.WebContents; |
| 32 import org.chromium.content_public.browser.WebContentsObserver; | 35 import org.chromium.content_public.browser.WebContentsObserver; |
| 33 import org.chromium.ui.OverscrollRefreshHandler; | 36 import org.chromium.ui.OverscrollRefreshHandler; |
| 34 import org.chromium.ui.accessibility.AXTextStyle; | 37 import org.chromium.ui.accessibility.AXTextStyle; |
| 35 import org.chromium.ui.base.WindowAndroid; | 38 import org.chromium.ui.base.WindowAndroid; |
| 36 | 39 |
| 37 import java.util.ArrayList; | 40 import java.util.ArrayList; |
| 38 import java.util.List; | 41 import java.util.List; |
| 39 import java.util.UUID; | 42 import java.util.UUID; |
| 40 | 43 |
| 41 /** | 44 /** |
| 42 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo ntentsImpl | 45 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo ntentsImpl |
| 43 * object. | 46 * object. |
| 44 */ | 47 */ |
| 45 @JNINamespace("content") | 48 @JNINamespace("content") |
| 46 //TODO(tedchoc): Remove the package restriction once this class moves to a non-p ublic content | 49 // TODO(tedchoc): Remove the package restriction once this class moves to a non- public content |
| 47 // package whose visibility will be enforced via DEPS. | 50 // package whose visibility will be enforced via DEPS. |
| 48 /* package */ class WebContentsImpl implements WebContents { | 51 /* package */ class WebContentsImpl implements WebContents, RenderFrameHostDeleg ate { |
| 49 private static final String PARCEL_VERSION_KEY = "version"; | 52 private static final String PARCEL_VERSION_KEY = "version"; |
| 50 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; | 53 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; |
| 51 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; | 54 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; |
| 52 | 55 |
| 53 private static final long PARCELABLE_VERSION_ID = 0; | 56 private static final long PARCELABLE_VERSION_ID = 0; |
| 54 // Non-final for testing purposes, so resetting of the UUID can happen. | 57 // Non-final for testing purposes, so resetting of the UUID can happen. |
| 55 private static UUID sParcelableUUID = UUID.randomUUID(); | 58 private static UUID sParcelableUUID = UUID.randomUUID(); |
| 56 | 59 |
| 57 /** | 60 /** |
| 58 * Used to reset the internal tracking for whether or not a serialized {@lin k WebContents} | 61 * Used to reset the internal tracking for whether or not a serialized {@lin k WebContents} |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 87 } | 90 } |
| 88 | 91 |
| 89 @Override | 92 @Override |
| 90 public WebContents[] newArray(int size) { | 93 public WebContents[] newArray(int size) { |
| 91 return new WebContents[size]; | 94 return new WebContents[size]; |
| 92 } | 95 } |
| 93 }; | 96 }; |
| 94 | 97 |
| 95 private long mNativeWebContentsAndroid; | 98 private long mNativeWebContentsAndroid; |
| 96 private NavigationController mNavigationController; | 99 private NavigationController mNavigationController; |
| 100 private RenderFrameHost mMainFrame; | |
| 97 | 101 |
| 98 // Lazily created proxy observer for handling all Java-based WebContentsObse rvers. | 102 // Lazily created proxy observer for handling all Java-based WebContentsObse rvers. |
| 99 private WebContentsObserverProxy mObserverProxy; | 103 private WebContentsObserverProxy mObserverProxy; |
| 100 | 104 |
| 101 // The media session for this WebContents. It is constructed by the native M ediaSession and has | 105 // The media session for this WebContents. It is constructed by the native M ediaSession and has |
| 102 // the same life time as native MediaSession. | 106 // the same life time as native MediaSession. |
| 103 private MediaSessionImpl mMediaSession; | 107 private MediaSessionImpl mMediaSession; |
| 104 | 108 |
| 105 private SmartClipCallback mSmartClipCallback; | 109 private SmartClipCallback mSmartClipCallback; |
| 106 | 110 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 @CalledByNative | 150 @CalledByNative |
| 147 private long getNativePointer() { | 151 private long getNativePointer() { |
| 148 return mNativeWebContentsAndroid; | 152 return mNativeWebContentsAndroid; |
| 149 } | 153 } |
| 150 | 154 |
| 151 @Override | 155 @Override |
| 152 public WindowAndroid getTopLevelNativeWindow() { | 156 public WindowAndroid getTopLevelNativeWindow() { |
| 153 return nativeGetTopLevelNativeWindow(mNativeWebContentsAndroid); | 157 return nativeGetTopLevelNativeWindow(mNativeWebContentsAndroid); |
| 154 } | 158 } |
| 155 | 159 |
| 160 public static WebContents fromRenderFrameHost(RenderFrameHost rfh) { | |
|
boliu
2017/03/06 23:12:38
nit: static methods at the top
rwlbuis
2017/03/07 19:44:56
Done.
| |
| 161 RenderFrameHostDelegate delegate = ((RenderFrameHostImpl) rfh).getRender FrameHostDelegate(); | |
| 162 if (delegate == null) { | |
| 163 return null; | |
| 164 } | |
| 165 return delegate.getAsWebContents(); | |
| 166 } | |
| 167 | |
| 156 @Override | 168 @Override |
| 157 public void destroy() { | 169 public void destroy() { |
| 158 if (!ThreadUtils.runningOnUiThread()) { | 170 if (!ThreadUtils.runningOnUiThread()) { |
| 159 throw new IllegalStateException("Attempting to destroy WebContents o n non-UI thread"); | 171 throw new IllegalStateException("Attempting to destroy WebContents o n non-UI thread"); |
| 160 } | 172 } |
| 161 if (mNativeWebContentsAndroid != 0) nativeDestroyWebContents(mNativeWebC ontentsAndroid); | 173 if (mNativeWebContentsAndroid != 0) nativeDestroyWebContents(mNativeWebC ontentsAndroid); |
| 162 } | 174 } |
| 163 | 175 |
| 164 @Override | 176 @Override |
| 165 public boolean isDestroyed() { | 177 public boolean isDestroyed() { |
| 166 return mNativeWebContentsAndroid == 0; | 178 return mNativeWebContentsAndroid == 0; |
| 167 } | 179 } |
| 168 | 180 |
| 169 @Override | 181 @Override |
| 170 public NavigationController getNavigationController() { | 182 public NavigationController getNavigationController() { |
| 171 return mNavigationController; | 183 return mNavigationController; |
| 172 } | 184 } |
| 173 | 185 |
| 174 @Override | 186 @Override |
| 187 public RenderFrameHost getMainFrame() { | |
| 188 if (mMainFrame == null) { | |
| 189 mMainFrame = nativeGetMainFrame(mNativeWebContentsAndroid); | |
| 190 } | |
| 191 return mMainFrame; | |
| 192 } | |
| 193 | |
| 194 @Override | |
| 175 public String getTitle() { | 195 public String getTitle() { |
| 176 return nativeGetTitle(mNativeWebContentsAndroid); | 196 return nativeGetTitle(mNativeWebContentsAndroid); |
| 177 } | 197 } |
| 178 | 198 |
| 179 @Override | 199 @Override |
| 180 public String getVisibleUrl() { | 200 public String getVisibleUrl() { |
| 181 return nativeGetVisibleURL(mNativeWebContentsAndroid); | 201 return nativeGetVisibleURL(mNativeWebContentsAndroid); |
| 182 } | 202 } |
| 183 | 203 |
| 184 @Override | 204 @Override |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 @CalledByNative | 571 @CalledByNative |
| 552 private static List<Rect> createSizeList() { | 572 private static List<Rect> createSizeList() { |
| 553 return new ArrayList<Rect>(); | 573 return new ArrayList<Rect>(); |
| 554 } | 574 } |
| 555 | 575 |
| 556 @CalledByNative | 576 @CalledByNative |
| 557 private static void createSizeAndAddToList(List<Rect> sizes, int width, int height) { | 577 private static void createSizeAndAddToList(List<Rect> sizes, int width, int height) { |
| 558 sizes.add(new Rect(0, 0, width, height)); | 578 sizes.add(new Rect(0, 0, width, height)); |
| 559 } | 579 } |
| 560 | 580 |
| 581 @Override | |
| 582 public WebContents getAsWebContents() { | |
| 583 return this; | |
| 584 } | |
| 585 | |
| 561 // This is static to avoid exposing a public destroy method on the native si de of this class. | 586 // This is static to avoid exposing a public destroy method on the native si de of this class. |
| 562 private static native void nativeDestroyWebContents(long webContentsAndroidP tr); | 587 private static native void nativeDestroyWebContents(long webContentsAndroidP tr); |
| 563 | 588 |
| 564 private static native WebContents nativeFromNativePtr(long webContentsAndroi dPtr); | 589 private static native WebContents nativeFromNativePtr(long webContentsAndroi dPtr); |
| 565 | 590 |
| 566 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon tentsAndroid); | 591 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon tentsAndroid); |
| 592 private native RenderFrameHost nativeGetMainFrame(long nativeWebContentsAndr oid); | |
| 567 private native String nativeGetTitle(long nativeWebContentsAndroid); | 593 private native String nativeGetTitle(long nativeWebContentsAndroid); |
| 568 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); | 594 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); |
| 569 private native boolean nativeIsLoading(long nativeWebContentsAndroid); | 595 private native boolean nativeIsLoading(long nativeWebContentsAndroid); |
| 570 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont entsAndroid); | 596 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont entsAndroid); |
| 571 private native void nativeStop(long nativeWebContentsAndroid); | 597 private native void nativeStop(long nativeWebContentsAndroid); |
| 572 private native void nativeCut(long nativeWebContentsAndroid); | 598 private native void nativeCut(long nativeWebContentsAndroid); |
| 573 private native void nativeCopy(long nativeWebContentsAndroid); | 599 private native void nativeCopy(long nativeWebContentsAndroid); |
| 574 private native void nativePaste(long nativeWebContentsAndroid); | 600 private native void nativePaste(long nativeWebContentsAndroid); |
| 575 private native void nativeReplace(long nativeWebContentsAndroid, String word ); | 601 private native void nativeReplace(long nativeWebContentsAndroid, String word ); |
| 576 private native void nativeSelectAll(long nativeWebContentsAndroid); | 602 private native void nativeSelectAll(long nativeWebContentsAndroid); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 ContentBitmapCallback callback, Bitmap.Config config, float scale, | 643 ContentBitmapCallback callback, Bitmap.Config config, float scale, |
| 618 float x, float y, float width, float height); | 644 float x, float y, float width, float height); |
| 619 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); | 645 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); |
| 620 private native int nativeDownloadImage(long nativeWebContentsAndroid, | 646 private native int nativeDownloadImage(long nativeWebContentsAndroid, |
| 621 String url, boolean isFavicon, int maxBitmapSize, | 647 String url, boolean isFavicon, int maxBitmapSize, |
| 622 boolean bypassCache, ImageDownloadCallback callback); | 648 boolean bypassCache, ImageDownloadCallback callback); |
| 623 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); | 649 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); |
| 624 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi d, boolean value); | 650 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi d, boolean value); |
| 625 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native WebContentsAndroid); | 651 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native WebContentsAndroid); |
| 626 } | 652 } |
| OLD | NEW |