blob: 28f91643df4476e1e2c973f5adce9b48aee4ebcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright 2014 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/domain_reliability_internals_ui.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "components/domain_reliability/service.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "grit/browser_resources.h"
using domain_reliability::DomainReliabilityService;
using domain_reliability::DomainReliabilityServiceFactory;
DomainReliabilityInternalsUI::DomainReliabilityInternalsUI(
content::WebUI* web_ui)
: content::WebUIController(web_ui) {
content::WebUIDataSource* html_source = content::WebUIDataSource::Create(
chrome::kChromeUIDomainReliabilityInternalsHost);
html_source->SetJsonPath("strings.js");
html_source->AddResourcePath("domain_reliability_internals.css",
IDR_DOMAIN_RELIABILITY_INTERNALS_CSS);
html_source->AddResourcePath("domain_reliability_internals.js",
IDR_DOMAIN_RELIABILITY_INTERNALS_JS);
html_source->SetDefaultResource(IDR_DOMAIN_RELIABILITY_INTERNALS_HTML);
web_ui->RegisterMessageCallback("updateData",
base::Bind(&DomainReliabilityInternalsUI::UpdateData,
base::Unretained(this)));
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, html_source);
}
DomainReliabilityInternalsUI::~DomainReliabilityInternalsUI() {}
void DomainReliabilityInternalsUI::UpdateData(
const base::ListValue* args) const {
Profile* profile = Profile::FromWebUI(web_ui());
DomainReliabilityServiceFactory* factory =
DomainReliabilityServiceFactory::GetInstance();
DCHECK(profile);
DCHECK(factory);
DomainReliabilityService* service = factory->GetForBrowserContext(profile);
if (!service) {
base::DictionaryValue* data = new base::DictionaryValue();
data->SetString("error", "no_service");
OnDataUpdated(scoped_ptr<base::Value>(data));
return;
}
service->GetWebUIData(base::Bind(
&DomainReliabilityInternalsUI::OnDataUpdated,
base::Unretained(this)));
}
void DomainReliabilityInternalsUI::OnDataUpdated(
scoped_ptr<base::Value> data) const {
web_ui()->CallJavascriptFunction(
"DomainReliabilityInternals.onDataUpdated", *data);
}
|