diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/favicon/favicon_handler.h | 2 | ||||
-rw-r--r-- | chrome/browser/resources/ntp4/most_visited_page.js | 21 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/favicon_webui_handler.cc | 72 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/favicon_webui_handler.h | 44 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/most_visited_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/new_tab_ui.cc | 5 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
7 files changed, 143 insertions, 5 deletions
diff --git a/chrome/browser/favicon/favicon_handler.h b/chrome/browser/favicon/favicon_handler.h index 8cc26be..e47ace3 100644 --- a/chrome/browser/favicon/favicon_handler.h +++ b/chrome/browser/favicon/favicon_handler.h @@ -64,7 +64,7 @@ class TabContents; // db knew about the favicon), or requests the renderer to download the // favicon. // -// When the renderer downloads the favicon SetFaviconImageData is invoked, +// When the renderer downloads the favicon SetFavicon is invoked, // at which point we update the favicon of the NavigationEntry and notify // the database to save the favicon. diff --git a/chrome/browser/resources/ntp4/most_visited_page.js b/chrome/browser/resources/ntp4/most_visited_page.js index bc1e8ea..b3b82c5 100644 --- a/chrome/browser/resources/ntp4/most_visited_page.js +++ b/chrome/browser/resources/ntp4/most_visited_page.js @@ -8,6 +8,10 @@ cr.define('ntp4', function() { var TilePage = ntp4.TilePage; /** + */ + var tileID = 0; + + /** * Creates a new Most Visited object for tiling. * @constructor * @extends {HTMLAnchorElement} @@ -63,6 +67,7 @@ cr.define('ntp4', function() { this.tabIndex = -1; this.data_ = null; + this.removeAttribute('id'); }, /** @@ -76,6 +81,8 @@ cr.define('ntp4', function() { return; } + var id = tileID++; + this.setAttribute('id', 'tile' + id); this.data_ = data; this.tabIndex = 0; this.classList.remove('filler'); @@ -84,7 +91,7 @@ cr.define('ntp4', function() { var faviconUrl = data.faviconUrl || 'chrome://favicon/' + data.url; colorBar.style.backgroundImage = url(faviconUrl); colorBar.dir = data.direction; - // TODO(estade): add a band of color based on the favicon. + chrome.send('getFaviconDominantColor', [faviconUrl, id]); var title = this.querySelector('.title'); title.textContent = data.title; @@ -99,6 +106,11 @@ cr.define('ntp4', function() { this.updatePinnedState_(); }, + setBarColor: function(r, g, b) { + var color = 'rgb(' + r + ', ' + g + ', ' + b + ')'; + // TODO(estade): use color. + }, + /** * Handles a click on the tile. * @param {Event} e The click event. @@ -359,8 +371,15 @@ cr.define('ntp4', function() { return oldData; }; + function setFaviconDominantColor(id, r, g, b) { + var tile = $('tile' + id); + if (tile) + tile.setBarColor(r, g, b); + }; + return { MostVisitedPage: MostVisitedPage, refreshData: refreshData, + setFaviconDominantColor: setFaviconDominantColor, }; }); diff --git a/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc new file mode 100644 index 0000000..a51c116 --- /dev/null +++ b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc @@ -0,0 +1,72 @@ +// 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/webui/ntp/favicon_webui_handler.h" + +#include "base/callback.h" +#include "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/url_constants.h" +#include "grit/app_resources.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/png_codec.h" +#include "ui/gfx/color_analysis.h" + +FaviconWebUIHandler::FaviconWebUIHandler() { +} + +FaviconWebUIHandler::~FaviconWebUIHandler() { +} + +void FaviconWebUIHandler::RegisterMessages() { + web_ui_->RegisterMessageCallback("getFaviconDominantColor", + NewCallback(this, &FaviconWebUIHandler::HandleGetFaviconDominantColor)); +} + +void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { + std::string path; + CHECK(args->GetString(0, &path)); + DCHECK(StartsWithASCII(path, "chrome://favicon/", false)); + path = path.substr(arraysize("chrome://favicon/") - 1); + + double id; + CHECK(args->GetDouble(1, &id)); + + FaviconService* favicon_service = + web_ui_->GetProfile()->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (!favicon_service || path.empty()) + return; + + FaviconService::Handle handle = favicon_service->GetFaviconForURL( + GURL(path), + history::FAVICON, + &consumer_, + NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); + consumer_.SetClientData(favicon_service, handle, static_cast<int>(id)); +} + +void FaviconWebUIHandler::OnFaviconDataAvailable( + FaviconService::Handle request_handle, + history::FaviconData favicon) { + FaviconService* favicon_service = + web_ui_->GetProfile()->GetFaviconService(Profile::EXPLICIT_ACCESS); + int id = consumer_.GetClientData(favicon_service, request_handle); + + if (favicon.is_valid()) { + // TODO(estade): cache the response + FundamentalValue id_value(id); + + color_utils::GridSampler sampler; + SkColor color = + color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665, + sampler); + FundamentalValue r(static_cast<int>(SkColorGetR(color))); + FundamentalValue g(static_cast<int>(SkColorGetG(color))); + FundamentalValue b(static_cast<int>(SkColorGetB(color))); + + web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor", + id_value, r, g, b); + } +} diff --git a/chrome/browser/ui/webui/ntp/favicon_webui_handler.h b/chrome/browser/ui/webui/ntp/favicon_webui_handler.h new file mode 100644 index 0000000..557cb96 --- /dev/null +++ b/chrome/browser/ui/webui/ntp/favicon_webui_handler.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "chrome/browser/favicon/favicon_service.h" +#include "content/browser/webui/web_ui.h" + +class GURL; +class ListValue; +class Profile; + +class FaviconWebUIHandler : public WebUIMessageHandler { + public: + FaviconWebUIHandler(); + virtual ~FaviconWebUIHandler(); + + // WebUIMessageHandler + virtual void RegisterMessages(); + + void HandleGetFaviconDominantColor(const ListValue* args); + + private: + // Called when favicon data is available from the history backend. + void OnFaviconDataAvailable(FaviconService::Handle request_handle, + history::FaviconData favicon); + + CancelableRequestConsumerTSimple<int> consumer_; + + // Raw PNG representation of the favicon to show when the favicon + // database doesn't have a favicon for a webpage. + scoped_refptr<RefCountedMemory> default_favicon_; + + DISALLOW_COPY_AND_ASSIGN(FaviconWebUIHandler); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_ diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc index 8d78c4a..a37d6ca 100644 --- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc +++ b/chrome/browser/ui/webui/ntp/most_visited_handler.cc @@ -84,8 +84,6 @@ WebUIMessageHandler* MostVisitedHandler::Attach(WebUI* web_ui) { } void MostVisitedHandler::RegisterMessages() { - // Register ourselves as the handler for the "getMostSisited" message from - // Javascript. web_ui_->RegisterMessageCallback("getMostVisited", NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 56e81f6..e7223f7 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -30,6 +30,7 @@ #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" +#include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" @@ -347,7 +348,7 @@ NewTabUI::NewTabUI(TabContents* contents) AddMessageHandler((new NTPLoginHandler())->Attach(this)); AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); AddMessageHandler((new browser_sync::ForeignSessionHandler())-> - Attach(this)); + Attach(this)); AddMessageHandler((new MostVisitedHandler())->Attach(this)); AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); AddMessageHandler((new MetricsHandler())->Attach(this)); @@ -361,6 +362,8 @@ NewTabUI::NewTabUI(TabContents* contents) AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); AddMessageHandler((new NewTabPageClosePromoHandler())->Attach(this)); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) + AddMessageHandler((new FaviconWebUIHandler())->Attach(this)); } // Initializing the CSS and HTML can require some CPU, so do it after diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6bcab16..a69aa2e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3355,6 +3355,8 @@ 'browser/ui/webui/net_internals_ui.h', 'browser/ui/webui/ntp/app_launcher_handler.cc', 'browser/ui/webui/ntp/app_launcher_handler.h', + 'browser/ui/webui/ntp/favicon_webui_handler.cc', + 'browser/ui/webui/ntp/favicon_webui_handler.h', 'browser/ui/webui/ntp/foreign_session_handler.cc', 'browser/ui/webui/ntp/foreign_session_handler.h', 'browser/ui/webui/ntp/most_visited_handler.cc', |