diff options
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/src/history.c b/src/history.c index 7185912f..56454009 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -37,7 +37,7 @@ void init_RecentUrl(iRecentUrl *d) { | |||
37 | d->normScrollY = 0; | 37 | d->normScrollY = 0; |
38 | d->cachedResponse = NULL; | 38 | d->cachedResponse = NULL; |
39 | d->cachedDoc = NULL; | 39 | d->cachedDoc = NULL; |
40 | d->flags.openedFromSidebar = iFalse; | 40 | d->flags = 0; |
41 | } | 41 | } |
42 | 42 | ||
43 | void deinit_RecentUrl(iRecentUrl *d) { | 43 | void deinit_RecentUrl(iRecentUrl *d) { |
@@ -110,6 +110,14 @@ iHistory *copy_History(const iHistory *d) { | |||
110 | return copy; | 110 | return copy; |
111 | } | 111 | } |
112 | 112 | ||
113 | void lock_History(iHistory *d) { | ||
114 | lock_Mutex(d->mtx); | ||
115 | } | ||
116 | |||
117 | void unlock_History(iHistory *d) { | ||
118 | unlock_Mutex(d->mtx); | ||
119 | } | ||
120 | |||
113 | iMemInfo memoryUsage_History(const iHistory *d) { | 121 | iMemInfo memoryUsage_History(const iHistory *d) { |
114 | iMemInfo mem = { 0, 0 }; | 122 | iMemInfo mem = { 0, 0 }; |
115 | iConstForEach(Array, i, &d->recent) { | 123 | iConstForEach(Array, i, &d->recent) { |
@@ -173,7 +181,7 @@ void serialize_History(const iHistory *d, iStream *outs) { | |||
173 | const iRecentUrl *item = i.value; | 181 | const iRecentUrl *item = i.value; |
174 | serialize_String(&item->url, outs); | 182 | serialize_String(&item->url, outs); |
175 | write32_Stream(outs, item->normScrollY * 1.0e6f); | 183 | write32_Stream(outs, item->normScrollY * 1.0e6f); |
176 | writeU16_Stream(outs, item->flags.openedFromSidebar ? iBit(1) : 0); | 184 | writeU16_Stream(outs, item->flags); |
177 | if (item->cachedResponse) { | 185 | if (item->cachedResponse) { |
178 | write8_Stream(outs, 1); | 186 | write8_Stream(outs, 1); |
179 | serialize_GmResponse(item->cachedResponse, outs); | 187 | serialize_GmResponse(item->cachedResponse, outs); |
@@ -197,10 +205,7 @@ void deserialize_History(iHistory *d, iStream *ins) { | |||
197 | set_String(&item.url, canonicalUrl_String(&item.url)); | 205 | set_String(&item.url, canonicalUrl_String(&item.url)); |
198 | item.normScrollY = (float) read32_Stream(ins) / 1.0e6f; | 206 | item.normScrollY = (float) read32_Stream(ins) / 1.0e6f; |
199 | if (version_Stream(ins) >= addedRecentUrlFlags_FileVersion) { | 207 | if (version_Stream(ins) >= addedRecentUrlFlags_FileVersion) { |
200 | uint16_t flags = readU16_Stream(ins); | 208 | item.flags = readU16_Stream(ins); |
201 | if (flags & iBit(1)) { | ||
202 | item.flags.openedFromSidebar = iTrue; | ||
203 | } | ||
204 | } | 209 | } |
205 | if (read8_Stream(ins)) { | 210 | if (read8_Stream(ins)) { |
206 | item.cachedResponse = new_GmResponse(); | 211 | item.cachedResponse = new_GmResponse(); |
@@ -246,18 +251,26 @@ const iString *url_History(const iHistory *d, size_t pos) { | |||
246 | return collectNew_String(); | 251 | return collectNew_String(); |
247 | } | 252 | } |
248 | 253 | ||
249 | iRecentUrl *findUrl_History(iHistory *d, const iString *url) { | 254 | #if 0 |
255 | iRecentUrl *findUrl_History(iHistory *d, const iString *url, int timeDir) { | ||
250 | url = canonicalUrl_String(url); | 256 | url = canonicalUrl_String(url); |
257 | // if (!timeDir) { | ||
258 | // timeDir = -1; | ||
259 | // } | ||
251 | lock_Mutex(d->mtx); | 260 | lock_Mutex(d->mtx); |
252 | iReverseForEach(Array, i, &d->recent) { | 261 | for (size_t i = size_Array(&d->recent) - 1 - d->recentPos; i < size_Array(&d->recent); |
253 | if (cmpStringCase_String(url, &((iRecentUrl *) i.value)->url) == 0) { | 262 | i += timeDir) { |
263 | iRecentUrl *item = at_Array(&d->recent, i); | ||
264 | if (cmpStringCase_String(url, &item->url) == 0) { | ||
254 | unlock_Mutex(d->mtx); | 265 | unlock_Mutex(d->mtx); |
255 | return i.value; | 266 | return item; /* FIXME: Returning an internal pointer; should remain locked. */ |
256 | } | 267 | } |
268 | if (!timeDir) break; | ||
257 | } | 269 | } |
258 | unlock_Mutex(d->mtx); | 270 | unlock_Mutex(d->mtx); |
259 | return NULL; | 271 | return NULL; |
260 | } | 272 | } |
273 | #endif | ||
261 | 274 | ||
262 | void replace_History(iHistory *d, const iString *url) { | 275 | void replace_History(iHistory *d, const iString *url) { |
263 | url = canonicalUrl_String(url); | 276 | url = canonicalUrl_String(url); |
@@ -297,20 +310,31 @@ void add_History(iHistory *d, const iString *url) { | |||
297 | unlock_Mutex(d->mtx); | 310 | unlock_Mutex(d->mtx); |
298 | } | 311 | } |
299 | 312 | ||
300 | iBool preceding_History(iHistory *d, iRecentUrl *recent_out) { | 313 | void undo_History(iHistory *d) { |
301 | iBool ok = iFalse; | ||
302 | lock_Mutex(d->mtx); | 314 | lock_Mutex(d->mtx); |
303 | if (!isEmpty_Array(&d->recent) && d->recentPos < size_Array(&d->recent) - 1) { | 315 | if (!isEmpty_Array(&d->recent) || d->recentPos != 0) { |
304 | const iRecentUrl *recent = constAt_Array(&d->recent, size_Array(&d->recent) - 1 - | 316 | deinit_RecentUrl(back_Array(&d->recent)); |
305 | (d->recentPos + 1)); | 317 | popBack_Array(&d->recent); |
306 | set_String(&recent_out->url, &recent->url); | 318 | } |
307 | recent_out->normScrollY = recent->normScrollY; | 319 | unlock_Mutex(d->mtx); |
308 | iChangeRef(recent_out->cachedDoc, recent->cachedDoc); | 320 | } |
321 | |||
322 | iRecentUrl *precedingLocked_History(iHistory *d) { | ||
323 | /* NOTE: Manual lock and unlock are required when using this; returning an internal pointer. */ | ||
324 | iBool ok = iFalse; | ||
325 | //lock_Mutex(d->mtx); | ||
326 | const size_t lastIndex = size_Array(&d->recent) - 1; | ||
327 | if (!isEmpty_Array(&d->recent) && d->recentPos < lastIndex) { | ||
328 | return at_Array(&d->recent, lastIndex - (d->recentPos + 1)); | ||
329 | // set_String(&recent_out->url, &recent->url); | ||
330 | // recent_out->normScrollY = recent->normScrollY; | ||
331 | // iChangeRef(recent_out->cachedDoc, recent->cachedDoc); | ||
309 | /* Cached response is not returned, would involve a deep copy. */ | 332 | /* Cached response is not returned, would involve a deep copy. */ |
310 | ok = iTrue; | 333 | // ok = iTrue; |
311 | } | 334 | } |
312 | unlock_Mutex(d->mtx); | 335 | //unlock_Mutex(d->mtx); |
313 | return ok; | 336 | // return ok; |
337 | return NULL; | ||
314 | } | 338 | } |
315 | 339 | ||
316 | #if 0 | 340 | #if 0 |
@@ -360,7 +384,7 @@ iBool goForward_History(iHistory *d) { | |||
360 | return iFalse; | 384 | return iFalse; |
361 | } | 385 | } |
362 | 386 | ||
363 | iBool atLatest_History(const iHistory *d) { | 387 | iBool atNewest_History(const iHistory *d) { |
364 | iBool isLatest; | 388 | iBool isLatest; |
365 | iGuardMutex(d->mtx, isLatest = (d->recentPos == 0)); | 389 | iGuardMutex(d->mtx, isLatest = (d->recentPos == 0)); |
366 | return isLatest; | 390 | return isLatest; |
@@ -391,12 +415,18 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) { | |||
391 | unlock_Mutex(d->mtx); | 415 | unlock_Mutex(d->mtx); |
392 | } | 416 | } |
393 | 417 | ||
394 | void setCachedDocument_History(iHistory *d, iGmDocument *doc, iBool openedFromSidebar) { | 418 | void setCachedDocument_History(iHistory *d, iGmDocument *doc) { |
395 | lock_Mutex(d->mtx); | 419 | lock_Mutex(d->mtx); |
396 | iRecentUrl *item = mostRecentUrl_History(d); | 420 | iRecentUrl *item = mostRecentUrl_History(d); |
421 | iAssert(size_GmDocument(doc).x > 0); | ||
397 | if (item) { | 422 | if (item) { |
398 | iAssert(equal_String(url_GmDocument(doc), &item->url)); | 423 | #if !defined (NDEBUG) |
399 | item->flags.openedFromSidebar = openedFromSidebar; | 424 | if (!equal_String(url_GmDocument(doc), &item->url)) { |
425 | printf("[History] Cache mismatch! Expecting data for item {%s} but document URL is {%s}\n", | ||
426 | cstr_String(&item->url), | ||
427 | cstr_String(url_GmDocument(doc))); | ||
428 | } | ||
429 | #endif | ||
400 | if (item->cachedDoc != doc) { | 430 | if (item->cachedDoc != doc) { |
401 | iRelease(item->cachedDoc); | 431 | iRelease(item->cachedDoc); |
402 | item->cachedDoc = ref_Object(doc); | 432 | item->cachedDoc = ref_Object(doc); |