summaryrefslogtreecommitdiff
path: root/mozilla-gnome-shell-search-fixes.patch
blob: 41a11e8550b4dc210381008c7fdc62fe5daabdf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
diff -up firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.cpp.gnome-shell-search-fixes firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.cpp
--- firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.cpp.gnome-shell-search-fixes	2020-04-07 08:01:50.587124776 +0200
+++ firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.cpp	2020-04-07 10:14:02.530380225 +0200
@@ -26,6 +26,8 @@
 #include "nsIStringBundle.h"
 #include "imgIContainer.h"
 #include "imgITools.h"
+#include "nsNetCID.h"
+#include "nsIIOService.h"
 
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 
@@ -289,20 +291,12 @@ AsyncFaviconDataReady::OnComplete(nsIURI
 }
 
 void nsGNOMEShellSearchProvider::ComposeSearchResultReply(
-    DBusMessage* reply, const char* aSearchTerm) {
+    DBusMessage* reply, const char* aSearchTerm, bool aSearchOnly) {
   uint32_t childCount = 0;
-  nsresult rv = mHistResultContainer->GetChildCount(&childCount);
-  if (NS_FAILED(rv) || childCount == 0) {
-    return;
-  }
-
-  // Obtain the favicon service and get the favicon for the specified page
-  nsCOMPtr<nsIFaviconService> favIconSvc(
-      do_GetService("@mozilla.org/browser/favicon-service;1"));
-  nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
+  nsresult rv = NS_OK;
 
-  if (childCount > MAX_SEARCH_RESULTS_NUM) {
-    childCount = MAX_SEARCH_RESULTS_NUM;
+  if (!aSearchOnly) {
+    nsresult rv = mHistResultContainer->GetChildCount(&childCount);
   }
 
   DBusMessageIter iter;
@@ -310,30 +304,41 @@ void nsGNOMEShellSearchProvider::Compose
   DBusMessageIter iterArray;
   dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &iterArray);
 
-  for (uint32_t i = 0; i < childCount; i++) {
-    nsCOMPtr<nsINavHistoryResultNode> child;
-    mHistResultContainer->GetChild(i, getter_AddRefs(child));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      continue;
-    }
-    if (!IsHistoryResultNodeURI(child)) {
-      continue;
+  if (NS_SUCCEEDED(rv) && childCount > 0) {
+    // Obtain the favicon service and get the favicon for the specified page
+    nsCOMPtr<nsIFaviconService> favIconSvc(
+        do_GetService("@mozilla.org/browser/favicon-service;1"));
+    nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
+
+    if (childCount > MAX_SEARCH_RESULTS_NUM) {
+      childCount = MAX_SEARCH_RESULTS_NUM;
     }
 
-    nsAutoCString uri;
-    child->GetUri(uri);
+    for (uint32_t i = 0; i < childCount; i++) {
+      nsCOMPtr<nsINavHistoryResultNode> child;
+      mHistResultContainer->GetChild(i, getter_AddRefs(child));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        continue;
+      }
+      if (!child || !IsHistoryResultNodeURI(child)) {
+        continue;
+      }
 
-    nsCOMPtr<nsIURI> iconIri;
-    ios->NewURI(uri, nullptr, nullptr, getter_AddRefs(iconIri));
-    nsCOMPtr<nsIFaviconDataCallback> callback =
-        new AsyncFaviconDataReady(this, i, mSearchSerial);
-    favIconSvc->GetFaviconDataForPage(iconIri, callback, 0);
+      nsAutoCString uri;
+      child->GetUri(uri);
 
-    nsAutoCString idKey;
-    GetIDKeyForURI(i, uri, idKey);
+      nsCOMPtr<nsIURI> iconIri;
+      ios->NewURI(uri, nullptr, nullptr, getter_AddRefs(iconIri));
+      nsCOMPtr<nsIFaviconDataCallback> callback =
+          new AsyncFaviconDataReady(this, i, mSearchSerial);
+      favIconSvc->GetFaviconDataForPage(iconIri, callback, 0);
 
-    const char* id = idKey.get();
-    dbus_message_iter_append_basic(&iterArray, DBUS_TYPE_STRING, &id);
+      nsAutoCString idKey;
+      GetIDKeyForURI(i, uri, idKey);
+
+      const char* id = idKey.get();
+      dbus_message_iter_append_basic(&iterArray, DBUS_TYPE_STRING, &id);
+    }
   }
 
   nsPrintfCString searchString("%s:%s", KEYWORD_SEARCH_STRING, aSearchTerm);
@@ -346,7 +351,7 @@ void nsGNOMEShellSearchProvider::Compose
 DBusHandlerResult nsGNOMEShellSearchProvider::GetInitialResultSet(
     DBusMessage* aMsg) {
   DBusMessage* reply;
-  char** stringArray;
+  char** stringArray = nullptr;
   int elements;
 
   if (!dbus_message_get_args(aMsg, nullptr, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
@@ -356,9 +361,10 @@ DBusHandlerResult nsGNOMEShellSearchProv
   } else {
     reply = dbus_message_new_method_return(aMsg);
     nsresult rv = NewHistorySearch(stringArray[0]);
-    if (NS_SUCCEEDED(rv)) {
-      ComposeSearchResultReply(reply, stringArray[0]);
-    }
+    ComposeSearchResultReply(reply, stringArray[0],
+                             /* search only */ NS_FAILED(rv));
+  }
+  if (stringArray) {
     dbus_free_string_array(stringArray);
   }
 
@@ -384,9 +390,8 @@ DBusHandlerResult nsGNOMEShellSearchProv
   } else {
     reply = dbus_message_new_method_return(aMsg);
     nsresult rv = NewHistorySearch(stringArray[0]);
-    if (NS_SUCCEEDED(rv)) {
-      ComposeSearchResultReply(reply, stringArray[0]);
-    }
+    ComposeSearchResultReply(reply, stringArray[0],
+                             /* search only */ NS_FAILED(rv));
   }
 
   if (unusedArray) {
@@ -556,6 +561,10 @@ void nsGNOMEShellSearchProvider::LaunchW
     nsCOMPtr<nsINavHistoryResultNode> child;
     mHistResultContainer->GetChild(keyIndex, getter_AddRefs(child));
 
+    if (!child) {
+      return;
+    }
+
     nsAutoCString uri;
     nsresult rv = child->GetUri(uri);
     if (NS_FAILED(rv)) {
diff -up firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.h.gnome-shell-search-fixes firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.h
--- firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.h.gnome-shell-search-fixes	2020-04-07 08:01:50.587124776 +0200
+++ firefox-75.0/browser/components/shell/nsGNOMEShellSearchProvider.h	2020-04-07 09:56:30.857553820 +0200
@@ -70,7 +70,8 @@ class nsGNOMEShellSearchProvider : publi
   bool IsHistoryResultNodeURI(nsINavHistoryResultNode* aHistoryNode);
   void AppendResultID(DBusMessageIter* aIter, const char* aID);
   void AppendSearchID(DBusMessageIter* aIter, const char* aID);
-  void ComposeSearchResultReply(DBusMessage* aReply, const char* aSearchTerm);
+  void ComposeSearchResultReply(DBusMessage* aReply, const char* aSearchTerm,
+                                bool aSearchOnly);
   void LaunchWithID(const char* aID, uint32_t aTimeStamp);
   void LaunchWithAllResults(uint32_t aTimeStamp);
 
bgstack15