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

Commit

Permalink
Toggle quick permission dialog when clicking the URL bar icons (#3036)
Browse files Browse the repository at this point in the history
* Toggle quick permission dialog when clicking the URL bar icons

* Reload affected sessions on all windows
  • Loading branch information
MortimerGoro authored Mar 25, 2020
1 parent 28cd676 commit f5e424d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mozilla.vrbrowser.db.SitePermission;
import org.mozilla.vrbrowser.ui.viewmodel.SitePermissionViewModel;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PermissionWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;
Expand Down Expand Up @@ -286,11 +287,20 @@ public void setPermissionAllowed(String uri, @SitePermission.Category int catego
mSitePermissionModel.deleteSite(site);
} else {
if (site == null) {
site = new SitePermission(uri, false, SitePermission.SITE_PERMISSION_WEBXR);
site = new SitePermission(uri, false, category);
mSitePermissions.add(site);
}
site.allowed = false;
mSitePermissionModel.insertSite(site);
}

// Reload URIs with the same domain
for (WindowWidget window: mWidgetManager.getWindows().getCurrentWindows()) {
Session session = window.getSession();
if (uri.equalsIgnoreCase(UrlUtils.getHost(session.getCurrentUri()))) {
session.reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ public void setClickable(boolean clickable) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

view.requestFocusFromTouch();
if (mDelegate != null) {
mDelegate.onWebXRButtonClicked();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.EditText;

import androidx.annotation.NonNull;
Expand All @@ -37,7 +36,6 @@
import org.mozilla.vrbrowser.browser.SessionChangeListener;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionState;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.NavigationBarBinding;
import org.mozilla.vrbrowser.db.SitePermission;
Expand Down Expand Up @@ -918,7 +916,7 @@ public void onPopUpButtonClicked() {

@Override
public void onWebXRButtonClicked() {
showQuickPermission(mBinding.navigationBarNavigation.urlBar.getWebxRButton(),
toggleQuickPermission(mBinding.navigationBarNavigation.urlBar.getWebxRButton(),
SitePermission.SITE_PERMISSION_WEBXR,
mViewModel.getIsWebXRBlocked().getValue().get());
}
Expand Down Expand Up @@ -1151,6 +1149,9 @@ private void showNotification(int notificationId, @NotificationPosition int posi

public void hideAllNotifications() {
NotificationManager.hideAll();
if (mQuickPermissionWidget != null && mQuickPermissionWidget.isVisible()) {
mQuickPermissionWidget.hide(KEEP_WIDGET);
}
}

private void hideNotification(int notificationId) {
Expand All @@ -1163,26 +1164,29 @@ private void hideNotification(int notificationId) {
}
};

private void showQuickPermission(UIButton target, @SitePermission.Category int aCategory, boolean aBlocked) {
private void toggleQuickPermission(UIButton target, @SitePermission.Category int aCategory, boolean aBlocked) {
if (mQuickPermissionWidget == null) {
mQuickPermissionWidget = new QuickPermissionWidget(getContext());
}

if (mQuickPermissionWidget.isVisible() && mQuickPermissionWidget.getCategory() == aCategory) {
mQuickPermissionWidget.hide(KEEP_WIDGET);
return;
}

String uri = UrlUtils.getHost(mAttachedWindow.getSession().getCurrentUri());
mQuickPermissionWidget.setData(uri, aCategory, aBlocked);
mQuickPermissionWidget.setDelegate(new QuickPermissionWidget.Delegate() {
@Override
public void onBlock() {
SessionStore.get().setPermissionAllowed(uri, aCategory, false);
mQuickPermissionWidget.onDismiss();
mAttachedWindow.getSession().reload();
}

@Override
public void onAllow() {
SessionStore.get().setPermissionAllowed(uri, aCategory, true);
mQuickPermissionWidget.onDismiss();
mAttachedWindow.getSession().reload();
}
});
mQuickPermissionWidget.getPlacement().parentHandle = getHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public void updateUI() {
mBinding.executePendingBindings();
}

public @SitePermission.Category int getCategory() {
return mCategory;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Expand Down

0 comments on commit f5e424d

Please sign in to comment.