Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp
Warning:line 506, column 5
Value stored to 'rv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_components_places0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/places -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/places -resource-dir /usr/lib/llvm-20/lib/clang/20 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/places -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/build -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-20/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2025-01-20-090804-167946-1 -x c++ Unified_cpp_components_places0.cpp
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "FaviconHelpers.h"
8
9#include "nsICacheEntry.h"
10#include "nsICachingChannel.h"
11#include "nsIClassOfService.h"
12#include "nsIAsyncVerifyRedirectCallback.h"
13#include "nsIHttpChannel.h"
14#include "nsIPrincipal.h"
15
16#include "nsComponentManagerUtils.h"
17#include "nsNavHistory.h"
18#include "nsFaviconService.h"
19
20#include "mozilla/dom/PlacesFavicon.h"
21#include "mozilla/dom/PlacesObservers.h"
22#include "mozilla/dom/Promise.h"
23#include "mozilla/storage.h"
24#include "mozilla/ScopeExit.h"
25#include "mozilla/Telemetry.h"
26#include "mozilla/StaticPrefs_network.h"
27#include "nsNetUtil.h"
28#include "nsPrintfCString.h"
29#include "nsStreamUtils.h"
30#include "nsStringStream.h"
31#include "nsIPrivateBrowsingChannel.h"
32#include "nsISupportsPriority.h"
33#include <algorithm>
34#include <deque>
35#include "mozilla/gfx/2D.h"
36#include "imgIContainer.h"
37#include "ImageOps.h"
38#include "imgIEncoder.h"
39
40using namespace mozilla;
41using namespace mozilla::places;
42using namespace mozilla::storage;
43
44namespace mozilla {
45namespace places {
46
47namespace {
48
49/**
50 * Fetches information about a page from the database.
51 *
52 * @param aDB
53 * Database connection to history tables.
54 * @param _page
55 * Page that should be fetched.
56 */
57nsresult FetchPageInfo(const RefPtr<Database>& aDB, PageData& _page) {
58 MOZ_ASSERT(_page.spec.Length(), "Must have a non-empty spec!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(_page.spec.Length())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(_page.spec.Length()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("_page.spec.Length()"
" (" "Must have a non-empty spec!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 58); AnnotateMozCrashReason("MOZ_ASSERT" "(" "_page.spec.Length()"
") (" "Must have a non-empty spec!" ")"); do { *((volatile int
*)__null) = 58; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
59 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 59); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 59; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
60
61 // The subquery finds the bookmarked uri we want to set the icon for,
62 // walking up redirects.
63 nsCString query = nsPrintfCString(
64 "SELECT h.id, pi.id, h.guid, ( "
65 "WITH RECURSIVE "
66 "destinations(visit_type, from_visit, place_id, rev_host, bm) AS ( "
67 "SELECT v.visit_type, v.from_visit, p.id, p.rev_host, b.id "
68 "FROM moz_places p "
69 "LEFT JOIN moz_historyvisits v ON v.place_id = p.id "
70 "LEFT JOIN moz_bookmarks b ON b.fk = p.id "
71 "WHERE p.id = h.id "
72 "UNION "
73 "SELECT src.visit_type, src.from_visit, src.place_id, p.rev_host, b.id "
74 "FROM moz_places p "
75 "JOIN moz_historyvisits src ON src.place_id = p.id "
76 "JOIN destinations dest ON dest.from_visit = src.id AND dest.visit_type "
77 "IN (%d, %d) "
78 "LEFT JOIN moz_bookmarks b ON b.fk = src.place_id "
79 "WHERE instr(p.rev_host, dest.rev_host) = 1 "
80 "OR instr(dest.rev_host, p.rev_host) = 1 "
81 ") "
82 "SELECT url "
83 "FROM moz_places p "
84 "JOIN destinations r ON r.place_id = p.id "
85 "WHERE bm NOTNULL "
86 "LIMIT 1 "
87 "), fixup_url(get_unreversed_host(h.rev_host)) AS host "
88 "FROM moz_places h "
89 "LEFT JOIN moz_pages_w_icons pi ON page_url_hash = hash(:page_url) AND "
90 "page_url = :page_url "
91 "WHERE h.url_hash = hash(:page_url) AND h.url = :page_url",
92 nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
93 nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY);
94
95 nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(query);
96 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 96); return NS_ERROR_UNEXPECTED; } } while (false)
;
97 mozStorageStatementScoper scoper(stmt);
98
99 nsresult rv = URIBinder::Bind(stmt, "page_url"_ns, _page.spec);
100 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 100); return rv; } } while (false)
;
101
102 bool hasResult;
103 rv = stmt->ExecuteStep(&hasResult);
104 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 104); return rv; } } while (false)
;
105 if (!hasResult) {
106 // The page does not exist.
107 return NS_ERROR_NOT_AVAILABLE;
108 }
109
110 rv = stmt->GetInt64(0, &_page.placeId);
111 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 111); return rv; } } while (false)
;
112 // May be null, and in such a case this will be 0.
113 _page.id = stmt->AsInt64(1);
114 rv = stmt->GetUTF8String(2, _page.guid);
115 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 115); return rv; } } while (false)
;
116 // Bookmarked url can be nullptr.
117 bool isNull;
118 rv = stmt->GetIsNull(3, &isNull);
119 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 119); return rv; } } while (false)
;
120 // The page could not be bookmarked.
121 if (!isNull) {
122 rv = stmt->GetUTF8String(3, _page.bookmarkedSpec);
123 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 123); return rv; } } while (false)
;
124 }
125
126 if (_page.host.IsEmpty()) {
127 rv = stmt->GetUTF8String(4, _page.host);
128 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 128); return rv; } } while (false)
;
129 }
130
131 if (!_page.canAddToHistory) {
132 // Either history is disabled or the scheme is not supported. In such a
133 // case we want to update the icon only if the page is bookmarked.
134
135 if (_page.bookmarkedSpec.IsEmpty()) {
136 // The page is not bookmarked. Since updating the icon with a disabled
137 // history would be a privacy leak, bail out as if the page did not exist.
138 return NS_ERROR_NOT_AVAILABLE;
139 } else {
140 // The page, or a redirect to it, is bookmarked. If the bookmarked spec
141 // is different from the requested one, use it.
142 if (!_page.bookmarkedSpec.Equals(_page.spec)) {
143 _page.spec = _page.bookmarkedSpec;
144 rv = FetchPageInfo(aDB, _page);
145 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 145); return rv; } } while (false)
;
146 }
147 }
148 }
149
150 return NS_OK;
151}
152
153/**
154 * Stores information about an icon in the database.
155 *
156 * @param aDB
157 * Database connection to history tables.
158 * @param aIcon
159 * Icon that should be stored.
160 * @param aMustReplace
161 * If set to true, the function will bail out with NS_ERROR_NOT_AVAILABLE
162 * if it can't find a previous stored icon to replace.
163 * @note Should be wrapped in a transaction.
164 */
165nsresult SetIconInfo(const RefPtr<Database>& aDB, IconData& aIcon,
166 bool aMustReplace = false) {
167 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 167); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 167; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
168 MOZ_ASSERT(aIcon.payloads.Length() > 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aIcon.payloads.Length() > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aIcon.payloads.Length() >
0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aIcon.payloads.Length() > 0", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 168); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIcon.payloads.Length() > 0"
")"); do { *((volatile int*)__null) = 168; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
169 MOZ_ASSERT(!aIcon.spec.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aIcon.spec.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aIcon.spec.IsEmpty()))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("!aIcon.spec.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 169); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIcon.spec.IsEmpty()"
")"); do { *((volatile int*)__null) = 169; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
170 MOZ_ASSERT(aIcon.expiration > 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aIcon.expiration > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aIcon.expiration > 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aIcon.expiration > 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 170); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIcon.expiration > 0"
")"); do { *((volatile int*)__null) = 170; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
171
172 // There are multiple cases possible at this point:
173 // 1. We must insert some payloads and no payloads exist in the table. This
174 // would be a straight INSERT.
175 // 2. The table contains the same number of payloads we are inserting. This
176 // would be a straight UPDATE.
177 // 3. The table contains more payloads than we are inserting. This would be
178 // an UPDATE and a DELETE.
179 // 4. The table contains less payloads than we are inserting. This would be
180 // an UPDATE and an INSERT.
181 // We can't just remove all the old entries and insert the new ones, cause
182 // we'd lose the referential integrity with pages. For the same reason we
183 // cannot use INSERT OR REPLACE, since it's implemented as DELETE AND INSERT.
184 // Thus, we follow this strategy:
185 // * SELECT all existing icon ids
186 // * For each payload, either UPDATE OR INSERT reusing icon ids.
187 // * If any previous icon ids is leftover, DELETE it.
188
189 nsCOMPtr<mozIStorageStatement> selectStmt = aDB->GetStatement(
190 "SELECT id FROM moz_icons "
191 "WHERE fixed_icon_url_hash = hash(fixup_url(:url)) "
192 "AND icon_url = :url ");
193 NS_ENSURE_STATE(selectStmt)do { if ((__builtin_expect(!!(!(selectStmt)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "selectStmt" ") failed",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 193); return NS_ERROR_UNEXPECTED; } } while (false)
;
194 mozStorageStatementScoper scoper(selectStmt);
195 nsresult rv = URIBinder::Bind(selectStmt, "url"_ns, aIcon.spec);
196 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 196); return rv; } } while (false)
;
197 std::deque<int64_t> ids;
198 bool hasResult = false;
199 while (NS_SUCCEEDED(selectStmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(selectStmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
200 int64_t id = selectStmt->AsInt64(0);
201 MOZ_ASSERT(id > 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(id > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(id > 0))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("id > 0", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 201); AnnotateMozCrashReason("MOZ_ASSERT" "(" "id > 0" ")"
); do { *((volatile int*)__null) = 201; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
202 ids.push_back(id);
203 }
204 if (aMustReplace && ids.empty()) {
205 return NS_ERROR_NOT_AVAILABLE;
206 }
207
208 nsCOMPtr<mozIStorageStatement> insertStmt = aDB->GetStatement(
209 "INSERT INTO moz_icons "
210 "(icon_url, fixed_icon_url_hash, width, root, expire_ms, data, flags) "
211 "VALUES (:url, hash(fixup_url(:url)), :width, :root, :expire, :data, "
212 ":flags) ");
213 NS_ENSURE_STATE(insertStmt)do { if ((__builtin_expect(!!(!(insertStmt)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "insertStmt" ") failed",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 213); return NS_ERROR_UNEXPECTED; } } while (false)
;
214 // ReplaceFaviconData may replace data for an already existing icon, and in
215 // that case it won't have the page uri at hand, thus it can't tell if the
216 // icon is a root icon or not. For that reason, never overwrite a root = 1.
217 nsCOMPtr<mozIStorageStatement> updateStmt = aDB->GetStatement(
218 "UPDATE moz_icons SET width = :width, "
219 "expire_ms = :expire, "
220 "data = :data, "
221 "root = (root OR :root), "
222 "flags = :flags "
223 "WHERE id = :id ");
224 NS_ENSURE_STATE(updateStmt)do { if ((__builtin_expect(!!(!(updateStmt)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "updateStmt" ") failed",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 224); return NS_ERROR_UNEXPECTED; } } while (false)
;
225
226 for (auto& payload : aIcon.payloads) {
227 // Sanity checks.
228 MOZ_ASSERT(payload.mimeType.EqualsLiteral(PNG_MIME_TYPE) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(payload.mimeType.EqualsLiteral("image/png") || payload
.mimeType.EqualsLiteral("image/svg+xml"))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(payload.mimeType.EqualsLiteral
("image/png") || payload.mimeType.EqualsLiteral("image/svg+xml"
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
" (" "Only png and svg payloads are supported" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
") (" "Only png and svg payloads are supported" ")"); do { *
((volatile int*)__null) = 230; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
229 payload.mimeType.EqualsLiteral(SVG_MIME_TYPE),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(payload.mimeType.EqualsLiteral("image/png") || payload
.mimeType.EqualsLiteral("image/svg+xml"))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(payload.mimeType.EqualsLiteral
("image/png") || payload.mimeType.EqualsLiteral("image/svg+xml"
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
" (" "Only png and svg payloads are supported" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
") (" "Only png and svg payloads are supported" ")"); do { *
((volatile int*)__null) = 230; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
230 "Only png and svg payloads are supported")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(payload.mimeType.EqualsLiteral("image/png") || payload
.mimeType.EqualsLiteral("image/svg+xml"))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(payload.mimeType.EqualsLiteral
("image/png") || payload.mimeType.EqualsLiteral("image/svg+xml"
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
" (" "Only png and svg payloads are supported" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "payload.mimeType.EqualsLiteral(\"image/png\") || payload.mimeType.EqualsLiteral(\"image/svg+xml\")"
") (" "Only png and svg payloads are supported" ")"); do { *
((volatile int*)__null) = 230; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
231 MOZ_ASSERT(!payload.mimeType.EqualsLiteral(SVG_MIME_TYPE) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!payload.mimeType.EqualsLiteral("image/svg+xml") || payload
.width == (65535))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!payload.mimeType.EqualsLiteral
("image/svg+xml") || payload.width == (65535)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
" (" "SVG payloads should have max width" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 233); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
") (" "SVG payloads should have max width" ")"); do { *((volatile
int*)__null) = 233; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
232 payload.width == UINT16_MAX,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!payload.mimeType.EqualsLiteral("image/svg+xml") || payload
.width == (65535))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!payload.mimeType.EqualsLiteral
("image/svg+xml") || payload.width == (65535)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
" (" "SVG payloads should have max width" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 233); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
") (" "SVG payloads should have max width" ")"); do { *((volatile
int*)__null) = 233; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
233 "SVG payloads should have max width")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!payload.mimeType.EqualsLiteral("image/svg+xml") || payload
.width == (65535))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!payload.mimeType.EqualsLiteral
("image/svg+xml") || payload.width == (65535)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
" (" "SVG payloads should have max width" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 233); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!payload.mimeType.EqualsLiteral(\"image/svg+xml\") || payload.width == (65535)"
") (" "SVG payloads should have max width" ")"); do { *((volatile
int*)__null) = 233; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
234 MOZ_ASSERT(payload.width > 0, "Payload should have a width")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(payload.width > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(payload.width > 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("payload.width > 0"
" (" "Payload should have a width" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 234); AnnotateMozCrashReason("MOZ_ASSERT" "(" "payload.width > 0"
") (" "Payload should have a width" ")"); do { *((volatile int
*)__null) = 234; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
235#ifdef DEBUG1
236 // Done to ensure we fetch the id. See the MOZ_ASSERT below.
237 payload.id = 0;
238#endif
239 if (!ids.empty()) {
240 // Pop the first existing id for reuse.
241 int64_t id = ids.front();
242 ids.pop_front();
243 mozStorageStatementScoper scoper(updateStmt);
244 rv = updateStmt->BindInt64ByName("id"_ns, id);
245 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 245); return rv; } } while (false)
;
246 rv = updateStmt->BindInt32ByName("width"_ns, payload.width);
247 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 247); return rv; } } while (false)
;
248 rv = updateStmt->BindInt64ByName("expire"_ns, aIcon.expiration / 1000);
249 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 249); return rv; } } while (false)
;
250 rv = updateStmt->BindInt32ByName("root"_ns, aIcon.rootIcon);
251 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 251); return rv; } } while (false)
;
252 rv = updateStmt->BindBlobByName("data"_ns, TO_INTBUFFER(payload.data)reinterpret_cast<uint8_t*>(const_cast<char*>(payload
.data.get()))
,
253 payload.data.Length());
254 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 254); return rv; } } while (false)
;
255 rv = updateStmt->BindInt32ByName("flags"_ns, aIcon.flags);
256 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 256); return rv; } } while (false)
;
257 rv = updateStmt->Execute();
258 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 258); return rv; } } while (false)
;
259 // Set the new payload id.
260 payload.id = id;
261 } else {
262 // Insert a new entry.
263 mozStorageStatementScoper scoper(insertStmt);
264 rv = URIBinder::Bind(insertStmt, "url"_ns, aIcon.spec);
265 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 265); return rv; } } while (false)
;
266 rv = insertStmt->BindInt32ByName("width"_ns, payload.width);
267 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 267); return rv; } } while (false)
;
268
269 rv = insertStmt->BindInt32ByName("root"_ns, aIcon.rootIcon);
270 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 270); return rv; } } while (false)
;
271 rv = insertStmt->BindInt64ByName("expire"_ns, aIcon.expiration / 1000);
272 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 272); return rv; } } while (false)
;
273 rv = insertStmt->BindBlobByName("data"_ns, TO_INTBUFFER(payload.data)reinterpret_cast<uint8_t*>(const_cast<char*>(payload
.data.get()))
,
274 payload.data.Length());
275 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 275); return rv; } } while (false)
;
276 rv = insertStmt->BindInt32ByName("flags"_ns, aIcon.flags);
277 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 277); return rv; } } while (false)
;
278 rv = insertStmt->Execute();
279 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 279); return rv; } } while (false)
;
280 // Set the new payload id.
281 payload.id = nsFaviconService::sLastInsertedIconId;
282 }
283 MOZ_ASSERT(payload.id > 0, "Payload should have an id")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(payload.id > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(payload.id > 0))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("payload.id > 0"
" (" "Payload should have an id" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 283); AnnotateMozCrashReason("MOZ_ASSERT" "(" "payload.id > 0"
") (" "Payload should have an id" ")"); do { *((volatile int
*)__null) = 283; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
284 }
285
286 if (!ids.empty()) {
287 // Remove any old leftover payload.
288 nsAutoCString sql("DELETE FROM moz_icons WHERE id IN (");
289 for (int64_t id : ids) {
290 sql.AppendInt(id);
291 sql.AppendLiteral(",");
292 }
293 sql.AppendLiteral(" 0)"); // Non-existing id to match the trailing comma.
294 nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(sql);
295 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 295); return NS_ERROR_UNEXPECTED; } } while (false)
;
296 mozStorageStatementScoper scoper(stmt);
297 rv = stmt->Execute();
298 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 298); return rv; } } while (false)
;
299 }
300
301 return NS_OK;
302}
303
304/**
305 * Fetches information on a icon url from the database.
306 *
307 * @param aDBConn
308 * Database connection to history tables.
309 * @param aPreferredWidth
310 * The preferred size to fetch.
311 * @param _icon
312 * Icon that should be fetched.
313 */
314nsresult FetchIconInfo(const RefPtr<Database>& aDB, uint16_t aPreferredWidth,
315 IconData& _icon) {
316 MOZ_ASSERT(_icon.spec.Length(), "Must have a non-empty spec!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(_icon.spec.Length())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(_icon.spec.Length()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("_icon.spec.Length()"
" (" "Must have a non-empty spec!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 316); AnnotateMozCrashReason("MOZ_ASSERT" "(" "_icon.spec.Length()"
") (" "Must have a non-empty spec!" ")"); do { *((volatile int
*)__null) = 316; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
317 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 317); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 317; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
318
319 if (_icon.status & ICON_STATUS_CACHED1 << 3) {
320 // The icon data has already been set by ReplaceFaviconData.
321 return NS_OK;
322 }
323
324 nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(
325 "/* do not warn (bug no: not worth having a compound index) */ "
326 "SELECT id, expire_ms, data, width, root "
327 "FROM moz_icons "
328 "WHERE fixed_icon_url_hash = hash(fixup_url(:url)) "
329 "AND icon_url = :url "
330 "ORDER BY width DESC ");
331 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 331); return NS_ERROR_UNEXPECTED; } } while (false)
;
332 mozStorageStatementScoper scoper(stmt);
333
334 DebugOnly<nsresult> rv = URIBinder::Bind(stmt, "url"_ns, _icon.spec);
335 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 335); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 335; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
336
337 bool hasResult = false;
338 while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
339 IconPayload payload;
340 rv = stmt->GetInt64(0, &payload.id);
341 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 341); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 341; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
342
343 // Expiration can be nullptr.
344 bool isNull;
345 rv = stmt->GetIsNull(1, &isNull);
346 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 346); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 346; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
347 if (!isNull) {
348 int64_t expire_ms;
349 rv = stmt->GetInt64(1, &expire_ms);
350 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 350); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 350; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
351 _icon.expiration = expire_ms * 1000;
352 }
353
354 uint8_t* data;
355 uint32_t dataLen = 0;
356 rv = stmt->GetBlob(2, &dataLen, &data);
357 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 357; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
358 payload.data.Adopt(TO_CHARBUFFER(data)reinterpret_cast<char*>(const_cast<uint8_t*>(data
))
, dataLen);
359
360 int32_t width;
361 rv = stmt->GetInt32(3, &width);
362 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 362); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 362; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
363 payload.width = width;
364 if (payload.width == UINT16_MAX(65535)) {
365 payload.mimeType.AssignLiteral(SVG_MIME_TYPE"image/svg+xml");
366 } else {
367 payload.mimeType.AssignLiteral(PNG_MIME_TYPE"image/png");
368 }
369
370 int32_t rootIcon;
371 rv = stmt->GetInt32(4, &rootIcon);
372 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 372); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 372; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
373 _icon.rootIcon = rootIcon;
374
375 if (aPreferredWidth == 0 || _icon.payloads.Length() == 0) {
376 _icon.payloads.AppendElement(payload);
377 } else if (payload.width >= aPreferredWidth) {
378 // Only retain the best matching payload.
379 _icon.payloads.ReplaceElementAt(0, payload);
380 } else {
381 break;
382 }
383 }
384
385 return NS_OK;
386}
387
388nsresult FetchMostFrecentSubPageIcon(const RefPtr<Database>& aDB,
389 const nsACString& aPageRoot,
390 const nsACString& aPageHost,
391 IconData& aIconData) {
392 nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(
393 "SELECT i.icon_url "
394 "FROM moz_pages_w_icons pwi "
395 "JOIN moz_icons_to_pages itp ON pwi.id = itp.page_id "
396 "JOIN moz_icons i ON itp.icon_id = i.id "
397 "JOIN moz_places p ON p.url_hash = pwi.page_url_hash "
398 "WHERE p.rev_host = get_unreversed_host(:pageHost || '.') || '.' "
399 "AND p.url BETWEEN :pageRoot AND :pageRoot || X'FFFF' "
400 "ORDER BY p.frecency DESC, i.width DESC "
401 "LIMIT 1");
402 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 402); return NS_ERROR_UNEXPECTED; } } while (false)
;
403 mozStorageStatementScoper scoperFallback(stmt);
404
405 nsresult rv = stmt->BindUTF8StringByName("pageRoot"_ns, aPageRoot);
406 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 406); return rv; } } while (false)
;
407 rv = stmt->BindUTF8StringByName("pageHost"_ns, aPageHost);
408 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 408); return rv; } } while (false)
;
409
410 bool hasResult;
411
412 if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
413 rv = stmt->GetUTF8String(0, aIconData.spec);
414 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 414); return rv; } } while (false)
;
415 }
416
417 return NS_OK;
418}
419
420nsresult FetchIconPerSpec(const RefPtr<Database>& aDB,
421 const nsCOMPtr<nsIURI>& aPageURI, IconData& aIconData,
422 uint16_t aPreferredWidth) {
423 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 423); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 423; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
424 MOZ_ASSERT(aPageURI, "URI must exist.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPageURI)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPageURI))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aPageURI" " (" "URI must exist."
")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 424); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPageURI" ") ("
"URI must exist." ")"); do { *((volatile int*)__null) = 424;
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
425
426 nsAutoCString pageSpec;
427 nsresult rv = aPageURI->GetSpec(pageSpec);
428 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 428); return rv; } } while (false)
;
429 MOZ_ASSERT(!pageSpec.IsEmpty(), "Page spec must not be empty.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!pageSpec.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!pageSpec.IsEmpty()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!pageSpec.IsEmpty()"
" (" "Page spec must not be empty." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 429); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!pageSpec.IsEmpty()"
") (" "Page spec must not be empty." ")"); do { *((volatile int
*)__null) = 429; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
430
431 nsAutoCString pageHostAndPort;
432 // It's expected that some URIs may not have a host/port.
433 Unused << aPageURI->GetHostPort(pageHostAndPort);
434
435 const uint16_t THRESHOLD_WIDTH = 64;
436
437 // This selects both associated and root domain icons, ordered by width,
438 // where an associated icon has priority over a root domain icon.
439 // If the preferred width is less than or equal to THRESHOLD_WIDTH, non-rich
440 // icons are prioritized over rich icons by ordering first by `isRich ASC`,
441 // then by width. If the preferred width is greater than THRESHOLD_WIDTH, the
442 // sorting prioritizes width, with no preference for rich or non-rich icons.
443 // Regardless, note that while this way we are far more efficient, we lost
444 // associations with root domain icons, so it's possible we'll return one for
445 // a specific size when an associated icon for that size doesn't exist.
446
447 nsCString query = nsPrintfCString(
448 "/* do not warn (bug no: not worth having a compound index) */ "
449 "SELECT width, icon_url, root, (flags & %d) as isRich "
450 "FROM moz_icons i "
451 "JOIN moz_icons_to_pages ON i.id = icon_id "
452 "JOIN moz_pages_w_icons p ON p.id = page_id "
453 "WHERE page_url_hash = hash(:url) AND page_url = :url "
454 "OR (:hash_idx AND page_url_hash = hash(substr(:url, 0, :hash_idx)) "
455 "AND page_url = substr(:url, 0, :hash_idx)) "
456 "UNION ALL "
457 "SELECT width, icon_url, root, (flags & %d) as isRich "
458 "FROM moz_icons i "
459 "WHERE fixed_icon_url_hash = hash(fixup_url(:hostAndPort) || "
460 "'/favicon.ico') "
461 "ORDER BY %s width DESC, root ASC",
462 nsIFaviconService::ICONDATA_FLAGS_RICH,
463 nsIFaviconService::ICONDATA_FLAGS_RICH,
464 // Prefer non-rich icons for small sizes (<= 64px).
465 aPreferredWidth <= THRESHOLD_WIDTH ? "isRich ASC, " : "");
466
467 nsCOMPtr<mozIStorageStatement> stmt = aDB->GetStatement(query);
468
469 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 469); return NS_ERROR_UNEXPECTED; } } while (false)
;
470 mozStorageStatementScoper scoper(stmt);
471
472 rv = URIBinder::Bind(stmt, "url"_ns, pageSpec);
473 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 473); return rv; } } while (false)
;
474 rv = stmt->BindUTF8StringByName("hostAndPort"_ns, pageHostAndPort);
475 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 475); return rv; } } while (false)
;
476 int32_t hashIdx = PromiseFlatCStringTPromiseFlatString<char>(pageSpec).RFind("#");
477 rv = stmt->BindInt32ByName("hash_idx"_ns, hashIdx + 1);
478 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 478); return rv; } } while (false)
;
479
480 // Return the biggest icon close to the preferred width. It may be bigger
481 // or smaller if the preferred width isn't found.
482 // If the size difference between the bigger icon and preferred width is more
483 // than 4 times greater than the difference between the preferred width and
484 // the smaller icon, we prefer the smaller icon.
485 // Non-rich icons are prioritized over rich ones for preferred widths <=
486 // THRESHOLD_WIDTH. After the inital selection, we check if a suitable SVG
487 // icon exists that could override the initial selection.
488
489 bool hasResult;
490
491 struct IconInfo {
492 int32_t width = 0;
493 int32_t isRich = 0;
494 nsAutoCString spec;
495 bool isSet() { return width > 0; };
496 };
497
498 IconInfo svgIcon;
499 IconInfo lastIcon;
500 IconInfo selectedIcon;
501
502 bool preferNonRichIcons = aPreferredWidth <= THRESHOLD_WIDTH;
503
504 while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep
(&hasResult))), 1)))
&& hasResult) {
505 int32_t width;
506 rv = stmt->GetInt32(0, &width);
Value stored to 'rv' is never read
507 if (lastIcon.width == width) {
508 // If we already found an icon for this width, we always prefer the first
509 // icon found, because it's a non-root icon, per the root ASC ordering.
510 continue;
511 }
512
513 int32_t isRich = stmt->AsInt32(3);
514 int32_t isSVG = (width == UINT16_MAX(65535));
515
516 nsAutoCString iconURL;
517 stmt->GetUTF8String(1, iconURL);
518
519 // If current icon is an SVG, and we haven't yet stored an SVG,
520 // store the SVG when the preferred width is below
521 // threshold, otherwise simply store the first SVG found regardless of
522 // richness.
523 if (isSVG && !svgIcon.isSet()) {
524 if ((preferNonRichIcons && !isRich) || !preferNonRichIcons) {
525 svgIcon = {width, isRich, iconURL};
526 }
527 }
528
529 if (preferNonRichIcons && lastIcon.isSet() && isRich && !lastIcon.isRich) {
530 // If we already found a non-rich icon, we prefer it to rich icons
531 // for small sizes.
532 break;
533 }
534
535 if (!aIconData.spec.IsEmpty() && width < aPreferredWidth) {
536 // We found the best match, or we already found a match so we don't need
537 // to fallback to the root domain icon.
538
539 // If the difference between the preferred size and the previously found
540 // larger icon is more than 4 times the difference between the preferred
541 // size and the smaller icon, choose the smaller icon.
542 if (aPreferredWidth - width < abs(lastIcon.width - aPreferredWidth) / 4) {
543 selectedIcon = {width, isRich};
544 rv = stmt->GetUTF8String(1, aIconData.spec);
545 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 545); return rv; } } while (false)
;
546 }
547 break;
548 }
549
550 lastIcon = {width, isRich};
551
552 selectedIcon = {width, isRich};
553 rv = stmt->GetUTF8String(1, aIconData.spec);
554 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 554); return rv; } } while (false)
;
555 }
556
557 // Check to see if we should overwrite the original icon selection with an
558 // SVG. We prefer the SVG if the selected icon's width differs from the
559 // preferred width. We also prefer the SVG if the selected icon is rich and
560 // the preferred width is below threshold. Note that since we only store
561 // non-rich SVGs for below-threshold requests, rich SVGs are not considered.
562 // For above-threshold requests, any SVG would overwrite the selected icon if
563 // its width differs from the requested size.
564 if (svgIcon.isSet() && !svgIcon.spec.IsEmpty()) {
565 if ((selectedIcon.width != aPreferredWidth) ||
566 (preferNonRichIcons && selectedIcon.isRich)) {
567 aIconData.spec = svgIcon.spec;
568 }
569 }
570
571 // If we reached this stage without finding an icon, we can check if the
572 // requested page spec is a host (no path) and if it contains any subpages
573 // that have an icon associated with them. If they do, we fetch the icon
574 // of the most frecent subpage.
575 if (aIconData.spec.IsEmpty()) {
576 nsAutoCString pageFilePath;
577 rv = aPageURI->GetFilePath(pageFilePath);
578 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 578); return rv; } } while (false)
;
579 if (pageFilePath == "/"_ns) {
580 nsAutoCString pageHost;
581 (void)aPageURI->GetHost(pageHost);
582
583 nsAutoCString pagePrePath;
584 (void)aPageURI->GetPrePath(pagePrePath);
585
586 if (!pageHost.IsEmpty() && !pagePrePath.IsEmpty()) {
587 rv = FetchMostFrecentSubPageIcon(aDB, pagePrePath, pageHost, aIconData);
588 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 588); return rv; } } while (false)
;
589 }
590 }
591 }
592
593 return NS_OK;
594}
595
596} // namespace
597
598////////////////////////////////////////////////////////////////////////////////
599//// AsyncAssociateIconToPage
600
601AsyncAssociateIconToPage::AsyncAssociateIconToPage(
602 const IconData& aIcon, const PageData& aPage,
603 const nsMainThreadPtrHandle<nsIFaviconDataCallback>& aCallback)
604 : Runnable("places::AsyncAssociateIconToPage"),
605 mCallback(aCallback),
606 mIcon(aIcon),
607 mPage(aPage) {
608 // May be created in both threads.
609}
610
611NS_IMETHODIMPnsresult
612AsyncAssociateIconToPage::Run() {
613 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 613); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 613; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
614 MOZ_ASSERT(!mPage.guid.IsEmpty(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mPage.guid.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mPage.guid.IsEmpty()))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("!mPage.guid.IsEmpty()"
" (" "Page info should have been fetched already" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 615); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mPage.guid.IsEmpty()"
") (" "Page info should have been fetched already" ")"); do {
*((volatile int*)__null) = 615; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
615 "Page info should have been fetched already")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mPage.guid.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mPage.guid.IsEmpty()))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("!mPage.guid.IsEmpty()"
" (" "Page info should have been fetched already" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 615); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mPage.guid.IsEmpty()"
") (" "Page info should have been fetched already" ")"); do {
*((volatile int*)__null) = 615; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
616 MOZ_ASSERT(mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty()" " ("
"The page should be addable to history or a bookmark" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 617); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty()"
") (" "The page should be addable to history or a bookmark" ")"
); do { *((volatile int*)__null) = 617; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
617 "The page should be addable to history or a bookmark")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty()" " ("
"The page should be addable to history or a bookmark" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 617); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPage.canAddToHistory || !mPage.bookmarkedSpec.IsEmpty()"
") (" "The page should be addable to history or a bookmark" ")"
); do { *((volatile int*)__null) = 617; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
618
619 bool shouldUpdateIcon = mIcon.status & ICON_STATUS_CHANGED1 << 0;
620 if (!shouldUpdateIcon) {
621 for (const auto& payload : mIcon.payloads) {
622 // If the entry is missing from the database, we should add it.
623 if (payload.id == 0) {
624 shouldUpdateIcon = true;
625 break;
626 }
627 }
628 }
629
630 RefPtr<Database> DB = Database::GetDatabase();
631 NS_ENSURE_STATE(DB)do { if ((__builtin_expect(!!(!(DB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "DB" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 631); return NS_ERROR_UNEXPECTED; } } while (false)
;
632
633 mozStorageTransaction transaction(
634 DB->MainConn(), false, mozIStorageConnection::TRANSACTION_IMMEDIATE);
635
636 // XXX Handle the error, bug 1696133.
637 Unused << NS_WARN_IF(NS_FAILED(transaction.Start()))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(transaction
.Start())), 0))), "NS_FAILED(transaction.Start())", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 637)
;
638
639 nsresult rv;
640 if (shouldUpdateIcon) {
641 rv = SetIconInfo(DB, mIcon);
642 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
643 (void)transaction.Commit();
644 return rv;
645 }
646
647 mIcon.status = (mIcon.status & ~(ICON_STATUS_CACHED1 << 3)) | ICON_STATUS_SAVED1 << 1;
648 }
649
650 // If the page does not have an id, don't try to insert a new one, cause we
651 // don't know where the page comes from. Not doing so we may end adding
652 // a page that otherwise we'd explicitly ignore, like a POST or an error page.
653 if (mPage.placeId == 0) {
654 rv = transaction.Commit();
655 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 655); return rv; } } while (false)
;
656 return NS_OK;
657 }
658
659 // Expire old favicons to keep up with website changes. Associated icons must
660 // be expired also when storing a root favicon, because a page may change to
661 // only have a root favicon.
662 // Note that here we could also be in the process of adding further payloads
663 // to a page, and we don't want to expire just added payloads. For this
664 // reason we only remove expired payloads.
665 // Oprhan icons are not removed at this time because it'd be expensive. The
666 // privacy implications are limited, since history removal methods also expire
667 // orphan icons.
668 if (mPage.id > 0) {
669 nsCOMPtr<mozIStorageStatement> stmt;
670 stmt = DB->GetStatement(
671 "DELETE FROM moz_icons_to_pages "
672 "WHERE page_id = :page_id "
673 "AND expire_ms < strftime('%s','now','localtime','utc') * 1000 ");
674 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 674); return NS_ERROR_UNEXPECTED; } } while (false)
;
675 mozStorageStatementScoper scoper(stmt);
676 rv = stmt->BindInt64ByName("page_id"_ns, mPage.id);
677 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 677); return rv; } } while (false)
;
678 rv = stmt->Execute();
679 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 679); return rv; } } while (false)
;
680 }
681
682 // Don't associate pages to root domain icons, since those will be returned
683 // regardless. This saves a lot of work and database space since we don't
684 // need to store urls and relations.
685 // Though, this is possible only if both the page and the icon have the same
686 // host, otherwise we couldn't relate them.
687 if (!mIcon.rootIcon || !mIcon.host.Equals(mPage.host)) {
688 // The page may have associated payloads already, and those could have to be
689 // expired. For example at a certain point a page could decide to stop
690 // serving its usual 16px and 32px pngs, and use an svg instead. On the
691 // other side, we could also be in the process of adding more payloads to
692 // this page, and we should not expire the payloads we just added. For this,
693 // we use the expiration field as an indicator and remove relations based on
694 // it being elapsed. We don't remove orphan icons at this time since it
695 // would have a cost. The privacy hit is limited since history removal
696 // methods already expire orphan icons.
697 if (mPage.id == 0) {
698 // We need to create the page entry.
699 nsCOMPtr<mozIStorageStatement> stmt;
700 stmt = DB->GetStatement(
701 "INSERT OR IGNORE INTO moz_pages_w_icons (page_url, page_url_hash) "
702 "VALUES (:page_url, hash(:page_url)) ");
703 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 703); return NS_ERROR_UNEXPECTED; } } while (false)
;
704 mozStorageStatementScoper scoper(stmt);
705 rv = URIBinder::Bind(stmt, "page_url"_ns, mPage.spec);
706 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 706); return rv; } } while (false)
;
707 rv = stmt->Execute();
708 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 708); return rv; } } while (false)
;
709 }
710
711 // Then we can create the relations.
712 nsCOMPtr<mozIStorageStatement> stmt;
713 stmt = DB->GetStatement(
714 "INSERT INTO moz_icons_to_pages (page_id, icon_id, expire_ms) "
715 "VALUES ((SELECT id from moz_pages_w_icons WHERE page_url_hash = "
716 "hash(:page_url) AND page_url = :page_url), "
717 ":icon_id, :expire) "
718 "ON CONFLICT(page_id, icon_id) DO "
719 "UPDATE SET expire_ms = :expire ");
720 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 720); return NS_ERROR_UNEXPECTED; } } while (false)
;
721
722 // For some reason using BindingParamsArray here fails execution, so we must
723 // execute the statements one by one.
724 // In the future we may want to investigate the reasons, sounds like related
725 // to contraints.
726 for (const auto& payload : mIcon.payloads) {
727 mozStorageStatementScoper scoper(stmt);
728 nsCOMPtr<mozIStorageBindingParams> params;
729 rv = URIBinder::Bind(stmt, "page_url"_ns, mPage.spec);
730 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 730); return rv; } } while (false)
;
731 rv = stmt->BindInt64ByName("icon_id"_ns, payload.id);
732 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 732); return rv; } } while (false)
;
733 rv = stmt->BindInt64ByName("expire"_ns, mIcon.expiration / 1000);
734 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 734); return rv; } } while (false)
;
735 rv = stmt->Execute();
736 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 736); return rv; } } while (false)
;
737 }
738 }
739
740 mIcon.status |= ICON_STATUS_ASSOCIATED1 << 2;
741
742 rv = transaction.Commit();
743 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 743); return rv; } } while (false)
;
744
745 // Finally, dispatch an event to the main thread to notify observers.
746 nsCOMPtr<nsIRunnable> event =
747 new NotifyIconObservers(mIcon, mPage, mCallback);
748 rv = NS_DispatchToMainThread(event);
749 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 749); return rv; } } while (false)
;
750
751 // If there is a bookmarked page that redirects to this one, try to update its
752 // icon as well.
753 if (!mPage.bookmarkedSpec.IsEmpty() &&
754 !mPage.bookmarkedSpec.Equals(mPage.spec)) {
755 // Create a new page struct to avoid polluting it with old data.
756 PageData bookmarkedPage;
757 bookmarkedPage.spec = mPage.bookmarkedSpec;
758 RefPtr<Database> DB = Database::GetDatabase();
759 if (DB && NS_SUCCEEDED(FetchPageInfo(DB, bookmarkedPage))((bool)(__builtin_expect(!!(!NS_FAILED_impl(FetchPageInfo(DB,
bookmarkedPage))), 1)))
) {
760 // This will be silent, so be sure to not pass in the current callback.
761 nsMainThreadPtrHandle<nsIFaviconDataCallback> nullCallback;
762 RefPtr<AsyncAssociateIconToPage> event =
763 new AsyncAssociateIconToPage(mIcon, bookmarkedPage, nullCallback);
764 Unused << event->Run();
765 }
766 }
767
768 return NS_OK;
769}
770
771////////////////////////////////////////////////////////////////////////////////
772//// AsyncSetIconForPage
773
774AsyncSetIconForPage::AsyncSetIconForPage(const IconData& aIcon,
775 const PageData& aPage,
776 dom::Promise* aPromise)
777 : Runnable("places::AsyncSetIconForPage"),
778 mPromise(new nsMainThreadPtrHolder<dom::Promise>(
779 "AsyncSetIconForPage::Promise", aPromise, false)),
780 mIcon(aIcon),
781 mPage(aPage) {}
782
783NS_IMETHODIMPnsresult
784AsyncSetIconForPage::Run() {
785 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 785); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 785; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
786 MOZ_ASSERT(mIcon.payloads.Length(), "The icon should have valid data")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIcon.payloads.Length())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIcon.payloads.Length()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("mIcon.payloads.Length()"
" (" "The icon should have valid data" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 786); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIcon.payloads.Length()"
") (" "The icon should have valid data" ")"); do { *((volatile
int*)__null) = 786; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
787 MOZ_ASSERT(mPage.spec.Length(), "The page should have spec")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPage.spec.Length())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPage.spec.Length()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("mPage.spec.Length()"
" (" "The page should have spec" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 787); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPage.spec.Length()"
") (" "The page should have spec" ")"); do { *((volatile int
*)__null) = 787; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
788 MOZ_ASSERT(mPage.guid.IsEmpty(), "The page should not have guid")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPage.guid.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPage.guid.IsEmpty()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("mPage.guid.IsEmpty()"
" (" "The page should not have guid" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 788); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPage.guid.IsEmpty()"
") (" "The page should not have guid" ")"); do { *((volatile
int*)__null) = 788; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
789
790 nsresult rv = NS_OK;
791 auto guard = MakeScopeExit([&]() {
792 NS_DispatchToMainThread(NS_NewRunnableFunction(
793 "AsyncSetIconForPage::Promise", [rv, promise = std::move(mPromise)]() {
794 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
795 promise->MaybeResolveWithUndefined();
796 } else {
797 promise->MaybeReject(rv);
798 }
799 }));
800 });
801
802 // Fetch the page data.
803 RefPtr<Database> DB = Database::GetDatabase();
804 if (MOZ_UNLIKELY(!DB)(__builtin_expect(!!(!DB), 0))) {
805 return (rv = NS_ERROR_UNEXPECTED);
806 }
807 rv = FetchPageInfo(DB, mPage);
808 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 808); return rv; } } while (false)
;
809
810 nsMainThreadPtrHandle<nsIFaviconDataCallback> nullCallback;
811 AsyncAssociateIconToPage event(mIcon, mPage, nullCallback);
812 return (rv = event.Run());
813}
814
815////////////////////////////////////////////////////////////////////////////////
816//// AsyncGetFaviconURLForPage
817
818AsyncGetFaviconURLForPage::AsyncGetFaviconURLForPage(
819 const nsCOMPtr<nsIURI>& aPageURI, uint16_t aPreferredWidth,
820 nsIFaviconDataCallback* aCallback)
821 : Runnable("places::AsyncGetFaviconURLForPage"),
822 mPreferredWidth(aPreferredWidth == 0 ? UINT16_MAX(65535) : aPreferredWidth),
823 mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(
824 "AsyncGetFaviconURLForPage::mCallback", aCallback)),
825 mPageURI(aPageURI) {
826 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 826); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 826; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
827}
828
829NS_IMETHODIMPnsresult
830AsyncGetFaviconURLForPage::Run() {
831 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 831); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 831; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
832
833 RefPtr<Database> DB = Database::GetDatabase();
834 NS_ENSURE_STATE(DB)do { if ((__builtin_expect(!!(!(DB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "DB" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 834); return NS_ERROR_UNEXPECTED; } } while (false)
;
835 IconData iconData;
836 nsresult rv = FetchIconPerSpec(DB, mPageURI, iconData, mPreferredWidth);
837 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 837); return rv; } } while (false)
;
838
839 // Now notify our callback of the icon spec we retrieved, even if empty.
840 PageData pageData;
841 mPageURI->GetSpec(pageData.spec);
842
843 nsCOMPtr<nsIRunnable> event =
844 new NotifyIconObservers(iconData, pageData, mCallback);
845 rv = NS_DispatchToMainThread(event);
846 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 846); return rv; } } while (false)
;
847
848 return NS_OK;
849}
850
851////////////////////////////////////////////////////////////////////////////////
852//// AsyncGetFaviconDataForPage
853
854AsyncGetFaviconDataForPage::AsyncGetFaviconDataForPage(
855 const nsCOMPtr<nsIURI>& aPageURI, uint16_t aPreferredWidth,
856 nsIFaviconDataCallback* aCallback)
857 : Runnable("places::AsyncGetFaviconDataForPage"),
858 mPreferredWidth(aPreferredWidth == 0 ? UINT16_MAX(65535) : aPreferredWidth),
859 mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(
860 "AsyncGetFaviconDataForPage::mCallback", aCallback)),
861 mPageURI(aPageURI) {
862 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 862); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 862; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
863}
864
865NS_IMETHODIMPnsresult
866AsyncGetFaviconDataForPage::Run() {
867 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 867); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 867; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
868
869 RefPtr<Database> DB = Database::GetDatabase();
870 NS_ENSURE_STATE(DB)do { if ((__builtin_expect(!!(!(DB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "DB" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 870); return NS_ERROR_UNEXPECTED; } } while (false)
;
871 IconData iconData;
872 nsresult rv = FetchIconPerSpec(DB, mPageURI, iconData, mPreferredWidth);
873 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 873); return rv; } } while (false)
;
874
875 if (!iconData.spec.IsEmpty()) {
876 rv = FetchIconInfo(DB, mPreferredWidth, iconData);
877 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
878 iconData.spec.Truncate();
879 }
880 }
881
882 PageData pageData;
883 mPageURI->GetSpec(pageData.spec);
884
885 nsCOMPtr<nsIRunnable> event =
886 new NotifyIconObservers(iconData, pageData, mCallback);
887 rv = NS_DispatchToMainThread(event);
888 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 888); return rv; } } while (false)
;
889 return NS_OK;
890}
891
892////////////////////////////////////////////////////////////////////////////////
893//// NotifyIconObservers
894
895NotifyIconObservers::NotifyIconObservers(
896 const IconData& aIcon, const PageData& aPage,
897 const nsMainThreadPtrHandle<nsIFaviconDataCallback>& aCallback)
898 : Runnable("places::NotifyIconObservers"),
899 mCallback(aCallback),
900 mIcon(aIcon),
901 mPage(aPage) {}
902
903// MOZ_CAN_RUN_SCRIPT_BOUNDARY until Runnable::Run is marked
904// MOZ_CAN_RUN_SCRIPT. See bug 1535398.
905MOZ_CAN_RUN_SCRIPT_BOUNDARY
906NS_IMETHODIMPnsresult
907NotifyIconObservers::Run() {
908 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 908); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 908; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
909
910 nsCOMPtr<nsIURI> iconURI;
911 if (!mIcon.spec.IsEmpty()) {
912 if (!NS_WARN_IF(NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(NS_NewURI
(getter_AddRefs(iconURI), mIcon.spec))), 0))), "NS_FAILED(NS_NewURI(getter_AddRefs(iconURI), mIcon.spec))"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 913)
913 NS_FAILED(NS_NewURI(getter_AddRefs(iconURI), mIcon.spec)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(NS_NewURI
(getter_AddRefs(iconURI), mIcon.spec))), 0))), "NS_FAILED(NS_NewURI(getter_AddRefs(iconURI), mIcon.spec))"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 913)
) {
914 // Notify observers only if something changed.
915 if (mIcon.status & ICON_STATUS_SAVED1 << 1 ||
916 mIcon.status & ICON_STATUS_ASSOCIATED1 << 2) {
917 nsCOMPtr<nsIURI> pageURI;
918 if (!NS_WARN_IF(NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(NS_NewURI
(getter_AddRefs(pageURI), mPage.spec))), 0))), "NS_FAILED(NS_NewURI(getter_AddRefs(pageURI), mPage.spec))"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 919)
919 NS_FAILED(NS_NewURI(getter_AddRefs(pageURI), mPage.spec)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(NS_NewURI
(getter_AddRefs(pageURI), mPage.spec))), 0))), "NS_FAILED(NS_NewURI(getter_AddRefs(pageURI), mPage.spec))"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 919)
) {
920 // Invalide page-icon image cache, since the icon is about to change.
921 nsFaviconService* favicons = nsFaviconService::GetFaviconService();
922 MOZ_ASSERT(favicons)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(favicons)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(favicons))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("favicons", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 922); AnnotateMozCrashReason("MOZ_ASSERT" "(" "favicons" ")"
); do { *((volatile int*)__null) = 922; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
923 if (favicons) {
924 nsCString pageIconSpec("page-icon:");
925 pageIconSpec.Append(mPage.spec);
926 nsCOMPtr<nsIURI> pageIconURI;
927 if (NS_SUCCEEDED(((bool)(__builtin_expect(!!(!NS_FAILED_impl(NS_NewURI(getter_AddRefs
(pageIconURI), pageIconSpec))), 1)))
928 NS_NewURI(getter_AddRefs(pageIconURI), pageIconSpec))((bool)(__builtin_expect(!!(!NS_FAILED_impl(NS_NewURI(getter_AddRefs
(pageIconURI), pageIconSpec))), 1)))
) {
929 favicons->ClearImageCache(pageIconURI);
930 }
931 }
932
933 // Notify about the favicon change.
934 dom::Sequence<OwningNonNull<dom::PlacesEvent>> events;
935 RefPtr<dom::PlacesFavicon> faviconEvent = new dom::PlacesFavicon();
936 AppendUTF8toUTF16(mPage.spec, faviconEvent->mUrl);
937 AppendUTF8toUTF16(mIcon.spec, faviconEvent->mFaviconUrl);
938 faviconEvent->mPageGuid.Assign(mPage.guid);
939 bool success =
940 !!events.AppendElement(faviconEvent.forget(), fallible);
941 MOZ_RELEASE_ASSERT(success)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(success)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(success))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("success", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 941); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "success"
")"); do { *((volatile int*)__null) = 941; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
942 dom::PlacesObservers::NotifyListeners(events);
943 }
944 }
945 }
946 }
947
948 if (!mCallback) {
949 return NS_OK;
950 }
951
952 if (mIcon.payloads.Length() > 0) {
953 IconPayload& payload = mIcon.payloads[0];
954 return mCallback->OnComplete(iconURI, payload.data.Length(),
955 TO_INTBUFFER(payload.data)reinterpret_cast<uint8_t*>(const_cast<char*>(payload
.data.get()))
, payload.mimeType,
956 payload.width);
957 }
958 return mCallback->OnComplete(iconURI, 0, TO_INTBUFFER(EmptyCString())reinterpret_cast<uint8_t*>(const_cast<char*>(EmptyCString
().get()))
, ""_ns,
959 0);
960}
961
962////////////////////////////////////////////////////////////////////////////////
963//// AsyncCopyFavicons
964
965AsyncCopyFavicons::AsyncCopyFavicons(PageData& aFromPage, PageData& aToPage,
966 nsIFaviconDataCallback* aCallback)
967 : Runnable("places::AsyncCopyFavicons"),
968 mFromPage(aFromPage),
969 mToPage(aToPage),
970 mCallback(new nsMainThreadPtrHolder<nsIFaviconDataCallback>(
971 "AsyncCopyFavicons::mCallback", aCallback)) {
972 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 972); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 972; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
973}
974
975NS_IMETHODIMPnsresult
976AsyncCopyFavicons::Run() {
977 MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 977); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 977; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
978
979 IconData icon;
980
981 // Ensure we'll callback and dispatch notifications to the main-thread.
982 auto cleanup = MakeScopeExit([&]() {
983 // If we bailed out early, just return a null icon uri, since we didn't
984 // copy anything.
985 if (!(icon.status & ICON_STATUS_ASSOCIATED1 << 2)) {
986 icon.spec.Truncate();
987 }
988 nsCOMPtr<nsIRunnable> event =
989 new NotifyIconObservers(icon, mToPage, mCallback);
990 NS_DispatchToMainThread(event);
991 });
992
993 RefPtr<Database> DB = Database::GetDatabase();
994 NS_ENSURE_STATE(DB)do { if ((__builtin_expect(!!(!(DB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "DB" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 994); return NS_ERROR_UNEXPECTED; } } while (false)
;
995
996 nsresult rv = FetchPageInfo(DB, mToPage);
997 if (rv == NS_ERROR_NOT_AVAILABLE || !mToPage.placeId) {
998 // We have never seen this page, or we can't add this page to history and
999 // and it's not a bookmark. We won't add the page.
1000 return NS_OK;
1001 }
1002 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1002); return rv; } } while (false)
;
1003
1004 nsCOMPtr<nsIURI> pageURI;
1005 rv = NS_NewURI(getter_AddRefs(pageURI), mFromPage.spec);
1006 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1006); return rv; } } while (false)
;
1007
1008 // Get just one icon, to check whether the page has any, and to notify
1009 // later.
1010 rv = FetchIconPerSpec(DB, pageURI, icon, UINT16_MAX(65535));
1011 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1011); return rv; } } while (false)
;
1012
1013 if (icon.spec.IsEmpty()) {
1014 // There's nothing to copy.
1015 return NS_OK;
1016 }
1017
1018 // Insert an entry in moz_pages_w_icons if needed.
1019 if (!mToPage.id) {
1020 // We need to create the page entry.
1021 nsCOMPtr<mozIStorageStatement> stmt;
1022 stmt = DB->GetStatement(
1023 "INSERT OR IGNORE INTO moz_pages_w_icons (page_url, page_url_hash) "
1024 "VALUES (:page_url, hash(:page_url)) ");
1025 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1025); return NS_ERROR_UNEXPECTED; } } while (false)
;
1026 mozStorageStatementScoper scoper(stmt);
1027 rv = URIBinder::Bind(stmt, "page_url"_ns, mToPage.spec);
1028 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1028); return rv; } } while (false)
;
1029 rv = stmt->Execute();
1030 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1030); return rv; } } while (false)
;
1031 // Required to to fetch the id and the guid.
1032 rv = FetchPageInfo(DB, mToPage);
1033 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1033); return rv; } } while (false)
;
1034 }
1035
1036 // Create the relations.
1037 nsCOMPtr<mozIStorageStatement> stmt = DB->GetStatement(
1038 "INSERT OR IGNORE INTO moz_icons_to_pages (page_id, icon_id, expire_ms) "
1039 "SELECT :id, icon_id, expire_ms "
1040 "FROM moz_icons_to_pages "
1041 "WHERE page_id = (SELECT id FROM moz_pages_w_icons WHERE page_url_hash = "
1042 "hash(:url) AND page_url = :url) ");
1043 NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1043); return NS_ERROR_UNEXPECTED; } } while (false)
;
1044 mozStorageStatementScoper scoper(stmt);
1045 rv = stmt->BindInt64ByName("id"_ns, mToPage.id);
1046 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1046); return rv; } } while (false)
;
1047 rv = URIBinder::Bind(stmt, "url"_ns, mFromPage.spec);
1048 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1048); return rv; } } while (false)
;
1049 rv = stmt->Execute();
1050 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/places/FaviconHelpers.cpp"
, 1050); return rv; } } while (false)
;
1051
1052 // Setting this will make us send pageChanged notifications.
1053 // The scope exit will take care of the callback and notifications.
1054 icon.status |= ICON_STATUS_ASSOCIATED1 << 2;
1055
1056 return NS_OK;
1057}
1058
1059} // namespace places
1060} // namespace mozilla