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.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import android.content.ContentResolver; | 7 import android.content.ContentResolver; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.net.Uri; | 9 import android.net.Uri; |
10 import android.os.AsyncTask; | 10 import android.os.AsyncTask; |
11 import android.os.Handler; | 11 import android.os.Handler; |
12 import android.os.Message; | 12 import android.os.Message; |
13 import android.provider.MediaStore; | 13 import android.provider.MediaStore; |
14 import android.util.Log; | 14 import android.util.Log; |
15 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
16 import android.view.View; | 16 import android.view.View; |
17 import android.webkit.ConsoleMessage; | 17 import android.webkit.ConsoleMessage; |
18 import android.webkit.ValueCallback; | 18 import android.webkit.ValueCallback; |
19 | 19 |
20 import org.chromium.base.ContentUriUtils; | 20 import org.chromium.base.ContentUriUtils; |
21 import org.chromium.base.ThreadUtils; | 21 import org.chromium.base.ThreadUtils; |
22 import org.chromium.content.browser.ContentVideoView; | 22 import org.chromium.content.browser.ContentVideoView; |
23 import org.chromium.content.browser.ContentViewCore; | |
24 | 23 |
25 /** | 24 /** |
26 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. | 25 * Adapts the AwWebContentsDelegate interface to the AwContentsClient interface. |
27 * This class also serves a secondary function of routing certain callbacks from the content layer | 26 * This class also serves a secondary function of routing certain callbacks from the content layer |
28 * to specific listener interfaces. | 27 * to specific listener interfaces. |
29 */ | 28 */ |
30 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { | 29 class AwWebContentsDelegateAdapter extends AwWebContentsDelegate { |
31 private static final String TAG = "AwWebContentsDelegateAdapter"; | 30 private static final String TAG = "AwWebContentsDelegateAdapter"; |
32 | 31 |
32 final AwContents mAwContents; | |
33 final AwContentsClient mContentsClient; | 33 final AwContentsClient mContentsClient; |
34 View mContainerView; | 34 View mContainerView; |
35 final Context mContext; | 35 final Context mContext; |
36 | 36 |
37 public AwWebContentsDelegateAdapter(AwContentsClient contentsClient, | 37 public AwWebContentsDelegateAdapter(AwContents awContents, AwContentsClient contentsClient, |
38 View containerView, Context context) { | 38 View containerView, Context context) { |
39 mAwContents = awContents; | |
39 mContentsClient = contentsClient; | 40 mContentsClient = contentsClient; |
40 setContainerView(containerView); | 41 setContainerView(containerView); |
41 mContext = context; | 42 mContext = context; |
42 } | 43 } |
43 | 44 |
44 public void setContainerView(View containerView) { | 45 public void setContainerView(View containerView) { |
45 mContainerView = containerView; | 46 mContainerView = containerView; |
46 } | 47 } |
47 | 48 |
48 @Override | 49 @Override |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // This is only called in chrome layers. | 129 // This is only called in chrome layers. |
129 assert false; | 130 assert false; |
130 } | 131 } |
131 | 132 |
132 @Override | 133 @Override |
133 public void closeContents() { | 134 public void closeContents() { |
134 mContentsClient.onCloseWindow(); | 135 mContentsClient.onCloseWindow(); |
135 } | 136 } |
136 | 137 |
137 @Override | 138 @Override |
138 public void showRepostFormWarningDialog(final ContentViewCore contentViewCor e) { | 139 public void showRepostFormWarningDialog() { |
139 // TODO(mkosiba) We should be using something akin to the JsResultReceiv er as the | 140 // TODO(mkosiba) We should be using something akin to the JsResultReceiv er as the |
140 // callback parameter (instead of ContentViewCore) and implement a way o f converting | 141 // callback parameter (instead of ContentViewCore) and implement a way o f converting |
141 // that to a pair of messages. | 142 // that to a pair of messages. |
142 final int msgContinuePendingReload = 1; | 143 final int msgContinuePendingReload = 1; |
143 final int msgCancelPendingReload = 2; | 144 final int msgCancelPendingReload = 2; |
144 | 145 |
145 // TODO(sgurun) Remember the URL to cancel the reload behavior | 146 // TODO(sgurun) Remember the URL to cancel the reload behavior |
146 // if it is different than the most recent NavigationController entry. | 147 // if it is different than the most recent NavigationController entry. |
147 final Handler handler = new Handler(ThreadUtils.getUiThreadLooper()) { | 148 final Handler handler = new Handler(ThreadUtils.getUiThreadLooper()) { |
148 @Override | 149 @Override |
149 public void handleMessage(Message msg) { | 150 public void handleMessage(Message msg) { |
150 if (contentViewCore.getWebContents() == null) return; | |
boliu
2014/10/09 18:38:47
Still need this check!
AKVT
2014/10/09 18:51:51
Done. Thanks
| |
151 | |
152 switch(msg.what) { | 151 switch(msg.what) { |
153 case msgContinuePendingReload: { | 152 case msgContinuePendingReload: { |
154 contentViewCore.getWebContents().getNavigationController () | 153 mAwContents.getNavigationController().continuePendingRel oad(); |
155 .continuePendingReload(); | |
156 break; | 154 break; |
157 } | 155 } |
158 case msgCancelPendingReload: { | 156 case msgCancelPendingReload: { |
159 contentViewCore.getWebContents().getNavigationController () | 157 mAwContents.getNavigationController().cancelPendingReloa d(); |
160 .cancelPendingReload(); | |
161 break; | 158 break; |
162 } | 159 } |
163 default: | 160 default: |
164 throw new IllegalStateException( | 161 throw new IllegalStateException( |
165 "WebContentsDelegateAdapter: unhandled message " + msg.what); | 162 "WebContentsDelegateAdapter: unhandled message " + msg.what); |
166 } | 163 } |
167 } | 164 } |
168 }; | 165 }; |
169 | 166 |
170 Message resend = handler.obtainMessage(msgContinuePendingReload); | 167 Message resend = handler.obtainMessage(msgContinuePendingReload); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 * or an empty string otherwise. | 252 * or an empty string otherwise. |
256 */ | 253 */ |
257 private String resolveFileName(String filePath) { | 254 private String resolveFileName(String filePath) { |
258 if (mContentResolver == null || filePath == null) return ""; | 255 if (mContentResolver == null || filePath == null) return ""; |
259 Uri uri = Uri.parse(filePath); | 256 Uri uri = Uri.parse(filePath); |
260 return ContentUriUtils.getDisplayName( | 257 return ContentUriUtils.getDisplayName( |
261 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME) ; | 258 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME) ; |
262 } | 259 } |
263 } | 260 } |
264 } | 261 } |
OLD | NEW |