Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/crashes_ui.h" | 5 #include "chrome/browser/ui/webui/crashes_ui.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "content/public/browser/web_ui_message_handler.h" | 25 #include "content/public/browser/web_ui_message_handler.h" |
| 26 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
| 27 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 32 | 32 |
| 33 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 34 #include "chrome/browser/chromeos/settings/cros_settings.h" | 34 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 35 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 36 #include "chromeos/dbus/debug_daemon_client.h" | |
| 35 #endif | 37 #endif |
| 36 | 38 |
| 37 using content::WebContents; | 39 using content::WebContents; |
| 38 using content::WebUIMessageHandler; | 40 using content::WebUIMessageHandler; |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 content::WebUIDataSource* CreateCrashesUIHTMLSource() { | 44 content::WebUIDataSource* CreateCrashesUIHTMLSource() { |
| 43 content::WebUIDataSource* source = | 45 content::WebUIDataSource* source = |
| 44 content::WebUIDataSource::Create(chrome::kChromeUICrashesHost); | 46 content::WebUIDataSource::Create(chrome::kChromeUICrashesHost); |
| 45 source->SetUseJsonJSFormatV2(); | 47 source->SetUseJsonJSFormatV2(); |
| 46 | 48 |
| 47 source->AddLocalizedString("crashesTitle", IDS_CRASHES_TITLE); | 49 source->AddLocalizedString("crashesTitle", IDS_CRASHES_TITLE); |
| 48 source->AddLocalizedString("crashCountFormat", | 50 source->AddLocalizedString("crashCountFormat", |
| 49 IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT); | 51 IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT); |
| 50 source->AddLocalizedString("crashHeaderFormat", | 52 source->AddLocalizedString("crashHeaderFormat", |
| 51 IDS_CRASHES_CRASH_HEADER_FORMAT); | 53 IDS_CRASHES_CRASH_HEADER_FORMAT); |
| 52 source->AddLocalizedString("crashTimeFormat", IDS_CRASHES_CRASH_TIME_FORMAT); | 54 source->AddLocalizedString("crashTimeFormat", IDS_CRASHES_CRASH_TIME_FORMAT); |
| 53 source->AddLocalizedString("bugLinkText", IDS_CRASHES_BUG_LINK_LABEL); | 55 source->AddLocalizedString("bugLinkText", IDS_CRASHES_BUG_LINK_LABEL); |
| 54 source->AddLocalizedString("noCrashesMessage", | 56 source->AddLocalizedString("noCrashesMessage", |
| 55 IDS_CRASHES_NO_CRASHES_MESSAGE); | 57 IDS_CRASHES_NO_CRASHES_MESSAGE); |
| 56 source->AddLocalizedString("disabledHeader", IDS_CRASHES_DISABLED_HEADER); | 58 source->AddLocalizedString("disabledHeader", IDS_CRASHES_DISABLED_HEADER); |
| 57 source->AddLocalizedString("disabledMessage", IDS_CRASHES_DISABLED_MESSAGE); | 59 source->AddLocalizedString("disabledMessage", IDS_CRASHES_DISABLED_MESSAGE); |
| 60 source->AddLocalizedString("uploadCrashesLinkText", | |
| 61 IDS_CRASHES_UPLOAD_MESSAGE); | |
| 58 source->SetJsonPath("strings.js"); | 62 source->SetJsonPath("strings.js"); |
| 59 source->AddResourcePath("crashes.js", IDR_CRASHES_JS); | 63 source->AddResourcePath("crashes.js", IDR_CRASHES_JS); |
| 60 source->SetDefaultResource(IDR_CRASHES_HTML); | 64 source->SetDefaultResource(IDR_CRASHES_HTML); |
| 61 return source; | 65 return source; |
| 62 } | 66 } |
| 63 | 67 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 65 // | 69 // |
| 66 // CrashesDOMHandler | 70 // CrashesDOMHandler |
| 67 // | 71 // |
| 68 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 69 | 73 |
| 70 // The handler for Javascript messages for the chrome://crashes/ page. | 74 // The handler for Javascript messages for the chrome://crashes/ page. |
| 71 class CrashesDOMHandler : public WebUIMessageHandler, | 75 class CrashesDOMHandler : public WebUIMessageHandler, |
| 72 public CrashUploadList::Delegate { | 76 public CrashUploadList::Delegate { |
| 73 public: | 77 public: |
| 74 explicit CrashesDOMHandler(); | 78 explicit CrashesDOMHandler(); |
| 75 virtual ~CrashesDOMHandler(); | 79 virtual ~CrashesDOMHandler(); |
| 76 | 80 |
| 77 // WebUIMessageHandler implementation. | 81 // WebUIMessageHandler implementation. |
| 78 virtual void RegisterMessages() OVERRIDE; | 82 virtual void RegisterMessages() OVERRIDE; |
| 79 | 83 |
| 80 // CrashUploadList::Delegate implemenation. | 84 // CrashUploadList::Delegate implemenation. |
| 81 virtual void OnUploadListAvailable() OVERRIDE; | 85 virtual void OnUploadListAvailable() OVERRIDE; |
| 82 | 86 |
| 83 private: | 87 private: |
| 84 // Asynchronously fetches the list of crashes. Called from JS. | 88 // Asynchronously fetches the list of crashes. Called from JS. |
| 85 void HandleRequestCrashes(const ListValue* args); | 89 void HandleRequestCrashes(const ListValue* args); |
| 86 | 90 |
| 91 #if defined(OS_CHROMEOS) | |
| 92 // Asynchronously triggers crash uploading. Called from JS. | |
| 93 void HandleRequestUploads(const ListValue* args); | |
| 94 #endif | |
| 95 | |
| 87 // Sends the recent crashes list JS. | 96 // Sends the recent crashes list JS. |
| 88 void UpdateUI(); | 97 void UpdateUI(); |
| 89 | 98 |
| 90 scoped_refptr<CrashUploadList> upload_list_; | 99 scoped_refptr<CrashUploadList> upload_list_; |
| 91 bool list_available_; | 100 bool list_available_; |
| 92 bool first_load_; | 101 bool first_load_; |
| 93 | 102 |
| 94 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 103 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); |
| 95 }; | 104 }; |
| 96 | 105 |
| 97 CrashesDOMHandler::CrashesDOMHandler() | 106 CrashesDOMHandler::CrashesDOMHandler() |
| 98 : list_available_(false), first_load_(true) { | 107 : list_available_(false), first_load_(true) { |
| 99 upload_list_ = CrashUploadList::Create(this); | 108 upload_list_ = CrashUploadList::Create(this); |
| 100 } | 109 } |
| 101 | 110 |
| 102 CrashesDOMHandler::~CrashesDOMHandler() { | 111 CrashesDOMHandler::~CrashesDOMHandler() { |
| 103 upload_list_->ClearDelegate(); | 112 upload_list_->ClearDelegate(); |
| 104 } | 113 } |
| 105 | 114 |
| 106 void CrashesDOMHandler::RegisterMessages() { | 115 void CrashesDOMHandler::RegisterMessages() { |
| 107 upload_list_->LoadUploadListAsynchronously(); | 116 upload_list_->LoadUploadListAsynchronously(); |
| 108 web_ui()->RegisterMessageCallback("requestCrashList", | 117 web_ui()->RegisterMessageCallback("requestCrashList", |
| 109 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 118 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, |
| 110 base::Unretained(this))); | 119 base::Unretained(this))); |
| 120 | |
| 121 #if defined(OS_CHROMEOS) | |
| 122 web_ui()->RegisterMessageCallback("requestCrashUpload", | |
| 123 base::Bind(&CrashesDOMHandler::HandleRequestUploads, | |
| 124 base::Unretained(this))); | |
| 125 #endif | |
| 111 } | 126 } |
| 112 | 127 |
| 113 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { | 128 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { |
| 114 if (first_load_) { | 129 if (first_load_) { |
| 115 first_load_ = false; | 130 first_load_ = false; |
| 116 if (list_available_) | 131 if (list_available_) |
| 117 UpdateUI(); | 132 UpdateUI(); |
| 118 } else { | 133 } else { |
| 119 list_available_ = false; | 134 list_available_ = false; |
| 120 upload_list_->LoadUploadListAsynchronously(); | 135 upload_list_->LoadUploadListAsynchronously(); |
| 121 } | 136 } |
| 122 } | 137 } |
| 123 | 138 |
| 139 #if defined(OS_CHROMEOS) | |
| 140 void CrashesDOMHandler::HandleRequestUploads(const ListValue* args) { | |
|
Lei Zhang
2013/10/08 20:08:57
Do we care if a user double/triple clicks the link
vapier
2013/10/08 20:16:24
nope. the system crash sender already handles tha
| |
| 141 chromeos::DebugDaemonClient* debugd_client = | |
| 142 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 143 DCHECK(debugd_client); | |
| 144 | |
| 145 debugd_client->UploadCrashes(); | |
| 146 } | |
| 147 #endif | |
| 148 | |
| 124 void CrashesDOMHandler::OnUploadListAvailable() { | 149 void CrashesDOMHandler::OnUploadListAvailable() { |
| 125 list_available_ = true; | 150 list_available_ = true; |
| 126 if (!first_load_) | 151 if (!first_load_) |
| 127 UpdateUI(); | 152 UpdateUI(); |
| 128 } | 153 } |
| 129 | 154 |
| 130 void CrashesDOMHandler::UpdateUI() { | 155 void CrashesDOMHandler::UpdateUI() { |
| 131 bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); | 156 bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); |
| 132 ListValue crash_list; | 157 ListValue crash_list; |
| 133 | 158 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 144 } | 169 } |
| 145 } | 170 } |
| 146 | 171 |
| 147 base::FundamentalValue enabled(crash_reporting_enabled); | 172 base::FundamentalValue enabled(crash_reporting_enabled); |
| 148 | 173 |
| 149 const chrome::VersionInfo version_info; | 174 const chrome::VersionInfo version_info; |
| 150 base::StringValue version(version_info.Version()); | 175 base::StringValue version(version_info.Version()); |
| 151 | 176 |
| 152 web_ui()->CallJavascriptFunction("updateCrashList", enabled, crash_list, | 177 web_ui()->CallJavascriptFunction("updateCrashList", enabled, crash_list, |
| 153 version); | 178 version); |
| 179 | |
| 180 #if defined(OS_CHROMEOS) | |
| 181 web_ui()->CallJavascriptFunction("updateCrashUploadStatus", enabled); | |
| 182 #endif | |
| 154 } | 183 } |
| 155 | 184 |
| 156 } // namespace | 185 } // namespace |
| 157 | 186 |
| 158 /////////////////////////////////////////////////////////////////////////////// | 187 /////////////////////////////////////////////////////////////////////////////// |
| 159 // | 188 // |
| 160 // CrashesUI | 189 // CrashesUI |
| 161 // | 190 // |
| 162 /////////////////////////////////////////////////////////////////////////////// | 191 /////////////////////////////////////////////////////////////////////////////// |
| 163 | 192 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 189 PrefService* prefs = g_browser_process->local_state(); | 218 PrefService* prefs = g_browser_process->local_state(); |
| 190 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 219 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 191 #else | 220 #else |
| 192 PrefService* prefs = g_browser_process->local_state(); | 221 PrefService* prefs = g_browser_process->local_state(); |
| 193 return prefs->GetBoolean(prefs::kMetricsReportingEnabled); | 222 return prefs->GetBoolean(prefs::kMetricsReportingEnabled); |
| 194 #endif | 223 #endif |
| 195 #else | 224 #else |
| 196 return false; | 225 return false; |
| 197 #endif | 226 #endif |
| 198 } | 227 } |
| OLD | NEW |