Bug 702037 - Merge Android History into mozilla-central. r=marco
authorDoug Turner <dougt@dougt.org>
Fri, 18 Nov 2011 14:42:52 -0800
changeset 80456 ac667309bea6bb2b1c3e93035023ac709d013c86
parent 80455 b370bc4a61748d53f7aaeaa7a6b5619bd057e148
child 80457 ea5e1f4e996a50623e77faf47579a2af88e3c7cf
child 81332 a335853be21913b4a60a676c76c968d87bc10a56
child 81907 9c8859beb0aceb6eb24a692f646bc6e56c07d0f6
child 105334 d3f02a9d4238de52da37126a94fcc6fbb054e905
push id21497
push userdougt@mozilla.com
push dateFri, 18 Nov 2011 22:47:46 +0000
treeherdermozilla-central@ac667309bea6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarco
bugs702037
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 702037 - Merge Android History into mozilla-central. r=marco
config/autoconf.mk.in
configure.in
toolkit/components/places/Database.cpp
toolkit/components/places/Makefile.in
toolkit/components/places/nsAndroidHistory.cpp
toolkit/components/places/nsAndroidHistory.h
toolkit/components/places/nsPlacesModule.cpp
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -135,16 +135,17 @@ MOZ_BRANDING_DIRECTORY = @MOZ_BRANDING_D
 XPCOM_USE_LEA = @XPCOM_USE_LEA@
 MOZ_INSTALLER	= @MOZ_INSTALLER@
 MOZ_UPDATER	= @MOZ_UPDATER@
 MOZ_UPDATE_CHANNEL	= @MOZ_UPDATE_CHANNEL@
 MOZ_UPDATE_PACKAGING	= @MOZ_UPDATE_PACKAGING@
 MOZ_DISABLE_PARENTAL_CONTROLS = @MOZ_DISABLE_PARENTAL_CONTROLS@
 NS_ENABLE_TSF = @NS_ENABLE_TSF@
 MOZ_SPELLCHECK = @MOZ_SPELLCHECK@
+MOZ_ANDROID_HISTORY = @MOZ_ANDROID_HISTORY@
 MOZ_JAVA_COMPOSITOR = @MOZ_JAVA_COMPOSITOR@
 MOZ_PROFILELOCKING = @MOZ_PROFILELOCKING@
 MOZ_FEEDS = @MOZ_FEEDS@
 MOZ_TOOLKIT_SEARCH = @MOZ_TOOLKIT_SEARCH@
 MOZ_PLACES = @MOZ_PLACES@
 MOZ_SAFE_BROWSING = @MOZ_SAFE_BROWSING@
 MOZ_URL_CLASSIFIER = @MOZ_URL_CLASSIFIER@
 MOZ_ZIPWRITER = @MOZ_ZIPWRITER@
--- a/configure.in
+++ b/configure.in
@@ -4676,17 +4676,17 @@ MOZ_PDF_PRINTING=
 MOZ_DISABLE_DOMCRYPTO=
 NSS_DISABLE_DBM=
 NECKO_WIFI=1
 NECKO_COOKIES=1
 NECKO_PROTOCOLS_DEFAULT="about data file ftp http res viewsource websocket wyciwyg device"
 USE_ARM_KUSER=
 BUILD_CTYPES=1
 MOZ_USE_NATIVE_POPUP_WINDOWS=
-
+MOZ_ANDROID_HISTORY=
 
 case "${target}" in
 *android*|*darwin*)
     ACCESSIBILITY=
     ;;
 *)
     ACCESSIBILITY=1
     ;;
@@ -8459,16 +8459,17 @@ AC_SUBST(MOZ_ANGLE)
 AC_SUBST(MOZ_DIRECTX_SDK_PATH)
 AC_SUBST(MOZ_DIRECTX_SDK_CPU_SUFFIX)
 AC_SUBST(MOZ_D3DX9_VERSION)
 AC_SUBST(MOZ_D3DX9_CAB)
 AC_SUBST(MOZ_D3DCOMPILER_CAB)
 AC_SUBST(MOZ_D3DX9_DLL)
 AC_SUBST(MOZ_D3DCOMPILER_DLL)
 
+AC_SUBST(MOZ_ANDROID_HISTORY)
 AC_SUBST(ENABLE_STRIP)
 AC_SUBST(PKG_SKIP_STRIP)
 AC_SUBST(USE_ELF_DYNSTR_GC)
 AC_SUBST(USE_ELF_HACK)
 AC_SUBST(INCREMENTAL_LINKER)
 AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
 AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
 
--- a/toolkit/components/places/Database.cpp
+++ b/toolkit/components/places/Database.cpp
@@ -292,16 +292,22 @@ Database::~Database()
   if (gDatabase == this) {
     gDatabase = nsnull;
   }
 }
 
 nsresult
 Database::Init()
 {
+#ifdef MOZ_ANDROID_HISTORY
+  // Currently places has deeply weaved it way throughout the gecko codebase.
+  // Here we disable all database creation and loading of places.
+  return NS_ERROR_NOT_IMPLEMENTED;
+#endif
+
   MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<mozIStorageService> storage =
     do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID);
   NS_ENSURE_STATE(storage);
 
   // Init the database file and connect to it.
   bool databaseCreated = false;
--- a/toolkit/components/places/Makefile.in
+++ b/toolkit/components/places/Makefile.in
@@ -96,16 +96,24 @@ CPPSRCS = \
   AsyncFaviconHelpers.cpp \
   PlaceInfo.cpp \
   VisitInfo.cpp \
   Database.cpp \
   $(NULL)
 
 LOCAL_INCLUDES += -I$(srcdir)/../build
 
+ifdef MOZ_ANDROID_HISTORY
+CPPSRCS += nsAndroidHistory.cpp
+LOCAL_INCLUDES += \
+  -I$(topsrcdir)/docshell/base \
+  -I$(topsrcdir)/content/base/src \
+  $(NULL)
+endif
+
 EXTRA_COMPONENTS = \
   toolkitplaces.manifest \
   nsLivemarkService.js \
   nsTaggingService.js \
   nsPlacesExpiration.js \
   PlacesCategoriesStarter.js \
   $(NULL)
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/nsAndroidHistory.cpp
@@ -0,0 +1,168 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Android code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Kartikaya Gupta <kgupta@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsAndroidHistory.h"
+#include "AndroidBridge.h"
+#include "Link.h"
+
+using namespace mozilla;
+using mozilla::dom::Link;
+
+NS_IMPL_ISUPPORTS1(nsAndroidHistory, IHistory)
+
+nsAndroidHistory* nsAndroidHistory::sHistory = NULL;
+
+/*static*/
+nsAndroidHistory*
+nsAndroidHistory::GetSingleton()
+{
+  if (!sHistory) {
+    sHistory = new nsAndroidHistory();
+    NS_ENSURE_TRUE(sHistory, nsnull);
+  }
+
+  NS_ADDREF(sHistory);
+  return sHistory;
+}
+
+nsAndroidHistory::nsAndroidHistory()
+{
+  mListeners.Init();
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
+{
+  if (!aContent || !aURI)
+    return NS_OK;
+
+  nsCAutoString uri;
+  nsresult rv = aURI->GetSpec(uri);
+  if (NS_FAILED(rv)) return rv;
+  nsString uriString = NS_ConvertUTF8toUTF16(uri);
+
+  nsTArray<Link*>* list = mListeners.Get(uriString);
+  if (! list) {
+    list = new nsTArray<Link*>();
+    mListeners.Put(uriString, list);
+  }
+  list->AppendElement(aContent);
+
+  AndroidBridge *bridge = AndroidBridge::Bridge();
+  if (bridge) {
+    bridge->CheckURIVisited(uriString);
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::UnregisterVisitedCallback(nsIURI *aURI, Link *aContent)
+{
+  if (!aContent || !aURI)
+    return NS_OK;
+
+  nsCAutoString uri;
+  nsresult rv = aURI->GetSpec(uri);
+  if (NS_FAILED(rv)) return rv;
+  nsString uriString = NS_ConvertUTF8toUTF16(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;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, PRUint32 aFlags)
+{
+  if (!aURI)
+    return NS_OK;
+
+  if (!(aFlags & VisitFlags::TOP_LEVEL))
+    return NS_OK;
+
+  AndroidBridge *bridge = AndroidBridge::Bridge();
+  if (bridge) {
+    nsCAutoString uri;
+    nsresult rv = aURI->GetSpec(uri);
+    if (NS_FAILED(rv)) return rv;
+    nsString uriString = NS_ConvertUTF8toUTF16(uri);
+    bridge->MarkURIVisited(uriString);
+  }
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
+{
+  // we don't do anything with this right now
+  return NS_OK;
+}
+
+void /*static*/
+nsAndroidHistory::NotifyURIVisited(const nsString& aUriString)
+{
+  if (! sHistory)
+    return;
+  sHistory->mPendingURIs.Push(aUriString);
+  NS_DispatchToMainThread(sHistory);
+}
+
+NS_IMETHODIMP
+nsAndroidHistory::Run()
+{
+  while (! mPendingURIs.IsEmpty()) {
+    nsString uriString = mPendingURIs.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;
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/nsAndroidHistory.h
@@ -0,0 +1,72 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Android code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Kartikaya Gupta <kgupta@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef NS_ANDROIDHISTORY_H
+#define NS_ANDROIDHISTORY_H
+
+#include "IHistory.h"
+#include "nsDataHashtable.h"
+#include "nsTPriorityQueue.h"
+#include "nsThreadUtils.h"
+
+#define NS_ANDROIDHISTORY_CID \
+    {0xCCAA4880, 0x44DD, 0x40A7, {0xA1, 0x3F, 0x61, 0x56, 0xFC, 0x88, 0x2C, 0x0B}}
+
+class nsAndroidHistory : public mozilla::IHistory, public nsIRunnable
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_IHISTORY
+  NS_DECL_NSIRUNNABLE
+
+  /**
+   * Obtains a pointer that has had AddRef called on it.  Used by the service
+   * manager only.
+   */
+  static nsAndroidHistory* GetSingleton();
+
+  nsAndroidHistory();
+  static void NotifyURIVisited(const nsString& str);
+
+private:
+  static nsAndroidHistory* sHistory;
+
+  nsDataHashtable<nsStringHashKey, nsTArray<mozilla::dom::Link *> *> mListeners;
+  nsTPriorityQueue<nsString> mPendingURIs;
+};
+
+#endif
--- a/toolkit/components/places/nsPlacesModule.cpp
+++ b/toolkit/components/places/nsPlacesModule.cpp
@@ -5,60 +5,81 @@
 #include "nsAnnotationService.h"
 #include "nsNavHistory.h"
 #include "nsNavBookmarks.h"
 #include "nsFaviconService.h"
 #include "nsPlacesImportExportService.h"
 #include "History.h"
 #include "nsDocShellCID.h"
 
+#ifdef MOZ_ANDROID_HISTORY
+#include "nsAndroidHistory.h"
+#endif
+
 using namespace mozilla::places;
 
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsNavHistory,
                                          nsNavHistory::GetSingleton)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsAnnotationService,
                                          nsAnnotationService::GetSingleton)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsNavBookmarks,
                                          nsNavBookmarks::GetSingleton)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsFaviconService,
                                          nsFaviconService::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(History, History::GetSingleton)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPlacesImportExportService,
                                          nsPlacesImportExportService::GetSingleton)
+#ifdef MOZ_ANDROID_HISTORY
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsAndroidHistory, nsAndroidHistory::GetSingleton)
+#else
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(History, History::GetSingleton)
+#endif
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAnnoProtocolHandler)
 NS_DEFINE_NAMED_CID(NS_NAVHISTORYSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_ANNOTATIONSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_ANNOPROTOCOLHANDLER_CID);
 NS_DEFINE_NAMED_CID(NS_NAVBOOKMARKSSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_FAVICONSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_PLACESIMPORTEXPORTSERVICE_CID);
+
+#ifdef MOZ_ANDROID_HISTORY
+NS_DEFINE_NAMED_CID(NS_ANDROIDHISTORY_CID);
+#else
 NS_DEFINE_NAMED_CID(NS_HISTORYSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_PLACESIMPORTEXPORTSERVICE_CID);
+#endif
 
 const mozilla::Module::CIDEntry kPlacesCIDs[] = {
   { &kNS_NAVHISTORYSERVICE_CID, false, NULL, nsNavHistoryConstructor },
   { &kNS_ANNOTATIONSERVICE_CID, false, NULL, nsAnnotationServiceConstructor },
   { &kNS_ANNOPROTOCOLHANDLER_CID, false, NULL, nsAnnoProtocolHandlerConstructor },
   { &kNS_NAVBOOKMARKSSERVICE_CID, false, NULL, nsNavBookmarksConstructor },
   { &kNS_FAVICONSERVICE_CID, false, NULL, nsFaviconServiceConstructor },
+#ifdef MOZ_ANDROID_HISTORY
+  { &kNS_ANDROIDHISTORY_CID, false, NULL, nsAndroidHistoryConstructor },
+#else
   { &kNS_HISTORYSERVICE_CID, false, NULL, HistoryConstructor },
+#endif
   { &kNS_PLACESIMPORTEXPORTSERVICE_CID, false, NULL, nsPlacesImportExportServiceConstructor },
   { NULL }
 };
 
 const mozilla::Module::ContractIDEntry kPlacesContracts[] = {
   { NS_NAVHISTORYSERVICE_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
   { NS_GLOBALHISTORY2_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
   { NS_DOWNLOADHISTORY_CONTRACTID, &kNS_NAVHISTORYSERVICE_CID },
   { NS_ANNOTATIONSERVICE_CONTRACTID, &kNS_ANNOTATIONSERVICE_CID },
   { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-anno", &kNS_ANNOPROTOCOLHANDLER_CID },
   { NS_NAVBOOKMARKSSERVICE_CONTRACTID, &kNS_NAVBOOKMARKSSERVICE_CID },
   { NS_FAVICONSERVICE_CONTRACTID, &kNS_FAVICONSERVICE_CID },
   { "@mozilla.org/embeddor.implemented/bookmark-charset-resolver;1", &kNS_NAVHISTORYSERVICE_CID },
+#ifdef MOZ_ANDROID_HISTORY
+  { NS_IHISTORY_CONTRACTID, &kNS_ANDROIDHISTORY_CID },
+#else
   { NS_IHISTORY_CONTRACTID, &kNS_HISTORYSERVICE_CID },
+#endif
   { NS_PLACESIMPORTEXPORTSERVICE_CONTRACTID, &kNS_PLACESIMPORTEXPORTSERVICE_CID },
   { NULL }
 };
 
 const mozilla::Module::CategoryEntry kPlacesCategories[] = {
   { "vacuum-participant", "Places", NS_NAVHISTORYSERVICE_CONTRACTID },
   { NULL }
 };