This source file includes following definitions.
- listener_
- SetListener
- DownloadFaviconCallback
- DidUpdateFaviconURL
#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"
#include "ui/gfx/size.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,
int http_status_code,
const GURL& image_url,
const std::vector<SkBitmap>& bitmaps,
const std::vector<gfx::Size>& original_bitmap_sizes) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (bitmaps.size() == 0) {
return;
}
if (listener_)
listener_->OnReceivedIcon(image_url, bitmaps[0]);
}
void IconHelper::DidUpdateFaviconURL(int32 page_id,
const std::vector<content::FaviconURL>& candidates) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
for (std::vector<content::FaviconURL>::const_iterator i = candidates.begin();
i != candidates.end(); ++i) {
if (!i->icon_url.is_valid())
continue;
switch(i->icon_type) {
case content::FaviconURL::FAVICON:
if (listener_ && !listener_->ShouldDownloadFavicon(i->icon_url)) break;
web_contents()->DownloadImage(i->icon_url,
true,
0,
base::Bind(
&IconHelper::DownloadFaviconCallback, base::Unretained(this)));
break;
case content::FaviconURL::TOUCH_ICON:
if (listener_)
listener_->OnReceivedTouchIconUrl(i->icon_url.spec(), false);
break;
case content::FaviconURL::TOUCH_PRECOMPOSED_ICON:
if (listener_)
listener_->OnReceivedTouchIconUrl(i->icon_url.spec(), true);
break;
case content::FaviconURL::INVALID_ICON:
break;
default:
NOTREACHED();
break;
}
}
}
}