Revision control

Copy as Markdown

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.focus.session;
import android.os.Bundle;
import androidx.annotation.NonNull;
import org.mozilla.focus.architecture.NonNullLiveData;
import org.mozilla.focus.architecture.NonNullMutableLiveData;
import java.util.UUID;
/**
* Keeping track of state / data of a single browsing session (tab).
*/
public class Session {
private final Source source;
private final String uuid;
private final NonNullMutableLiveData<String> url;
private final NonNullMutableLiveData<Integer> progress;
private final NonNullMutableLiveData<Boolean> secure;
private final NonNullMutableLiveData<Boolean> loading;
private Bundle webviewState;
private boolean isRecorded;
private boolean isBlockingEnabled;
/* package */ Session(Source source, String url) {
this.uuid = UUID.randomUUID().toString();
this.source = source;
// See SessionCallbackProxy for where these are set.
this.url = new NonNullMutableLiveData<>(url);
this.progress = new NonNullMutableLiveData<>(0);
this.secure = new NonNullMutableLiveData<>(false);
this.loading = new NonNullMutableLiveData<>(false);
this.isBlockingEnabled = true;
this.isRecorded = false;
}
/* package */ Session(String url) {
this(Source.CUSTOM_TAB, url);
}
public Source getSource() {
return source;
}
public String getUUID() {
return uuid;
}
/* package */ void setUrl(String url) {
this.url.setValue(url);
}
public NonNullLiveData<String> getUrl() {
return url;
}
/* package */ void setProgress(int progress) {
this.progress.setValue(progress);
}
public NonNullLiveData<Integer> getProgress() {
return progress;
}
/* package */ void setSecure(boolean secure) {
this.secure.setValue(secure);
}
public NonNullLiveData<Boolean> getSecure() {
return secure;
}
/* package */ void setLoading(boolean loading) {
this.loading.setValue(loading);
}
public NonNullLiveData<Boolean> getLoading() {
return loading;
}
/* package */ void clearSearchTerms() {
}
public void saveWebViewState(Bundle bundle) {
this.webviewState = bundle;
}
public Bundle getWebViewState() {
return webviewState;
}
public boolean hasWebViewState() {
return webviewState != null;
}
public boolean isRecorded() {
return isRecorded;
}
public void markAsRecorded() {
isRecorded = true;
}
public boolean isSameAs(@NonNull Session session) {
return uuid.equals(session.getUUID());
}
public boolean isBlockingEnabled() {
return isBlockingEnabled;
}
public void setBlockingEnabled(boolean blockingEnabled) {
this.isBlockingEnabled = blockingEnabled;
}
}