| 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; | 151 if (mAwContents.getNavigationController() == null) return; |
| 151 | 152 |
| 152 switch(msg.what) { | 153 switch(msg.what) { |
| 153 case msgContinuePendingReload: { | 154 case msgContinuePendingReload: { |
| 154 contentViewCore.getWebContents().getNavigationController
() | 155 mAwContents.getNavigationController().continuePendingRel
oad(); |
| 155 .continuePendingReload(); | |
| 156 break; | 156 break; |
| 157 } | 157 } |
| 158 case msgCancelPendingReload: { | 158 case msgCancelPendingReload: { |
| 159 contentViewCore.getWebContents().getNavigationController
() | 159 mAwContents.getNavigationController().cancelPendingReloa
d(); |
| 160 .cancelPendingReload(); | |
| 161 break; | 160 break; |
| 162 } | 161 } |
| 163 default: | 162 default: |
| 164 throw new IllegalStateException( | 163 throw new IllegalStateException( |
| 165 "WebContentsDelegateAdapter: unhandled message "
+ msg.what); | 164 "WebContentsDelegateAdapter: unhandled message "
+ msg.what); |
| 166 } | 165 } |
| 167 } | 166 } |
| 168 }; | 167 }; |
| 169 | 168 |
| 170 Message resend = handler.obtainMessage(msgContinuePendingReload); | 169 Message resend = handler.obtainMessage(msgContinuePendingReload); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 * or an empty string otherwise. | 254 * or an empty string otherwise. |
| 256 */ | 255 */ |
| 257 private String resolveFileName(String filePath) { | 256 private String resolveFileName(String filePath) { |
| 258 if (mContentResolver == null || filePath == null) return ""; | 257 if (mContentResolver == null || filePath == null) return ""; |
| 259 Uri uri = Uri.parse(filePath); | 258 Uri uri = Uri.parse(filePath); |
| 260 return ContentUriUtils.getDisplayName( | 259 return ContentUriUtils.getDisplayName( |
| 261 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME)
; | 260 uri, mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME)
; |
| 262 } | 261 } |
| 263 } | 262 } |
| 264 } | 263 } |
| OLD | NEW |