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; | |
25 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; | 23 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; |
26 import org.chromium.content_public.browser.AccessibilitySnapshotNode; | 24 import org.chromium.content_public.browser.AccessibilitySnapshotNode; |
27 import org.chromium.content_public.browser.ContentBitmapCallback; | 25 import org.chromium.content_public.browser.ContentBitmapCallback; |
28 import org.chromium.content_public.browser.ImageDownloadCallback; | 26 import org.chromium.content_public.browser.ImageDownloadCallback; |
29 import org.chromium.content_public.browser.JavaScriptCallback; | 27 import org.chromium.content_public.browser.JavaScriptCallback; |
30 import org.chromium.content_public.browser.MessagePort; | 28 import org.chromium.content_public.browser.MessagePort; |
31 import org.chromium.content_public.browser.NavigationController; | 29 import org.chromium.content_public.browser.NavigationController; |
32 import org.chromium.content_public.browser.RenderFrameHost; | |
33 import org.chromium.content_public.browser.SmartClipCallback; | 30 import org.chromium.content_public.browser.SmartClipCallback; |
34 import org.chromium.content_public.browser.WebContents; | 31 import org.chromium.content_public.browser.WebContents; |
35 import org.chromium.content_public.browser.WebContentsObserver; | 32 import org.chromium.content_public.browser.WebContentsObserver; |
36 import org.chromium.ui.OverscrollRefreshHandler; | 33 import org.chromium.ui.OverscrollRefreshHandler; |
37 import org.chromium.ui.accessibility.AXTextStyle; | 34 import org.chromium.ui.accessibility.AXTextStyle; |
38 import org.chromium.ui.base.WindowAndroid; | 35 import org.chromium.ui.base.WindowAndroid; |
39 | 36 |
40 import java.util.ArrayList; | 37 import java.util.ArrayList; |
41 import java.util.List; | 38 import java.util.List; |
42 import java.util.UUID; | 39 import java.util.UUID; |
43 | 40 |
44 /** | 41 /** |
45 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo
ntentsImpl | 42 * The WebContentsImpl Java wrapper to allow communicating with the native WebCo
ntentsImpl |
46 * object. | 43 * object. |
47 */ | 44 */ |
48 @JNINamespace("content") | 45 @JNINamespace("content") |
49 // TODO(tedchoc): Remove the package restriction once this class moves to a non-
public content | 46 //TODO(tedchoc): Remove the package restriction once this class moves to a non-p
ublic content |
50 // package whose visibility will be enforced via DEPS. | 47 // package whose visibility will be enforced via DEPS. |
51 /* package */ class WebContentsImpl implements WebContents, RenderFrameHostDeleg
ate { | 48 /* package */ class WebContentsImpl implements WebContents { |
52 private static final String PARCEL_VERSION_KEY = "version"; | 49 private static final String PARCEL_VERSION_KEY = "version"; |
53 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; | 50 private static final String PARCEL_WEBCONTENTS_KEY = "webcontents"; |
54 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; | 51 private static final String PARCEL_PROCESS_GUARD_KEY = "processguard"; |
55 | 52 |
56 private static final long PARCELABLE_VERSION_ID = 0; | 53 private static final long PARCELABLE_VERSION_ID = 0; |
57 // Non-final for testing purposes, so resetting of the UUID can happen. | 54 // Non-final for testing purposes, so resetting of the UUID can happen. |
58 private static UUID sParcelableUUID = UUID.randomUUID(); | 55 private static UUID sParcelableUUID = UUID.randomUUID(); |
59 | 56 |
60 /** | 57 /** |
61 * Used to reset the internal tracking for whether or not a serialized {@lin
k WebContents} | 58 * Used to reset the internal tracking for whether or not a serialized {@lin
k WebContents} |
(...skipping 26 matching lines...) Expand all Loading... |
88 // Attempt to retrieve the WebContents object from the nativ
e pointer. | 85 // Attempt to retrieve the WebContents object from the nativ
e pointer. |
89 return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS
_KEY)); | 86 return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS
_KEY)); |
90 } | 87 } |
91 | 88 |
92 @Override | 89 @Override |
93 public WebContents[] newArray(int size) { | 90 public WebContents[] newArray(int size) { |
94 return new WebContents[size]; | 91 return new WebContents[size]; |
95 } | 92 } |
96 }; | 93 }; |
97 | 94 |
98 public static WebContents fromRenderFrameHost(RenderFrameHost rfh) { | |
99 RenderFrameHostDelegate delegate = ((RenderFrameHostImpl) rfh).getRender
FrameHostDelegate(); | |
100 if (delegate == null || !(delegate instanceof WebContents)) { | |
101 return null; | |
102 } | |
103 return (WebContents) delegate; | |
104 } | |
105 | |
106 private long mNativeWebContentsAndroid; | 95 private long mNativeWebContentsAndroid; |
107 private NavigationController mNavigationController; | 96 private NavigationController mNavigationController; |
108 private RenderFrameHost mMainFrame; | |
109 | 97 |
110 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. | 98 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. |
111 private WebContentsObserverProxy mObserverProxy; | 99 private WebContentsObserverProxy mObserverProxy; |
112 | 100 |
113 // The media session for this WebContents. It is constructed by the native M
ediaSession and has | 101 // The media session for this WebContents. It is constructed by the native M
ediaSession and has |
114 // the same life time as native MediaSession. | 102 // the same life time as native MediaSession. |
115 private MediaSessionImpl mMediaSession; | 103 private MediaSessionImpl mMediaSession; |
116 | 104 |
117 private SmartClipCallback mSmartClipCallback; | 105 private SmartClipCallback mSmartClipCallback; |
118 | 106 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 public boolean isDestroyed() { | 165 public boolean isDestroyed() { |
178 return mNativeWebContentsAndroid == 0; | 166 return mNativeWebContentsAndroid == 0; |
179 } | 167 } |
180 | 168 |
181 @Override | 169 @Override |
182 public NavigationController getNavigationController() { | 170 public NavigationController getNavigationController() { |
183 return mNavigationController; | 171 return mNavigationController; |
184 } | 172 } |
185 | 173 |
186 @Override | 174 @Override |
187 public RenderFrameHost getMainFrame() { | |
188 if (mMainFrame == null) { | |
189 mMainFrame = nativeGetMainFrame(mNativeWebContentsAndroid); | |
190 } | |
191 return mMainFrame; | |
192 } | |
193 | |
194 @Override | |
195 public String getTitle() { | 175 public String getTitle() { |
196 return nativeGetTitle(mNativeWebContentsAndroid); | 176 return nativeGetTitle(mNativeWebContentsAndroid); |
197 } | 177 } |
198 | 178 |
199 @Override | 179 @Override |
200 public String getVisibleUrl() { | 180 public String getVisibleUrl() { |
201 return nativeGetVisibleURL(mNativeWebContentsAndroid); | 181 return nativeGetVisibleURL(mNativeWebContentsAndroid); |
202 } | 182 } |
203 | 183 |
204 @Override | 184 @Override |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 private static void createSizeAndAddToList(List<Rect> sizes, int width, int
height) { | 557 private static void createSizeAndAddToList(List<Rect> sizes, int width, int
height) { |
578 sizes.add(new Rect(0, 0, width, height)); | 558 sizes.add(new Rect(0, 0, width, height)); |
579 } | 559 } |
580 | 560 |
581 // This is static to avoid exposing a public destroy method on the native si
de of this class. | 561 // This is static to avoid exposing a public destroy method on the native si
de of this class. |
582 private static native void nativeDestroyWebContents(long webContentsAndroidP
tr); | 562 private static native void nativeDestroyWebContents(long webContentsAndroidP
tr); |
583 | 563 |
584 private static native WebContents nativeFromNativePtr(long webContentsAndroi
dPtr); | 564 private static native WebContents nativeFromNativePtr(long webContentsAndroi
dPtr); |
585 | 565 |
586 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon
tentsAndroid); | 566 private native WindowAndroid nativeGetTopLevelNativeWindow(long nativeWebCon
tentsAndroid); |
587 private native RenderFrameHost nativeGetMainFrame(long nativeWebContentsAndr
oid); | |
588 private native String nativeGetTitle(long nativeWebContentsAndroid); | 567 private native String nativeGetTitle(long nativeWebContentsAndroid); |
589 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); | 568 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); |
590 private native boolean nativeIsLoading(long nativeWebContentsAndroid); | 569 private native boolean nativeIsLoading(long nativeWebContentsAndroid); |
591 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont
entsAndroid); | 570 private native boolean nativeIsLoadingToDifferentDocument(long nativeWebCont
entsAndroid); |
592 private native void nativeStop(long nativeWebContentsAndroid); | 571 private native void nativeStop(long nativeWebContentsAndroid); |
593 private native void nativeCut(long nativeWebContentsAndroid); | 572 private native void nativeCut(long nativeWebContentsAndroid); |
594 private native void nativeCopy(long nativeWebContentsAndroid); | 573 private native void nativeCopy(long nativeWebContentsAndroid); |
595 private native void nativePaste(long nativeWebContentsAndroid); | 574 private native void nativePaste(long nativeWebContentsAndroid); |
596 private native void nativeReplace(long nativeWebContentsAndroid, String word
); | 575 private native void nativeReplace(long nativeWebContentsAndroid, String word
); |
597 private native void nativeSelectAll(long nativeWebContentsAndroid); | 576 private native void nativeSelectAll(long nativeWebContentsAndroid); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 ContentBitmapCallback callback, Bitmap.Config config, float scale, | 617 ContentBitmapCallback callback, Bitmap.Config config, float scale, |
639 float x, float y, float width, float height); | 618 float x, float y, float width, float height); |
640 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); | 619 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); |
641 private native int nativeDownloadImage(long nativeWebContentsAndroid, | 620 private native int nativeDownloadImage(long nativeWebContentsAndroid, |
642 String url, boolean isFavicon, int maxBitmapSize, | 621 String url, boolean isFavicon, int maxBitmapSize, |
643 boolean bypassCache, ImageDownloadCallback callback); | 622 boolean bypassCache, ImageDownloadCallback callback); |
644 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); | 623 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); |
645 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); | 624 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); |
646 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); | 625 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); |
647 } | 626 } |
OLD | NEW |