From 2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 9 May 2016 14:22:11 +0200 Subject: BASELINE: Update Chromium to 51.0.2704.41 Also adds in all smaller components by reversing logic for exclusion. Change-Id: Ibf90b506e7da088ea2f65dcf23f2b0992c504422 Reviewed-by: Joerg Bornemann --- chromium/components/favicon/ios/DEPS | 3 + chromium/components/favicon/ios/OWNERS | 1 + .../components/favicon/ios/favicon_url_util.cc | 51 ++++++++++ chromium/components/favicon/ios/favicon_url_util.h | 28 ++++++ .../components/favicon/ios/web_favicon_driver.h | 67 +++++++++++++ .../components/favicon/ios/web_favicon_driver.mm | 111 +++++++++++++++++++++ 6 files changed, 261 insertions(+) create mode 100644 chromium/components/favicon/ios/DEPS create mode 100644 chromium/components/favicon/ios/OWNERS create mode 100644 chromium/components/favicon/ios/favicon_url_util.cc create mode 100644 chromium/components/favicon/ios/favicon_url_util.h create mode 100644 chromium/components/favicon/ios/web_favicon_driver.h create mode 100644 chromium/components/favicon/ios/web_favicon_driver.mm (limited to 'chromium/components/favicon/ios') diff --git a/chromium/components/favicon/ios/DEPS b/chromium/components/favicon/ios/DEPS new file mode 100644 index 00000000000..0fc0ddddacd --- /dev/null +++ b/chromium/components/favicon/ios/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ios/web/public", +] diff --git a/chromium/components/favicon/ios/OWNERS b/chromium/components/favicon/ios/OWNERS new file mode 100644 index 00000000000..378261e8802 --- /dev/null +++ b/chromium/components/favicon/ios/OWNERS @@ -0,0 +1 @@ +sdefresne@chromium.org \ No newline at end of file diff --git a/chromium/components/favicon/ios/favicon_url_util.cc b/chromium/components/favicon/ios/favicon_url_util.cc new file mode 100644 index 00000000000..95bcfda262b --- /dev/null +++ b/chromium/components/favicon/ios/favicon_url_util.cc @@ -0,0 +1,51 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/favicon/ios/favicon_url_util.h" + +#include +#include + +#include "components/favicon/core/favicon_url.h" +#include "components/favicon_base/favicon_types.h" +#include "ios/web/public/favicon_url.h" + +namespace favicon { +namespace { + +favicon_base::IconType IconTypeFromWebIconType( + web::FaviconURL::IconType icon_type) { + switch (icon_type) { + case web::FaviconURL::FAVICON: + return favicon_base::FAVICON; + case web::FaviconURL::TOUCH_ICON: + return favicon_base::TOUCH_ICON; + case web::FaviconURL::TOUCH_PRECOMPOSED_ICON: + return favicon_base::TOUCH_PRECOMPOSED_ICON; + case web::FaviconURL::INVALID_ICON: + return favicon_base::INVALID_ICON; + } + NOTREACHED(); + return favicon_base::INVALID_ICON; +} + +} // namespace + +FaviconURL FaviconURLFromWebFaviconURL( + const web::FaviconURL& favicon_url) { + return FaviconURL(favicon_url.icon_url, + IconTypeFromWebIconType(favicon_url.icon_type), + favicon_url.icon_sizes); +} + +std::vector FaviconURLsFromWebFaviconURLs( + const std::vector& favicon_urls) { + std::vector result; + result.reserve(favicon_urls.size()); + std::transform(favicon_urls.begin(), favicon_urls.end(), + std::back_inserter(result), FaviconURLFromWebFaviconURL); + return result; +} + +} // namespace favicon diff --git a/chromium/components/favicon/ios/favicon_url_util.h b/chromium/components/favicon/ios/favicon_url_util.h new file mode 100644 index 00000000000..a76db0761e8 --- /dev/null +++ b/chromium/components/favicon/ios/favicon_url_util.h @@ -0,0 +1,28 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_FAVICON_IOS_FAVICON_URL_UTIL_H_ +#define COMPONENTS_FAVICON_IOS_FAVICON_URL_UTIL_H_ + +#include + +namespace web { +struct FaviconURL; +} + +namespace favicon { + +struct FaviconURL; + +// Creates a favicon::FaviconURL from a web::FaviconURL. +FaviconURL FaviconURLFromWebFaviconURL( + const web::FaviconURL& favicon_url); + +// Creates favicon::FaviconURLs from web::FaviconURLs. +std::vector FaviconURLsFromWebFaviconURLs( + const std::vector& favicon_urls); + +} // namespace favicon + +#endif // COMPONENTS_FAVICON_IOS_FAVICON_URL_UTIL_H_ diff --git a/chromium/components/favicon/ios/web_favicon_driver.h b/chromium/components/favicon/ios/web_favicon_driver.h new file mode 100644 index 00000000000..ad900d9e443 --- /dev/null +++ b/chromium/components/favicon/ios/web_favicon_driver.h @@ -0,0 +1,67 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_ +#define COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_ + +#include "base/macros.h" +#include "components/favicon/core/favicon_driver_impl.h" +#include "ios/web/public/web_state/web_state_observer.h" +#include "ios/web/public/web_state/web_state_user_data.h" + +namespace web { +struct FaviconStatus; +class WebState; +} + +namespace favicon { + +// WebFaviconDriver is an implementation of FaviconDriver that listen to +// WebState events to start download of favicons and to get informed when the +// favicon download has completed. +class WebFaviconDriver : public web::WebStateObserver, + public web::WebStateUserData, + public FaviconDriverImpl { + public: + static void CreateForWebState(web::WebState* web_state, + FaviconService* favicon_service, + history::HistoryService* history_service, + bookmarks::BookmarkModel* bookmark_model); + + // FaviconDriver implementation. + void FetchFavicon(const GURL& url) override; + gfx::Image GetFavicon() const override; + bool FaviconIsValid() const override; + int StartDownload(const GURL& url, int max_bitmap_size) override; + bool IsOffTheRecord() override; + GURL GetActiveURL() override; + void OnFaviconUpdated( + const GURL& page_url, + FaviconDriverObserver::NotificationIconType notification_icon_type, + const GURL& icon_url, + bool icon_url_changed, + const gfx::Image& image) override; + + private: + friend class web::WebStateUserData; + + WebFaviconDriver(web::WebState* web_state, + FaviconService* favicon_service, + history::HistoryService* history_service, + bookmarks::BookmarkModel* bookmark_model); + ~WebFaviconDriver() override; + + // web::WebStateObserver implementation. + void FaviconUrlUpdated( + const std::vector& candidates) override; + + // The URL passed to FetchFavicon(). + GURL fetch_favicon_url_; + + DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver); +}; + +} // namespace favicon + +#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_ diff --git a/chromium/components/favicon/ios/web_favicon_driver.mm b/chromium/components/favicon/ios/web_favicon_driver.mm new file mode 100644 index 00000000000..03777812d27 --- /dev/null +++ b/chromium/components/favicon/ios/web_favicon_driver.mm @@ -0,0 +1,111 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/favicon/ios/web_favicon_driver.h" + +#include "base/bind.h" +#include "components/favicon/core/favicon_url.h" +#include "components/favicon/ios/favicon_url_util.h" +#include "ios/web/public/browser_state.h" +#include "ios/web/public/favicon_status.h" +#include "ios/web/public/navigation_item.h" +#include "ios/web/public/navigation_manager.h" +#include "ios/web/public/web_state/web_state.h" +#include "ui/gfx/image/image.h" + +DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver); + +namespace favicon { + +// static +void WebFaviconDriver::CreateForWebState( + web::WebState* web_state, + FaviconService* favicon_service, + history::HistoryService* history_service, + bookmarks::BookmarkModel* bookmark_model) { + if (FromWebState(web_state)) + return; + + web_state->SetUserData(UserDataKey(), + new WebFaviconDriver(web_state, favicon_service, + history_service, bookmark_model)); +} + +void WebFaviconDriver::FetchFavicon(const GURL& url) { + fetch_favicon_url_ = url; + FaviconDriverImpl::FetchFavicon(url); +} + +gfx::Image WebFaviconDriver::GetFavicon() const { + web::NavigationItem* item = + web_state()->GetNavigationManager()->GetLastCommittedItem(); + return item ? item->GetFavicon().image : gfx::Image(); +} + +bool WebFaviconDriver::FaviconIsValid() const { + web::NavigationItem* item = + web_state()->GetNavigationManager()->GetLastCommittedItem(); + return item ? item->GetFavicon().valid : false; +} + +int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { + if (WasUnableToDownloadFavicon(url)) { + DVLOG(1) << "Skip Failed FavIcon: " << url; + return 0; + } + + return web_state()->DownloadImage( + url, true, max_image_size, false, + base::Bind(&FaviconDriverImpl::DidDownloadFavicon, + base::Unretained(this))); +} + +bool WebFaviconDriver::IsOffTheRecord() { + DCHECK(web_state()); + return web_state()->GetBrowserState()->IsOffTheRecord(); +} + +GURL WebFaviconDriver::GetActiveURL() { + web::NavigationItem* item = + web_state()->GetNavigationManager()->GetVisibleItem(); + return item ? item->GetURL() : GURL(); +} + +void WebFaviconDriver::OnFaviconUpdated( + const GURL& page_url, + FaviconDriverObserver::NotificationIconType notification_icon_type, + const GURL& icon_url, + bool icon_url_changed, + const gfx::Image& image) { + // Check whether the active URL has changed since FetchFavicon() was called. + // On iOS, the active URL can change between calls to FetchFavicon(). For + // instance, FetchFavicon() is not synchronously called when the active URL + // changes as a result of CRWSessionController::goToEntry(). + web::NavigationItem* item = + web_state()->GetNavigationManager()->GetVisibleItem(); + if (!item || item->GetURL() != page_url) + return; + + NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, + icon_url_changed, image); +} + +WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, + FaviconService* favicon_service, + history::HistoryService* history_service, + bookmarks::BookmarkModel* bookmark_model) + : web::WebStateObserver(web_state), + FaviconDriverImpl(favicon_service, history_service, bookmark_model) { +} + +WebFaviconDriver::~WebFaviconDriver() { +} + +void WebFaviconDriver::FaviconUrlUpdated( + const std::vector& candidates) { + DCHECK(!candidates.empty()); + OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); +} + +} // namespace favicon -- cgit v1.2.1