summaryrefslogtreecommitdiff
path: root/mobile/android/components/build
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/components/build')
-rw-r--r--mobile/android/components/build/moz.build31
-rw-r--r--mobile/android/components/build/nsAndroidHistory.cpp395
-rw-r--r--mobile/android/components/build/nsAndroidHistory.h97
-rw-r--r--mobile/android/components/build/nsBrowserComponents.h7
-rw-r--r--mobile/android/components/build/nsBrowserModule.cpp47
-rw-r--r--mobile/android/components/build/nsIShellService.idl26
-rw-r--r--mobile/android/components/build/nsShellService.cpp30
-rw-r--r--mobile/android/components/build/nsShellService.h29
8 files changed, 662 insertions, 0 deletions
diff --git a/mobile/android/components/build/moz.build b/mobile/android/components/build/moz.build
new file mode 100644
index 0000000000..7a5c439e72
--- /dev/null
+++ b/mobile/android/components/build/moz.build
@@ -0,0 +1,31 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+XPIDL_SOURCES += [
+ 'nsIShellService.idl',
+]
+
+XPIDL_MODULE = 'browsercomps'
+
+EXPORTS += [
+ 'nsBrowserComponents.h',
+]
+
+SOURCES += [
+ 'nsBrowserModule.cpp',
+ 'nsShellService.cpp',
+]
+
+if CONFIG['MOZ_ANDROID_HISTORY']:
+ SOURCES += [
+ 'nsAndroidHistory.cpp',
+ ]
+ LOCAL_INCLUDES += [
+ '/docshell/base',
+ '/dom/base',
+ ]
+
+FINAL_LIBRARY = 'xul'
diff --git a/mobile/android/components/build/nsAndroidHistory.cpp b/mobile/android/components/build/nsAndroidHistory.cpp
new file mode 100644
index 0000000000..2610781c07
--- /dev/null
+++ b/mobile/android/components/build/nsAndroidHistory.cpp
@@ -0,0 +1,395 @@
+/* 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/. */
+
+#include "nsThreadUtils.h"
+#include "nsAndroidHistory.h"
+#include "nsComponentManagerUtils.h"
+#include "nsIURI.h"
+#include "nsIObserverService.h"
+#include "GeneratedJNIWrappers.h"
+#include "Link.h"
+
+#include "mozilla/Services.h"
+#include "mozilla/Preferences.h"
+
+#define NS_LINK_VISITED_EVENT_TOPIC "link-visited"
+
+// We copy Places here.
+// Note that we don't yet observe this pref at runtime.
+#define PREF_HISTORY_ENABLED "places.history.enabled"
+
+// Time we wait to see if a pending visit is really a redirect
+#define PENDING_REDIRECT_TIMEOUT 3000
+
+using namespace mozilla;
+using mozilla::dom::Link;
+
+NS_IMPL_ISUPPORTS(nsAndroidHistory, IHistory, nsIRunnable, nsITimerCallback)
+
+nsAndroidHistory* nsAndroidHistory::sHistory = nullptr;
+
+/*static*/
+nsAndroidHistory*
+nsAndroidHistory::GetSingleton()
+{
+ if (!sHistory) {
+ sHistory = new nsAndroidHistory();
+ NS_ENSURE_TRUE(sHistory, nullptr);
+ }
+
+ NS_ADDREF(sHistory);
+ return sHistory;
+}
+
+nsAndroidHistory::nsAndroidHistory()
+ : mHistoryEnabled(true)
+{
+ LoadPrefs();
+
+ mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
+{
+ if (!aContent || !aURI)
+ return NS_OK;
+
+ // Silently return if URI is something we would never add to DB.
+ bool canAdd;
+ nsresult rv = CanAddURI(aURI, &canAdd);
+ NS_ENSURE_SUCCESS(rv, rv);
+ if (!canAdd) {
+ return NS_OK;
+ }
+
+ nsAutoCString uri;
+ rv = aURI->GetSpec(uri);
+ if (NS_FAILED(rv)) return rv;
+ NS_ConvertUTF8toUTF16 uriString(uri);
+
+ nsTArray<Link*>* list = mListeners.Get(uriString);
+ if (! list) {
+ list = new nsTArray<Link*>();
+ mListeners.Put(uriString, list);
+ }
+ list->AppendElement(aContent);
+
+ if (jni::IsAvailable()) {
+ java::GeckoAppShell::CheckURIVisited(uriString);
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::UnregisterVisitedCallback(nsIURI *aURI, Link *aContent)
+{
+ if (!aContent || !aURI)
+ return NS_OK;
+
+ nsAutoCString uri;
+ nsresult rv = aURI->GetSpec(uri);
+ if (NS_FAILED(rv)) return rv;
+ NS_ConvertUTF8toUTF16 uriString(uri);
+
+ nsTArray<Link*>* list = mListeners.Get(uriString);
+ if (! list)
+ return NS_OK;
+
+ list->RemoveElement(aContent);
+ if (list->IsEmpty()) {
+ mListeners.Remove(uriString);
+ delete list;
+ }
+ return NS_OK;
+}
+
+void
+nsAndroidHistory::AppendToRecentlyVisitedURIs(nsIURI* aURI) {
+ if (mRecentlyVisitedURIs.Length() < RECENTLY_VISITED_URI_SIZE) {
+ // Append a new element while the array is not full.
+ mRecentlyVisitedURIs.AppendElement(aURI);
+ } else {
+ // Otherwise, replace the oldest member.
+ mRecentlyVisitedURIsNextIndex %= RECENTLY_VISITED_URI_SIZE;
+ mRecentlyVisitedURIs.ElementAt(mRecentlyVisitedURIsNextIndex) = aURI;
+ mRecentlyVisitedURIsNextIndex++;
+ }
+}
+
+bool
+nsAndroidHistory::ShouldRecordHistory() {
+ return mHistoryEnabled;
+}
+
+void
+nsAndroidHistory::LoadPrefs() {
+ mHistoryEnabled = Preferences::GetBool(PREF_HISTORY_ENABLED, true);
+}
+
+inline bool
+nsAndroidHistory::IsRecentlyVisitedURI(nsIURI* aURI) {
+ bool equals = false;
+ RecentlyVisitedArray::index_type i;
+ RecentlyVisitedArray::size_type length = mRecentlyVisitedURIs.Length();
+ for (i = 0; i < length && !equals; ++i) {
+ aURI->Equals(mRecentlyVisitedURIs.ElementAt(i), &equals);
+ }
+ return equals;
+}
+
+void
+nsAndroidHistory::AppendToEmbedURIs(nsIURI* aURI) {
+ if (mEmbedURIs.Length() < EMBED_URI_SIZE) {
+ // Append a new element while the array is not full.
+ mEmbedURIs.AppendElement(aURI);
+ } else {
+ // Otherwise, replace the oldest member.
+ mEmbedURIsNextIndex %= EMBED_URI_SIZE;
+ mEmbedURIs.ElementAt(mEmbedURIsNextIndex) = aURI;
+ mEmbedURIsNextIndex++;
+ }
+}
+
+inline bool
+nsAndroidHistory::IsEmbedURI(nsIURI* aURI) {
+ bool equals = false;
+ EmbedArray::index_type i;
+ EmbedArray::size_type length = mEmbedURIs.Length();
+ for (i = 0; i < length && !equals; ++i) {
+ aURI->Equals(mEmbedURIs.ElementAt(i), &equals);
+ }
+ return equals;
+}
+
+inline bool
+nsAndroidHistory::RemovePendingVisitURI(nsIURI* aURI) {
+ // Remove the first pending URI that matches. Return a boolean to
+ // let the caller know if we removed a URI or not.
+ bool equals = false;
+ PendingVisitArray::index_type i;
+ for (i = 0; i < mPendingVisitURIs.Length(); ++i) {
+ aURI->Equals(mPendingVisitURIs.ElementAt(i), &equals);
+ if (equals) {
+ mPendingVisitURIs.RemoveElementAt(i);
+ return true;
+ }
+ }
+ return false;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::Notify(nsITimer *timer)
+{
+ // Any pending visits left in the queue have exceeded our threshold for
+ // redirects, so save them
+ PendingVisitArray::index_type i;
+ for (i = 0; i < mPendingVisitURIs.Length(); ++i) {
+ SaveVisitURI(mPendingVisitURIs.ElementAt(i));
+ }
+ mPendingVisitURIs.Clear();
+
+ return NS_OK;
+}
+
+void
+nsAndroidHistory::SaveVisitURI(nsIURI* aURI) {
+ // Add the URI to our cache so we can take a fast path later
+ AppendToRecentlyVisitedURIs(aURI);
+
+ if (jni::IsAvailable()) {
+ // Save this URI in our history
+ nsAutoCString spec;
+ (void)aURI->GetSpec(spec);
+ java::GeckoAppShell::MarkURIVisited(NS_ConvertUTF8toUTF16(spec));
+ }
+
+ // Finally, notify that we've been visited.
+ nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
+ if (obsService) {
+ obsService->NotifyObservers(aURI, NS_LINK_VISITED_EVENT_TOPIC, nullptr);
+ }
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, uint32_t aFlags)
+{
+ if (!aURI) {
+ return NS_OK;
+ }
+
+ if (!(aFlags & VisitFlags::TOP_LEVEL)) {
+ return NS_OK;
+ }
+
+ if (aFlags & VisitFlags::UNRECOVERABLE_ERROR) {
+ return NS_OK;
+ }
+
+ // Silently return if URI is something we shouldn't add to DB.
+ bool canAdd;
+ nsresult rv = CanAddURI(aURI, &canAdd);
+ NS_ENSURE_SUCCESS(rv, rv);
+ if (!canAdd) {
+ return NS_OK;
+ }
+
+ if (aLastVisitedURI) {
+ if (aFlags & VisitFlags::REDIRECT_SOURCE ||
+ aFlags & VisitFlags::REDIRECT_PERMANENT ||
+ aFlags & VisitFlags::REDIRECT_TEMPORARY) {
+ // aLastVisitedURI redirected to aURI. We want to ignore aLastVisitedURI,
+ // so remove the pending visit. We want to give aURI a chance to be saved,
+ // so don't return early.
+ RemovePendingVisitURI(aLastVisitedURI);
+ }
+
+ bool same;
+ rv = aURI->Equals(aLastVisitedURI, &same);
+ NS_ENSURE_SUCCESS(rv, rv);
+ if (same && IsRecentlyVisitedURI(aURI)) {
+ // Do not save refresh visits if we have visited this URI recently.
+ return NS_OK;
+ }
+
+ // Since we have a last visited URI and we were not redirected, it is
+ // safe to save the visit if it's still pending.
+ if (RemovePendingVisitURI(aLastVisitedURI)) {
+ SaveVisitURI(aLastVisitedURI);
+ }
+ }
+
+ // Let's wait and see if this visit is not a redirect.
+ mPendingVisitURIs.AppendElement(aURI);
+ mTimer->InitWithCallback(this, PENDING_REDIRECT_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
+{
+ // Silently return if URI is something we shouldn't add to DB.
+ bool canAdd;
+ nsresult rv = CanAddURI(aURI, &canAdd);
+ NS_ENSURE_SUCCESS(rv, rv);
+ if (!canAdd) {
+ return NS_OK;
+ }
+
+ if (IsEmbedURI(aURI)) {
+ return NS_OK;
+ }
+
+ if (jni::IsAvailable()) {
+ nsAutoCString uri;
+ nsresult rv = aURI->GetSpec(uri);
+ if (NS_FAILED(rv)) return rv;
+ if (RemovePendingVisitURI(aURI)) {
+ // We have a title, so aURI isn't a redirect, so save the visit now before setting the title.
+ SaveVisitURI(aURI);
+ }
+ NS_ConvertUTF8toUTF16 uriString(uri);
+ java::GeckoAppShell::SetURITitle(uriString, aTitle);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::NotifyVisited(nsIURI *aURI)
+{
+ if (aURI && sHistory) {
+ nsAutoCString spec;
+ (void)aURI->GetSpec(spec);
+ sHistory->mPendingLinkURIs.Push(NS_ConvertUTF8toUTF16(spec));
+ NS_DispatchToMainThread(sHistory);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::Run()
+{
+ while (! mPendingLinkURIs.IsEmpty()) {
+ nsString uriString = mPendingLinkURIs.Pop();
+ nsTArray<Link*>* list = sHistory->mListeners.Get(uriString);
+ if (list) {
+ for (unsigned int i = 0; i < list->Length(); i++) {
+ list->ElementAt(i)->SetLinkState(eLinkState_Visited);
+ }
+ // as per the IHistory interface contract, remove the
+ // Link pointers once they have been notified
+ mListeners.Remove(uriString);
+ delete list;
+ }
+ }
+ return NS_OK;
+}
+
+// Filter out unwanted URIs such as "chrome:", "mailbox:", etc.
+//
+// The model is if we don't know differently then add which basically means
+// we are suppose to try all the things we know not to allow in and then if
+// we don't bail go on and allow it in.
+//
+// Logic ported from nsNavHistory::CanAddURI.
+
+NS_IMETHODIMP
+nsAndroidHistory::CanAddURI(nsIURI* aURI, bool* canAdd)
+{
+ NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
+ NS_ENSURE_ARG(aURI);
+ NS_ENSURE_ARG_POINTER(canAdd);
+
+ // See if we're disabled.
+ if (!ShouldRecordHistory()) {
+ *canAdd = false;
+ return NS_OK;
+ }
+
+ nsAutoCString scheme;
+ nsresult rv = aURI->GetScheme(scheme);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ // first check the most common cases (HTTP, HTTPS) to allow in to avoid most
+ // of the work
+ if (scheme.EqualsLiteral("http")) {
+ *canAdd = true;
+ return NS_OK;
+ }
+ if (scheme.EqualsLiteral("https")) {
+ *canAdd = true;
+ return NS_OK;
+ }
+ if (scheme.EqualsLiteral("about")) {
+ nsAutoCString path;
+ rv = aURI->GetPath(path);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ if (StringBeginsWith(path, NS_LITERAL_CSTRING("reader"))) {
+ *canAdd = true;
+ return NS_OK;
+ }
+ }
+
+ // now check for all bad things
+ if (scheme.EqualsLiteral("about") ||
+ scheme.EqualsLiteral("imap") ||
+ scheme.EqualsLiteral("news") ||
+ scheme.EqualsLiteral("mailbox") ||
+ scheme.EqualsLiteral("moz-anno") ||
+ scheme.EqualsLiteral("view-source") ||
+ scheme.EqualsLiteral("chrome") ||
+ scheme.EqualsLiteral("resource") ||
+ scheme.EqualsLiteral("data") ||
+ scheme.EqualsLiteral("wyciwyg") ||
+ scheme.EqualsLiteral("javascript") ||
+ scheme.EqualsLiteral("blob")) {
+ *canAdd = false;
+ return NS_OK;
+ }
+ *canAdd = true;
+ return NS_OK;
+}
diff --git a/mobile/android/components/build/nsAndroidHistory.h b/mobile/android/components/build/nsAndroidHistory.h
new file mode 100644
index 0000000000..382fbcd2ec
--- /dev/null
+++ b/mobile/android/components/build/nsAndroidHistory.h
@@ -0,0 +1,97 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * 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/. */
+
+#ifndef NS_ANDROIDHISTORY_H
+#define NS_ANDROIDHISTORY_H
+
+#include "IHistory.h"
+#include "nsDataHashtable.h"
+#include "nsTPriorityQueue.h"
+#include "nsIRunnable.h"
+#include "nsIURI.h"
+#include "nsITimer.h"
+
+
+#define NS_ANDROIDHISTORY_CID \
+ {0xCCAA4880, 0x44DD, 0x40A7, {0xA1, 0x3F, 0x61, 0x56, 0xFC, 0x88, 0x2C, 0x0B}}
+
+// Max size of History::mRecentlyVisitedURIs
+#define RECENTLY_VISITED_URI_SIZE 8
+
+// Max size of History::mEmbedURIs
+#define EMBED_URI_SIZE 128
+
+class nsAndroidHistory final : public mozilla::IHistory,
+ public nsIRunnable,
+ public nsITimerCallback
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_IHISTORY
+ NS_DECL_NSIRUNNABLE
+ NS_DECL_NSITIMERCALLBACK
+
+ /**
+ * Obtains a pointer that has had AddRef called on it. Used by the service
+ * manager only.
+ */
+ static nsAndroidHistory* GetSingleton();
+
+ nsAndroidHistory();
+
+private:
+ ~nsAndroidHistory() {}
+
+ static nsAndroidHistory* sHistory;
+
+ // Will mimic the value of the places.history.enabled preference.
+ bool mHistoryEnabled;
+
+ void LoadPrefs();
+ bool ShouldRecordHistory();
+ nsresult CanAddURI(nsIURI* aURI, bool* canAdd);
+
+ /**
+ * We need to manage data used to determine a:visited status.
+ */
+ nsDataHashtable<nsStringHashKey, nsTArray<mozilla::dom::Link *> *> mListeners;
+ nsTPriorityQueue<nsString> mPendingLinkURIs;
+
+ /**
+ * Redirection (temporary and permanent) flags are sent with the redirected
+ * URI, not the original URI. Since we want to ignore the original URI, we
+ * need to cache the pending visit and make sure it doesn't redirect.
+ */
+ RefPtr<nsITimer> mTimer;
+ typedef AutoTArray<nsCOMPtr<nsIURI>, RECENTLY_VISITED_URI_SIZE> PendingVisitArray;
+ PendingVisitArray mPendingVisitURIs;
+
+ bool RemovePendingVisitURI(nsIURI* aURI);
+ void SaveVisitURI(nsIURI* aURI);
+
+ /**
+ * mRecentlyVisitedURIs remembers URIs which are recently added to the DB,
+ * to avoid saving these locations repeatedly in a short period.
+ */
+ typedef AutoTArray<nsCOMPtr<nsIURI>, RECENTLY_VISITED_URI_SIZE> RecentlyVisitedArray;
+ RecentlyVisitedArray mRecentlyVisitedURIs;
+ RecentlyVisitedArray::index_type mRecentlyVisitedURIsNextIndex;
+
+ void AppendToRecentlyVisitedURIs(nsIURI* aURI);
+ bool IsRecentlyVisitedURI(nsIURI* aURI);
+
+ /**
+ * mEmbedURIs remembers URIs which are explicitly not added to the DB,
+ * to avoid wasting time on these locations.
+ */
+ typedef AutoTArray<nsCOMPtr<nsIURI>, EMBED_URI_SIZE> EmbedArray;
+ EmbedArray::index_type mEmbedURIsNextIndex;
+ EmbedArray mEmbedURIs;
+
+ void AppendToEmbedURIs(nsIURI* aURI);
+ bool IsEmbedURI(nsIURI* aURI);
+};
+
+#endif
diff --git a/mobile/android/components/build/nsBrowserComponents.h b/mobile/android/components/build/nsBrowserComponents.h
new file mode 100644
index 0000000000..c9830d9c5d
--- /dev/null
+++ b/mobile/android/components/build/nsBrowserComponents.h
@@ -0,0 +1,7 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+// Needed for building our components as part of libxul
+#define APP_COMPONENT_MODULES MODULE(nsBrowserCompsModule)
diff --git a/mobile/android/components/build/nsBrowserModule.cpp b/mobile/android/components/build/nsBrowserModule.cpp
new file mode 100644
index 0000000000..6f9fe67bf1
--- /dev/null
+++ b/mobile/android/components/build/nsBrowserModule.cpp
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "mozilla/ModuleUtils.h"
+
+#include "nsShellService.h"
+
+#ifdef MOZ_ANDROID_HISTORY
+#include "nsDocShellCID.h"
+#include "nsAndroidHistory.h"
+#define NS_ANDROIDHISTORY_CID \
+ {0xCCAA4880, 0x44DD, 0x40A7, {0xA1, 0x3F, 0x61, 0x56, 0xFC, 0x88, 0x2C, 0x0B}}
+#endif
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsShellService)
+NS_DEFINE_NAMED_CID(nsShellService_CID);
+
+#ifdef MOZ_ANDROID_HISTORY
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsAndroidHistory, nsAndroidHistory::GetSingleton)
+NS_DEFINE_NAMED_CID(NS_ANDROIDHISTORY_CID);
+#endif
+
+static const mozilla::Module::CIDEntry kBrowserCIDs[] = {
+ { &knsShellService_CID, false, nullptr, nsShellServiceConstructor },
+#ifdef MOZ_ANDROID_HISTORY
+ { &kNS_ANDROIDHISTORY_CID, false, nullptr, nsAndroidHistoryConstructor },
+#endif
+ { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
+ { nsShellService_ContractID, &knsShellService_CID },
+#ifdef MOZ_ANDROID_HISTORY
+ { NS_IHISTORY_CONTRACTID, &kNS_ANDROIDHISTORY_CID },
+#endif
+ { nullptr }
+};
+
+static const mozilla::Module kBrowserModule = {
+ mozilla::Module::kVersion,
+ kBrowserCIDs,
+ kBrowserContracts
+};
+
+NSMODULE_DEFN(nsBrowserCompsModule) = &kBrowserModule;
diff --git a/mobile/android/components/build/nsIShellService.idl b/mobile/android/components/build/nsIShellService.idl
new file mode 100644
index 0000000000..e7f8d92776
--- /dev/null
+++ b/mobile/android/components/build/nsIShellService.idl
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(fd2450a3-966b-44a9-a8eb-316256bb80b4)]
+interface nsIShellService : nsISupports
+{
+ /**
+ * This method displays a UI to switch to (or launch) a different task
+ */
+ void switchTask();
+
+ /**
+ * This method creates a shortcut on a desktop or homescreen that opens in
+ * the our application.
+ *
+ * @param aTitle the user-friendly name of the shortcut.
+ * @param aURI the URI to open.
+ * @param aIconData obsolete and ignored, but remains for backward compatibility; pass an empty string
+ * @param aIntent obsolete and ignored, but remains for backward compatibility; pass an empty string
+ */
+ void createShortcut(in AString aTitle, in AString aURI, in AString aIconData, in AString aIntent);
+};
diff --git a/mobile/android/components/build/nsShellService.cpp b/mobile/android/components/build/nsShellService.cpp
new file mode 100644
index 0000000000..86cac86b44
--- /dev/null
+++ b/mobile/android/components/build/nsShellService.cpp
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsShellService.h"
+#include "nsString.h"
+
+#include "GeneratedJNIWrappers.h"
+
+using namespace mozilla;
+
+NS_IMPL_ISUPPORTS(nsShellService, nsIShellService)
+
+NS_IMETHODIMP
+nsShellService::SwitchTask()
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsShellService::CreateShortcut(const nsAString& aTitle, const nsAString& aURI,
+ const nsAString& aIcondata, const nsAString& aIntent)
+{
+ if (!aTitle.Length() || !aURI.Length())
+ return NS_ERROR_FAILURE;
+
+ java::GeckoAppShell::CreateShortcut(aTitle, aURI);
+ return NS_OK;
+}
diff --git a/mobile/android/components/build/nsShellService.h b/mobile/android/components/build/nsShellService.h
new file mode 100644
index 0000000000..ba56cbcaec
--- /dev/null
+++ b/mobile/android/components/build/nsShellService.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef __NS_SHELLSERVICE_H__
+#define __NS_SHELLSERVICE_H__
+
+#include "nsIShellService.h"
+
+class nsShellService final : public nsIShellService
+{
+public:
+
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSISHELLSERVICE
+
+ nsShellService() {}
+
+private:
+ ~nsShellService() {}
+};
+
+#define nsShellService_CID \
+{0xae9ebe1c, 0x61e9, 0x45fa, {0x8f, 0x34, 0xc1, 0x07, 0x80, 0x3a, 0x5b, 0x44}}
+
+#define nsShellService_ContractID "@mozilla.org/browser/shell-service;1"
+
+#endif