diff options
author | acleung@chromium.org <acleung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-22 23:54:08 +0000 |
---|---|---|
committer | acleung@chromium.org <acleung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-22 23:54:08 +0000 |
commit | b8da3a35c5ec40581963920758c63136110a9f05 (patch) | |
tree | a88109a0f1d6eaa4726279f50b6dfdd70b4b9daa /android_webview/browser | |
parent | 95a083fa27868960efe258e099aa49488260edd8 (diff) | |
download | chromium_src-b8da3a35c5ec40581963920758c63136110a9f05.zip chromium_src-b8da3a35c5ec40581963920758c63136110a9f05.tar.gz chromium_src-b8da3a35c5ec40581963920758c63136110a9f05.tar.bz2 |
Implements onReceivedIcon
This patch implements both WebChromeClient.onReceivedIcon and WebView.getFavIcon, and provides most the support for WebChromeClient.onReceivedTouchIcon.
It also includes instrumentation tests for onReceivedIcon.
What is still missing:
Ability to turn it on and off.
TouchIcon currently isn't working.
Navigation history is not updated as of this patch.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11575022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/browser')
-rw-r--r-- | android_webview/browser/icon_helper.cc | 79 | ||||
-rw-r--r-- | android_webview/browser/icon_helper.h | 51 |
2 files changed, 130 insertions, 0 deletions
diff --git a/android_webview/browser/icon_helper.cc b/android_webview/browser/icon_helper.cc new file mode 100644 index 0000000..4cbe07a --- /dev/null +++ b/android_webview/browser/icon_helper.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2013 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 "android_webview/browser/icon_helper.h" + +#include "base/bind.h" +#include "base/callback.h" +#include "base/logging.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/favicon_url.h" +#include "third_party/skia/include/core/SkBitmap.h" + +using content::BrowserThread; +using content::WebContents; + +namespace android_webview { + +IconHelper::IconHelper(WebContents* web_contents) + : WebContentsObserver(web_contents), + listener_(NULL) { +} + +IconHelper::~IconHelper() { +} + +void IconHelper::SetListener(Listener* listener) { + listener_ = listener; +} + +void IconHelper::DownloadFaviconCallback( + int id, const GURL& image_url, int requested_size, + const std::vector<SkBitmap>& bitmaps) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (bitmaps.size() == 0) { + return; + } + + // We can protentially have multiple frames of the icon + // in different sizes. We need more fine grain API spec + // to let clients pick out the frame they want. + + // TODO(acleung): Pick the best icon to return based on size. + if (listener_) + listener_->OnReceivedIcon(bitmaps[0]); +} + +void IconHelper::DidUpdateFaviconURL(int32 page_id, + const std::vector<content::FaviconURL>& candidates) { + for (std::vector<content::FaviconURL>::const_iterator i = candidates.begin(); + i != candidates.end(); ++i) { + if (i->icon_url.is_empty()) + continue; + + switch(i->icon_type) { + case content::FaviconURL::FAVICON: + // TODO(acleung): only fetch the URL if favicon downloading is enabled. + // (currently that is, the app has called WebIconDatabase.open() + // but we should decouple that setting via a boolean setting) + web_contents()->DownloadFavicon(i->icon_url, 0, base::Bind( + &IconHelper::DownloadFaviconCallback, base::Unretained(this))); + break; + // TODO(acleung): Touch Icon doesn't seem to work ATM. + case content::FaviconURL::TOUCH_ICON: + break; + case content::FaviconURL::TOUCH_PRECOMPOSED_ICON: + break; + case content::FaviconURL::INVALID_ICON: + // Silently ignore it. Only trigger a callback on valid icons. + break; + default: + NOTREACHED(); + break; + } + } +} + +} // namespace android_webview diff --git a/android_webview/browser/icon_helper.h b/android_webview/browser/icon_helper.h new file mode 100644 index 0000000..e684cdf --- /dev/null +++ b/android_webview/browser/icon_helper.h @@ -0,0 +1,51 @@ +// Copyright (c) 2013 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 ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ +#define ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ + +#include <string> +#include "content/public/browser/web_contents_observer.h" + +class SkBitmap; + +namespace content { +struct FaviconURL; +} + +namespace android_webview { + +// A helper that observes favicon changes for Webview. +class IconHelper : public content::WebContentsObserver { + public: + class Listener { + public: + virtual void OnReceivedIcon(const SkBitmap& bitmap) = 0; + virtual void OnReceivedTouchIconUrl(const std::string& url, + const bool precomposed) = 0; + protected: + virtual ~Listener() {} + }; + + explicit IconHelper(content::WebContents* web_contents); + virtual ~IconHelper(); + + void SetListener(Listener* listener); + + // From WebContentsObserver + virtual void DidUpdateFaviconURL(int32 page_id, + const std::vector<content::FaviconURL>& candidates) OVERRIDE; + + void DownloadFaviconCallback(int id, const GURL& image_url, + int requested_size, const std::vector<SkBitmap>& bitmaps); + + private: + Listener* listener_; + + DISALLOW_COPY_AND_ASSIGN(IconHelper); +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ |