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

Toggle quick permission dialog when clicking the URL bar icons #3036

Merged
merged 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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