summaryrefslogtreecommitdiff
path: root/chromium/components/favicon/ios
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-09 14:22:11 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-05-09 15:11:45 +0000
commit2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c (patch)
treee75f511546c5fd1a173e87c1f9fb11d7ac8d1af3 /chromium/components/favicon/ios
parenta4f3d46271c57e8155ba912df46a05559d14726e (diff)
downloadqtwebengine-chromium-2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c.tar.gz
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 <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'chromium/components/favicon/ios')
-rw-r--r--chromium/components/favicon/ios/DEPS3
-rw-r--r--chromium/components/favicon/ios/OWNERS1
-rw-r--r--chromium/components/favicon/ios/favicon_url_util.cc51
-rw-r--r--chromium/components/favicon/ios/favicon_url_util.h28
-rw-r--r--chromium/components/favicon/ios/web_favicon_driver.h67
-rw-r--r--chromium/components/favicon/ios/web_favicon_driver.mm111
6 files changed, 261 insertions, 0 deletions
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 <algorithm>
+#include <iterator>
+
+#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<FaviconURL> FaviconURLsFromWebFaviconURLs(
+ const std::vector<web::FaviconURL>& favicon_urls) {
+ std::vector<FaviconURL> 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 <vector>
+
+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<FaviconURL> FaviconURLsFromWebFaviconURLs(
+ const std::vector<web::FaviconURL>& 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<WebFaviconDriver>,
+ 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>;
+
+ 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<web::FaviconURL>& 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<web::FaviconURL>& candidates) {
+ DCHECK(!candidates.empty());
+ OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates));
+}
+
+} // namespace favicon