-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74423de
commit 7474489
Showing
13 changed files
with
562 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/br/com/nullexcept/webappmanager/app/basewebapp/DialogOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package br.com.nullexcept.webappmanager.app.basewebapp; | ||
|
||
import android.view.View; | ||
|
||
import androidx.appcompat.app.AlertDialog; | ||
|
||
import br.com.nullexcept.webappmanager.R; | ||
import br.com.nullexcept.webappmanager.app.BaseWebAppActivity; | ||
|
||
public class DialogOptions { | ||
private AlertDialog dialog; | ||
public DialogOptions(BaseWebAppActivity ctx){ | ||
ctx.runOnUiThread(()->{ | ||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx); | ||
View view = ctx.getLayoutInflater().inflate(R.layout.dialog_actions,null, false); | ||
|
||
view.findViewById(R.id.opt_addons_store).setOnClickListener(v -> { | ||
dialog.dismiss(); | ||
ctx.loadUrl("https://addons.mozilla.org/pt-BR/android/"); | ||
}); | ||
view.findViewById(R.id.opt_gecko_settings).setOnClickListener(v -> { | ||
dialog.dismiss(); | ||
ctx.loadUrl("about:preferences"); | ||
}); | ||
builder.setView(view); | ||
dialog = builder.create(); | ||
}); | ||
} | ||
|
||
public AlertDialog getDialog() { | ||
return dialog; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/br/com/nullexcept/webappmanager/web/WebSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package br.com.nullexcept.webappmanager.web; | ||
|
||
import org.mozilla.geckoview.GeckoSession; | ||
import org.mozilla.geckoview.MediaSession; | ||
|
||
import br.com.nullexcept.webappmanager.app.BaseWebAppActivity; | ||
import br.com.nullexcept.webappmanager.config.Config; | ||
import br.com.nullexcept.webappmanager.web.delegates.ContentListener; | ||
import br.com.nullexcept.webappmanager.web.delegates.NavigationListener; | ||
import br.com.nullexcept.webappmanager.web.delegates.ProcessListener; | ||
import br.com.nullexcept.webappmanager.web.delegates.PromptListener; | ||
|
||
public class WebSession extends GeckoSession { | ||
private Class current; | ||
public WebSession(Object current){ | ||
this.current = current.getClass(); | ||
getSettings().setUserAgentOverride(config().user_agent); | ||
setProgressDelegate(new ProcessListener(this)); | ||
setContentDelegate(new ContentListener(this)); | ||
setNavigationDelegate(new NavigationListener(this)); | ||
setPromptDelegate(new PromptListener(this)); | ||
} | ||
|
||
public void log(Object... items){ | ||
context().log(items); | ||
} | ||
|
||
public void error(Object... items){ | ||
context().error(items); | ||
} | ||
|
||
public Config config(){ | ||
try { | ||
return (Config) current.getField("CURRENT_CONFIG").get(null); | ||
} catch (Exception e) {} | ||
return null; | ||
} | ||
|
||
public BaseWebAppActivity context(){ | ||
try { | ||
return (BaseWebAppActivity) current.getField("CURRENT_CONTEXT").get(null); | ||
} catch (Exception e) {} | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/br/com/nullexcept/webappmanager/web/delegates/ContentListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package br.com.nullexcept.webappmanager.web.delegates; | ||
|
||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.mozilla.geckoview.GeckoSession; | ||
|
||
import br.com.nullexcept.webappmanager.R; | ||
import br.com.nullexcept.webappmanager.web.WebSession; | ||
|
||
public class ContentListener implements GeckoSession.ContentDelegate { | ||
private WebSession session; | ||
public ContentListener(WebSession session){ | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public void onTitleChange(@NonNull GeckoSession current, @Nullable String title) { | ||
GeckoSession.ContentDelegate.super.onTitleChange(current, title); | ||
session.context().runOnUiThread(()->{ | ||
((TextView)session.context().findViewById(R.id.title)).setText(title); | ||
}); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/br/com/nullexcept/webappmanager/web/delegates/NavigationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package br.com.nullexcept.webappmanager.web.delegates; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.mozilla.geckoview.AllowOrDeny; | ||
import org.mozilla.geckoview.GeckoResult; | ||
import org.mozilla.geckoview.GeckoSession; | ||
import org.mozilla.geckoview.WebExtension; | ||
import org.mozilla.geckoview.WebExtensionController; | ||
|
||
import java.util.List; | ||
|
||
import br.com.nullexcept.webappmanager.R; | ||
import br.com.nullexcept.webappmanager.web.WebSession; | ||
|
||
public class NavigationListener implements GeckoSession.NavigationDelegate { | ||
private WebSession session; | ||
public NavigationListener(WebSession session){ | ||
this.session = session; | ||
} | ||
@Nullable | ||
@Override | ||
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession current, @NonNull String uri) { | ||
session.loadUri(uri); | ||
session.log("Requested new session!!"); | ||
return null; | ||
} | ||
|
||
@SuppressLint("WrongThread") | ||
@Nullable | ||
@Override | ||
public GeckoResult<AllowOrDeny> onLoadRequest(@NonNull GeckoSession session, @NonNull LoadRequest request) { | ||
String url = request.uri+""; | ||
if (url.startsWith("https://addons.mozilla.org/") && url.endsWith(".xpi")){ | ||
this.session.log("REQUIRES INSTALL NEW PLUGIN"); | ||
this.session.context().getRuntime().getWebExtensionController().install(url).accept(webExtension -> { | ||
NavigationListener.this.session.context().getRuntime().getWebExtensionController().enable(webExtension, WebExtensionController.EnableSource.USER); | ||
}); | ||
} | ||
return GeckoSession.NavigationDelegate.super.onLoadRequest(session, request); | ||
} | ||
|
||
@Override | ||
public void onLocationChange(@NonNull GeckoSession current, @Nullable String url, @NonNull List<GeckoSession.PermissionDelegate.ContentPermission> perms) { | ||
GeckoSession.NavigationDelegate.super.onLocationChange(current, url, perms); | ||
session.context().runOnUiThread(()->{ | ||
((TextView)session.context().findViewById(R.id.url)).setText(url); | ||
}); | ||
} | ||
} |
Oops, something went wrong.