diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 169db022b..504435933 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -22,7 +22,6 @@ import android.os.Handler; import android.os.Looper; import android.text.format.Time; import android.util.Log; -import android.webkit.WebSettings; import com.fsck.k9.activity.MessageCompose; import com.fsck.k9.controller.MessagingController; @@ -180,13 +179,6 @@ public class K9 extends Application private static boolean useGalleryBugWorkaround = false; private static boolean galleryBuggy; - /** - * We use WebSettings.getBlockNetworkLoads() to prevent the WebView that displays email - * bodies from loading external resources over the network. Unfortunately this method - * isn't exposed via the official Android API. That's why we use reflection to be able - * to call the method. - */ - private static final Method mGetBlockNetworkLoads = getMethod(WebSettings.class, "setBlockNetworkLoads"); /** * The MIME type(s) of attachments we're willing to view. @@ -948,12 +940,11 @@ public class K9 extends Application mMessageViewReturnToList = messageViewReturnToList; } - private static Method getMethod(Class classObject, String methodName) + public static Method getMethod(Class classObject, String methodName) { try { - Method method = classObject.getMethod(methodName, boolean.class); - return method; + return classObject.getMethod(methodName, boolean.class); } catch (NoSuchMethodException e) { @@ -968,21 +959,6 @@ public class K9 extends Application return null; } - public static void setBlockNetworkLoads(WebSettings webSettings, boolean state) - { - if (mGetBlockNetworkLoads != null) - { - try - { - mGetBlockNetworkLoads.invoke(webSettings, state); - } - catch (Exception e) - { - Log.e(K9.LOG_TAG, "Error on invoking WebSettings.setBlockNetworkLoads()", e); - } - } - } - public static FontSizes getFontSizes() { return fontSizes; diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 3e36aa7fd..443d41b00 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -100,6 +101,14 @@ public class MessageView extends K9Activity implements OnClickListener private static final String SHOW_PICTURES = "showPictures"; private static final String STATE_PGP_DATA = "pgpData"; + /** + * We use WebSettings.getBlockNetworkLoads() to prevent the WebView that displays email + * bodies from loading external resources over the network. Unfortunately this method + * isn't exposed via the official Android API. That's why we use reflection to be able + * to call the method. + */ + private static final Method mGetBlockNetworkLoads = K9.getMethod(WebSettings.class, "setBlockNetworkLoads"); + private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1; private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2; @@ -1867,8 +1876,7 @@ public class MessageView extends K9Activity implements OnClickListener */ private void setLoadPictures(boolean enable) { - K9.setBlockNetworkLoads(mMessageContentView.getSettings(), !enable); - mMessageContentView.getSettings().setBlockNetworkImage(!enable); + blockNetworkDataInWebView(mMessageContentView, !enable); mShowPictures = enable; mHandler.showShowPictures(false); } @@ -2807,6 +2815,39 @@ public class MessageView extends K9Activity implements OnClickListener webSettings.setTextSize(K9.getFontSizes().getMessageViewContent()); + // Disable network images by default. This is overriden by preferences. + blockNetworkDataInWebView(view, true); + } + + /** + * Configure a web view to load or not load network data. A true setting here means that + * network data will be blocked. + * @param view {@link android.webkit.WebView} to adjust network data settings on. + * @param shouldBlockNetworkData True if network data should be blocked, false to allow network data. + */ + public static void blockNetworkDataInWebView(final WebView view, final boolean shouldBlockNetworkData) + { + // Sanity check to make sure we don't blow up. + if (view == null || view.getSettings() == null) + { + return; + } + + // Block network loads. + if (mGetBlockNetworkLoads != null) + { + try + { + mGetBlockNetworkLoads.invoke(view.getSettings(), shouldBlockNetworkData); + } + catch (Exception e) + { + Log.e(K9.LOG_TAG, "Error on invoking WebSettings.setBlockNetworkLoads()", e); + } + } + + // Block network images. + view.getSettings().setBlockNetworkImage(shouldBlockNetworkData); } }