Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Reload WebXR sites when settings are changed (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored Mar 25, 2020
1 parent f5e424d commit d4af5a0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,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);
}
}
}
}

0 comments on commit d4af5a0

Please sign in to comment.