Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2949023002: [WIP] Fix history.replaceState() not propagating back favicons (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 // If the user is adding older history, we need to make sure our times 466 // If the user is adding older history, we need to make sure our times
467 // are correct. 467 // are correct.
468 if (request.time < first_recorded_time_) 468 if (request.time < first_recorded_time_)
469 first_recorded_time_ = request.time; 469 first_recorded_time_ = request.time;
470 470
471 ui::PageTransition request_transition = request.transition; 471 ui::PageTransition request_transition = request.transition;
472 bool is_keyword_generated = ui::PageTransitionCoreTypeIs( 472 bool is_keyword_generated = ui::PageTransitionCoreTypeIs(
473 request_transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED); 473 request_transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED);
474 474
475 RedirectList redirects = request.redirects;
sky 2017/06/22 15:26:39 This is worth a comment. Also, avoid the potential
476 if (request.replaced_entry_url.has_value()) {
477 RedirectList prior_redirects;
478 GetCachedRecentRedirects(*request.replaced_entry_url, &prior_redirects);
479 prior_redirects.insert(prior_redirects.end(), redirects.begin(),
480 redirects.end());
481 redirects = std::move(prior_redirects);
482 }
483
475 // If the user is navigating to a not-previously-typed intranet hostname, 484 // If the user is navigating to a not-previously-typed intranet hostname,
476 // change the transition to TYPED so that the omnibox will learn that this is 485 // change the transition to TYPED so that the omnibox will learn that this is
477 // a known host. 486 // a known host.
478 bool has_redirects = request.redirects.size() > 1; 487 bool has_redirects = redirects.size() > 1;
479 if (ui::PageTransitionIsMainFrame(request_transition) && 488 if (ui::PageTransitionIsMainFrame(request_transition) &&
480 !ui::PageTransitionCoreTypeIs(request_transition, 489 !ui::PageTransitionCoreTypeIs(request_transition,
481 ui::PAGE_TRANSITION_TYPED) && 490 ui::PAGE_TRANSITION_TYPED) &&
482 !is_keyword_generated) { 491 !is_keyword_generated) {
483 // Check both the start and end of a redirect chain, since the user will 492 // Check both the start and end of a redirect chain, since the user will
484 // consider both to have been "navigated to". 493 // consider both to have been "navigated to".
485 if (IsUntypedIntranetHost(request.url) || 494 if (IsUntypedIntranetHost(request.url) ||
486 (has_redirects && IsUntypedIntranetHost(request.redirects[0]))) { 495 (has_redirects && IsUntypedIntranetHost(redirects[0]))) {
487 request_transition = ui::PageTransitionFromInt( 496 request_transition = ui::PageTransitionFromInt(
488 ui::PAGE_TRANSITION_TYPED | 497 ui::PAGE_TRANSITION_TYPED |
489 ui::PageTransitionGetQualifier(request_transition)); 498 ui::PageTransitionGetQualifier(request_transition));
490 } 499 }
491 } 500 }
492 501
493 if (!has_redirects) { 502 if (!has_redirects) {
494 // The single entry is both a chain start and end. 503 // The single entry is both a chain start and end.
495 ui::PageTransition t = ui::PageTransitionFromInt( 504 ui::PageTransition t = ui::PageTransitionFromInt(
496 request_transition | ui::PAGE_TRANSITION_CHAIN_START | 505 request_transition | ui::PAGE_TRANSITION_CHAIN_START |
(...skipping 11 matching lines...) Expand all
508 request.time); 517 request.time);
509 518
510 // Update the referrer's duration. 519 // Update the referrer's duration.
511 UpdateVisitDuration(from_visit_id, request.time); 520 UpdateVisitDuration(from_visit_id, request.time);
512 } 521 }
513 } else { 522 } else {
514 // Redirect case. Add the redirect chain. 523 // Redirect case. Add the redirect chain.
515 524
516 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START; 525 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START;
517 526
518 RedirectList redirects = request.redirects;
519 if (redirects[0].SchemeIs(url::kAboutScheme)) { 527 if (redirects[0].SchemeIs(url::kAboutScheme)) {
520 // When the redirect source + referrer is "about" we skip it. This 528 // When the redirect source + referrer is "about" we skip it. This
521 // happens when a page opens a new frame/window to about:blank and then 529 // happens when a page opens a new frame/window to about:blank and then
522 // script sets the URL to somewhere else (used to hide the referrer). It 530 // script sets the URL to somewhere else (used to hide the referrer). It
523 // would be nice to keep all these redirects properly but we don't ever 531 // would be nice to keep all these redirects properly but we don't ever
524 // see the initial about:blank load, so we don't know where the 532 // see the initial about:blank load, so we don't know where the
525 // subsequent client redirect came from. 533 // subsequent client redirect came from.
526 // 534 //
527 // In this case, we just don't bother hooking up the source of the 535 // In this case, we just don't bother hooking up the source of the
528 // redirects, so we remove it. 536 // redirects, so we remove it.
(...skipping 11 matching lines...) Expand all
540 // chain. 548 // chain.
541 if (request.referrer.is_valid()) { 549 if (request.referrer.is_valid()) {
542 DCHECK_EQ(request.referrer, redirects[0]); 550 DCHECK_EQ(request.referrer, redirects[0]);
543 redirects.erase(redirects.begin()); 551 redirects.erase(redirects.begin());
544 552
545 // If the navigation entry for this visit has replaced that for the 553 // If the navigation entry for this visit has replaced that for the
546 // first visit, remove the CHAIN_END marker from the first visit. This 554 // first visit, remove the CHAIN_END marker from the first visit. This
547 // can be called a lot, for example, the page cycler, and most of the 555 // can be called a lot, for example, the page cycler, and most of the
548 // time we won't have changed anything. 556 // time we won't have changed anything.
549 VisitRow visit_row; 557 VisitRow visit_row;
550 if (request.did_replace_entry && 558 if (request.replaced_entry_url.has_value() &&
551 db_->GetRowForVisit(last_ids.second, &visit_row) && 559 db_->GetRowForVisit(last_ids.second, &visit_row) &&
552 visit_row.transition & ui::PAGE_TRANSITION_CHAIN_END) { 560 visit_row.transition & ui::PAGE_TRANSITION_CHAIN_END) {
553 visit_row.transition = ui::PageTransitionFromInt( 561 visit_row.transition = ui::PageTransitionFromInt(
554 visit_row.transition & ~ui::PAGE_TRANSITION_CHAIN_END); 562 visit_row.transition & ~ui::PAGE_TRANSITION_CHAIN_END);
555 db_->UpdateVisitRow(visit_row); 563 db_->UpdateVisitRow(visit_row);
556 } 564 }
557 } 565 }
558 } 566 }
559 567
560 for (size_t redirect_index = 0; redirect_index < redirects.size(); 568 for (size_t redirect_index = 0; redirect_index < redirects.size();
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 const GURL& page_url, 2087 const GURL& page_url,
2080 favicon_base::IconType icon_type, 2088 favicon_base::IconType icon_type,
2081 const std::vector<favicon_base::FaviconID>& icon_ids) { 2089 const std::vector<favicon_base::FaviconID>& icon_ids) {
2082 if (!thumbnail_db_) 2090 if (!thumbnail_db_)
2083 return false; 2091 return false;
2084 2092
2085 // Find all the pages whose favicons we should set, we want to set it for 2093 // Find all the pages whose favicons we should set, we want to set it for
2086 // all the pages in the redirect chain if it redirected. 2094 // all the pages in the redirect chain if it redirected.
2087 RedirectList redirects; 2095 RedirectList redirects;
2088 GetCachedRecentRedirects(page_url, &redirects); 2096 GetCachedRecentRedirects(page_url, &redirects);
2089 bool mappings_changed = SetFaviconMappingsForPages(redirects, icon_type,
2090 icon_ids);
2091 if (page_url.has_ref()) {
2092 // Refs often gets added by Javascript, but the redirect chain is keyed to
2093 // the URL without a ref.
2094 GURL::Replacements replacements;
2095 replacements.ClearRef();
2096 GURL page_url_without_ref = page_url.ReplaceComponents(replacements);
2097 GetCachedRecentRedirects(page_url_without_ref, &redirects);
2098 mappings_changed |= SetFaviconMappingsForPages(redirects, icon_type,
2099 icon_ids);
2100 }
2101 2097
2102 return mappings_changed; 2098 return SetFaviconMappingsForPages(redirects, icon_type, icon_ids);
2103 } 2099 }
2104 2100
2105 bool HistoryBackend::SetFaviconMappingsForPages( 2101 bool HistoryBackend::SetFaviconMappingsForPages(
2106 const std::vector<GURL>& page_urls, 2102 const std::vector<GURL>& page_urls,
2107 favicon_base::IconType icon_type, 2103 favicon_base::IconType icon_type,
2108 const std::vector<favicon_base::FaviconID>& icon_ids) { 2104 const std::vector<favicon_base::FaviconID>& icon_ids) {
2109 bool mappings_changed = false; 2105 bool mappings_changed = false;
2110 for (auto i(page_urls.begin()); i != page_urls.end(); ++i) { 2106 for (auto i(page_urls.begin()); i != page_urls.end(); ++i) {
2111 mappings_changed |= SetFaviconMappingsForPage(*i, icon_type, icon_ids); 2107 mappings_changed |= SetFaviconMappingsForPage(*i, icon_type, icon_ids);
2112 } 2108 }
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2639 // transaction is currently open. 2635 // transaction is currently open.
2640 db_->CommitTransaction(); 2636 db_->CommitTransaction();
2641 db_->Vacuum(); 2637 db_->Vacuum();
2642 db_->BeginTransaction(); 2638 db_->BeginTransaction();
2643 db_->GetStartDate(&first_recorded_time_); 2639 db_->GetStartDate(&first_recorded_time_);
2644 2640
2645 return true; 2641 return true;
2646 } 2642 }
2647 2643
2648 } // namespace history 2644 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698