Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: chrome/browser/ui/webui/ntp/favicon_webui_handler.cc

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Profile helper function, rebase Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" 5 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 18 matching lines...) Expand all
29 std::string path; 29 std::string path;
30 CHECK(args->GetString(0, &path)); 30 CHECK(args->GetString(0, &path));
31 DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) << 31 DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) <<
32 "path is " << path; 32 "path is " << path;
33 path = path.substr(arraysize("chrome://favicon/size/32/") - 1); 33 path = path.substr(arraysize("chrome://favicon/size/32/") - 1);
34 34
35 double id; 35 double id;
36 CHECK(args->GetDouble(1, &id)); 36 CHECK(args->GetDouble(1, &id));
37 37
38 FaviconService* favicon_service = 38 FaviconService* favicon_service =
39 web_ui_->GetProfile()->GetFaviconService(Profile::EXPLICIT_ACCESS); 39 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS);
40 if (!favicon_service || path.empty()) 40 if (!favicon_service || path.empty())
41 return; 41 return;
42 42
43 FaviconService::Handle handle = favicon_service->GetFaviconForURL( 43 FaviconService::Handle handle = favicon_service->GetFaviconForURL(
44 GURL(path), 44 GURL(path),
45 history::FAVICON, 45 history::FAVICON,
46 &consumer_, 46 &consumer_,
47 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); 47 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable));
48 consumer_.SetClientData(favicon_service, handle, static_cast<int>(id)); 48 consumer_.SetClientData(favicon_service, handle, static_cast<int>(id));
49 } 49 }
50 50
51 void FaviconWebUIHandler::OnFaviconDataAvailable( 51 void FaviconWebUIHandler::OnFaviconDataAvailable(
52 FaviconService::Handle request_handle, 52 FaviconService::Handle request_handle,
53 history::FaviconData favicon) { 53 history::FaviconData favicon) {
54 FaviconService* favicon_service = 54 FaviconService* favicon_service =
55 web_ui_->GetProfile()->GetFaviconService(Profile::EXPLICIT_ACCESS); 55 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS);
56 int id = consumer_.GetClientData(favicon_service, request_handle); 56 int id = consumer_.GetClientData(favicon_service, request_handle);
57 FundamentalValue id_value(id); 57 FundamentalValue id_value(id);
58 scoped_ptr<StringValue> color_value; 58 scoped_ptr<StringValue> color_value;
59 59
60 if (favicon.is_valid()) { 60 if (favicon.is_valid()) {
61 // TODO(estade): cache the response 61 // TODO(estade): cache the response
62 color_utils::GridSampler sampler; 62 color_utils::GridSampler sampler;
63 SkColor color = 63 SkColor color =
64 color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665, 64 color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665,
65 sampler); 65 sampler);
66 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)", 66 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)",
67 SkColorGetR(color), 67 SkColorGetR(color),
68 SkColorGetG(color), 68 SkColorGetG(color),
69 SkColorGetB(color)); 69 SkColorGetB(color));
70 color_value.reset(new StringValue(css_color)); 70 color_value.reset(new StringValue(css_color));
71 } else { 71 } else {
72 color_value.reset(new StringValue("#919191")); 72 color_value.reset(new StringValue("#919191"));
73 } 73 }
74 74
75 web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor", 75 web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor",
76 id_value, *color_value); 76 id_value, *color_value);
77 } 77 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.cc ('k') | chrome/browser/ui/webui/ntp/foreign_session_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698