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