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.EventForwarder; | 38 import org.chromium.ui.base.EventForwarder; |
36 import org.chromium.ui.base.WindowAndroid; | 39 import org.chromium.ui.base.WindowAndroid; |
37 | 40 |
38 import java.util.ArrayList; | 41 import java.util.ArrayList; |
39 import java.util.List; | 42 import java.util.List; |
40 import java.util.UUID; | 43 import java.util.UUID; |
41 | 44 |
42 /** | 45 /** |
43 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo
ntentsImpl | 46 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo
ntentsImpl |
44 * object. | 47 * object. |
45 */ | 48 */ |
46 @JNINamespace("content") | 49 @JNINamespace("content") |
47 //TODO(tedchoc): Remove the package restriction once this class moves to a non-p
ublic content | 50 // TODO(tedchoc): Remove the package restriction once this class moves to a non-
public content |
48 // package whose visibility will be enforced via DEPS. | 51 // package whose visibility will be enforced via DEPS. |
49 /* package */ class WebContentsImpl implements WebContents { | 52 /* package */ class WebContentsImpl implements WebContents, RenderFrameHostDeleg
ate { |
50 private static final String PARCEL_VERSION_KEY = "version"; | 53 private static final String PARCEL_VERSION_KEY = "version"; |
51 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; | 54 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; |
52 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; | 55 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; |
53 | 56 |
54 private static final long PARCELABLE_VERSION_ID = 0; | 57 private static final long PARCELABLE_VERSION_ID = 0; |
55 // Non-final for testing purposes, so resetting of the UUID can happen. | 58 // Non-final for testing purposes, so resetting of the UUID can happen. |
56 private static UUID sParcelableUUID = UUID.randomUUID(); | 59 private static UUID sParcelableUUID = UUID.randomUUID(); |
57 | 60 |
58 /** | 61 /** |
59 * Used to reset the internal tracking for whether or not a serialized {@lin
k WebContents} | 62 * Used to reset the internal tracking for whether or not a serialized {@lin
k WebContents} |
(...skipping 26 matching lines...) Expand all Loading... |
86 // Attempt to retrieve the WebContents object from the nativ
e pointer. | 89 // Attempt to retrieve the WebContents object from the nativ
e pointer. |
87 return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS
_KEY)); | 90 return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS
_KEY)); |
88 } | 91 } |
89 | 92 |
90 @Override | 93 @Override |
91 public WebContents[] newArray(int size) { | 94 public WebContents[] newArray(int size) { |
92 return new WebContents[size]; | 95 return new WebContents[size]; |
93 } | 96 } |
94 }; | 97 }; |
95 | 98 |
| 99 public static WebContents fromRenderFrameHost(RenderFrameHost rfh) { |
| 100 RenderFrameHostDelegate delegate = ((RenderFrameHostImpl) rfh).getRender
FrameHostDelegate(); |
| 101 if (delegate == null || !(delegate instanceof WebContents)) { |
| 102 return null; |
| 103 } |
| 104 return (WebContents) delegate; |
| 105 } |
| 106 |
96 private long mNativeWebContentsAndroid; | 107 private long mNativeWebContentsAndroid; |
97 private NavigationController mNavigationController; | 108 private NavigationController mNavigationController; |
| 109 private RenderFrameHost mMainFrame; |
98 | 110 |
99 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. | 111 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. |
100 private WebContentsObserverProxy mObserverProxy; | 112 private WebContentsObserverProxy mObserverProxy; |
101 | 113 |
102 // The media session for this WebContents. It is constructed by the native M
ediaSession and has | 114 // The media session for this WebContents. It is constructed by the native M
ediaSession and has |
103 // the same life time as native MediaSession. | 115 // the same life time as native MediaSession. |
104 private MediaSessionImpl mMediaSession; | 116 private MediaSessionImpl mMediaSession; |
105 | 117 |
106 private SmartClipCallback mSmartClipCallback; | 118 private SmartClipCallback mSmartClipCallback; |
107 | 119 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 public boolean isDestroyed() { | 180 public boolean isDestroyed() { |
169 return mNativeWebContentsAndroid == 0; | 181 return mNativeWebContentsAndroid == 0; |
170 } | 182 } |
171 | 183 |
172 @Override | 184 @Override |
173 public NavigationController getNavigationController() { | 185 public NavigationController getNavigationController() { |
174 return mNavigationController; | 186 return mNavigationController; |
175 } | 187 } |
176 | 188 |
177 @Override | 189 @Override |
| 190 public RenderFrameHost getMainFrame() { |
| 191 if (mMainFrame == null) { |
| 192 mMainFrame = nativeGetMainFrame(mNativeWebContentsAndroid); |
| 193 } |
| 194 return mMainFrame; |
| 195 } |
| 196 |
| 197 @Override |
178 public String getTitle() { | 198 public String getTitle() { |
179 return nativeGetTitle(mNativeWebContentsAndroid); | 199 return nativeGetTitle(mNativeWebContentsAndroid); |
180 } | 200 } |
181 | 201 |
182 @Override | 202 @Override |
183 public String getVisibleUrl() { | 203 public String getVisibleUrl() { |
184 return nativeGetVisibleURL(mNativeWebContentsAndroid); | 204 return nativeGetVisibleURL(mNativeWebContentsAndroid); |
185 } | 205 } |
186 | 206 |
187 @Override | 207 @Override |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 private static void createSizeAndAddToList(List<Rect> sizes, int width, int
height) { | 587 private static void createSizeAndAddToList(List<Rect> sizes, int width, int
height) { |
568 sizes.add(new Rect(0, 0, width, height)); | 588 sizes.add(new Rect(0, 0, width, height)); |
569 } | 589 } |
570 | 590 |
571 // This is static to avoid exposing a public destroy method on the native si
de of this class. | 591 // This is static to avoid exposing a public destroy method on the native si
de of this class. |
572 private static native void nativeDestroyWebContents(long webContentsAndroidP
tr); | 592 private static native void nativeDestroyWebContents(long webContentsAndroidP
tr); |
573 | 593 |
574 private static native WebContents nativeFromNativePtr(long webContentsAndroi
dPtr); | 594 private static native WebContents nativeFromNativePtr(long webContentsAndroi
dPtr); |
575 | 595 |
576 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon
tentsAndroid); | 596 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon
tentsAndroid); |
| 597 private native RenderFrameHost nativeGetMainFrame(long nativeWebContentsAndr
oid); |
577 private native String nativeGetTitle(long nativeWebContentsAndroid); | 598 private native String nativeGetTitle(long nativeWebContentsAndroid); |
578 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); | 599 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); |
579 private native boolean nativeIsLoading(long nativeWebContentsAndroid); | 600 private native boolean nativeIsLoading(long nativeWebContentsAndroid); |
580 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont
entsAndroid); | 601 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont
entsAndroid); |
581 private native void nativeStop(long nativeWebContentsAndroid); | 602 private native void nativeStop(long nativeWebContentsAndroid); |
582 private native void nativeCut(long nativeWebContentsAndroid); | 603 private native void nativeCut(long nativeWebContentsAndroid); |
583 private native void nativeCopy(long nativeWebContentsAndroid); | 604 private native void nativeCopy(long nativeWebContentsAndroid); |
584 private native void nativePaste(long nativeWebContentsAndroid); | 605 private native void nativePaste(long nativeWebContentsAndroid); |
585 private native void nativeReplace(long nativeWebContentsAndroid, String word
); | 606 private native void nativeReplace(long nativeWebContentsAndroid, String word
); |
586 private native void nativeSelectAll(long nativeWebContentsAndroid); | 607 private native void nativeSelectAll(long nativeWebContentsAndroid); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 long nativeWebContentsAndroid, int width, int height, ContentBitmapC
allback callback); | 648 long nativeWebContentsAndroid, int width, int height, ContentBitmapC
allback callback); |
628 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); | 649 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); |
629 private native int nativeDownloadImage(long nativeWebContentsAndroid, | 650 private native int nativeDownloadImage(long nativeWebContentsAndroid, |
630 String url, boolean isFavicon, int maxBitmapSize, | 651 String url, boolean isFavicon, int maxBitmapSize, |
631 boolean bypassCache, ImageDownloadCallback callback); | 652 boolean bypassCache, ImageDownloadCallback callback); |
632 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); | 653 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); |
633 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); | 654 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); |
634 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); | 655 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); |
635 private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWeb
ContentsAndroid); | 656 private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWeb
ContentsAndroid); |
636 } | 657 } |
OLD | NEW |