Commit 8a9967c6 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chrome: moves SaveFaviconEvenIfInIncognito() into chrome

This function is only used in chrome, and should be moved there.

BUG=1076463
TEST=covered by tests

Change-Id: I5916d68e5761635839e6ce1db680d45116ea0331
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2311520Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791069}
parent 7e06e6a3
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "chrome/grit/platform_locale_settings.h" #include "chrome/grit/platform_locale_settings.h"
#include "components/favicon/content/content_favicon_driver.h" #include "components/favicon/content/content_favicon_driver.h"
#include "components/favicon/core/fallback_url_util.h" #include "components/favicon/core/fallback_url_util.h"
#include "components/favicon/core/favicon_service.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -164,4 +166,35 @@ gfx::Image GetDefaultFavicon() { ...@@ -164,4 +166,35 @@ gfx::Image GetDefaultFavicon() {
resource_id); resource_id);
} }
void SaveFaviconEvenIfInIncognito(content::WebContents* contents) {
content::NavigationEntry* entry =
contents->GetController().GetLastCommittedEntry();
if (!entry)
return;
Profile* original_profile =
Profile::FromBrowserContext(contents->GetBrowserContext())
->GetOriginalProfile();
favicon::FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(original_profile,
ServiceAccessType::EXPLICIT_ACCESS);
if (!favicon_service)
return;
// Make sure the page is in history, otherwise adding the favicon does
// nothing.
GURL page_url = entry->GetURL();
favicon_service->AddPageNoVisitForBookmark(page_url, entry->GetTitle());
const content::FaviconStatus& favicon_status = entry->GetFavicon();
if (!favicon_status.valid || favicon_status.url.is_empty() ||
favicon_status.image.IsEmpty()) {
return;
}
favicon_service->SetFavicons({page_url}, favicon_status.url,
favicon_base::IconType::kFavicon,
favicon_status.image);
}
} // namespace favicon } // namespace favicon
...@@ -37,6 +37,10 @@ gfx::Image TabFaviconFromWebContents(content::WebContents* contents); ...@@ -37,6 +37,10 @@ gfx::Image TabFaviconFromWebContents(content::WebContents* contents);
// into account if necessary. // into account if necessary.
gfx::Image GetDefaultFavicon(); gfx::Image GetDefaultFavicon();
// Saves the favicon for the last committed navigation entry to the favicon
// database.
void SaveFaviconEvenIfInIncognito(content::WebContents* contents);
} // namespace favicon } // namespace favicon
#endif // CHROME_BROWSER_FAVICON_FAVICON_UTILS_H_ #endif // CHROME_BROWSER_FAVICON_FAVICON_UTILS_H_
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/dom_distiller/tab_utils.h" #include "chrome/browser/dom_distiller/tab_utils.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/media/router/media_router_dialog_controller.h" // nogncheck #include "chrome/browser/media/router/media_router_dialog_controller.h" // nogncheck
#include "chrome/browser/media/router/media_router_feature.h" #include "chrome/browser/media/router/media_router_feature.h"
...@@ -971,8 +972,7 @@ void BookmarkCurrentTab(Browser* browser) { ...@@ -971,8 +972,7 @@ void BookmarkCurrentTab(Browser* browser) {
web_contents->GetBrowserContext()->IsOffTheRecord()) { web_contents->GetBrowserContext()->IsOffTheRecord()) {
// If we're incognito the favicon may not have been saved. Save it now // If we're incognito the favicon may not have been saved. Save it now
// so that bookmarks have an icon for the page. // so that bookmarks have an icon for the page.
favicon::ContentFaviconDriver::FromWebContents(web_contents) favicon::SaveFaviconEvenIfInIncognito(web_contents);
->SaveFaviconEvenIfInIncognito();
} }
bool was_bookmarked_by_user = bookmarks::IsBookmarkedByUser(model, url); bool was_bookmarked_by_user = bookmarks::IsBookmarkedByUser(model, url);
bookmarks::AddIfNotBookmarked(model, url, title); bookmarks::AddIfNotBookmarked(model, url, title);
......
...@@ -47,28 +47,6 @@ void ContentFaviconDriver::CreateForWebContents( ...@@ -47,28 +47,6 @@ void ContentFaviconDriver::CreateForWebContents(
web_contents, favicon_service))); web_contents, favicon_service)));
} }
void ContentFaviconDriver::SaveFaviconEvenIfInIncognito() {
content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
if (!entry)
return;
// Make sure the page is in history, otherwise adding the favicon does
// nothing.
GURL page_url = entry->GetURL();
favicon_service()->AddPageNoVisitForBookmark(page_url, entry->GetTitle());
const content::FaviconStatus& favicon_status = entry->GetFavicon();
if (!favicon_service() || !favicon_status.valid ||
favicon_status.url.is_empty() || favicon_status.image.IsEmpty()) {
return;
}
favicon_service()->SetFavicons({page_url}, favicon_status.url,
favicon_base::IconType::kFavicon,
favicon_status.image);
}
gfx::Image ContentFaviconDriver::GetFavicon() const { gfx::Image ContentFaviconDriver::GetFavicon() const {
// Like GetTitle(), we also want to use the favicon for the last committed // Like GetTitle(), we also want to use the favicon for the last committed
// entry rather than a pending navigation entry. // entry rather than a pending navigation entry.
......
...@@ -37,10 +37,6 @@ class ContentFaviconDriver ...@@ -37,10 +37,6 @@ class ContentFaviconDriver
return favicon_urls_.value_or(std::vector<blink::mojom::FaviconURL>()); return favicon_urls_.value_or(std::vector<blink::mojom::FaviconURL>());
} }
// Saves the favicon for the last committed navigation entry to the thumbnail
// database.
void SaveFaviconEvenIfInIncognito();
// FaviconDriver implementation. // FaviconDriver implementation.
gfx::Image GetFavicon() const override; gfx::Image GetFavicon() const override;
bool FaviconIsValid() const override; bool FaviconIsValid() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment