Chromium Code Reviews| Index: chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc |
| diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e16a3c1b759306705dbeb024ee91c327add3da83 |
| --- /dev/null |
| +++ b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc |
| @@ -0,0 +1,85 @@ |
| +// Copyright (c) 2011 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 "chrome/browser/ui/touch/tabs/touch_tab_strip_controller.h" |
| + |
| +#include "chrome/browser/extensions/extension_tab_helper.h" |
| +#include "chrome/browser/favicon/favicon_tab_helper.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| +#include "chrome/browser/ui/views/tabs/base_tab_strip.h" |
| +#include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| + |
| +TouchTabStripController::TouchTabStripController(Browser* browser, |
| + TabStripModel* model) : |
|
sky
2011/06/09 16:53:00
nit: ':' on next line, and each parameter on its o
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Done.
|
| + BrowserTabStripController(browser, model), profile_(NULL) { |
| + if (browser) |
| + profile_ = browser->profile(); |
| +} |
| + |
| +TouchTabStripController::~TouchTabStripController() { |
| +} |
| + |
| +void TouchTabStripController::TabChangedAt(TabContentsWrapper* contents, |
| + int model_index, TabChangeType change_type) { |
|
sky
2011/06/09 16:53:00
nit: each param on its own line. See http://dev.ch
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Done.
|
| + // request a large icon if needed |
| + if (profile_ != NULL && change_type == ALL) { |
|
sky
2011/06/09 16:53:00
You care about INVALIDATE_URL or INVALIDATE_TAB.
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Done.
|
| + FaviconService* favicon_service = profile_->GetFaviconService( |
| + Profile::EXPLICIT_ACCESS); |
| + if (favicon_service && contents->tab_contents()) { |
|
sky
2011/06/09 16:53:00
contents->tab_contents() is always non-null.
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Done.
|
| + const GURL &page_url = contents->tab_contents()->GetURL(); |
| + if (model_index_map_[model_index] != page_url && touch_icon_map_.find( |
| + page_url) == touch_icon_map_.end()) { |
| + CancelableRequestProvider::Handle h = |
| + favicon_service->GetFaviconForURL( |
| + page_url, |
| + history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON, |
| + &consumer_, |
| + NewCallback(this, |
| + &TouchTabStripController::OnTouchIconAvailable)); |
| + model_index_map_[model_index] = page_url; |
| + consumer_.SetClientData(favicon_service, h, model_index); |
| + } |
| + } |
| + } |
| + |
| + // Finally call parent's method |
| + BrowserTabStripController::TabChangedAt(contents, model_index, change_type); |
| +} |
| + |
| +void TouchTabStripController::SetTabRendererDataFromModel( |
| + TabContents* contents, int model_index, TabRendererData* data) { |
| + // Call parent first |
| + BrowserTabStripController::SetTabRendererDataFromModel(contents, model_index, |
| + data); |
| + // Lookup for a touch icon |
| + if (touch_icon_map_.find(data->url) != touch_icon_map_.end()) { |
| + data->favicon = touch_icon_map_[data->url]; |
| + } |
| +} |
| + |
| +void TouchTabStripController::OnTouchIconAvailable(FaviconService::Handle h, |
| + history::FaviconData favicon) { |
| + if (profile_) { |
| + FaviconService* favicon_service = profile_->GetFaviconService( |
| + Profile::EXPLICIT_ACCESS); |
| + int model_index = consumer_.GetClientData(favicon_service, h); |
| + if (IsValidIndex(model_index)) { |
| + if (!favicon.is_valid()) { |
| + model_index_map_[model_index] = GURL::EmptyGURL(); |
| + return; |
| + } |
| + // The decoder will leave our bitmap empty on error. |
| + gfx::PNGCodec::Decode(favicon.image_data->front(), |
| + favicon.image_data->size(), |
| + &(touch_icon_map_[model_index_map_[model_index]])); |
| + // refresh |
| + browser_->GetTabContentsAt(model_index)->NotifyNavigationStateChanged( |
| + TabContents::INVALIDATE_TAB); |
| + } |
| + } |
| +} |
| + |