1// Copyright (c) 2012 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/performance_monitor/performance_monitor_ui.h" 6 7#include "base/strings/utf_string_conversions.h" 8#include "base/values.h" 9#include "chrome/browser/performance_monitor/performance_monitor.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/ui/webui/performance_monitor/performance_monitor_handler.h" 12#include "chrome/common/url_constants.h" 13#include "content/public/browser/web_ui.h" 14#include "content/public/browser/web_ui_data_source.h" 15#include "grit/browser_resources.h" 16#include "grit/generated_resources.h" 17 18namespace { 19 20content::WebUIDataSource* CreateWebUIHTMLSource() { 21 content::WebUIDataSource* source = 22 content::WebUIDataSource::Create(chrome::kChromeUIPerformanceMonitorHost); 23 24 source->SetJsonPath("strings.js"); 25 source->AddResourcePath("chart.css", IDR_PERFORMANCE_MONITOR_CHART_CSS); 26 source->AddResourcePath("chart.js", IDR_PERFORMANCE_MONITOR_CHART_JS); 27 source->AddResourcePath("jquery.js", IDR_PERFORMANCE_MONITOR_JQUERY_JS); 28 source->AddResourcePath("flot.js", IDR_PERFORMANCE_MONITOR_JQUERY_FLOT_JS); 29 source->SetDefaultResource(IDR_PERFORMANCE_MONITOR_HTML); 30 31 source->AddString("enableFlagsURL", ASCIIToUTF16(chrome::kChromeUIFlagsURL)); 32 33 source->AddLocalizedString("title", IDS_PERFORMANCE_MONITOR_TITLE); 34 source->AddLocalizedString("flagNotEnabledWarning", 35 IDS_PERFORMANCE_MONITOR_FLAG_NOT_ENABLED_WARNING); 36 source->AddLocalizedString("enableFlag", IDS_PERFORMANCE_MONITOR_ENABLE_FLAG); 37 source->AddLocalizedString("noAggregationWarning", 38 IDS_PERFORMANCE_MONITOR_NO_AGGREGATION_WARNING); 39 source->AddLocalizedString("timeRangeSection", 40 IDS_PERFORMANCE_MONITOR_TIME_RANGE_SECTION); 41 source->AddLocalizedString("timeResolutionCategory", 42 IDS_PERFORMANCE_MONITOR_TIME_RESOLUTION_CATEGORY); 43 source->AddLocalizedString("timeLastFifteenMinutes", 44 IDS_PERFORMANCE_MONITOR_TIME_LAST_FIFTEEN_MINUTES); 45 source->AddLocalizedString("timeLastHour", 46 IDS_PERFORMANCE_MONITOR_TIME_LAST_HOUR); 47 source->AddLocalizedString("timeLastDay", 48 IDS_PERFORMANCE_MONITOR_TIME_LAST_DAY); 49 source->AddLocalizedString("timeLastWeek", 50 IDS_PERFORMANCE_MONITOR_TIME_LAST_WEEK); 51 source->AddLocalizedString("timeLastMonth", 52 IDS_PERFORMANCE_MONITOR_TIME_LAST_MONTH); 53 source->AddLocalizedString("timeLastQuarter", 54 IDS_PERFORMANCE_MONITOR_TIME_LAST_QUARTER); 55 source->AddLocalizedString("timeRangeButtonHeading", 56 IDS_PERFORMANCE_MONITOR_TIME_RANGE_BUTTON_HEADING); 57 source->AddLocalizedString("aggregationCategory", 58 IDS_PERFORMANCE_MONITOR_AGGREGATION_CATEGORY); 59 source->AddLocalizedString("metricsSection", 60 IDS_PERFORMANCE_MONITOR_METRICS_SECTION); 61 source->AddLocalizedString("eventsSection", 62 IDS_PERFORMANCE_MONITOR_EVENTS_SECTION); 63 source->AddLocalizedString("eventTimeMouseover", 64 IDS_PERFORMANCE_MONITOR_EVENT_TIME_MOUSEOVER); 65 66 return source; 67} 68 69} // namespace 70 71namespace performance_monitor { 72 73PerformanceMonitorUI::PerformanceMonitorUI(content::WebUI* web_ui) 74 : WebUIController(web_ui) { 75 web_ui->AddMessageHandler(new PerformanceMonitorHandler()); 76 77 content::WebUIDataSource* html_source = CreateWebUIHTMLSource(); 78 html_source->SetUseJsonJSFormatV2(); 79 80 Profile* profile = Profile::FromWebUI(web_ui); 81 content::WebUIDataSource::Add(profile, html_source); 82} 83 84} // namespace performance_monitor 85