Android Browser 支持屏蔽webaudio的功能

在android浏览器中,我们都知道可以设置屏蔽image,即选择image是否加载。

同样的道理,那既然在webkit中提供了webaudio的接口,那我们也可以实现这个功能。
具体实现如下:
Package/app/Browser中的修改如下:
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 41e2fd9..7389f34 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -338,6 +338,10 @@
     <string name="pref_allow_apptabs">Allow multiple tabs per app</string>
     <!-- Settings label -->
     <string name="pref_content_load_images">Load images</string>
+    <!--chao begin -->
+    <string name="pref_content_load_audio">Load audio</string>
+    <string name="pref_content_load_audio_summary">Play audio on web pages</string>
+    <!--chao -->
     <!-- Settings label -->
     <string name="pref_content_load_images_summary">Display images on web pages</string>
      <!-- Settings label -->
diff --git a/res/xml/bandwidth_preferences.xml b/res/xml/bandwidth_preferences.xml
index 1762b80..ae00881 100644
--- a/res/xml/bandwidth_preferences.xml
+++ b/res/xml/bandwidth_preferences.xml
@@ -37,7 +37,13 @@
         android:defaultValue="true"
         android:title="@string/pref_content_load_images"
         android:summary="@string/pref_content_load_images_summary" />
-
+<!-- add by chao-->
+    <CheckBoxPreference
+        android:key="load_audio"
+        android:defaultValue="true"
+        android:title="@string/pref_content_load_audio"
+        android:summary="@string/pref_content_load_audio_summary" />
+<!-- add by chao -->
     <CheckBoxPreference
         android:key="video_playback"
         android:defaultValue="true"
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index bf7a519..d426a8d 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -91,6 +91,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.WeakHashMap;
 
+import android.util.Log;
 /**
  * Class for managing settings
  */
@@ -330,6 +331,9 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
         settings.setLayoutAlgorithm(getLayoutAlgorithm());
         settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
         settings.setLoadsImagesAutomatically(loadImages());
+        // -- add by chao
+        settings.setLoadsAudioAutomatically(loadAudio());
+        // add by chao --
         settings.setLoadWithOverviewMode(loadPageInOverviewMode());
         settings.setSavePassword(rememberPasswords());
         settings.setSaveFormData(saveFormdata());
@@ -757,9 +761,17 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
     }
 
     public boolean loadImages() {
+        Log.e("chao","loadImages");
         return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
     }
 
+    // -- add by chao
+    public boolean loadAudio()
+    {
+        Log.d("chao","loadAudio");
+        return mPrefs.getBoolean(PREF_LOAD_AUDIO, true);
+    }
+    // add by chao --
     public boolean videoPlayback() {
         return mPrefs.getBoolean(PREF_VIDEO_PLAYBACK, true);
     }
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index 145b805..43ec640 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -109,6 +109,9 @@ public interface PreferenceKeys {
     static final String PREF_LOAD_IMAGES = "load_images";
     static final String PREF_VIDEO_PLAYBACK = "video_playback";
 
+    // -- add by chao
+    static final String PREF_LOAD_AUDIO = "load_audio";
+    // add by chao --
     // ----------------------
     // Keys for browser recovery
     // ----------------------

在framework中的修改如下:
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index aa68904..da2c61e 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -848,6 +848,12 @@ public abstract class WebSettings {
         throw new MustOverrideException();
     }
 
+    // -- add by chao 
+    public synchronized void setLoadsAudioAutomatically(boolean flag) {
+        throw new MustOverrideException();
+    }
+
+    // add by chao
     /**
      * Gets whether the WebView loads image resources. This includes
      * images embedded using the data URI scheme.*/
@@ -859,6 +865,12 @@ public abstract class WebSettings {
         throw new MustOverrideException();
     }
 
+    // -- add by chao
+    public synchronized boolean getLoadsAudioAutomatically() {
+        throw new MustOverrideException();
+    }
+    // add by chao --
+
     /**
      * Sets whether the WebView should not load image resources from the
      * network (resources accessed via http and https URI schemes).  Note*/
diff --git a/core/java/android/webkit/WebSettingsClassic.java b/core/java/android/webkit/WebSettingsClassic.java
index 73968a7..0614c5a 100644
--- a/core/java/android/webkit/WebSettingsClassic.java
+++ b/core/java/android/webkit/WebSettingsClassic.java
@@ -62,6 +62,7 @@ import android.os.Message;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.util.EventLog;
+import android.util.Log;
 import android.os.SystemProperties;
 import java.util.Locale;
 
@@ -116,6 +117,9 @@ public class WebSettingsClassic extends WebSettings {
     private int             mDefaultFixedFontSize = 13;
     private int             mPageCacheCapacity = 0;
     private boolean         mLoadsImagesAutomatically = true;
+    // -- add by chao
+    private boolean         mLoadsAudioAutomatically = true;
+    // add by chao --
     private boolean         mBlockNetworkImage = false;
     private boolean         mBlockNetworkLoads;
     private boolean         mJavaScriptEnabled = false;
@@ -1142,6 +1146,16 @@ public class WebSettingsClassic extends WebSettings {
         }
     }
 
+    // -- add by chao
+    @Override
+    public synchronized void setLoadsAudioAutomatically(boolean flag) {
+        if (mLoadsAudioAutomatically != flag) {
+            Log.d("chao","setLoadsAudioAutomatically flag = " + flag);
+            mLoadsAudioAutomatically = flag;
+            postSync();
+        }
+    }
+    // add by chao --
     /**
      * @see android.webkit.WebSettings#getLoadsImagesAutomatically()
      */
@@ -1149,6 +1163,13 @@ public class WebSettingsClassic extends WebSettings {
     public synchronized boolean getLoadsImagesAutomatically() {
         return mLoadsImagesAutomatically;
     }
+  
+    // -- add by chao
+    @Override
+    public synchronized boolean getLoadsAudioAutomatically() {
+        return mLoadsAudioAutomatically;
+    }
+    // add by chao
 
     /**
      * @see android.webkit.WebSettings#setBlockNetworkImage(boolean)

extern中的修改如下:
diff --git a/Source/WebCore/page/Settings.cpp b/Source/WebCore/page/Settings.cpp
index 79e38d1..6dfc878 100644
--- a/Source/WebCore/page/Settings.cpp
+++ b/Source/WebCore/page/Settings.cpp
@@ -40,7 +40,7 @@
 #include "ResourceHandle.h"
 #include "StorageMap.h"
 #include <limits>
-
+#include "AndroidLog.h"
 using namespace std;
 
 namespace WebCore {
@@ -917,6 +917,7 @@ void Settings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTime
 
 void Settings::setWebAudioEnabled(bool enabled)
 {
+    ALOGE("setWebAudioEnable = %d  --chao\n", enabled);
     m_webAudioEnabled = enabled;
 }
 
diff --git a/Source/WebKit/android/jni/WebSettings.cpp b/Source/WebKit/android/jni/WebSettings.cpp
index fe5ae0b..8348f6b 100644
--- a/Source/WebKit/android/jni/WebSettings.cpp
+++ b/Source/WebKit/android/jni/WebSettings.cpp
@@ -61,6 +61,7 @@
 #include <config.h>
 #include <wtf/Platform.h>
 
+#include "AndroidLog.h"
 #include "ApplicationCacheStorage.h"
 #include "BitmapAllocatorAndroid.h"
 #include "CachedResourceLoader.h"
@@ -127,6 +128,9 @@ struct FieldIds {
         mDefaultFontSize = env->GetFieldID(clazz, "mDefaultFontSize", "I");
         mDefaultFixedFontSize = env->GetFieldID(clazz, "mDefaultFixedFontSize", "I");
         mLoadsImagesAutomatically = env->GetFieldID(clazz, "mLoadsImagesAutomatically", "Z");
+// add by chao
+        mLoadsAudioAutomatically = env->GetFieldID(clazz, "mLoadsAudioAutomatically", "Z");
+// add by chao end
 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
         mBlockNetworkImage = env->GetFieldID(clazz, "mBlockNetworkImage", "Z");
 #endif
@@ -216,6 +220,9 @@ struct FieldIds {
         ALOG_ASSERT(mDefaultFontSize, "Could not find field mDefaultFontSize");
         ALOG_ASSERT(mDefaultFixedFontSize, "Could not find field mDefaultFixedFontSize");
         ALOG_ASSERT(mLoadsImagesAutomatically, "Could not find field mLoadsImagesAutomatically");
+// add by chao 
+        ALOG_ASSERT(mLoadsAudioAutomatically, "Could not find field mLoadsAudioAutomatically");
+// add by chao --
 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
         ALOG_ASSERT(mBlockNetworkImage, "Could not find field mBlockNetworkImage");
 #endif
@@ -277,6 +284,9 @@ struct FieldIds {
     jfieldID mDefaultFontSize;
     jfieldID mDefaultFixedFontSize;
     jfieldID mLoadsImagesAutomatically;
+// --add by chao
+    jfieldID mLoadsAudioAutomatically;
+// add by chao --
 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
     jfieldID mBlockNetworkImage;
 #endif
@@ -471,6 +481,11 @@ public:
         if (flag)
             cachedResourceLoader->setAutoLoadImages(true);
 
+// -- add by chao
+        flag = env->GetBooleanField(obj, gFieldIds->mLoadsAudioAutomatically);
+        ALOGE("setWebAudioEnabled = %d  --chao \n", flag);
+        s->setWebAudioEnabled(flag);
+// add by chao --
 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
         flag = env->GetBooleanField(obj, gFieldIds->mBlockNetworkImage);
         s->setBlockNetworkImage(flag);

在browser的设置中,我们就可以看到并使用这个选项了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值