OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/webui/engagement/site_engagement_ui.h" | |
6 | |
7 #include "chrome/browser/engagement/site_engagement_service.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/common/url_constants.h" | |
10 #include "content/public/browser/web_ui.h" | |
11 #include "content/public/browser/web_ui_controller.h" | |
12 #include "content/public/browser/web_ui_data_source.h" | |
13 #include "grit/browser_resources.h" | |
14 #include "mojo/common/url_type_converters.h" | |
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
16 | |
Sam McNally
2015/09/10 08:24:46
namespace {
calamity
2015/09/11 07:48:23
Done.
| |
17 // Implementation of SiteEngagementUIHandler that gets information from the | |
18 // SiteEngagementService to provide data for the WebUI. | |
19 class SiteEngagementUIHandlerImpl : public SiteEngagementUIHandler { | |
20 public: | |
21 // SiteEngagementUIHandlerImpl is deleted when the supplied pipe is destroyed. | |
22 SiteEngagementUIHandlerImpl( | |
23 Profile* profile, | |
24 mojo::InterfaceRequest<SiteEngagementUIHandler> request) | |
25 : profile_(profile), binding_(this, request.Pass()) {} | |
26 | |
27 ~SiteEngagementUIHandlerImpl() override {} | |
28 | |
29 // SiteEngagementUIHandler overrides: | |
30 void GetSiteEngagementInfo( | |
31 const GetSiteEngagementInfoCallback& callback) override { | |
32 mojo::Array<SiteEngagementInfoPtr> engagement_info(0); | |
33 | |
34 SiteEngagementService* service = SiteEngagementService::Get(profile_); | |
35 DCHECK(service); | |
36 | |
37 for (auto info : service->GetScoreMap()) { | |
38 SiteEngagementInfoPtr origin_info(SiteEngagementInfo::New()); | |
39 origin_info->origin = mojo::String::From(info.first); | |
40 origin_info->score = info.second; | |
41 engagement_info.push_back(origin_info.Pass()); | |
42 } | |
43 | |
44 callback.Run(engagement_info.Pass()); | |
45 } | |
46 | |
47 private: | |
48 // The Profile* handed to us in our constructor. | |
49 Profile* profile_; | |
50 | |
51 mojo::StrongBinding<SiteEngagementUIHandler> binding_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(SiteEngagementUIHandlerImpl); | |
54 }; | |
55 | |
Sam McNally
2015/09/10 08:24:46
} // namespace
calamity
2015/09/11 07:48:23
Done.
| |
56 SiteEngagementUI::SiteEngagementUI(content::WebUI* web_ui) | |
57 : MojoWebUIController<SiteEngagementUIHandler>(web_ui) { | |
58 // Set up the chrome://site-engagement/ source. | |
59 scoped_ptr<content::WebUIDataSource> source( | |
60 content::WebUIDataSource::Create(chrome::kChromeUISiteEngagementHost)); | |
61 source->AddResourcePath("engagement_table.html", | |
62 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_HTML); | |
63 source->AddResourcePath("engagement_table.css", | |
64 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_CSS); | |
65 source->AddResourcePath("engagement_table.js", | |
66 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_JS); | |
67 source->AddResourcePath("site_engagement.js", IDR_SITE_ENGAGEMENT_JS); | |
68 source->SetDefaultResource(IDR_SITE_ENGAGEMENT_HTML); | |
69 | |
70 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source.release()); | |
71 | |
72 AddMojoResourcePath( | |
73 "chrome/browser/ui/webui/engagement/site_engagement.mojom", | |
74 IDR_SITE_ENGAGEMENT_MOJO_JS); | |
75 } | |
76 | |
77 SiteEngagementUI::~SiteEngagementUI() {} | |
78 | |
79 void SiteEngagementUI::BindUIHandler( | |
80 mojo::InterfaceRequest<SiteEngagementUIHandler> request) { | |
81 // SiteEngagementUIHandlerImpl deletes itself when the pipe is closed. | |
82 new SiteEngagementUIHandlerImpl(Profile::FromWebUI(web_ui()), request.Pass()); | |
83 } | |
OLD | NEW |