| 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", IDS_CRASHES_UPLOAD_MESSAGE
     ); | 
| 58   source->SetJsonPath("strings.js"); | 61   source->SetJsonPath("strings.js"); | 
| 59   source->AddResourcePath("crashes.js", IDR_CRASHES_JS); | 62   source->AddResourcePath("crashes.js", IDR_CRASHES_JS); | 
| 60   source->SetDefaultResource(IDR_CRASHES_HTML); | 63   source->SetDefaultResource(IDR_CRASHES_HTML); | 
| 61   return source; | 64   return source; | 
| 62 } | 65 } | 
| 63 | 66 | 
| 64 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// | 
| 65 // | 68 // | 
| 66 // CrashesDOMHandler | 69 // CrashesDOMHandler | 
| 67 // | 70 // | 
| 68 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// | 
| 69 | 72 | 
| 70 // The handler for Javascript messages for the chrome://crashes/ page. | 73 // The handler for Javascript messages for the chrome://crashes/ page. | 
| 71 class CrashesDOMHandler : public WebUIMessageHandler, | 74 class CrashesDOMHandler : public WebUIMessageHandler, | 
| 72                           public CrashUploadList::Delegate { | 75                           public CrashUploadList::Delegate { | 
| 73  public: | 76  public: | 
| 74   explicit CrashesDOMHandler(); | 77   explicit CrashesDOMHandler(); | 
| 75   virtual ~CrashesDOMHandler(); | 78   virtual ~CrashesDOMHandler(); | 
| 76 | 79 | 
| 77   // WebUIMessageHandler implementation. | 80   // WebUIMessageHandler implementation. | 
| 78   virtual void RegisterMessages() OVERRIDE; | 81   virtual void RegisterMessages() OVERRIDE; | 
| 79 | 82 | 
| 80   // CrashUploadList::Delegate implemenation. | 83   // CrashUploadList::Delegate implemenation. | 
| 81   virtual void OnUploadListAvailable() OVERRIDE; | 84   virtual void OnUploadListAvailable() OVERRIDE; | 
| 82 | 85 | 
| 83  private: | 86  private: | 
| 84   // Asynchronously fetches the list of crashes. Called from JS. | 87   // Asynchronously fetches the list of crashes. Called from JS. | 
| 85   void HandleRequestCrashes(const ListValue* args); | 88   void HandleRequestCrashes(const ListValue* args); | 
| 86 | 89 | 
|  | 90 #if defined(OS_CHROMEOS) | 
|  | 91   // Asynchronously triggers crash uploading. Called from JS. | 
|  | 92   void HandleRequestUploads(const ListValue* args); | 
|  | 93 #endif | 
|  | 94 | 
| 87   // Sends the recent crashes list JS. | 95   // Sends the recent crashes list JS. | 
| 88   void UpdateUI(); | 96   void UpdateUI(); | 
| 89 | 97 | 
| 90   scoped_refptr<CrashUploadList> upload_list_; | 98   scoped_refptr<CrashUploadList> upload_list_; | 
| 91   bool list_available_; | 99   bool list_available_; | 
| 92   bool first_load_; | 100   bool first_load_; | 
| 93 | 101 | 
| 94   DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 102   DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 
| 95 }; | 103 }; | 
| 96 | 104 | 
| 97 CrashesDOMHandler::CrashesDOMHandler() | 105 CrashesDOMHandler::CrashesDOMHandler() | 
| 98     : list_available_(false), first_load_(true) { | 106     : list_available_(false), first_load_(true) { | 
| 99   upload_list_ = CrashUploadList::Create(this); | 107   upload_list_ = CrashUploadList::Create(this); | 
| 100 } | 108 } | 
| 101 | 109 | 
| 102 CrashesDOMHandler::~CrashesDOMHandler() { | 110 CrashesDOMHandler::~CrashesDOMHandler() { | 
| 103   upload_list_->ClearDelegate(); | 111   upload_list_->ClearDelegate(); | 
| 104 } | 112 } | 
| 105 | 113 | 
| 106 void CrashesDOMHandler::RegisterMessages() { | 114 void CrashesDOMHandler::RegisterMessages() { | 
| 107   upload_list_->LoadUploadListAsynchronously(); | 115   upload_list_->LoadUploadListAsynchronously(); | 
| 108   web_ui()->RegisterMessageCallback("requestCrashList", | 116   web_ui()->RegisterMessageCallback("requestCrashList", | 
| 109       base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 117       base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 
| 110                  base::Unretained(this))); | 118                  base::Unretained(this))); | 
|  | 119 | 
|  | 120 #if defined(OS_CHROMEOS) | 
|  | 121   web_ui()->RegisterMessageCallback("requestCrashUpload", | 
|  | 122       base::Bind(&CrashesDOMHandler::HandleRequestUploads, | 
|  | 123                  base::Unretained(this))); | 
|  | 124 #endif | 
| 111 } | 125 } | 
| 112 | 126 | 
| 113 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { | 127 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { | 
| 114   if (first_load_) { | 128   if (first_load_) { | 
| 115     first_load_ = false; | 129     first_load_ = false; | 
| 116     if (list_available_) | 130     if (list_available_) | 
| 117       UpdateUI(); | 131       UpdateUI(); | 
| 118   } else { | 132   } else { | 
| 119     list_available_ = false; | 133     list_available_ = false; | 
| 120     upload_list_->LoadUploadListAsynchronously(); | 134     upload_list_->LoadUploadListAsynchronously(); | 
| 121   } | 135   } | 
| 122 } | 136 } | 
| 123 | 137 | 
|  | 138 #if defined(OS_CHROMEOS) | 
|  | 139 void CrashesDOMHandler::HandleRequestUploads(const ListValue* args) { | 
|  | 140   chromeos::DebugDaemonClient* debugd_client = | 
|  | 141       chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 
|  | 142   DCHECK(debugd_client); | 
|  | 143 | 
|  | 144   debugd_client->UploadCrashes(); | 
|  | 145 } | 
|  | 146 #endif | 
|  | 147 | 
| 124 void CrashesDOMHandler::OnUploadListAvailable() { | 148 void CrashesDOMHandler::OnUploadListAvailable() { | 
| 125   list_available_ = true; | 149   list_available_ = true; | 
| 126   if (!first_load_) | 150   if (!first_load_) | 
| 127     UpdateUI(); | 151     UpdateUI(); | 
| 128 } | 152 } | 
| 129 | 153 | 
| 130 void CrashesDOMHandler::UpdateUI() { | 154 void CrashesDOMHandler::UpdateUI() { | 
| 131   bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); | 155   bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); | 
| 132   ListValue crash_list; | 156   ListValue crash_list; | 
| 133 | 157 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 144     } | 168     } | 
| 145   } | 169   } | 
| 146 | 170 | 
| 147   base::FundamentalValue enabled(crash_reporting_enabled); | 171   base::FundamentalValue enabled(crash_reporting_enabled); | 
| 148 | 172 | 
| 149   const chrome::VersionInfo version_info; | 173   const chrome::VersionInfo version_info; | 
| 150   base::StringValue version(version_info.Version()); | 174   base::StringValue version(version_info.Version()); | 
| 151 | 175 | 
| 152   web_ui()->CallJavascriptFunction("updateCrashList", enabled, crash_list, | 176   web_ui()->CallJavascriptFunction("updateCrashList", enabled, crash_list, | 
| 153                                    version); | 177                                    version); | 
|  | 178 | 
|  | 179 #if defined(OS_CHROMEOS) | 
|  | 180   web_ui()->CallJavascriptFunction("updateCrashUploadStatus", enabled); | 
|  | 181 #endif | 
| 154 } | 182 } | 
| 155 | 183 | 
| 156 }  // namespace | 184 }  // namespace | 
| 157 | 185 | 
| 158 /////////////////////////////////////////////////////////////////////////////// | 186 /////////////////////////////////////////////////////////////////////////////// | 
| 159 // | 187 // | 
| 160 // CrashesUI | 188 // CrashesUI | 
| 161 // | 189 // | 
| 162 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// | 
| 163 | 191 | 
| 164 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 192 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 
| 165   web_ui->AddMessageHandler(new CrashesDOMHandler()); | 193   web_ui->AddMessageHandler(new CrashesDOMHandler()); | 
| 166 | 194 | 
| 167   // Set up the chrome://crashes/ source. | 195   // Set up the chrome://crashes/ source. | 
| 168   Profile* profile = Profile::FromWebUI(web_ui); | 196   Profile* profile = Profile::FromWebUI(web_ui); | 
| 169   content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); | 197   content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); | 
| 170 } | 198 } | 
| 171 | 199 | 
| 172 // static | 200 // static | 
| 173 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( | 201 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( | 
| 174       ui::ScaleFactor scale_factor) { | 202       ui::ScaleFactor scale_factor) { | 
| 175   return ResourceBundle::GetSharedInstance(). | 203   return ResourceBundle::GetSharedInstance(). | 
| 176       LoadDataResourceBytesForScale(IDR_SAD_FAVICON, scale_factor); | 204       LoadDataResourceBytesForScale(IDR_SAD_FAVICON, scale_factor); | 
| 177 } | 205 } | 
| 178 | 206 | 
| 179 // static | 207 // static | 
| 180 bool CrashesUI::CrashReportingUIEnabled() { | 208 bool CrashesUI::CrashReportingUIEnabled() { | 
|  | 209   return true; | 
| 181 #if defined(GOOGLE_CHROME_BUILD) | 210 #if defined(GOOGLE_CHROME_BUILD) | 
| 182 #if defined(OS_CHROMEOS) | 211 #if defined(OS_CHROMEOS) | 
| 183   bool reporting_enabled = false; | 212   bool reporting_enabled = false; | 
| 184   chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 213   chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 
| 185                                             &reporting_enabled); | 214                                             &reporting_enabled); | 
| 186   return reporting_enabled; | 215   return reporting_enabled; | 
| 187 #elif defined(OS_ANDROID) | 216 #elif defined(OS_ANDROID) | 
| 188   // Android has it's own setings for metrics / crash uploading. | 217   // Android has it's own setings for metrics / crash uploading. | 
| 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 | 
|---|