OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import org.chromium.android_webview.AwContents.VisualStateCallback; | 7 import org.chromium.android_webview.AwContents.VisualStateCallback; |
8 import org.chromium.base.ThreadUtils; | 8 import org.chromium.base.ThreadUtils; |
| 9 import org.chromium.content_public.browser.NavigationEntry; |
9 import org.chromium.content_public.browser.WebContents; | 10 import org.chromium.content_public.browser.WebContents; |
10 import org.chromium.content_public.browser.WebContentsObserver; | 11 import org.chromium.content_public.browser.WebContentsObserver; |
11 import org.chromium.net.NetError; | 12 import org.chromium.net.NetError; |
| 13 import org.chromium.ui.base.PageTransition; |
12 | 14 |
13 import java.lang.ref.WeakReference; | 15 import java.lang.ref.WeakReference; |
14 | 16 |
15 /** | 17 /** |
16 * Routes notifications from WebContents to AwContentsClient and other listeners
. | 18 * Routes notifications from WebContents to AwContentsClient and other listeners
. |
17 */ | 19 */ |
18 public class AwWebContentsObserver extends WebContentsObserver { | 20 public class AwWebContentsObserver extends WebContentsObserver { |
19 // TODO(tobiasjs) similarly to WebContentsObserver.mWebContents, mAwContents | 21 // TODO(tobiasjs) similarly to WebContentsObserver.mWebContents, mAwContents |
20 // needs to be a WeakReference, which suggests that there exists a strong | 22 // needs to be a WeakReference, which suggests that there exists a strong |
21 // reference to an AwWebContentsObserver instance. This is not intentional, | 23 // reference to an AwWebContentsObserver instance. This is not intentional, |
22 // and should be found and cleaned up. | 24 // and should be found and cleaned up. |
23 private final WeakReference<AwContents> mAwContents; | 25 private final WeakReference<AwContents> mAwContents; |
24 private final AwContentsClient mAwContentsClient; | 26 private final AwContentsClient mAwContentsClient; |
25 private boolean mHasStartedAnyProvisionalLoad = false; | 27 private boolean mStartedNonApiProvisionalLoadInMainFrame = false; |
26 | 28 |
27 public AwWebContentsObserver( | 29 public AwWebContentsObserver( |
28 WebContents webContents, AwContents awContents, AwContentsClient awC
ontentsClient) { | 30 WebContents webContents, AwContents awContents, AwContentsClient awC
ontentsClient) { |
29 super(webContents); | 31 super(webContents); |
30 mAwContents = new WeakReference<AwContents>(awContents); | 32 mAwContents = new WeakReference<AwContents>(awContents); |
31 mAwContentsClient = awContentsClient; | 33 mAwContentsClient = awContentsClient; |
32 } | 34 } |
33 | 35 |
34 boolean hasStartedAnyProvisionalLoad() { | 36 boolean hasStartedNonApiProvisionalLoadInMainFrame() { |
35 return mHasStartedAnyProvisionalLoad; | 37 return mStartedNonApiProvisionalLoadInMainFrame; |
36 } | 38 } |
37 | 39 |
38 @Override | 40 @Override |
39 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainF
rame) { | 41 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainF
rame) { |
40 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUr
l(); | 42 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUr
l(); |
41 boolean isErrorUrl = | 43 boolean isErrorUrl = |
42 unreachableWebDataUrl != null && unreachableWebDataUrl.equals(va
lidatedUrl); | 44 unreachableWebDataUrl != null && unreachableWebDataUrl.equals(va
lidatedUrl); |
43 if (isMainFrame && !isErrorUrl) { | 45 if (isMainFrame && !isErrorUrl) { |
44 mAwContentsClient.onPageFinished(validatedUrl); | 46 mAwContentsClient.onPageFinished(validatedUrl); |
45 } | 47 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 94 } |
93 | 95 |
94 @Override | 96 @Override |
95 public void didStartProvisionalLoadForFrame( | 97 public void didStartProvisionalLoadForFrame( |
96 long frameId, | 98 long frameId, |
97 long parentFrameId, | 99 long parentFrameId, |
98 boolean isMainFrame, | 100 boolean isMainFrame, |
99 String validatedUrl, | 101 String validatedUrl, |
100 boolean isErrorPage, | 102 boolean isErrorPage, |
101 boolean isIframeSrcdoc) { | 103 boolean isIframeSrcdoc) { |
102 mHasStartedAnyProvisionalLoad = true; | 104 if (!isMainFrame) return; |
| 105 AwContents awContents = mAwContents.get(); |
| 106 if (awContents != null) { |
| 107 NavigationEntry pendingEntry = awContents.getNavigationController().
getPendingEntry(); |
| 108 if (pendingEntry != null |
| 109 && (pendingEntry.getTransition() & PageTransition.FROM_API)
== 0) { |
| 110 mStartedNonApiProvisionalLoadInMainFrame = true; |
| 111 } |
| 112 } |
103 } | 113 } |
104 } | 114 } |
OLD | NEW |