From 547c79b0621ef5879d01998b8eaa8914a8ef4f13 Mon Sep 17 00:00:00 2001 From: Selim Gurun Date: Wed, 27 Aug 2014 15:38:35 -0700 Subject: Update API name to comply with changes to API Bug: 17253647 API council requested a change to an API name. This is the plumbing side of the change. Change-Id: I12e85c36df9a96c27855d01afddeae586d57d1c1 --- .../java/com/android/webview/chromium/FileChooserParamsAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java b/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java index 24cc06c..44f765b 100644 --- a/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java +++ b/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java @@ -55,7 +55,7 @@ public class FileChooserParamsAdapter extends FileChooserParams { } @Override - public String getDefaultFilename() { + public String getFilenameHint() { return mParams.defaultFilename; } -- cgit v1.2.3 From 3688d4e395b6ce345514f15304b9c670ed1ab875 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 28 Aug 2014 15:43:47 +0100 Subject: Cherry pick "StrictMode warning reading command line file." Cherry pick I659d8b42459bfecc299374b774405e952a74bf2d to master-chromium. Change-Id: If30edb8c324dada8ed99da400a5f9c5fab89f938 --- .../com/android/webview/chromium/WebViewChromiumFactoryProvider.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java index d24df5c..c688d44 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java @@ -26,6 +26,7 @@ import android.content.SharedPreferences; import android.os.Build; import android.os.FileUtils; import android.os.Looper; +import android.os.StrictMode; import android.os.SystemProperties; import android.os.Trace; import android.util.Log; @@ -99,7 +100,10 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { public WebViewChromiumFactoryProvider() { if (Build.IS_DEBUGGABLE) { + // Suppress the StrictMode violation as this codepath is only hit on debugglable builds. + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); CommandLine.initFromFile(COMMAND_LINE_FILE); + StrictMode.setThreadPolicy(oldPolicy); } else { CommandLine.init(null); } -- cgit v1.2.3 From 7afad6eccb2e0f8b491b0c9da160ed6a328522d3 Mon Sep 17 00:00:00 2001 From: Selim Gurun Date: Wed, 3 Sep 2014 12:37:51 -0700 Subject: Remove the plumbing for optOutDataReductionProxy API Bug: 17253647 Change-Id: Ic722cd96bf8bfb895aa812a1181b1e0870ce0a1f --- .../webview/chromium/DataReductionProxyManager.java | 15 --------------- .../webview/chromium/WebViewChromiumFactoryProvider.java | 5 ----- 2 files changed, 20 deletions(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/DataReductionProxyManager.java b/chromium/java/com/android/webview/chromium/DataReductionProxyManager.java index dcb9c1e..7fe449c 100644 --- a/chromium/java/com/android/webview/chromium/DataReductionProxyManager.java +++ b/chromium/java/com/android/webview/chromium/DataReductionProxyManager.java @@ -70,9 +70,6 @@ public final class DataReductionProxyManager { } } - // Accessed from multiple threads. - private volatile static boolean sOptedOutDataReductionProxy = false; - private ProxySettingListener mProxySettingListener; private ContentObserver mProxySettingObserver; @@ -142,10 +139,6 @@ public final class DataReductionProxyManager { } private static boolean isDataReductionProxyEnabled(Context context) { - if (sOptedOutDataReductionProxy) { - return false; - } - boolean enabled = getProxySetting(context.getContentResolver(), WEBVIEW_DATA_REDUCTION_PROXY) != 0; // intentional fallback. remove before L release. @@ -180,12 +173,4 @@ public final class DataReductionProxyManager { } return enabled; } - - // UI thread - public static void optOutDataReductionProxy() { - if (!sOptedOutDataReductionProxy) { - sOptedOutDataReductionProxy = true; - AwContentsStatics.setDataReductionProxyEnabled(false); - } - } } diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java index c688d44..b185378 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java @@ -349,11 +349,6 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { } } - @Override - public void optOutDataReductionProxy() { - DataReductionProxyManager.optOutDataReductionProxy(); - } - // TODO: Add @Override. public void enableSlowWholeDocumentDraw() { WebViewChromium.enableSlowWholeDocumentDraw(); -- cgit v1.2.3 From 318568c4b5933ce429c402d076bf65da69775706 Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Wed, 3 Sep 2014 13:29:38 -0700 Subject: Update some content classes to content_public Corresponds to chromium https://codereview.chromium.org/406023002/ Patch authored by ajith.v@samsung.com Change-Id: I6da4b2afc54c8d6491726e1d6abeeeb2b83ca9db --- .../java/com/android/webview/chromium/WebBackForwardListChromium.java | 2 +- chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java | 2 +- chromium/java/com/android/webview/chromium/WebViewChromium.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java b/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java index ad2b64b..b584ee9 100644 --- a/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java +++ b/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java @@ -16,7 +16,7 @@ package com.android.webview.chromium; -import org.chromium.content.browser.NavigationHistory; +import org.chromium.content_public.browser.NavigationHistory; import android.webkit.WebBackForwardList; import android.webkit.WebHistoryItem; diff --git a/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java b/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java index 18ab645..e36384b 100644 --- a/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java +++ b/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java @@ -16,7 +16,7 @@ package com.android.webview.chromium; -import org.chromium.content.browser.NavigationEntry; +import org.chromium.content_public.browser.NavigationEntry; import android.graphics.Bitmap; import android.webkit.WebHistoryItem; diff --git a/chromium/java/com/android/webview/chromium/WebViewChromium.java b/chromium/java/com/android/webview/chromium/WebViewChromium.java index 2254265..a6111aa 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromium.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromium.java @@ -69,7 +69,7 @@ import org.chromium.android_webview.AwLayoutSizer; import org.chromium.android_webview.AwSettings; import org.chromium.android_webview.AwPrintDocumentAdapter; import org.chromium.base.ThreadUtils; -import org.chromium.content.browser.LoadUrlParams; +import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.net.NetworkChangeNotifier; import java.io.BufferedWriter; -- cgit v1.2.3 From 556ee2ee901252baba7a701c693b456bd799d433 Mon Sep 17 00:00:00 2001 From: Marcin Kosiba Date: Fri, 5 Sep 2014 11:23:51 +0100 Subject: Prepare for rename of WebResourceRequest.hasUserGestureInsecure to hasGesture. This is to match frameworks/base API changes. BUG: 17253647 Change-Id: Ica8c1afcef634d170951bac4c2b5c519794c57a4 (cherry picked from commit 98f9a279824c46479f89fbad2a900ef648e5f579) --- .../com/android/webview/chromium/WebViewContentsClientAdapter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java b/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java index 674b4b3..c2cc671 100644 --- a/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java +++ b/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java @@ -287,11 +287,14 @@ public class WebViewContentsClientAdapter extends AwContentsClient { return mParams.isMainFrame; } - @Override public boolean hasUserGestureInsecure() { return mParams.hasUserGesture; } + public boolean hasGesture() { + return mParams.hasUserGesture; + } + @Override public String getMethod() { return mParams.method; -- cgit v1.2.3 From 36206a5214eb24ab619db0046d0dcba9be240c63 Mon Sep 17 00:00:00 2001 From: Tao Bai Date: Tue, 2 Sep 2014 14:10:38 -0700 Subject: Implement FileChooserParams.createIntent and parseResult BUG:17253647, 16624450 Change-Id: Ief3861fafabf2799f1d3575b30e2ceddbbb0f0d9 --- .../webview/chromium/FileChooserParamsAdapter.java | 33 +++- .../android/webview/chromium/UploadHelperImpl.java | 172 --------------------- .../chromium/WebViewChromiumFactoryProvider.java | 7 + 3 files changed, 35 insertions(+), 177 deletions(-) delete mode 100644 chromium/java/com/android/webview/chromium/UploadHelperImpl.java (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java b/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java index 44f765b..07222f2 100644 --- a/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java +++ b/chromium/java/com/android/webview/chromium/FileChooserParamsAdapter.java @@ -16,20 +16,34 @@ package com.android.webview.chromium; +import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.webkit.WebChromeClient.FileChooserParams; -import android.webkit.WebChromeClient.UploadHelper; import org.chromium.android_webview.AwContentsClient; public class FileChooserParamsAdapter extends FileChooserParams { private AwContentsClient.FileChooserParams mParams; - private Context mContext; + + public static Uri[] parseFileChooserResult(int resultCode, Intent intent) { + if (resultCode == Activity.RESULT_CANCELED) { + return null; + } + Uri result = intent == null || resultCode != Activity.RESULT_OK ? null + : intent.getData(); + + Uri[] uris = null; + if (result != null) { + uris = new Uri[1]; + uris[0] = result; + } + return uris; + } FileChooserParamsAdapter(AwContentsClient.FileChooserParams params, Context context) { mParams = params; - mContext = context; } @Override @@ -60,7 +74,16 @@ public class FileChooserParamsAdapter extends FileChooserParams { } @Override - public UploadHelper getUploadHelper() { - return new UploadHelperImpl(mParams, mContext); + public Intent createIntent() { + // TODO: Move this code to Aw. Once code is moved + // and merged to M37 get rid of this. + String mimeType = "*/*"; + if (mParams.acceptTypes != null && !mParams.acceptTypes.trim().isEmpty()) + mimeType = mParams.acceptTypes.split(";")[0]; + + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType(mimeType); + return i; } } diff --git a/chromium/java/com/android/webview/chromium/UploadHelperImpl.java b/chromium/java/com/android/webview/chromium/UploadHelperImpl.java deleted file mode 100644 index 0892d1b..0000000 --- a/chromium/java/com/android/webview/chromium/UploadHelperImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.webview.chromium; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Environment; -import android.provider.MediaStore; -import android.webkit.WebChromeClient; - -import org.chromium.android_webview.AwContentsClient; - -import java.io.File; - -public class UploadHelperImpl extends WebChromeClient.UploadHelper { - - private final static String IMAGE_MIME_TYPE = "image/*"; - private final static String VIDEO_MIME_TYPE = "video/*"; - private final static String AUDIO_MIME_TYPE = "audio/*"; - - private AwContentsClient.FileChooserParams mParams; - private Context mContext; - private String mCameraFilePath; - - public UploadHelperImpl(AwContentsClient.FileChooserParams params, Context context) { - mParams = params; - mContext = context; - } - - @Override - public Intent buildIntent() { - // TODO(sgurun) Move this code to Aw. Once code is moved - // and merged to M37 get rid of this. - String mimeType = "*/*"; - if (mParams.acceptTypes != null) { - mimeType = mParams.acceptTypes.split(";")[0]; - } - boolean capture = mParams.capture; - if (mimeType.equals(IMAGE_MIME_TYPE)) { - if (capture) { - // Specified 'image/*' and requested capture. Launch the camera. - return createCameraIntent(); - } else { - // Specified just 'image/*', and no capture. Show a traditional picker filtered - // on accept type by sending an intent for both the Camera and image/* OPENABLE. - Intent chooser = createChooserIntent(createCameraIntent()); - chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(IMAGE_MIME_TYPE)); - return chooser; - } - } else if (mimeType.equals(VIDEO_MIME_TYPE)) { - if (capture) { - // Specified 'video/*' and requested capture. Launch the camcorder. - return createCamcorderIntent(); - } else { - // Specified just 'video/*', and no capture. Show a traditional file picker, - // filtered on accept type by sending an intent for both camcorder - // and video/* OPENABLE. - Intent chooser = createChooserIntent(createCamcorderIntent()); - chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(VIDEO_MIME_TYPE)); - return chooser; - } - } else if (mimeType.equals(AUDIO_MIME_TYPE)) { - if (capture) { - // Specified 'audio/*' and requested capture. Launch the sound recorder. - return createSoundRecorderIntent(); - } else { - // Specified just 'audio/*', and no capture. Show a traditional file picker, - // filtered on accept type by sending an intent for both the sound - // recorder and audio/* OPENABLE. - Intent chooser = createChooserIntent(createSoundRecorderIntent()); - chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(AUDIO_MIME_TYPE)); - return chooser; - } - } - return createDefaultOpenableIntent(); - } - - @Override - public Uri[] parseResult(int resultCode, Intent intent) { - if (resultCode == Activity.RESULT_CANCELED) { - return null; - } - Uri result = intent == null || resultCode != Activity.RESULT_OK ? null - : intent.getData(); - - // As we ask the camera to save the result of the user taking - // a picture, the camera application does not return anything other - // than RESULT_OK. So we need to check whether the file we expected - // was written to disk in the in the case that we - // did not get an intent returned but did get a RESULT_OK. If it was, - // we assume that this result has came back from the camera. - if (result == null && intent == null && resultCode == Activity.RESULT_OK - && mCameraFilePath != null) { - File cameraFile = new File(mCameraFilePath); - if (cameraFile.exists()) { - result = Uri.fromFile(cameraFile); - // Broadcast to the media scanner that we have a new photo - // so it will be added into the gallery for the user. - mContext.sendBroadcast( - new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result)); - } - } - - Uri[] uris = null; - if (result != null) { - uris = new Uri[1]; - uris[0] = result; - } - return uris; - } - - private Intent createDefaultOpenableIntent() { - // Create and return a chooser with the default OPENABLE - // actions including the camera, camcorder and sound - // recorder where available. - Intent i = new Intent(Intent.ACTION_GET_CONTENT); - i.addCategory(Intent.CATEGORY_OPENABLE); - i.setType("*/*"); - - Intent chooser = createChooserIntent(createCameraIntent(), createCamcorderIntent(), - createSoundRecorderIntent()); - chooser.putExtra(Intent.EXTRA_INTENT, i); - return chooser; - } - - private Intent createChooserIntent(Intent... intents) { - Intent chooser = new Intent(Intent.ACTION_CHOOSER); - chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents); - return chooser; - } - - private Intent createOpenableIntent(String type) { - Intent i = new Intent(Intent.ACTION_GET_CONTENT); - i.addCategory(Intent.CATEGORY_OPENABLE); - i.setType(type); - return i; - } - - private Intent createCameraIntent() { - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - File cameraDataDir = Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_DCIM); - mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator + - System.currentTimeMillis() + ".jpg"; - intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath))); - return intent; - } - - private Intent createCamcorderIntent() { - return new Intent(MediaStore.ACTION_VIDEO_CAPTURE); - } - - private Intent createSoundRecorderIntent() { - return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); - } -} diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java index b185378..5cc3ed2 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java @@ -22,7 +22,9 @@ import android.app.ActivityManager; import android.app.ActivityThread; import android.content.ComponentCallbacks2; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Build; import android.os.FileUtils; import android.os.Looper; @@ -353,6 +355,11 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { public void enableSlowWholeDocumentDraw() { WebViewChromium.enableSlowWholeDocumentDraw(); } + + @Override + public Uri[] parseFileChooserResult(int resultCode, Intent intent) { + return FileChooserParamsAdapter.parseFileChooserResult(resultCode, intent); + } }; } } -- cgit v1.2.3 From aa36c6b5770974fae04acef747292eaafa7aa6c4 Mon Sep 17 00:00:00 2001 From: Vivek Galatage Date: Thu, 11 Sep 2014 17:04:14 -0700 Subject: WebViewChromiumFactoryProvider should import ResourceExtractor fromorg.chromium.base Chromium repository CL, https://codereview.chromium.org/548023002 will migrate ResourceExtractor.java inside org.chromium.base package. The same should be reflected while importing ResourceExtractor in WebViewChromiumFactoryProvider.java Change-Id: Iced2182763d6e0769003c3bb096465ca8bbf68ac (cherry picked from commit 03af49abac867afc9ace9324cf65079c7706496c) Conflicts: chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java --- .../com/android/webview/chromium/WebViewChromiumFactoryProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java index 5cc3ed2..5a947e8 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java @@ -57,13 +57,13 @@ import org.chromium.base.CommandLine; import org.chromium.base.MemoryPressureListener; import org.chromium.base.PathService; import org.chromium.base.PathUtils; +import org.chromium.base.ResourceExtractor; import org.chromium.base.ThreadUtils; import org.chromium.base.TraceEvent; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.app.ContentMain; import org.chromium.content.browser.ContentViewStatics; -import org.chromium.content.browser.ResourceExtractor; import java.io.File; import java.lang.ref.WeakReference; -- cgit v1.2.3 From a63a43a08e447d69f7472d13b97cd402064f683a Mon Sep 17 00:00:00 2001 From: Marcin Kosiba Date: Fri, 5 Sep 2014 11:26:08 +0100 Subject: Match rename of WebResourceRequest.hasUserGestureInsecure to hasGesture. This is to match frameworks/base API changes. BUG: 17253647 Change-Id: Id88a7f0652da2dc2994dd4025cee77e8103fa6f5 --- .../com/android/webview/chromium/WebViewContentsClientAdapter.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java b/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java index c2cc671..8d92630 100644 --- a/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java +++ b/chromium/java/com/android/webview/chromium/WebViewContentsClientAdapter.java @@ -287,10 +287,7 @@ public class WebViewContentsClientAdapter extends AwContentsClient { return mParams.isMainFrame; } - public boolean hasUserGestureInsecure() { - return mParams.hasUserGesture; - } - + @Override public boolean hasGesture() { return mParams.hasUserGesture; } -- cgit v1.2.3 From c4da9b7d1b82e905cfb36809f58e13557b56b8a4 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Wed, 10 Sep 2014 19:32:41 +0100 Subject: Remove check for styleable resources in WebView ResourceRewriter. We know that we don't have any stylable resources in the WebView, so we can eliminate the check in our ResourceRewriter; this removes a costly repeated call to Class.getSimpleName(). Bug: 16870075 Change-Id: I48d1e581bc3bc89013b910d2b46cf480f1e9dcfc (cherry picked from commit 91c538cbe7e746f1a972b463f3497a56addf579c) (cherry picked from commit deb7453daf56a2d4cf99be2d9bf0e2d97ba6fecc) --- .../android/webview/chromium/ResourceRewriter.java | 46 +++------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/ResourceRewriter.java b/chromium/java/com/android/webview/chromium/ResourceRewriter.java index 3410044..637a64f 100644 --- a/chromium/java/com/android/webview/chromium/ResourceRewriter.java +++ b/chromium/java/com/android/webview/chromium/ResourceRewriter.java @@ -34,15 +34,15 @@ class ResourceRewriter { // Rewrite the R 'constants' for all library apks. SparseArray packageIdentifiers = ctx.getResources().getAssets() .getAssignedPackageIdentifiers(); + final int N = packageIdentifiers.size(); for (int i = 0; i < N; i++) { final int id = packageIdentifiers.keyAt(i); - final String name = packageIdentifiers.valueAt(i); if (id == 0x01 || id == 0x7f) { continue; } - // TODO(mkosiba): We should use jarjar to remove the redundant R classes here, but due + // TODO: We should use jarjar to remove the redundant R classes here, but due // to a bug in jarjar it's not possible to rename classes with '$' in their name. // See b/15684775. rewriteRValues(com.android.webview.chromium.R.class, id); @@ -65,7 +65,8 @@ class ResourceRewriter { " is not rewritable"); } - if (field.getType() != int.class && field.getType() != Integer.class) { + Class fieldType = field.getType(); + if (fieldType != int.class && fieldType != Integer.class) { throw new IllegalArgumentException("Field " + field.getName() + " is not an integer"); } @@ -80,53 +81,18 @@ class ResourceRewriter { } } - private static void rewriteIntArrayField(Field field, int packageId) { - int requiredModifiers = Modifier.STATIC | Modifier.PUBLIC; - - if ((field.getModifiers() & requiredModifiers) != requiredModifiers) { - throw new IllegalArgumentException("Field " + field.getName() + - " is not rewritable"); - } - - if (field.getType() != int[].class) { - throw new IllegalArgumentException("Field " + field.getName() + - " is not an integer array"); - } - - try { - int[] array = (int[]) field.get(null); - for (int i = 0; i < array.length; i++) { - array[i] = (array[i] & 0x00ffffff) | (packageId << 24); - } - } catch (IllegalAccessException e) { - // This should not occur (we check above if we can write to it) - throw new IllegalArgumentException(e); - } - } - private static void rewriteRValues(final Class rClazz, int id) { try { - Class[] declaredClasses = rClazz.getDeclaredClasses(); - for (Class clazz : declaredClasses) { + for (Class clazz : rClazz.getDeclaredClasses()) { try { - if (clazz.getSimpleName().equals("styleable")) { - for (Field field : clazz.getDeclaredFields()) { - if (field.getType() == int[].class) { - rewriteIntArrayField(field, id); - } - } - - } else { - for (Field field : clazz.getDeclaredFields()) { + for (Field field : clazz.getDeclaredFields()) { rewriteIntField(field, id); - } } } catch (Exception e) { throw new IllegalArgumentException("Failed to rewrite R values for " + clazz.getName(), e); } } - } catch (Exception e) { throw new IllegalArgumentException("Failed to rewrite R values", e); } -- cgit v1.2.3 From afe44e87c563c17ce1e44306fe7047613865cebe Mon Sep 17 00:00:00 2001 From: Marcin Kosiba Date: Thu, 11 Sep 2014 18:07:08 +0100 Subject: Don't use reflection to rewrite the WebView resources. Bug: 16870075 Change-Id: Ie65a3a277ecb3c55622d5bab5916833768b1f21b (cherry picked from commit a17d86e955b57c52637ccb8c46b01a71425d76b8) (cherry picked from commit 2dfa59a347a15f1226811fda15a64e56d162f30c) --- .../android/webview/chromium/ResourceRewriter.java | 52 ++-------------------- 1 file changed, 3 insertions(+), 49 deletions(-) (limited to 'chromium/java/com/android/webview') diff --git a/chromium/java/com/android/webview/chromium/ResourceRewriter.java b/chromium/java/com/android/webview/chromium/ResourceRewriter.java index 637a64f..99fa46f 100644 --- a/chromium/java/com/android/webview/chromium/ResourceRewriter.java +++ b/chromium/java/com/android/webview/chromium/ResourceRewriter.java @@ -45,57 +45,11 @@ class ResourceRewriter { // TODO: We should use jarjar to remove the redundant R classes here, but due // to a bug in jarjar it's not possible to rename classes with '$' in their name. // See b/15684775. - rewriteRValues(com.android.webview.chromium.R.class, id); - rewriteRValues(org.chromium.content.R.class, id); - rewriteRValues(org.chromium.ui.R.class, id); + com.android.webview.chromium.R.onResourcesLoaded(id); + org.chromium.ui.R.onResourcesLoaded(id); + org.chromium.content.R.onResourcesLoaded(id); break; } - - } - - private static void rewriteIntField(Field field, int packageId) throws IllegalAccessException { - int requiredModifiers = Modifier.STATIC | Modifier.PUBLIC; - int bannedModifiers = Modifier.FINAL; - - int mod = field.getModifiers(); - if ((mod & requiredModifiers) != requiredModifiers || - (mod & bannedModifiers) != 0) { - throw new IllegalArgumentException("Field " + field.getName() + - " is not rewritable"); - } - - Class fieldType = field.getType(); - if (fieldType != int.class && fieldType != Integer.class) { - throw new IllegalArgumentException("Field " + field.getName() + - " is not an integer"); - } - - try { - int resId = field.getInt(null); - int newId = (resId & 0x00ffffff) | (packageId << 24); - field.setInt(null, newId); - } catch (IllegalAccessException e) { - // This should not occur (we check above if we can write to it) - throw new IllegalArgumentException(e); - } } - - private static void rewriteRValues(final Class rClazz, int id) { - try { - for (Class clazz : rClazz.getDeclaredClasses()) { - try { - for (Field field : clazz.getDeclaredFields()) { - rewriteIntField(field, id); - } - } catch (Exception e) { - throw new IllegalArgumentException("Failed to rewrite R values for " + - clazz.getName(), e); - } - } - } catch (Exception e) { - throw new IllegalArgumentException("Failed to rewrite R values", e); - } - } - } -- cgit v1.2.3