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

Fixes #3169 Hide Tracking icon for file URIs #3206

Merged
merged 2 commits into from
Apr 22, 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 @@ -15,6 +15,7 @@
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;

import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.ui.widgets.Windows;
Expand Down Expand Up @@ -67,6 +68,8 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isWebXRBlocked;
private MutableLiveData<ObservableBoolean> isTrackingEnabled;
private MutableLiveData<ObservableBoolean> isDrmUsed;
private MediatorLiveData<ObservableBoolean> isUrlBarButtonsVisible;
private MediatorLiveData<ObservableBoolean> isUrlBarIconsVisible;

public WindowViewModel(Application application) {
super(application);
Expand Down Expand Up @@ -162,6 +165,15 @@ public WindowViewModel(Application application) {

isTrackingEnabled = new MutableLiveData<>(new ObservableBoolean(true));
isDrmUsed = new MutableLiveData<>(new ObservableBoolean(false));

isUrlBarButtonsVisible = new MediatorLiveData<>();
isUrlBarButtonsVisible.addSource(url, mIsUrlBarButtonsVisibleObserver);
isUrlBarButtonsVisible.setValue(new ObservableBoolean(false));

isUrlBarIconsVisible = new MediatorLiveData<>();
isUrlBarIconsVisible.addSource(isLoading, mIsUrlBarIconsVisibleObserver);
isUrlBarIconsVisible.addSource(isInsecureVisible, mIsUrlBarIconsVisibleObserver);
isUrlBarIconsVisible.setValue(new ObservableBoolean(false));
}

private Observer<ObservableBoolean> mIsTopBarVisibleObserver = new Observer<ObservableBoolean>() {
Expand Down Expand Up @@ -297,6 +309,34 @@ public void onChanged(Spannable aUrl) {
}
};

private Observer<Spannable> mIsUrlBarButtonsVisibleObserver = new Observer<Spannable>() {
@Override
public void onChanged(Spannable aUrl) {
isUrlBarButtonsVisible.postValue(new ObservableBoolean(
!isFocused.getValue().get() &&
!isLibraryVisible.getValue().get() &&
!UrlUtils.isContentFeed(getApplication(), aUrl.toString()) &&
!UrlUtils.isFileUri(aUrl.toString()) &&
(
(SettingsStore.getInstance(getApplication()).getTrackingProtectionLevel() != ContentBlocking.EtpLevel.NONE) ||
isPopUpAvailable.getValue().get() ||
isDrmUsed.getValue().get() ||
isWebXRUsed.getValue().get()
)
));
}
};

private Observer<ObservableBoolean> mIsUrlBarIconsVisibleObserver = new Observer<ObservableBoolean>() {
@Override
public void onChanged(ObservableBoolean o) {
isUrlBarIconsVisible.postValue(new ObservableBoolean(
isLoading.getValue().get() ||
isInsecureVisible.getValue().get()
));
}
};

public void refresh() {
url.postValue(url.getValue());
hint.postValue(getHintValue());
Expand Down Expand Up @@ -730,4 +770,14 @@ public MutableLiveData<ObservableBoolean> getIsDrmUsed() {
public void setIsDrmUsed(boolean isEnabled) {
this.isDrmUsed.postValue(new ObservableBoolean(isEnabled));
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsUrlBarButtonsVisible() {
return isUrlBarButtonsVisible;
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsUrlBarIconsVisible() {
return isUrlBarIconsVisible;
}
}
27 changes: 17 additions & 10 deletions app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SettingsStore;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -124,16 +125,22 @@ public static String titleBarUrl(@Nullable String aUri) {
}

if (URLUtil.isValidUrl(aUri)) {
try {
URI uri = URI.create(aUri);
URL url = new URL(
uri.getScheme() != null ? uri.getScheme() : "",
uri.getAuthority() != null ? uri.getAuthority() : "",
"");
return url.toString();

} catch (MalformedURLException | IllegalArgumentException e) {
return "";
if (UrlUtils.isFileUri(aUri)) {
File file = new File(aUri);
return file.getName();

} else {
try {
URI uri = URI.create(aUri);
URL url = new URL(
uri.getScheme() != null ? uri.getScheme() : "",
uri.getAuthority() != null ? uri.getAuthority() : "",
"");
return url.toString();

} catch (MalformedURLException | IllegalArgumentException e) {
return "";
}
}

} else {
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/layout/navigation_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
android:layout_marginStart="2dp"
android:addStatesFromChildren="true"
android:orientation="horizontal"
app:visibleGone="@{!viewmodel.isLibraryVisible &amp;&amp; !UrlUtils.isContentFeed(context, viewmodel.url.toString())}">
app:visibleGone="@{!viewmodel.isFocused &amp;&amp; viewmodel.isUrlBarButtonsVisible}">

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/tracking"
Expand Down Expand Up @@ -143,16 +143,15 @@
<View
android:layout_width="4dp"
android:layout_height="match_parent"
app:visibleGone="@{!UrlUtils.isHomeUri(context, viewmodel.url.toString())}"/>

app:visibleGone="@{!viewmodel.isUrlBarIconsVisible}"/>
</LinearLayout>

<View
android:id="@+id/padding"
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_toEndOf="@id/startButtonsLayout"
app:visibleGone="@{(!settingsViewmodel.isTrackingProtectionEnabled &amp;&amp; !viewmodel.isPopUpAvailable &amp;&amp; !viewmodel.isWebXRUsed) || viewmodel.isLibraryVisible || UrlUtils.isHomeUri(context, viewmodel.url.toString())}"/>
app:visibleGone="@{!viewmodel.isUrlBarButtonsVisible || viewmodel.isFocused}"/>

<LinearLayout
android:id="@+id/icons"
Expand All @@ -161,7 +160,7 @@
android:orientation="horizontal"
android:layout_toEndOf="@id/padding"
android:layout_centerVertical="true"
app:visibleGone="@{!viewmodel.isFocused}">
app:visibleGone="@{viewmodel.isUrlBarIconsVisible &amp;&amp; !viewmodel.isFocused}">
<ImageView
android:id="@+id/loadingView"
android:layout_width="24dp"
Expand Down