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/feedback_ui.h" | 5 #include "chrome/browser/ui/webui/feedback_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // for this functionality since we need to make *sure* we never get | 196 // for this functionality since we need to make *sure* we never get |
197 // instantiated again while we are open - with singleton tabs, that can | 197 // instantiated again while we are open - with singleton tabs, that can |
198 // happen). | 198 // happen). |
199 int feedback_tab_index = GetIndexOfFeedbackTab(browser); | 199 int feedback_tab_index = GetIndexOfFeedbackTab(browser); |
200 if (feedback_tab_index >= 0) { | 200 if (feedback_tab_index >= 0) { |
201 // Do not refresh screenshot, do not create a new tab. | 201 // Do not refresh screenshot, do not create a new tab. |
202 browser->tab_strip_model()->ActivateTabAt(feedback_tab_index, true); | 202 browser->tab_strip_model()->ActivateTabAt(feedback_tab_index, true); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 std::vector<unsigned char>* last_screenshot_png = | 206 if (category_tag != kAppLauncherCategoryTag) { |
207 FeedbackUtil::GetScreenshotPng(); | 207 std::vector<unsigned char>* last_screenshot_png = |
208 last_screenshot_png->clear(); | 208 FeedbackUtil::GetScreenshotPng(); |
| 209 last_screenshot_png->clear(); |
209 | 210 |
210 gfx::NativeWindow native_window; | 211 gfx::NativeWindow native_window; |
211 gfx::Rect snapshot_bounds; | 212 gfx::Rect snapshot_bounds; |
212 | 213 |
213 #if defined(OS_CHROMEOS) | 214 #if defined(OS_CHROMEOS) |
214 // For ChromeOS, don't use the browser window but the root window | 215 // For ChromeOS, don't use the browser window but the root window |
215 // instead to grab the screenshot. We want everything on the screen, not | 216 // instead to grab the screenshot. We want everything on the screen, not |
216 // just the current browser. | 217 // just the current browser. |
217 native_window = ash::Shell::GetPrimaryRootWindow(); | 218 native_window = ash::Shell::GetPrimaryRootWindow(); |
218 snapshot_bounds = gfx::Rect(native_window->bounds()); | 219 snapshot_bounds = gfx::Rect(native_window->bounds()); |
219 #else | 220 #else |
220 native_window = browser->window()->GetNativeWindow(); | 221 native_window = browser->window()->GetNativeWindow(); |
221 snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); | 222 snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); |
222 #endif | 223 #endif |
223 bool success = chrome::GrabWindowSnapshotForUser(native_window, | 224 bool success = chrome::GrabWindowSnapshotForUser(native_window, |
224 last_screenshot_png, | 225 last_screenshot_png, |
225 snapshot_bounds); | 226 snapshot_bounds); |
226 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); | 227 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); |
227 | 228 } |
228 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) + "?" + | 229 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) + "?" + |
229 kSessionIDParameter + base::IntToString(browser->session_id().id()) + | 230 kSessionIDParameter + base::IntToString(browser->session_id().id()) + |
230 "&" + kTabIndexParameter + | 231 "&" + kTabIndexParameter + |
231 base::IntToString(browser->tab_strip_model()->active_index()) + | 232 base::IntToString(browser->tab_strip_model()->active_index()) + |
232 "&" + kDescriptionParameter + | 233 "&" + kDescriptionParameter + |
233 net::EscapeUrlEncodedData(description_template, false) + "&" + | 234 net::EscapeUrlEncodedData(description_template, false) + "&" + |
234 kCategoryTagParameter + net::EscapeUrlEncodedData(category_tag, false); | 235 kCategoryTagParameter + net::EscapeUrlEncodedData(category_tag, false); |
235 | 236 |
236 #if defined(OS_CHROMEOS) | 237 #if defined(OS_CHROMEOS) |
237 feedback_url = feedback_url + "&" + kTimestampParameter + | 238 feedback_url = feedback_url + "&" + kTimestampParameter + |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void ClobberScreenshotsSource(); | 276 void ClobberScreenshotsSource(); |
276 | 277 |
277 void CancelFeedbackCollection(); | 278 void CancelFeedbackCollection(); |
278 void CloseFeedbackTab(); | 279 void CloseFeedbackTab(); |
279 | 280 |
280 WebContents* tab_; | 281 WebContents* tab_; |
281 ScreenshotSource* screenshot_source_; | 282 ScreenshotSource* screenshot_source_; |
282 | 283 |
283 FeedbackData* feedback_data_; | 284 FeedbackData* feedback_data_; |
284 std::string target_tab_url_; | 285 std::string target_tab_url_; |
| 286 std::string category_tag_; |
285 #if defined(OS_CHROMEOS) | 287 #if defined(OS_CHROMEOS) |
286 // Variables to track SyslogsProvider::RequestSyslogs. | 288 // Variables to track SyslogsProvider::RequestSyslogs. |
287 CancelableTaskTracker::TaskId syslogs_task_id_; | 289 CancelableTaskTracker::TaskId syslogs_task_id_; |
288 CancelableTaskTracker syslogs_tracker_; | 290 CancelableTaskTracker syslogs_tracker_; |
289 | 291 |
290 // Timestamp of when the feedback request was initiated. | 292 // Timestamp of when the feedback request was initiated. |
291 std::string timestamp_; | 293 std::string timestamp_; |
292 #endif | 294 #endif |
293 | 295 |
294 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler); | 296 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 source->AddLocalizedString("noscreenshot", | 336 source->AddLocalizedString("noscreenshot", |
335 IDS_FEEDBACK_INCLUDE_NO_SCREENSHOT); | 337 IDS_FEEDBACK_INCLUDE_NO_SCREENSHOT); |
336 | 338 |
337 source->AddLocalizedString("send-report", IDS_FEEDBACK_SEND_REPORT); | 339 source->AddLocalizedString("send-report", IDS_FEEDBACK_SEND_REPORT); |
338 source->AddLocalizedString("cancel", IDS_CANCEL); | 340 source->AddLocalizedString("cancel", IDS_CANCEL); |
339 | 341 |
340 source->AddLocalizedString("no-description", IDS_FEEDBACK_NO_DESCRIPTION); | 342 source->AddLocalizedString("no-description", IDS_FEEDBACK_NO_DESCRIPTION); |
341 source->AddLocalizedString("no-saved-screenshots", | 343 source->AddLocalizedString("no-saved-screenshots", |
342 IDS_FEEDBACK_NO_SAVED_SCREENSHOTS_HELP); | 344 IDS_FEEDBACK_NO_SAVED_SCREENSHOTS_HELP); |
343 source->AddLocalizedString("privacy-note", IDS_FEEDBACK_PRIVACY_NOTE); | 345 source->AddLocalizedString("privacy-note", IDS_FEEDBACK_PRIVACY_NOTE); |
| 346 source->AddLocalizedString("launcher-title", IDS_FEEDBACK_LAUNCHER_TITLE); |
| 347 source->AddLocalizedString("launcher-description", |
| 348 IDS_FEEDBACK_LAUNCHER_DESCRIPTION_LABEL); |
344 | 349 |
345 source->SetJsonPath("strings.js"); | 350 source->SetJsonPath("strings.js"); |
346 source->AddResourcePath("feedback.js", IDR_FEEDBACK_JS); | 351 source->AddResourcePath("feedback.js", IDR_FEEDBACK_JS); |
347 source->SetDefaultResource( | 352 source->SetDefaultResource( |
348 successful_init ? IDR_FEEDBACK_HTML : IDR_FEEDBACK_HTML_INVALID); | 353 successful_init ? IDR_FEEDBACK_HTML : IDR_FEEDBACK_HTML_INVALID); |
349 | 354 |
350 return source; | 355 return source; |
351 } | 356 } |
352 | 357 |
353 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 std::string custom_page_url; | 417 std::string custom_page_url; |
413 if (Tokenize(query, std::string("&"), ¶ms)) { | 418 if (Tokenize(query, std::string("&"), ¶ms)) { |
414 for (std::vector<std::string>::iterator it = params.begin(); | 419 for (std::vector<std::string>::iterator it = params.begin(); |
415 it != params.end(); ++it) { | 420 it != params.end(); ++it) { |
416 std::string query_str = *it; | 421 std::string query_str = *it; |
417 if (StartsWithASCII(query_str, std::string(kSessionIDParameter), true)) { | 422 if (StartsWithASCII(query_str, std::string(kSessionIDParameter), true)) { |
418 ReplaceFirstSubstringAfterOffset( | 423 ReplaceFirstSubstringAfterOffset( |
419 &query_str, 0, kSessionIDParameter, ""); | 424 &query_str, 0, kSessionIDParameter, ""); |
420 if (!base::StringToInt(query_str, &session_id)) | 425 if (!base::StringToInt(query_str, &session_id)) |
421 return false; | 426 return false; |
422 continue; | 427 } else if (StartsWithASCII(*it, std::string(kTabIndexParameter), true)) { |
423 } | |
424 if (StartsWithASCII(*it, std::string(kTabIndexParameter), true)) { | |
425 ReplaceFirstSubstringAfterOffset( | 428 ReplaceFirstSubstringAfterOffset( |
426 &query_str, 0, kTabIndexParameter, ""); | 429 &query_str, 0, kTabIndexParameter, ""); |
427 if (!base::StringToInt(query_str, &index)) | 430 if (!base::StringToInt(query_str, &index)) |
428 return false; | 431 return false; |
429 continue; | 432 } else if (StartsWithASCII(*it, std::string(kCustomPageUrlParameter), |
430 } | 433 true)) { |
431 if (StartsWithASCII(*it, std::string(kCustomPageUrlParameter), true)) { | |
432 ReplaceFirstSubstringAfterOffset( | 434 ReplaceFirstSubstringAfterOffset( |
433 &query_str, 0, kCustomPageUrlParameter, ""); | 435 &query_str, 0, kCustomPageUrlParameter, ""); |
434 custom_page_url = query_str; | 436 custom_page_url = query_str; |
435 continue; | 437 } else if (StartsWithASCII(*it, std::string(kCategoryTagParameter), |
436 } | 438 true)) { |
| 439 ReplaceFirstSubstringAfterOffset( |
| 440 &query_str, 0, kCategoryTagParameter, ""); |
| 441 category_tag_ = query_str; |
437 #if defined(OS_CHROMEOS) | 442 #if defined(OS_CHROMEOS) |
438 if (StartsWithASCII(*it, std::string(kTimestampParameter), true)) { | 443 } else if (StartsWithASCII(*it, std::string(kTimestampParameter), true)) { |
439 ReplaceFirstSubstringAfterOffset( | 444 ReplaceFirstSubstringAfterOffset( |
440 &query_str, 0, kTimestampParameter, ""); | 445 &query_str, 0, kTimestampParameter, ""); |
441 timestamp_ = query_str; | 446 timestamp_ = query_str; |
442 continue; | 447 #endif |
443 } | 448 } |
444 #endif | |
445 } | 449 } |
446 } | 450 } |
447 | 451 |
448 // If we don't have a page url specified, get it from the tab index. | 452 // If we don't have a page url specified, get it from the tab index. |
449 if (custom_page_url.empty()) { | 453 if (custom_page_url.empty()) { |
450 if (session_id == -1) | 454 if (session_id == -1) |
451 return false; | 455 return false; |
452 | 456 |
453 Browser* browser = chrome::FindBrowserWithID(session_id); | 457 Browser* browser = chrome::FindBrowserWithID(session_id); |
454 // Sanity checks. | 458 // Sanity checks. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 base::Unretained(this))); | 500 base::Unretained(this))); |
497 } | 501 } |
498 | 502 |
499 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) { | 503 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) { |
500 // Will delete itself when feedback_data_->SendReport() is called. | 504 // Will delete itself when feedback_data_->SendReport() is called. |
501 feedback_data_ = new FeedbackData(); | 505 feedback_data_ = new FeedbackData(); |
502 | 506 |
503 // Send back values which the dialog js needs initially. | 507 // Send back values which the dialog js needs initially. |
504 DictionaryValue dialog_defaults; | 508 DictionaryValue dialog_defaults; |
505 | 509 |
| 510 if (category_tag_ == chrome::kAppLauncherCategoryTag) |
| 511 dialog_defaults.SetBoolean("launcherFeedback", true); |
| 512 |
506 // Current url. | 513 // Current url. |
507 dialog_defaults.SetString("currentUrl", target_tab_url_); | 514 dialog_defaults.SetString("currentUrl", target_tab_url_); |
508 | 515 |
509 // Are screenshots disabled? | 516 // Are screenshots disabled? |
510 dialog_defaults.SetBoolean( | 517 dialog_defaults.SetBoolean( |
511 "disableScreenshots", | 518 "disableScreenshots", |
512 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); | 519 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); |
513 | 520 |
514 // User e-mail | 521 // User e-mail |
515 std::string user_email = GetUserEmail(); | 522 std::string user_email = GetUserEmail(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 LOG(ERROR) << "Unable to attach file: " << attached_filename; | 654 LOG(ERROR) << "Unable to attach file: " << attached_filename; |
648 // Clear the filename so feedback_util doesn't try to attach the file. | 655 // Clear the filename so feedback_util doesn't try to attach the file. |
649 attached_filename = ""; | 656 attached_filename = ""; |
650 } | 657 } |
651 } | 658 } |
652 } | 659 } |
653 #endif | 660 #endif |
654 | 661 |
655 // Update the data in feedback_data_ so it can be sent | 662 // Update the data in feedback_data_ so it can be sent |
656 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) | 663 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) |
657 , std::string() | 664 , category_tag |
658 , page_url | 665 , page_url |
659 , description | 666 , description |
660 , user_email | 667 , user_email |
661 , image_ptr | 668 , image_ptr |
662 #if defined(OS_CHROMEOS) | 669 #if defined(OS_CHROMEOS) |
663 , send_sys_info | 670 , send_sys_info |
664 , false // sent_report | 671 , false // sent_report |
665 , timestamp_ | 672 , timestamp_ |
666 , attached_filename | 673 , attached_filename |
667 , attached_filedata | 674 , attached_filedata |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 screenshot_filepaths.begin() + sort_size, | 768 screenshot_filepaths.begin() + sort_size, |
762 screenshot_filepaths.end(), | 769 screenshot_filepaths.end(), |
763 ScreenshotTimestampComp); | 770 ScreenshotTimestampComp); |
764 for (size_t i = 0; i < sort_size; ++i) | 771 for (size_t i = 0; i < sort_size; ++i) |
765 saved_screenshots->push_back( | 772 saved_screenshots->push_back( |
766 std::string(ScreenshotSource::kScreenshotUrlRoot) + | 773 std::string(ScreenshotSource::kScreenshotUrlRoot) + |
767 std::string(ScreenshotSource::kScreenshotSaved) + | 774 std::string(ScreenshotSource::kScreenshotSaved) + |
768 screenshot_filepaths[i]); | 775 screenshot_filepaths[i]); |
769 } | 776 } |
770 #endif | 777 #endif |
OLD | NEW |