Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: chrome/browser/ui/webui/feedback_ui.cc

Issue 9006003: Refactor and fix feedback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2011 -> 2012 Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/bug_report_ui.h" 5 #include "chrome/browser/ui/webui/feedback_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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/bug_report_data.h" 17 #include "chrome/browser/feedback/feedback_data.h"
18 #include "chrome/browser/bug_report_util.h" 18 #include "chrome/browser/feedback/feedback_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
25 #include "chrome/browser/ui/webui/screenshot_source.h" 25 #include "chrome/browser/ui/webui/screenshot_source.h"
26 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 26 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 chromeos::UserManager* manager = chromeos::UserManager::Get(); 104 chromeos::UserManager* manager = chromeos::UserManager::Get();
105 if (!manager) 105 if (!manager)
106 return std::string(); 106 return std::string();
107 else 107 else
108 return manager->logged_in_user().display_email(); 108 return manager->logged_in_user().display_email();
109 } 109 }
110 #endif 110 #endif
111 111
112 // Returns the index of the feedback tab if already open, -1 otherwise 112 // Returns the index of the feedback tab if already open, -1 otherwise
113 int GetIndexOfFeedbackTab(Browser* browser) { 113 int GetIndexOfFeedbackTab(Browser* browser) {
114 GURL bug_report_url(chrome::kChromeUIBugReportURL); 114 GURL feedback_url(chrome::kChromeUIFeedbackURL);
115 for (int i = 0; i < browser->tab_count(); ++i) { 115 for (int i = 0; i < browser->tab_count(); ++i) {
116 WebContents* tab = browser->GetTabContentsWrapperAt(i)->web_contents(); 116 WebContents* tab = browser->GetTabContentsWrapperAt(i)->web_contents();
117 if (tab && tab->GetURL().GetWithEmptyPath() == bug_report_url) 117 if (tab && tab->GetURL().GetWithEmptyPath() == feedback_url)
118 return i; 118 return i;
119 } 119 }
120 120
121 return -1; 121 return -1;
122 } 122 }
123 123
124 } // namespace 124 } // namespace
125 125
126 126
127 namespace browser { 127 namespace browser {
128 128
129 void ShowHtmlBugReportView(Browser* browser, 129 void ShowHtmlFeedbackView(Browser* browser,
130 const std::string& description_template, 130 const std::string& description_template,
131 size_t issue_type) { 131 const std::string& category_tag) {
132 // First check if we're already open (we cannot depend on ShowSingletonTab 132 // First check if we're already open (we cannot depend on ShowSingletonTab
133 // for this functionality since we need to make *sure* we never get 133 // for this functionality since we need to make *sure* we never get
134 // instantiated again while we are open - with singleton tabs, that can 134 // instantiated again while we are open - with singleton tabs, that can
135 // happen) 135 // happen)
136 int feedback_tab_index = GetIndexOfFeedbackTab(browser); 136 int feedback_tab_index = GetIndexOfFeedbackTab(browser);
137 if (feedback_tab_index >= 0) { 137 if (feedback_tab_index >= 0) {
138 // Do not refresh screenshot, do not create a new tab 138 // Do not refresh screenshot, do not create a new tab
139 browser->ActivateTabAt(feedback_tab_index, true); 139 browser->ActivateTabAt(feedback_tab_index, true);
140 return; 140 return;
141 } 141 }
142 142
143 std::vector<unsigned char>* last_screenshot_png = 143 std::vector<unsigned char>* last_screenshot_png =
144 BugReportUtil::GetScreenshotPng(); 144 FeedbackUtil::GetScreenshotPng();
145 last_screenshot_png->clear(); 145 last_screenshot_png->clear();
146 146
147 gfx::NativeWindow native_window = browser->window()->GetNativeHandle(); 147 gfx::NativeWindow native_window = browser->window()->GetNativeHandle();
148 gfx::Rect snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); 148 gfx::Rect snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size());
149 bool success = browser::GrabWindowSnapshot(native_window, 149 bool success = browser::GrabWindowSnapshot(native_window,
150 last_screenshot_png, 150 last_screenshot_png,
151 snapshot_bounds); 151 snapshot_bounds);
152 BugReportUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); 152 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect());
153 153
154 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + 154 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) +
155 "#" + base::IntToString(browser->active_index()) + 155 "#" + base::IntToString(browser->active_index()) +
156 "?description=" + net::EscapeUrlEncodedData(description_template, false) + 156 "?description=" + net::EscapeUrlEncodedData(description_template, false) +
157 "&issueType=" + base::IntToString(issue_type); 157 "&categoryTag=" + net::EscapeUrlEncodedData(category_tag, false);
158 browser->ShowSingletonTab(GURL(bug_report_url)); 158 browser->ShowSingletonTab(GURL(feedback_url));
159 } 159 }
160 160
161 } // namespace browser 161 } // namespace browser
162 162
163 // The handler for Javascript messages related to the "bug report" dialog 163 // The handler for Javascript messages related to the "bug report" dialog
164 class BugReportHandler : public WebUIMessageHandler, 164 class FeedbackHandler : public WebUIMessageHandler,
165 public base::SupportsWeakPtr<BugReportHandler> { 165 public base::SupportsWeakPtr<FeedbackHandler> {
166 public: 166 public:
167 explicit BugReportHandler(content::WebContents* tab); 167 explicit FeedbackHandler(content::WebContents* tab);
168 virtual ~BugReportHandler(); 168 virtual ~FeedbackHandler();
169 169
170 // Init work after Attach. Returns true on success. 170 // Init work after Attach. Returns true on success.
171 bool Init(); 171 bool Init();
172 172
173 // WebUIMessageHandler implementation. 173 // WebUIMessageHandler implementation.
174 virtual void RegisterMessages() OVERRIDE; 174 virtual void RegisterMessages() OVERRIDE;
175 175
176 private: 176 private:
177 void HandleGetDialogDefaults(const ListValue* args); 177 void HandleGetDialogDefaults(const ListValue* args);
178 void HandleRefreshCurrentScreenshot(const ListValue* args); 178 void HandleRefreshCurrentScreenshot(const ListValue* args);
179 #if defined(OS_CHROMEOS) 179 #if defined(OS_CHROMEOS)
180 void HandleRefreshSavedScreenshots(const ListValue* args); 180 void HandleRefreshSavedScreenshots(const ListValue* args);
181 #endif 181 #endif
182 void HandleSendReport(const ListValue* args); 182 void HandleSendReport(const ListValue* args);
183 void HandleCancel(const ListValue* args); 183 void HandleCancel(const ListValue* args);
184 void HandleOpenSystemTab(const ListValue* args); 184 void HandleOpenSystemTab(const ListValue* args);
185 185
186 void SetupScreenshotsSource(); 186 void SetupScreenshotsSource();
187 void ClobberScreenshotsSource(); 187 void ClobberScreenshotsSource();
188 188
189 void CancelFeedbackCollection(); 189 void CancelFeedbackCollection();
190 void CloseFeedbackTab(); 190 void CloseFeedbackTab();
191 191
192 WebContents* tab_; 192 WebContents* tab_;
193 ScreenshotSource* screenshot_source_; 193 ScreenshotSource* screenshot_source_;
194 194
195 BugReportData* bug_report_data_; 195 FeedbackData* feedback_data_;
196 std::string target_tab_url_; 196 std::string target_tab_url_;
197 #if defined(OS_CHROMEOS) 197 #if defined(OS_CHROMEOS)
198 // Variables to track SyslogsProvider::RequestSyslogs callback. 198 // Variables to track SyslogsProvider::RequestSyslogs callback.
199 chromeos::system::SyslogsProvider::Handle syslogs_handle_; 199 chromeos::system::SyslogsProvider::Handle syslogs_handle_;
200 CancelableRequestConsumer syslogs_consumer_; 200 CancelableRequestConsumer syslogs_consumer_;
201 #endif 201 #endif
202 202
203 DISALLOW_COPY_AND_ASSIGN(BugReportHandler); 203 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler);
204 }; 204 };
205 205
206 ChromeWebUIDataSource* CreateBugReportUIHTMLSource(bool successful_init) { 206 ChromeWebUIDataSource* CreateFeedbackUIHTMLSource(bool successful_init) {
207 ChromeWebUIDataSource* source = 207 ChromeWebUIDataSource* source =
208 new ChromeWebUIDataSource(chrome::kChromeUIBugReportHost); 208 new ChromeWebUIDataSource(chrome::kChromeUIFeedbackHost);
209 209
210 source->AddLocalizedString("title", IDS_BUGREPORT_TITLE); 210 source->AddLocalizedString("title", IDS_FEEDBACK_TITLE);
211 source->AddLocalizedString("page-title", IDS_BUGREPORT_REPORT_PAGE_TITLE); 211 source->AddLocalizedString("page-title", IDS_FEEDBACK_REPORT_PAGE_TITLE);
212 source->AddLocalizedString("issue-with", IDS_BUGREPORT_ISSUE_WITH); 212 source->AddLocalizedString("page-url", IDS_FEEDBACK_REPORT_URL_LABEL);
213 source->AddLocalizedString("page-url", IDS_BUGREPORT_REPORT_URL_LABEL); 213 source->AddLocalizedString("description", IDS_FEEDBACK_DESCRIPTION_LABEL);
214 source->AddLocalizedString("description", IDS_BUGREPORT_DESCRIPTION_LABEL);
215 source->AddLocalizedString("current-screenshot", 214 source->AddLocalizedString("current-screenshot",
216 IDS_BUGREPORT_SCREENSHOT_LABEL); 215 IDS_FEEDBACK_SCREENSHOT_LABEL);
217 source->AddLocalizedString("saved-screenshot", 216 source->AddLocalizedString("saved-screenshot",
218 IDS_BUGREPORT_SAVED_SCREENSHOT_LABEL); 217 IDS_FEEDBACK_SAVED_SCREENSHOT_LABEL);
219 #if defined(OS_CHROMEOS) 218 #if defined(OS_CHROMEOS)
220 source->AddLocalizedString("user-email", IDS_BUGREPORT_USER_EMAIL_LABEL); 219 source->AddLocalizedString("user-email", IDS_FEEDBACK_USER_EMAIL_LABEL);
221 source->AddLocalizedString("sysinfo", 220 source->AddLocalizedString("sysinfo",
222 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX); 221 IDS_FEEDBACK_INCLUDE_SYSTEM_INFORMATION_CHKBOX);
223 source->AddLocalizedString("currentscreenshots", 222 source->AddLocalizedString("currentscreenshots",
224 IDS_BUGREPORT_CURRENT_SCREENSHOTS); 223 IDS_FEEDBACK_CURRENT_SCREENSHOTS);
225 source->AddLocalizedString("savedscreenshots", 224 source->AddLocalizedString("savedscreenshots",
226 IDS_BUGREPORT_SAVED_SCREENSHOTS); 225 IDS_FEEDBACK_SAVED_SCREENSHOTS);
227 source->AddLocalizedString("choose-different-screenshot", 226 source->AddLocalizedString("choose-different-screenshot",
228 IDS_BUGREPORT_CHOOSE_DIFFERENT_SCREENSHOT); 227 IDS_FEEDBACK_CHOOSE_DIFFERENT_SCREENSHOT);
229 source->AddLocalizedString("choose-original-screenshot", 228 source->AddLocalizedString("choose-original-screenshot",
230 IDS_BUGREPORT_CHOOSE_ORIGINAL_SCREENSHOT); 229 IDS_FEEDBACK_CHOOSE_ORIGINAL_SCREENSHOT);
231 #else 230 #else
232 source->AddLocalizedString("currentscreenshots", 231 source->AddLocalizedString("currentscreenshots",
233 IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE); 232 IDS_FEEDBACK_INCLUDE_NEW_SCREEN_IMAGE);
234 #endif 233 #endif
235 source->AddLocalizedString("noscreenshot", 234 source->AddLocalizedString("noscreenshot",
236 IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT); 235 IDS_FEEDBACK_INCLUDE_NO_SCREENSHOT);
237 236
238 source->AddLocalizedString("send-report", IDS_BUGREPORT_SEND_REPORT); 237 source->AddLocalizedString("send-report", IDS_FEEDBACK_SEND_REPORT);
239 source->AddLocalizedString("cancel", IDS_CANCEL); 238 source->AddLocalizedString("cancel", IDS_CANCEL);
240 239
241 // Option strings for the "issue with" drop-down. 240 source->AddLocalizedString("no-description", IDS_FEEDBACK_NO_DESCRIPTION);
242 source->AddLocalizedString("issue-choose", IDS_BUGREPORT_CHOOSE_ISSUE);
243 source->AddLocalizedString("no-issue-selected",
244 IDS_BUGREPORT_NO_ISSUE_SELECTED);
245 source->AddLocalizedString("no-description", IDS_BUGREPORT_NO_DESCRIPTION);
246 source->AddLocalizedString("no-saved-screenshots", 241 source->AddLocalizedString("no-saved-screenshots",
247 IDS_BUGREPORT_NO_SAVED_SCREENSHOTS_HELP); 242 IDS_FEEDBACK_NO_SAVED_SCREENSHOTS_HELP);
248 source->AddLocalizedString("privacy-note", IDS_BUGREPORT_PRIVACY_NOTE); 243 source->AddLocalizedString("privacy-note", IDS_FEEDBACK_PRIVACY_NOTE);
249
250 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync
251 // with the order in the userfeedback ChromeData proto buffer
252 #if defined(OS_CHROMEOS)
253 // Dropdown for ChromeOS:
254 //
255 // Connectivity
256 // Sync
257 // Crash
258 // Page Formatting
259 // Extensions or Apps
260 // Standby or Resume
261 // Phishing Page
262 // General Feedback/Other
263 // Autofill (hidden by default)
264
265 source->AddLocalizedString("issue-connectivity", IDS_BUGREPORT_CONNECTIVITY);
266 source->AddLocalizedString("issue-sync", IDS_BUGREPORT_SYNC);
267 source->AddLocalizedString("issue-crashes", IDS_BUGREPORT_CRASHES);
268 source->AddLocalizedString("issue-page-formatting",
269 IDS_BUGREPORT_PAGE_FORMATTING);
270 source->AddLocalizedString("issue-extensions", IDS_BUGREPORT_EXTENSIONS);
271 source->AddLocalizedString("issue-standby", IDS_BUGREPORT_STANDBY_RESUME);
272 source->AddLocalizedString("issue-phishing", IDS_BUGREPORT_PHISHING_PAGE);
273 source->AddLocalizedString("issue-other", IDS_BUGREPORT_GENERAL);
274 source->AddLocalizedString("issue-autofill", IDS_BUGREPORT_AUTOFILL);
275 #else
276 // Dropdown for Chrome:
277 //
278 // Page formatting or layout
279 // Pages not loading
280 // Plug-ins (e.g. Adobe Flash Player, Quicktime, etc)
281 // Tabs or windows
282 // Synced preferences
283 // Crashes
284 // Extensions or apps
285 // Phishing
286 // Other
287 // Autofill (hidden by default)
288
289 source->AddLocalizedString("issue-page-formatting",
290 IDS_BUGREPORT_PAGE_FORMATTING);
291 source->AddLocalizedString("issue-page-load", IDS_BUGREPORT_PAGE_LOAD);
292 source->AddLocalizedString("issue-plugins", IDS_BUGREPORT_PLUGINS);
293 source->AddLocalizedString("issue-tabs", IDS_BUGREPORT_TABS);
294 source->AddLocalizedString("issue-sync", IDS_BUGREPORT_SYNC);
295 source->AddLocalizedString("issue-crashes", IDS_BUGREPORT_CRASHES);
296 source->AddLocalizedString("issue-extensions", IDS_BUGREPORT_EXTENSIONS);
297 source->AddLocalizedString("issue-phishing", IDS_BUGREPORT_PHISHING_PAGE);
298 source->AddLocalizedString("issue-other", IDS_BUGREPORT_OTHER);
299 source->AddLocalizedString("issue-autofill", IDS_BUGREPORT_AUTOFILL);
300 #endif
301 244
302 source->set_json_path("strings.js"); 245 source->set_json_path("strings.js");
303 source->add_resource_path("bug_report.js", IDR_BUGREPORT_JS); 246 source->add_resource_path("feedback.js", IDR_FEEDBACK_JS);
304 source->set_default_resource( 247 source->set_default_resource(
305 successful_init ? IDR_BUGREPORT_HTML : IDR_BUGREPORT_HTML_INVALID); 248 successful_init ? IDR_FEEDBACK_HTML : IDR_FEEDBACK_HTML_INVALID);
306 249
307 return source; 250 return source;
308 } 251 }
309 252
310 //////////////////////////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////////////////////////
311 // 254 //
312 // BugReportHandler 255 // FeedbackHandler
313 // 256 //
314 //////////////////////////////////////////////////////////////////////////////// 257 ////////////////////////////////////////////////////////////////////////////////
315 BugReportHandler::BugReportHandler(WebContents* tab) 258 FeedbackHandler::FeedbackHandler(WebContents* tab)
316 : tab_(tab), 259 : tab_(tab),
317 screenshot_source_(NULL), 260 screenshot_source_(NULL),
318 bug_report_data_(NULL) 261 feedback_data_(NULL)
319 #if defined(OS_CHROMEOS) 262 #if defined(OS_CHROMEOS)
320 , syslogs_handle_(0) 263 , syslogs_handle_(0)
321 #endif 264 #endif
322 { 265 {
323 } 266 }
324 267
325 BugReportHandler::~BugReportHandler() { 268 FeedbackHandler::~FeedbackHandler() {
326 // Just in case we didn't send off bug_report_data_ to SendReport 269 // Just in case we didn't send off feedback_data_ to SendReport
327 if (bug_report_data_) { 270 if (feedback_data_) {
328 // If we're deleting the report object, cancel feedback collection first 271 // If we're deleting the report object, cancel feedback collection first
329 CancelFeedbackCollection(); 272 CancelFeedbackCollection();
330 delete bug_report_data_; 273 delete feedback_data_;
331 } 274 }
332 // Make sure we don't leave any screenshot data around. 275 // Make sure we don't leave any screenshot data around.
333 BugReportUtil::ClearScreenshotPng(); 276 FeedbackUtil::ClearScreenshotPng();
334 } 277 }
335 278
336 void BugReportHandler::ClobberScreenshotsSource() { 279 void FeedbackHandler::ClobberScreenshotsSource() {
337 // Re-create our screenshots data source (this clobbers the last source) 280 // Re-create our screenshots data source (this clobbers the last source)
338 // setting the screenshot to NULL, effectively disabling the source 281 // setting the screenshot to NULL, effectively disabling the source
339 // TODO(rkc): Once there is a method to 'remove' a source, change this code 282 // TODO(rkc): Once there is a method to 'remove' a source, change this code
340 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 283 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
341 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL)); 284 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL));
342 285
343 BugReportUtil::ClearScreenshotPng(); 286 FeedbackUtil::ClearScreenshotPng();
344 } 287 }
345 288
346 void BugReportHandler::SetupScreenshotsSource() { 289 void FeedbackHandler::SetupScreenshotsSource() {
347 // If we don't already have a screenshot source object created, create one. 290 // If we don't already have a screenshot source object created, create one.
348 if (!screenshot_source_) { 291 if (!screenshot_source_) {
349 screenshot_source_ = 292 screenshot_source_ =
350 new ScreenshotSource(BugReportUtil::GetScreenshotPng()); 293 new ScreenshotSource(FeedbackUtil::GetScreenshotPng());
351 } 294 }
352 // Add the source to the data manager. 295 // Add the source to the data manager.
353 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 296 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
354 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); 297 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_);
355 } 298 }
356 299
357 bool BugReportHandler::Init() { 300 bool FeedbackHandler::Init() {
358 std::string page_url; 301 std::string page_url;
359 if (tab_->GetController().GetActiveEntry()) { 302 if (tab_->GetController().GetActiveEntry()) {
360 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); 303 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec();
361 } 304 }
362 305
363 std::string params = page_url.substr(strlen(chrome::kChromeUIBugReportURL)); 306 std::string params = page_url.substr(strlen(chrome::kChromeUIFeedbackURL));
364 // Erase the # - the first character. 307 // Erase the # - the first character.
365 if (params.length()) 308 if (params.length())
366 params.erase(params.begin(), params.begin() + 1); 309 params.erase(params.begin(), params.begin() + 1);
367 310
368 size_t additional_params_pos = params.find('?'); 311 size_t additional_params_pos = params.find('?');
369 if (additional_params_pos != std::string::npos) 312 if (additional_params_pos != std::string::npos)
370 params.erase(params.begin() + additional_params_pos, params.end()); 313 params.erase(params.begin() + additional_params_pos, params.end());
371 314
372 int index = 0; 315 int index = 0;
373 if (!base::StringToInt(params, &index)) 316 if (!base::StringToInt(params, &index))
(...skipping 11 matching lines...) Expand all
385 if (target_tab) { 328 if (target_tab) {
386 target_tab_url_ = target_tab->GetURL().spec(); 329 target_tab_url_ = target_tab->GetURL().spec();
387 } 330 }
388 331
389 // Setup the screenshot source after we've verified input is legit. 332 // Setup the screenshot source after we've verified input is legit.
390 SetupScreenshotsSource(); 333 SetupScreenshotsSource();
391 334
392 return true; 335 return true;
393 } 336 }
394 337
395 void BugReportHandler::RegisterMessages() { 338 void FeedbackHandler::RegisterMessages() {
396 SetupScreenshotsSource(); 339 SetupScreenshotsSource();
397 340
398 web_ui()->RegisterMessageCallback("getDialogDefaults", 341 web_ui()->RegisterMessageCallback("getDialogDefaults",
399 base::Bind(&BugReportHandler::HandleGetDialogDefaults, 342 base::Bind(&FeedbackHandler::HandleGetDialogDefaults,
400 base::Unretained(this))); 343 base::Unretained(this)));
401 web_ui()->RegisterMessageCallback("refreshCurrentScreenshot", 344 web_ui()->RegisterMessageCallback("refreshCurrentScreenshot",
402 base::Bind(&BugReportHandler::HandleRefreshCurrentScreenshot, 345 base::Bind(&FeedbackHandler::HandleRefreshCurrentScreenshot,
403 base::Unretained(this))); 346 base::Unretained(this)));
404 #if defined(OS_CHROMEOS) 347 #if defined(OS_CHROMEOS)
405 web_ui()->RegisterMessageCallback("refreshSavedScreenshots", 348 web_ui()->RegisterMessageCallback("refreshSavedScreenshots",
406 base::Bind(&BugReportHandler::HandleRefreshSavedScreenshots, 349 base::Bind(&FeedbackHandler::HandleRefreshSavedScreenshots,
407 base::Unretained(this))); 350 base::Unretained(this)));
408 #endif 351 #endif
409 web_ui()->RegisterMessageCallback("sendReport", 352 web_ui()->RegisterMessageCallback("sendReport",
410 base::Bind(&BugReportHandler::HandleSendReport, 353 base::Bind(&FeedbackHandler::HandleSendReport,
411 base::Unretained(this))); 354 base::Unretained(this)));
412 web_ui()->RegisterMessageCallback("cancel", 355 web_ui()->RegisterMessageCallback("cancel",
413 base::Bind(&BugReportHandler::HandleCancel, 356 base::Bind(&FeedbackHandler::HandleCancel,
414 base::Unretained(this))); 357 base::Unretained(this)));
415 web_ui()->RegisterMessageCallback("openSystemTab", 358 web_ui()->RegisterMessageCallback("openSystemTab",
416 base::Bind(&BugReportHandler::HandleOpenSystemTab, 359 base::Bind(&FeedbackHandler::HandleOpenSystemTab,
417 base::Unretained(this))); 360 base::Unretained(this)));
418 } 361 }
419 362
420 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { 363 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) {
421 // Will delete itself when bug_report_data_->SendReport() is called. 364 // Will delete itself when feedback_data_->SendReport() is called.
422 bug_report_data_ = new BugReportData(); 365 feedback_data_ = new FeedbackData();
423 366
424 // send back values which the dialog js needs initially 367 // send back values which the dialog js needs initially
425 ListValue dialog_defaults; 368 ListValue dialog_defaults;
426 369
427 // 0: current url 370 // 0: current url
428 if (target_tab_url_.length()) 371 if (target_tab_url_.length())
429 dialog_defaults.Append(new StringValue(target_tab_url_)); 372 dialog_defaults.Append(new StringValue(target_tab_url_));
430 else 373 else
431 dialog_defaults.Append(new StringValue("")); 374 dialog_defaults.Append(new StringValue(""));
432 375
433 #if defined(OS_CHROMEOS) 376 #if defined(OS_CHROMEOS)
434 // 1: about:system 377 // 1: about:system
435 dialog_defaults.Append(new StringValue(chrome::kChromeUISystemInfoURL)); 378 dialog_defaults.Append(new StringValue(chrome::kChromeUISystemInfoURL));
436 // Trigger the request for system information here. 379 // Trigger the request for system information here.
437 chromeos::system::SyslogsProvider* provider = 380 chromeos::system::SyslogsProvider* provider =
438 chromeos::system::SyslogsProvider::GetInstance(); 381 chromeos::system::SyslogsProvider::GetInstance();
439 if (provider) { 382 if (provider) {
440 syslogs_handle_ = provider->RequestSyslogs( 383 syslogs_handle_ = provider->RequestSyslogs(
441 true, // don't compress. 384 true, // don't compress.
442 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, 385 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK,
443 &syslogs_consumer_, 386 &syslogs_consumer_,
444 base::Bind(&BugReportData::SyslogsComplete, 387 base::Bind(&FeedbackData::SyslogsComplete,
445 base::Unretained(bug_report_data_))); 388 base::Unretained(feedback_data_)));
446 } 389 }
447 // 2: user e-mail 390 // 2: user e-mail
448 dialog_defaults.Append(new StringValue(GetUserEmail())); 391 dialog_defaults.Append(new StringValue(GetUserEmail()));
449 #endif 392 #endif
450 393
451 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); 394 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults);
452 } 395 }
453 396
454 void BugReportHandler::HandleRefreshCurrentScreenshot(const ListValue*) { 397 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) {
455 std::string current_screenshot(kCurrentScreenshotUrl); 398 std::string current_screenshot(kCurrentScreenshotUrl);
456 StringValue screenshot(current_screenshot); 399 StringValue screenshot(current_screenshot);
457 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); 400 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot);
458 } 401 }
459 402
460 403
461 #if defined(OS_CHROMEOS) 404 #if defined(OS_CHROMEOS)
462 void BugReportHandler::HandleRefreshSavedScreenshots(const ListValue*) { 405 void FeedbackHandler::HandleRefreshSavedScreenshots(const ListValue*) {
463 std::vector<std::string> saved_screenshots; 406 std::vector<std::string> saved_screenshots;
464 GetScreenshotUrls(&saved_screenshots); 407 GetScreenshotUrls(&saved_screenshots);
465 408
466 ListValue screenshots_list; 409 ListValue screenshots_list;
467 for (size_t i = 0; i < saved_screenshots.size(); ++i) 410 for (size_t i = 0; i < saved_screenshots.size(); ++i)
468 screenshots_list.Append(new StringValue(saved_screenshots[i])); 411 screenshots_list.Append(new StringValue(saved_screenshots[i]));
469 web_ui()->CallJavascriptFunction("setupSavedScreenshots", screenshots_list); 412 web_ui()->CallJavascriptFunction("setupSavedScreenshots", screenshots_list);
470 } 413 }
471 #endif 414 #endif
472 415
473 416
474 void BugReportHandler::HandleSendReport(const ListValue* list_value) { 417 void FeedbackHandler::HandleSendReport(const ListValue* list_value) {
475 if (!bug_report_data_) { 418 if (!feedback_data_) {
476 LOG(ERROR) << "Bug report hasn't been intialized yet."; 419 LOG(ERROR) << "Bug report hasn't been intialized yet.";
477 return; 420 return;
478 } 421 }
422 // TODO(rkc): Find a better way to do this check.
423 #if defined(OS_CHROMEOS)
424 if (list_value->GetSize() != 6) {
425 #else
426 if (list_value->GetSize() != 4) {
427 #endif
428 LOG(ERROR) << "Feedback data corrupt! Feedback not sent.";
429 return;
430 }
479 431
480 ListValue::const_iterator i = list_value->begin(); 432 ListValue::const_iterator i = list_value->begin();
481 if (i == list_value->end()) {
482 LOG(ERROR) << "Incorrect data passed to sendReport.";
483 return;
484 }
485
486 // #0 - Problem type.
487 int problem_type;
488 std::string problem_type_str;
489 (*i)->GetAsString(&problem_type_str);
490 if (!base::StringToInt(problem_type_str, &problem_type)) {
491 LOG(ERROR) << "Incorrect data passed to sendReport.";
492 return;
493 }
494 if (++i == list_value->end()) {
495 LOG(ERROR) << "Incorrect data passed to sendReport.";
496 return;
497 }
498
499 // #1 - Page url.
500 std::string page_url; 433 std::string page_url;
501 (*i)->GetAsString(&page_url); 434 (*i++)->GetAsString(&page_url);
502 if (++i == list_value->end()) { 435 std::string category_tag;
503 LOG(ERROR) << "Incorrect data passed to sendReport."; 436 (*i++)->GetAsString(&category_tag);
504 return;
505 }
506
507 // #2 - Description.
508 std::string description; 437 std::string description;
509 (*i)->GetAsString(&description); 438 (*i++)->GetAsString(&description);
510 if (++i == list_value->end()) {
511 LOG(ERROR) << "Incorrect data passed to sendReport.";
512 return;
513 }
514
515 // #3 - Screenshot to send.
516 std::string screenshot_path; 439 std::string screenshot_path;
517 (*i)->GetAsString(&screenshot_path); 440 (*i++)->GetAsString(&screenshot_path);
518 screenshot_path.erase(0, strlen(kScreenshotBaseUrl)); 441 screenshot_path.erase(0, strlen(kScreenshotBaseUrl));
519 442
520 // Get the image to send in the report. 443 // Get the image to send in the report.
521 ScreenshotDataPtr image_ptr; 444 ScreenshotDataPtr image_ptr;
522 if (!screenshot_path.empty()) 445 if (!screenshot_path.empty())
523 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); 446 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path);
524 447
525 #if defined(OS_CHROMEOS) 448 #if defined(OS_CHROMEOS)
526 if (++i == list_value->end()) {
527 LOG(ERROR) << "Incorrect data passed to sendReport.";
528 return;
529 }
530
531 // #4 - User e-mail
532 std::string user_email; 449 std::string user_email;
533 (*i)->GetAsString(&user_email); 450 (*i++)->GetAsString(&user_email);
534 if (++i == list_value->end()) {
535 LOG(ERROR) << "Incorrect data passed to sendReport.";
536 return;
537 }
538
539 // #5 - System info checkbox.
540 std::string sys_info_checkbox; 451 std::string sys_info_checkbox;
541 (*i)->GetAsString(&sys_info_checkbox); 452 (*i++)->GetAsString(&sys_info_checkbox);
542 bool send_sys_info = (sys_info_checkbox == "true"); 453 bool send_sys_info = (sys_info_checkbox == "true");
543 454
544 // If we aren't sending the sys_info, cancel the gathering of the syslogs. 455 // If we aren't sending the sys_info, cancel the gathering of the syslogs.
545 if (!send_sys_info) 456 if (!send_sys_info)
546 CancelFeedbackCollection(); 457 CancelFeedbackCollection();
547 #endif 458 #endif
548 459
549 // Update the data in bug_report_data_ so it can be sent 460 // Update the data in feedback_data_ so it can be sent
550 bug_report_data_->UpdateData(Profile::FromWebUI(web_ui()) 461 feedback_data_->UpdateData(Profile::FromWebUI(web_ui())
551 , target_tab_url_ 462 , target_tab_url_
552 , problem_type 463 , std::string()
553 , page_url 464 , page_url
554 , description 465 , description
555 , image_ptr 466 , image_ptr
556 #if defined(OS_CHROMEOS) 467 #if defined(OS_CHROMEOS)
557 , user_email 468 , user_email
558 , send_sys_info 469 , send_sys_info
559 , false // sent_report 470 , false // sent_report
560 #endif 471 #endif
561 ); 472 );
562 473
563 #if defined(OS_CHROMEOS) 474 #if defined(OS_CHROMEOS)
564 // If we don't require sys_info, or we have it, or we never requested it 475 // If we don't require sys_info, or we have it, or we never requested it
565 // (because libcros failed to load), then send the report now. 476 // (because libcros failed to load), then send the report now.
566 // Otherwise, the report will get sent when we receive sys_info. 477 // Otherwise, the report will get sent when we receive sys_info.
567 if (!send_sys_info || bug_report_data_->sys_info() != NULL || 478 if (!send_sys_info || feedback_data_->sys_info() != NULL ||
568 syslogs_handle_ == 0) { 479 syslogs_handle_ == 0) {
569 bug_report_data_->SendReport(); 480 feedback_data_->SendReport();
570 } 481 }
571 #else 482 #else
572 bug_report_data_->SendReport(); 483 feedback_data_->SendReport();
573 #endif 484 #endif
574 // Lose the pointer to the BugReportData object; the object will delete itself 485 // Lose the pointer to the FeedbackData object; the object will delete itself
575 // from SendReport, whether we called it, or will be called by the log 486 // from SendReport, whether we called it, or will be called by the log
576 // completion routine. 487 // completion routine.
577 bug_report_data_ = NULL; 488 feedback_data_ = NULL;
578 489
579 // Whether we sent the report, or if it will be sent by the Syslogs complete 490 // Whether we sent the report, or if it will be sent by the Syslogs complete
580 // function, close our feedback tab anyway, we have no more use for it. 491 // function, close our feedback tab anyway, we have no more use for it.
581 CloseFeedbackTab(); 492 CloseFeedbackTab();
582 } 493 }
583 494
584 void BugReportHandler::HandleCancel(const ListValue*) { 495 void FeedbackHandler::HandleCancel(const ListValue*) {
585 CloseFeedbackTab(); 496 CloseFeedbackTab();
586 } 497 }
587 498
588 void BugReportHandler::HandleOpenSystemTab(const ListValue* args) { 499 void FeedbackHandler::HandleOpenSystemTab(const ListValue* args) {
589 #if defined(OS_CHROMEOS) 500 #if defined(OS_CHROMEOS)
590 BrowserList::GetLastActive()->OpenSystemTabAndActivate(); 501 BrowserList::GetLastActive()->OpenSystemTabAndActivate();
591 #endif 502 #endif
592 } 503 }
593 504
594 void BugReportHandler::CancelFeedbackCollection() { 505 void FeedbackHandler::CancelFeedbackCollection() {
595 #if defined(OS_CHROMEOS) 506 #if defined(OS_CHROMEOS)
596 if (syslogs_handle_ != 0) { 507 if (syslogs_handle_ != 0) {
597 chromeos::system::SyslogsProvider* provider = 508 chromeos::system::SyslogsProvider* provider =
598 chromeos::system::SyslogsProvider::GetInstance(); 509 chromeos::system::SyslogsProvider::GetInstance();
599 if (provider) 510 if (provider && syslogs_consumer_.HasPendingRequests())
600 provider->CancelRequest(syslogs_handle_); 511 provider->CancelRequest(syslogs_handle_);
601 } 512 }
602 #endif 513 #endif
603 } 514 }
604 515
605 void BugReportHandler::CloseFeedbackTab() { 516 void FeedbackHandler::CloseFeedbackTab() {
606 ClobberScreenshotsSource(); 517 ClobberScreenshotsSource();
607 518
608 Browser* browser = BrowserList::GetLastActive(); 519 Browser* browser = BrowserList::GetLastActive();
609 if (browser) { 520 if (browser) {
610 browser->CloseTabContents(tab_); 521 browser->CloseTabContents(tab_);
611 } else { 522 } else {
612 LOG(FATAL) << "Failed to get last active browser."; 523 LOG(FATAL) << "Failed to get last active browser.";
613 } 524 }
614 } 525 }
615 526
616 //////////////////////////////////////////////////////////////////////////////// 527 ////////////////////////////////////////////////////////////////////////////////
617 // 528 //
618 // BugReportUI 529 // FeedbackUI
619 // 530 //
620 //////////////////////////////////////////////////////////////////////////////// 531 ////////////////////////////////////////////////////////////////////////////////
621 BugReportUI::BugReportUI(WebContents* tab) : HtmlDialogUI(tab) { 532 FeedbackUI::FeedbackUI(WebContents* tab) : HtmlDialogUI(tab) {
622 BugReportHandler* handler = new BugReportHandler(tab); 533 FeedbackHandler* handler = new FeedbackHandler(tab);
623 AddMessageHandler(handler); 534 AddMessageHandler(handler);
624 535
625 // The handler's init will determine whether we show the error html page. 536 // The handler's init will determine whether we show the error html page.
626 ChromeWebUIDataSource* html_source = 537 ChromeWebUIDataSource* html_source =
627 CreateBugReportUIHTMLSource(handler->Init()); 538 CreateFeedbackUIHTMLSource(handler->Init());
628 539
629 // Set up the chrome://bugreport/ source. 540 // Set up the chrome://feedback/ source.
630 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 541 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
631 profile->GetChromeURLDataManager()->AddDataSource(html_source); 542 profile->GetChromeURLDataManager()->AddDataSource(html_source);
632 } 543 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/feedback_ui.h ('k') | chrome/browser/userfeedback/proto/annotations.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698