Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/touch/tabs/touch_tab_strip_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/extension_tab_helper.h" | |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 12 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" | |
| 13 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | |
| 14 #include "ui/gfx/codec/png_codec.h" | |
| 15 | |
| 16 TouchTabStripController::TouchTabStripController(Browser* browser, | |
| 17 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.
| |
| 18 BrowserTabStripController(browser, model), profile_(NULL) { | |
| 19 if (browser) | |
| 20 profile_ = browser->profile(); | |
| 21 } | |
| 22 | |
| 23 TouchTabStripController::~TouchTabStripController() { | |
| 24 } | |
| 25 | |
| 26 void TouchTabStripController::TabChangedAt(TabContentsWrapper* contents, | |
| 27 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.
| |
| 28 // request a large icon if needed | |
| 29 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.
| |
| 30 FaviconService* favicon_service = profile_->GetFaviconService( | |
| 31 Profile::EXPLICIT_ACCESS); | |
| 32 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.
| |
| 33 const GURL &page_url = contents->tab_contents()->GetURL(); | |
| 34 if (model_index_map_[model_index] != page_url && touch_icon_map_.find( | |
| 35 page_url) == touch_icon_map_.end()) { | |
| 36 CancelableRequestProvider::Handle h = | |
| 37 favicon_service->GetFaviconForURL( | |
| 38 page_url, | |
| 39 history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON, | |
| 40 &consumer_, | |
| 41 NewCallback(this, | |
| 42 &TouchTabStripController::OnTouchIconAvailable)); | |
| 43 model_index_map_[model_index] = page_url; | |
| 44 consumer_.SetClientData(favicon_service, h, model_index); | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 // Finally call parent's method | |
| 50 BrowserTabStripController::TabChangedAt(contents, model_index, change_type); | |
| 51 } | |
| 52 | |
| 53 void TouchTabStripController::SetTabRendererDataFromModel( | |
| 54 TabContents* contents, int model_index, TabRendererData* data) { | |
| 55 // Call parent first | |
| 56 BrowserTabStripController::SetTabRendererDataFromModel(contents, model_index, | |
| 57 data); | |
| 58 // Lookup for a touch icon | |
| 59 if (touch_icon_map_.find(data->url) != touch_icon_map_.end()) { | |
| 60 data->favicon = touch_icon_map_[data->url]; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void TouchTabStripController::OnTouchIconAvailable(FaviconService::Handle h, | |
| 65 history::FaviconData favicon) { | |
| 66 if (profile_) { | |
| 67 FaviconService* favicon_service = profile_->GetFaviconService( | |
| 68 Profile::EXPLICIT_ACCESS); | |
| 69 int model_index = consumer_.GetClientData(favicon_service, h); | |
| 70 if (IsValidIndex(model_index)) { | |
| 71 if (!favicon.is_valid()) { | |
| 72 model_index_map_[model_index] = GURL::EmptyGURL(); | |
| 73 return; | |
| 74 } | |
| 75 // The decoder will leave our bitmap empty on error. | |
| 76 gfx::PNGCodec::Decode(favicon.image_data->front(), | |
| 77 favicon.image_data->size(), | |
| 78 &(touch_icon_map_[model_index_map_[model_index]])); | |
| 79 // refresh | |
| 80 browser_->GetTabContentsAt(model_index)->NotifyNavigationStateChanged( | |
| 81 TabContents::INVALIDATE_TAB); | |
| 82 } | |
| 83 } | |
| 84 } | |
| 85 | |
| OLD | NEW |