Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload WebXR sites when settings are changed #3031

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ public void setWebXRState(@SessionState.WebXRState int aWebXRState) {
}
}

public @SessionState.WebXRState int getWebXRState() {
return mState.mWebXRState;
}

// Session Settings

protected void setServo(final boolean enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public void setSites(@NonNull List<SitePermission> sites) {
}
}

public List<SitePermission> getSites() {
return mDisplayList;
}

private void notifyDiff(List<SitePermission> newDisplayList) {
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffUtil.Callback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import org.mozilla.geckoview.StorageController;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionState;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.OptionsPrivacyBinding;
import org.mozilla.vrbrowser.db.SitePermission;
import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.utils.DeviceType;

import java.util.ArrayList;
Expand All @@ -36,8 +38,6 @@ class PrivacyOptionsView extends SettingsView {

private OptionsPrivacyBinding mBinding;
private ArrayList<Pair<SwitchSetting, String>> mPermissionButtons;
private SettingsView mPopUpsBlockingExceptions;
private SettingsView mWebXRSitesExceptions;

public PrivacyOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
super(aContext, aWidgetManager);
Expand Down Expand Up @@ -87,9 +87,6 @@ protected void updateUI() {
TextView permissionsTitleText = findViewById(R.id.permissionsTitle);
permissionsTitleText.setText(getContext().getString(R.string.security_options_permissions_title, getContext().getString(R.string.app_name)));

mPopUpsBlockingExceptions = new SitePermissionsOptionsView(getContext(), mWidgetManager, SitePermission.SITE_PERMISSION_POPUP);
mWebXRSitesExceptions = new SitePermissionsOptionsView(getContext(), mWidgetManager, SitePermission.SITE_PERMISSION_WEBXR);

mPermissionButtons = new ArrayList<>();
mPermissionButtons.add(Pair.create(findViewById(R.id.cameraPermissionSwitch), Manifest.permission.CAMERA));
mPermissionButtons.add(Pair.create(findViewById(R.id.microphonePermissionSwitch), Manifest.permission.RECORD_AUDIO));
Expand Down Expand Up @@ -323,6 +320,9 @@ private void setWebXR(boolean value, boolean doApply) {

if (doApply) {
SettingsStore.getInstance(getContext()).setWebXREnabled(value);
for (WindowWidget window: mWidgetManager.getWindows().getCurrentWindows()) {
window.getSession().reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.databinding.OptionsExceptionsBinding;
import org.mozilla.vrbrowser.db.SitePermission;
import org.mozilla.vrbrowser.ui.adapters.SitePermissionAdapter;
import org.mozilla.vrbrowser.ui.callbacks.PermissionSiteItemCallback;
import org.mozilla.vrbrowser.ui.viewmodel.SitePermissionViewModel;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.util.List;

Expand Down Expand Up @@ -102,7 +106,13 @@ public Point getDimensions() {

@Override
protected boolean reset() {
List<SitePermission> sites = mAdapter.getSites();
mViewModel.deleteAll(mCategory);
if (sites != null) {
for (SitePermission site: sites) {
reloadIfSameDomain(site.url);
}
}
return true;
}

Expand Down Expand Up @@ -150,6 +160,19 @@ public void onChanged(List<SitePermission> sites) {
@Override
public void onDelete(@NonNull SitePermission item) {
mViewModel.deleteSite(item);
reloadIfSameDomain(item.url);
}
};

private void reloadIfSameDomain(String aHost) {
if (mCategory != SitePermission.SITE_PERMISSION_WEBXR) {
return;
}
for (WindowWidget window: mWidgetManager.getWindows().getCurrentWindows()) {
Session session = window.getSession();
if (aHost.equalsIgnoreCase(UrlUtils.getHost(session.getCurrentUri()))) {
session.reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
}
}
}
}