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

Commit 5ae1cbb

Browse files
keianhzoMortimerGoro
authored andcommitted
Add support for tab/windows adb parameters (#2423)
1 parent 323d928 commit 5ae1cbb

File tree

1 file changed

+68
-22
lines changed

1 file changed

+68
-22
lines changed

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,8 @@ protected void onNewIntent(final Intent intent) {
484484
setIntent(intent);
485485
final String action = intent.getAction();
486486
if (Intent.ACTION_VIEW.equals(action)) {
487-
if (intent.getData() != null) {
488-
loadFromIntent(intent);
489-
}
487+
loadFromIntent(intent);
488+
490489
} else if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
491490
Log.e(LOGTAG, "Restarted after a crash");
492491
}
@@ -505,33 +504,80 @@ void loadFromIntent(final Intent intent) {
505504
}
506505

507506
Uri uri = intent.getData();
508-
if (uri == null && intent.getExtras() != null && intent.getExtras().containsKey("url")) {
509-
uri = Uri.parse(intent.getExtras().getString("url"));
510-
}
511507

512-
Session activeSession = SessionStore.get().getActiveSession();
508+
boolean openInWindow = false;
509+
boolean openInTab = false;
510+
boolean openInBackground = false;
513511

514512
Bundle extras = intent.getExtras();
515-
if (extras != null && extras.containsKey("homepage")) {
516-
Uri homepageUri = Uri.parse(extras.getString("homepage"));
517-
SettingsStore.getInstance(this).setHomepage(homepageUri.toString());
518-
}
519-
if (extras != null && extras.containsKey("e10s")) {
520-
boolean wasEnabled = SettingsStore.getInstance(this).isMultiprocessEnabled();
521-
boolean enabled = extras.getBoolean("e10s", wasEnabled);
522-
if (wasEnabled != enabled) {
523-
SettingsStore.getInstance(this).setMultiprocessEnabled(enabled);
524-
SessionStore.get().resetMultiprocess();
513+
if (extras != null) {
514+
// If there is no data uri and there is a url parameter we get that
515+
if (uri == null && extras.containsKey("url")) {
516+
uri = Uri.parse(intent.getExtras().getString("url"));
517+
}
518+
519+
// Overwrite the stored homepage
520+
if (extras.containsKey("homepage")) {
521+
Uri homepageUri = Uri.parse(extras.getString("homepage"));
522+
SettingsStore.getInstance(this).setHomepage(homepageUri.toString());
523+
}
524+
525+
// Enable/Disbale e10s
526+
if (extras.containsKey("e10s")) {
527+
boolean wasEnabled = SettingsStore.getInstance(this).isMultiprocessEnabled();
528+
boolean enabled = extras.getBoolean("e10s", wasEnabled);
529+
if (wasEnabled != enabled) {
530+
SettingsStore.getInstance(this).setMultiprocessEnabled(enabled);
531+
SessionStore.get().resetMultiprocess();
532+
}
533+
}
534+
535+
// Open the provided URL in a new tab, if there is no URL provided we just open the homepage
536+
if (extras.containsKey("create_new_tab")) {
537+
openInTab = extras.getBoolean("create_new_tab", false);
538+
if (uri == null) {
539+
uri = Uri.parse(SettingsStore.getInstance(this).getHomepage());
540+
}
541+
}
542+
543+
// Open the tab in background/foreground, if there is no URL provided we just open the homepage
544+
if (extras.containsKey("background")) {
545+
openInBackground = extras.getBoolean("background", false);
546+
if (uri == null) {
547+
uri = Uri.parse(SettingsStore.getInstance(this).getHomepage());
548+
}
549+
}
550+
551+
// Open the provided URL in a new window, if there is no URL provided we just open the homepage
552+
if (extras.containsKey("create_new_window")) {
553+
openInWindow = extras.getBoolean("create_new_window", false);
554+
if (uri == null) {
555+
uri = Uri.parse(SettingsStore.getInstance(this).getHomepage());
556+
}
525557
}
526558
}
527559

528-
if (activeSession != null) {
529-
if (uri != null) {
530-
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());
531-
activeSession.loadUri(uri.toString());
560+
// If there is a URI we open it
561+
if (uri != null) {
562+
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());
563+
564+
if (openInWindow) {
565+
openNewWindow(uri.toString());
566+
567+
} else if (openInTab) {
568+
if (openInBackground) {
569+
openNewTab(uri.toString());
570+
571+
} else {
572+
openNewTabForeground(uri.toString());
573+
}
574+
532575
} else {
533-
mWindows.getFocusedWindow().loadHomeIfNotRestored();
576+
SessionStore.get().getActiveSession().loadUri(uri.toString());
534577
}
578+
579+
} else {
580+
mWindows.getFocusedWindow().loadHomeIfNotRestored();
535581
}
536582
}
537583

0 commit comments

Comments
 (0)