From 08fab3352a7cee93121b58ce7b4b2807314dd141 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine LaFayette Date: Fri, 2 Mar 2012 16:56:50 -0500 Subject: Runtime enablement of WebGL Add Labs setting for enabling and disabling WebGL. Need to make sure WebGL has been compiled in before showing runtime enablement settings in Labs menu. Requesting information from the native side through JNI. (cherry-picked commit from a2f7564cd95da42fad70e3c54497df7e7e8b1ea9) Change-Id: Ie11bfa69941c2d75cfec04132908e07391c602fd --- res/values/strings.xml | 16 ++++++++++------ res/xml-sw600dp/lab_preferences.xml | 5 +++++ res/xml/lab_preferences.xml | 5 +++++ src/com/android/browser/BrowserSettings.java | 16 ++++++++++++++++ src/com/android/browser/PreferenceKeys.java | 1 + .../browser/preferences/LabPreferencesFragment.java | 9 +++++++++ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 411aefb..68839fe 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4,9 +4,9 @@ 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. @@ -173,7 +173,7 @@ This URL can\'t be bookmarked. Bookmark last-viewed page Map - + @@ -653,6 +653,10 @@ Use fullscreen mode to hide the status bar + + WebGL + + Enables WebGL Bandwidth management @@ -727,7 +731,7 @@ Add - + Browser @@ -847,7 +851,7 @@ Touch to free up space. Clear stored data - + Delete all data stored by this website? OK diff --git a/res/xml-sw600dp/lab_preferences.xml b/res/xml-sw600dp/lab_preferences.xml index a7151e0..95cacb0 100644 --- a/res/xml-sw600dp/lab_preferences.xml +++ b/res/xml-sw600dp/lab_preferences.xml @@ -21,4 +21,9 @@ android:defaultValue="false" android:title="@string/pref_lab_quick_controls" android:summary="@string/pref_lab_quick_controls_summary" /> + diff --git a/res/xml/lab_preferences.xml b/res/xml/lab_preferences.xml index 3320cee..8fca4c7 100644 --- a/res/xml/lab_preferences.xml +++ b/res/xml/lab_preferences.xml @@ -26,4 +26,9 @@ android:defaultValue="false" android:title="@string/pref_lab_fullscreen" android:summary="@string/pref_lab_fullscreen_summary" /> + diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 4073f1c..8ed824e 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -129,6 +129,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private static String sFactoryResetUrl; + private static boolean sWebGLAvailable; + public static void initialize(final Context context) { sInstance = new BrowserSettings(context); } @@ -275,6 +277,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, settings.setSaveFormData(saveFormdata()); settings.setUseWideViewPort(isWideViewport()); settings.setAutoFillProfile(getAutoFillProfile()); + setIsWebGLAvailable(settings.isWebGLAvailable()); + settings.setWebGLEnabled(isWebGLAvailable() && isWebGLEnabled()); String ua = mCustomUserAgents.get(settings); if (ua != null) { @@ -841,6 +845,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f); } + public boolean isWebGLEnabled() { + return mPrefs.getBoolean(PREF_ENABLE_WEBGL, true); + } + // ----------------------------- // getter/setters for privacy_security_preferences.xml // ----------------------------- @@ -917,6 +925,14 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting()); } + private static void setIsWebGLAvailable(boolean available) { + sWebGLAvailable = available; + } + + public static boolean isWebGLAvailable() { + return sWebGLAvailable; + } + // ----------------------------- // getter/setters for browser recovery // ----------------------------- diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java index 1828032..2de1073 100644 --- a/src/com/android/browser/PreferenceKeys.java +++ b/src/com/android/browser/PreferenceKeys.java @@ -83,6 +83,7 @@ public interface PreferenceKeys { // ---------------------- static final String PREF_ENABLE_QUICK_CONTROLS = "enable_quick_controls"; static final String PREF_FULLSCREEN = "fullscreen"; + static final String PREF_ENABLE_WEBGL = "enable_webgl"; // ---------------------- // Keys for privacy_security_preferences.xml diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java index 222b5fa..8d33c95 100644 --- a/src/com/android/browser/preferences/LabPreferencesFragment.java +++ b/src/com/android/browser/preferences/LabPreferencesFragment.java @@ -17,8 +17,10 @@ package com.android.browser.preferences; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; import com.android.browser.BrowserSettings; import com.android.browser.PreferenceKeys; @@ -32,5 +34,12 @@ public class LabPreferencesFragment extends PreferenceFragment { super.onCreate(savedInstanceState); // Load the XML preferences file addPreferencesFromResource(R.xml.lab_preferences); + + if (!BrowserSettings.isWebGLAvailable()) { + CheckBoxPreference webGL = (CheckBoxPreference) + findPreference(PreferenceKeys.PREF_ENABLE_WEBGL); + PreferenceScreen screen = getPreferenceScreen(); + screen.removePreference(webGL); + } } } -- cgit v1.1