Skip to content

Commit

Permalink
Link to crashes/ for internal accounts
Browse files Browse the repository at this point in the history
Make the crash ID clickable for Googlers and redirect to http://crash/crash_id


Fixed: 1009148
Change-Id: Icf26d9c7ac2bf78beb00a17d5a85d50c29c94ecb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888534
Commit-Queue: Joon Ahn <joonbug@chromium.org>
Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: calamity <calamity@chromium.org>
Reviewed-by: Ian Barkley-Yeung <iby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714031}
  • Loading branch information
Joon Ahn authored and Commit Bot committed Nov 9, 2019
1 parent 1b92767 commit f5590fb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
15 changes: 14 additions & 1 deletion chrome/browser/ui/webui/crashes_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "components/crash/core/browser/crashes_ui_util.h"
#include "components/grit/components_resources.h"
#include "components/grit/components_scaled_resources.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "ui/base/resource/resource_bundle.h"

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -181,6 +184,14 @@ void CrashesDOMHandler::UpdateUI() {
using_crashpad = crash_reporter::IsCrashpadEnabled();
#endif

bool is_internal = false;
auto* identity_manager =
IdentityManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()));
if (identity_manager) {
is_internal = gaia::IsGoogleInternalAccountEmail(
identity_manager->GetPrimaryAccountInfo().email);
}

// Manual uploads currently are supported only for Crashpad-using platforms
// and only if crash uploads are not disabled by policy.
bool support_manual_uploads =
Expand All @@ -201,6 +212,7 @@ void CrashesDOMHandler::UpdateUI() {
base::Value version(version_info::GetVersionNumber());
base::Value os_string(base::SysInfo::OperatingSystemName() + " " +
base::SysInfo::OperatingSystemVersion());
base::Value is_google_account(is_internal);

std::vector<const base::Value*> args;
args.push_back(&enabled);
Expand All @@ -209,6 +221,7 @@ void CrashesDOMHandler::UpdateUI() {
args.push_back(&crash_list);
args.push_back(&version);
args.push_back(&os_string);
args.push_back(&is_google_account);
web_ui()->CallJavascriptFunctionUnsafe(
crash_reporter::kCrashesUIUpdateCrashList, args);
}
Expand Down Expand Up @@ -247,7 +260,7 @@ CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) {

// static
base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes(
ui::ScaleFactor scale_factor) {
ui::ScaleFactor scale_factor) {
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
IDR_CRASH_SAD_FAVICON, scale_factor);
}
23 changes: 19 additions & 4 deletions components/crash/core/browser/resources/crashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ function requestCrashes() {
* @param {array} crashes The list of crashes.
* @param {string} version The browser version.
* @param {string} os The OS name and version.
* @param {boolean} isGoogleAccount whether primary account is internal.
*/
function updateCrashList(
enabled, dynamicBackend, manualUploads,
crashes, version, os) {
crashes, version, os, isGoogleAccount) {
$('countBanner').textContent =
loadTimeData.getStringF('crashCountFormat',
crashes.length.toLocaleString());
Expand Down Expand Up @@ -55,9 +56,23 @@ function updateCrashList(
var title = document.createElement('h3');
var uploaded = crash.state == 'uploaded';
if (uploaded) {
title.textContent = loadTimeData.getStringF('crashHeaderFormat',
crash.id,
crash.local_id);
const crashHeaderText = loadTimeData.getString('crashHeaderFormat');
const pieces = loadTimeData
.getSubstitutedStringPieces(
crashHeaderText, crash.id, crash.local_id)
.map(piece => {
// Create crash/ link for Googler Accounts.
if (isGoogleAccount && piece.value === crash.id) {
const crashLink = document.createElement('a');
crashLink.href = `http://crash/${crash.id}`;
crashLink.target = '_blank';
crashLink.textContent = crash.id;
return crashLink;
} else {
return piece.value;
}
});
title.append.apply(title, pieces);
} else {
title.textContent = loadTimeData.getStringF('crashHeaderFormatLocalOnly',
crash.local_id);
Expand Down
5 changes: 5 additions & 0 deletions google_apis/gaia/gaia_auth_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace gaia {
namespace {

const char kGmailDomain[] = "gmail.com";
const char kGoogleDomain[] = "google.com";
const char kGooglemailDomain[] = "googlemail.com";

const void* const kURLRequestUserDataKey = &kURLRequestUserDataKey;
Expand Down Expand Up @@ -105,6 +106,10 @@ std::string ExtractDomainName(const std::string& email_address) {
return std::string();
}

bool IsGoogleInternalAccountEmail(const std::string& email) {
return ExtractDomainName(email) == kGoogleDomain;
}

bool IsGaiaSignonRealm(const GURL& url) {
if (!url.SchemeIsCryptographic())
return false;
Expand Down
4 changes: 4 additions & 0 deletions google_apis/gaia/gaia_auth_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ bool AreEmailsSame(const std::string& email1, const std::string& email2);
// Extract the domain part from the canonical form of the given email.
std::string ExtractDomainName(const std::string& email);

// Returns whether the user's email is Google internal. This check is meant
// to be used sparingly since it ship Googler-only code to all users.
bool IsGoogleInternalAccountEmail(const std::string& email);

bool IsGaiaSignonRealm(const GURL& url);

// Parses JSON data returned by /ListAccounts call, returning a vector of
Expand Down
5 changes: 5 additions & 0 deletions google_apis/gaia/gaia_auth_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ TEST(GaiaAuthUtilTest, ExtractDomainName) {
EXPECT_EQ(domain, ExtractDomainName("who@EXAMPLE.cOm"));
}

TEST(GaiaAuthUtilTest, IsGoogleInternalAccountEmail) {
EXPECT_TRUE(IsGoogleInternalAccountEmail("hello@google.com"));
EXPECT_FALSE(IsGoogleInternalAccountEmail("internal@gmail.com"));
}

TEST(GaiaAuthUtilTest, SanitizeMissingDomain) {
EXPECT_EQ("nodomain@gmail.com", SanitizeEmail("nodomain"));
}
Expand Down

0 comments on commit f5590fb

Please sign in to comment.