Skip to content

Commit

Permalink
Move crashes_ui resources and utils to //components/crash
Browse files Browse the repository at this point in the history
TBR=jochen

Review URL: https://codereview.chromium.org/1389913002

Cr-Commit-Position: refs/heads/master@{#353044}
  • Loading branch information
droger authored and Commit bot committed Oct 8, 2015
1 parent 2cbf915 commit b7e240e
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 53 deletions.
1 change: 0 additions & 1 deletion build/ios/grit_whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ IDR_POLICY_HTML
IDR_POLICY_JS
IDR_PREF_HASH_SEED_BIN
IDR_PRINTER_FAVICON
IDR_SAD_FAVICON
IDR_SAD_TAB
IDR_SIGNIN_INTERNALS_INDEX_HTML
IDR_SIGNIN_INTERNALS_INDEX_JS
Expand Down
1 change: 0 additions & 1 deletion chrome/app/theme/theme_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@
<structure type="chrome_scaled_image" name="IDR_RELOAD_P" file="common/browser_reload_pressed.png" />
</if>
<structure type="chrome_scaled_image" name="IDR_RESTORE_BUTTON_MASK" file="common/restore_button_mask.png" />
<structure type="chrome_scaled_image" name="IDR_SAD_FAVICON" file="common/favicon_sad_tab.png" />
<if expr="is_macosx">
<structure type="chrome_scaled_image" name="IDR_SAD_TAB" file="legacy/sadtab.png" />
</if>
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ source_set("ui") {
"//chrome/installer/util",
"//components/autofill/content/browser:risk_proto",
"//components/bubble:bubble",
"//components/crash/core/browser",
"//components/net_log",
"//components/page_load_metrics/browser",
"//components/power",
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "grit/components_scaled_resources.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h"
Expand Down Expand Up @@ -1578,8 +1579,9 @@ - (void)updateIconsForContents:(content::WebContents*)contents
ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_THROBBER).CopyNSImage();
static NSImage* sadFaviconImage =
ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_SAD_FAVICON).CopyNSImage();
ResourceBundle::GetSharedInstance()
.GetNativeImageNamed(IDR_CRASH_SAD_FAVICON)
.CopyNSImage();

// Take closing tabs into account.
NSInteger index = [self indexFromModelIndex:modelIndex];
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/ui/views/tabs/tab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/user_metrics.h"
#include "grit/components_scaled_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/accessibility/ax_view_state.h"
Expand Down Expand Up @@ -1372,7 +1373,8 @@ void Tab::PaintIcon(gfx::Canvas* canvas) {
} else if (should_display_crashed_favicon_) {
// Paint crash favicon.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON));
gfx::ImageSkia crashed_favicon(
*rb.GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON));
bounds.set_y(bounds.y() + favicon_hiding_offset_);
DrawIconCenter(canvas, crashed_favicon, 0,
crashed_favicon.width(),
Expand Down
65 changes: 23 additions & 42 deletions chrome/browser/ui/webui/crashes_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

#include "chrome/browser/ui/webui/crashes_ui.h"

#include <vector>

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/i18n/time_formatting.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
Expand All @@ -19,6 +16,7 @@
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/google_chrome_strings.h"
#include "components/crash/core/browser/crashes_ui_util.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
Expand All @@ -28,8 +26,8 @@
#include "grit/components_chromium_strings.h"
#include "grit/components_google_chrome_strings.h"
#include "grit/components_resources.h"
#include "grit/components_scaled_resources.h"
#include "grit/components_strings.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"

#if defined(OS_CHROMEOS)
Expand All @@ -46,22 +44,16 @@ content::WebUIDataSource* CreateCrashesUIHTMLSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUICrashesHost);

source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME);
source->AddLocalizedString("crashesTitle", IDS_CRASH_TITLE);
source->AddLocalizedString("crashCountFormat",
IDS_CRASH_CRASH_COUNT_BANNER_FORMAT);
source->AddLocalizedString("crashHeaderFormat",
IDS_CRASH_CRASH_HEADER_FORMAT);
source->AddLocalizedString("crashTimeFormat", IDS_CRASH_CRASH_TIME_FORMAT);
source->AddLocalizedString("bugLinkText", IDS_CRASH_BUG_LINK_LABEL);
source->AddLocalizedString("noCrashesMessage",
IDS_CRASH_NO_CRASHES_MESSAGE);
source->AddLocalizedString("disabledHeader", IDS_CRASH_DISABLED_HEADER);
source->AddLocalizedString("disabledMessage", IDS_CRASH_DISABLED_MESSAGE);
source->AddLocalizedString("uploadCrashesLinkText",
IDS_CRASH_UPLOAD_MESSAGE);
for (size_t i = 0; i < crash::kCrashesUILocalizedStringsCount; ++i) {
source->AddLocalizedString(
crash::kCrashesUILocalizedStrings[i].name,
crash::kCrashesUILocalizedStrings[i].resource_id);
}

source->AddLocalizedString(crash::kCrashesUIShortProductName,
IDS_SHORT_PRODUCT_NAME);
source->SetJsonPath("strings.js");
source->AddResourcePath("crashes.js", IDR_CRASH_CRASHES_JS);
source->AddResourcePath(crash::kCrashesUICrashesJS, IDR_CRASH_CRASHES_JS);
source->SetDefaultResource(IDR_CRASH_CRASHES_HTML);
return source;
}
Expand Down Expand Up @@ -115,12 +107,14 @@ CrashesDOMHandler::~CrashesDOMHandler() {

void CrashesDOMHandler::RegisterMessages() {
upload_list_->LoadUploadListAsynchronously();
web_ui()->RegisterMessageCallback("requestCrashList",
web_ui()->RegisterMessageCallback(
crash::kCrashesUIRequestCrashList,
base::Bind(&CrashesDOMHandler::HandleRequestCrashes,
base::Unretained(this)));

#if defined(OS_CHROMEOS)
web_ui()->RegisterMessageCallback("requestCrashUpload",
web_ui()->RegisterMessageCallback(
crash::kCrashesUIRequestCrashUpload,
base::Bind(&CrashesDOMHandler::HandleRequestUploads,
base::Unretained(this)));
#endif
Expand Down Expand Up @@ -156,35 +150,22 @@ void CrashesDOMHandler::OnUploadListAvailable() {
void CrashesDOMHandler::UpdateUI() {
bool crash_reporting_enabled =
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
base::ListValue crash_list;
bool system_crash_reporter = false;

bool system_crash_reporter = false;
#if defined(OS_CHROMEOS)
// Chrome OS has a system crash reporter.
system_crash_reporter = true;
#endif

if (crash_reporting_enabled) {
std::vector<CrashUploadList::UploadInfo> crashes;
upload_list_->GetUploads(50, &crashes);

for (std::vector<CrashUploadList::UploadInfo>::iterator i = crashes.begin();
i != crashes.end(); ++i) {
base::DictionaryValue* crash = new base::DictionaryValue();
crash->SetString("id", i->id);
crash->SetString("time", base::TimeFormatFriendlyDateAndTime(i->time));
crash->SetString("local_id", i->local_id);
crash_list.Append(crash);
}
}
base::ListValue crash_list;
if (crash_reporting_enabled)
crash::UploadListToValue(upload_list_.get(), &crash_list);

base::FundamentalValue enabled(crash_reporting_enabled);
base::FundamentalValue dynamic_backend(system_crash_reporter);

base::StringValue version(version_info::GetVersionNumber());

web_ui()->CallJavascriptFunction("updateCrashList", enabled, dynamic_backend,
crash_list, version);
web_ui()->CallJavascriptFunction(crash::kCrashesUIUpdateCrashList, enabled,
dynamic_backend, crash_list, version);
}

} // namespace
Expand All @@ -206,6 +187,6 @@ CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) {
// static
base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes(
ui::ScaleFactor scale_factor) {
return ResourceBundle::GetSharedInstance().
LoadDataResourceBytesForScale(IDR_SAD_FAVICON, scale_factor);
return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
IDR_CRASH_SAD_FAVICON, scale_factor);
}
1 change: 1 addition & 0 deletions chrome/chrome_browser_ui.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,7 @@
'installer_util',
'../components/components.gyp:app_modal',
'../components/components.gyp:autofill_content_risk_proto',
'../components/components.gyp:crash_core_browser',
'../components/components.gyp:flags_ui',
'../components/components.gyp:net_log',
'../components/components.gyp:page_load_metrics_browser',
Expand Down
17 changes: 17 additions & 0 deletions components/crash.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

{
'targets': [
{
# GN version: //components/crash/core/browser
'target_name': 'crash_core_browser',
'type': 'static_library',
'include_dirs': [
'..',
],
'dependencies': [
'upload_list',
'../base/base.gyp:base',
'../components/components_strings.gyp:components_strings',
],
'sources': [
'crash/core/browser/crashes_ui_util.cc',
'crash/core/browser/crashes_ui_util.h',
],
},
{
# GN version: //components/crash/core/common
'target_name': 'crash_core_common',
Expand Down
15 changes: 15 additions & 0 deletions components/crash/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2015 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.

source_set("browser") {
sources = [
"crashes_ui_util.cc",
"crashes_ui_util.h",
]
deps = [
"//base",
"//components/strings",
"//components/upload_list",
]
}
6 changes: 6 additions & 0 deletions components/crash/core/browser/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include_rules = [
"+components/upload_list",
"+grit/components_chromium_strings.h",
"+grit/components_google_chrome_strings.h",
"+grit/components_strings.h",
]
53 changes: 53 additions & 0 deletions components/crash/core/browser/crashes_ui_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2015 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 "components/crash/core/browser/crashes_ui_util.h"

#include <vector>

#include "base/i18n/time_formatting.h"
#include "base/macros.h"
#include "base/values.h"
#include "components/upload_list/upload_list.h"
#include "grit/components_chromium_strings.h"
#include "grit/components_google_chrome_strings.h"
#include "grit/components_strings.h"

namespace crash {

const CrashesUILocalizedString kCrashesUILocalizedStrings[] = {
{"bugLinkText", IDS_CRASH_BUG_LINK_LABEL},
{"crashCountFormat", IDS_CRASH_CRASH_COUNT_BANNER_FORMAT},
{"crashHeaderFormat", IDS_CRASH_CRASH_HEADER_FORMAT},
{"crashTimeFormat", IDS_CRASH_CRASH_TIME_FORMAT},
{"crashesTitle", IDS_CRASH_TITLE},
{"disabledHeader", IDS_CRASH_DISABLED_HEADER},
{"disabledMessage", IDS_CRASH_DISABLED_MESSAGE},
{"noCrashesMessage", IDS_CRASH_NO_CRASHES_MESSAGE},
{"uploadCrashesLinkText", IDS_CRASH_UPLOAD_MESSAGE},
};

const size_t kCrashesUILocalizedStringsCount =
arraysize(kCrashesUILocalizedStrings);

const char kCrashesUICrashesJS[] = "crashes.js";
const char kCrashesUIRequestCrashList[] = "requestCrashList";
const char kCrashesUIRequestCrashUpload[] = "requestCrashUpload";
const char kCrashesUIShortProductName[] = "shortProductName";
const char kCrashesUIUpdateCrashList[] = "updateCrashList";

void UploadListToValue(UploadList* upload_list, base::ListValue* out_value) {
std::vector<UploadList::UploadInfo> crashes;
upload_list->GetUploads(50, &crashes);

for (const auto& info : crashes) {
base::DictionaryValue* crash = new base::DictionaryValue();
crash->SetString("id", info.id);
crash->SetString("time", base::TimeFormatFriendlyDateAndTime(info.time));
crash->SetString("local_id", info.local_id);
out_value->Append(crash);
}
}

} // namespace crash
42 changes: 42 additions & 0 deletions components/crash/core/browser/crashes_ui_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2015 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.

#ifndef COMPONENTS_CRASH_CORE_BROWSER_CRASHES_UI_UTIL_H_
#define COMPONENTS_CRASH_CORE_BROWSER_CRASHES_UI_UTIL_H_

#include <stddef.h>

namespace base {
class ListValue;
}

class UploadList;

namespace crash {

// Mapping between a WebUI resource (identified by |name|) and a GRIT resource
// (identified by |resource_id|).
struct CrashesUILocalizedString {
const char* name;
int resource_id;
};

// List of localized strings that must be added to the WebUI.
extern const CrashesUILocalizedString kCrashesUILocalizedStrings[];
extern const size_t kCrashesUILocalizedStringsCount;

// Strings used by the WebUI resources.
// Must match the constants used in the resource files.
extern const char kCrashesUICrashesJS[];
extern const char kCrashesUIRequestCrashList[];
extern const char kCrashesUIRequestCrashUpload[];
extern const char kCrashesUIShortProductName[];
extern const char kCrashesUIUpdateCrashList[];

// Converts and appends the most recent uploads to |out_value|.
void UploadListToValue(UploadList* upload_list, base::ListValue* out_value);

} // namespace crash

#endif // COMPONENTS_CRASH_CORE_BROWSER_CRASHES_UI_UTIL_H_
12 changes: 6 additions & 6 deletions components/resources/OWNERS
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
per-file autofill_scaled_resources.grdp=estade@chromium.org
per-file crash_resources.grdp=cpu@chromium.org
per-file crash_resources.grdp=jochen@chromium.org
per-file crash_resources.grdp=mark@chromium.org
per-file crash_resources.grdp=rsesek@chromium.org
per-file crash_resources.grdp=scottmg@chromium.org
per-file crash_resources.grdp=thestig@chromium.org
per-file crash_*=cpu@chromium.org
per-file crash_*=jochen@chromium.org
per-file crash_*=mark@chromium.org
per-file crash_*=rsesek@chromium.org
per-file crash_*=scottmg@chromium.org
per-file crash_*=thestig@chromium.org
per-file data_reduction_proxy*=bengr@chromium.org
per-file data_reduction_proxy*=sclittle@chromium.org
per-file data_reduction_proxy*=megjablon@chromium.org
Expand Down
1 change: 1 addition & 0 deletions components/resources/components_scaled_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<release seq="1">
<structures fallback_to_low_resolution="true">
<part file="autofill_scaled_resources.grdp" />
<part file="crash_scaled_resources.grdp" />
<part file="omnibox_scaled_resources.grdp" />
</structures>
</release>
Expand Down
4 changes: 4 additions & 0 deletions components/resources/crash_scaled_resources.grdp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<structure type="chrome_scaled_image" name="IDR_CRASH_SAD_FAVICON" file="crash/favicon_sad_tab.png" />
</grit-part>

0 comments on commit b7e240e

Please sign in to comment.