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

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

Issue 9104030: Include a timestamp with and add a keyboard shortcut for Feedback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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) 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 <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/string_util.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/time.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "chrome/browser/feedback/feedback_data.h" 19 #include "chrome/browser/feedback/feedback_data.h"
18 #include "chrome/browser/feedback/feedback_util.h" 20 #include "chrome/browser/feedback/feedback_util.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
25 #include "chrome/browser/ui/webui/screenshot_source.h" 27 #include "chrome/browser/ui/webui/screenshot_source.h"
(...skipping 23 matching lines...) Expand all
49 #endif 51 #endif
50 52
51 using content::BrowserThread; 53 using content::BrowserThread;
52 using content::WebContents; 54 using content::WebContents;
53 using content::WebUIMessageHandler; 55 using content::WebUIMessageHandler;
54 56
55 namespace { 57 namespace {
56 58
57 const char kScreenshotBaseUrl[] = "chrome://screenshots/"; 59 const char kScreenshotBaseUrl[] = "chrome://screenshots/";
58 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; 60 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current";
61
62 const char kCategoryTagParameter[] = "categoryTag=";
63 const char kDescriptionParameter[] = "description=";
64
59 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
60 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; 66 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/";
61 const char kScreenshotPattern[] = "screenshot-*.png"; 67 const char kScreenshotPattern[] = "screenshot-*.png";
62 68
69 const char kTimestampParameter[] = "timestamp=";
70
63 const size_t kMaxSavedScreenshots = 2; 71 const size_t kMaxSavedScreenshots = 2;
64 #endif 72 #endif
65 73
66 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
67 75
68 void GetSavedScreenshots(std::vector<std::string>* saved_screenshots, 76 void GetSavedScreenshots(std::vector<std::string>* saved_screenshots,
69 base::WaitableEvent* done) { 77 base::WaitableEvent* done) {
70 saved_screenshots->clear(); 78 saved_screenshots->clear();
71 79
72 FilePath fileshelf_path; 80 FilePath fileshelf_path;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 131 }
124 132
125 } // namespace 133 } // namespace
126 134
127 135
128 namespace browser { 136 namespace browser {
129 137
130 void ShowHtmlFeedbackView(Browser* browser, 138 void ShowHtmlFeedbackView(Browser* browser,
131 const std::string& description_template, 139 const std::string& description_template,
132 const std::string& category_tag) { 140 const std::string& category_tag) {
141 #if defined(OS_CHROMEOS)
142 // Grab the timestamp before we do anything else - this is crucial to help
143 // diagnose some hardware issues.
144 base::Time now = base::Time::Now();
145 std::string timestamp = base::DoubleToString(now.ToDoubleT());
zel 2012/01/31 16:38:03 format this to string where you really need the st
rkc 2012/01/31 18:16:45 Same reason as given in the other comment.
146 #endif
147
133 // First check if we're already open (we cannot depend on ShowSingletonTab 148 // First check if we're already open (we cannot depend on ShowSingletonTab
134 // for this functionality since we need to make *sure* we never get 149 // for this functionality since we need to make *sure* we never get
135 // instantiated again while we are open - with singleton tabs, that can 150 // instantiated again while we are open - with singleton tabs, that can
136 // happen) 151 // happen)
137 int feedback_tab_index = GetIndexOfFeedbackTab(browser); 152 int feedback_tab_index = GetIndexOfFeedbackTab(browser);
138 if (feedback_tab_index >= 0) { 153 if (feedback_tab_index >= 0) {
139 // Do not refresh screenshot, do not create a new tab 154 // Do not refresh screenshot, do not create a new tab
140 browser->ActivateTabAt(feedback_tab_index, true); 155 browser->ActivateTabAt(feedback_tab_index, true);
141 return; 156 return;
142 } 157 }
143 158
144 std::vector<unsigned char>* last_screenshot_png = 159 std::vector<unsigned char>* last_screenshot_png =
145 FeedbackUtil::GetScreenshotPng(); 160 FeedbackUtil::GetScreenshotPng();
146 last_screenshot_png->clear(); 161 last_screenshot_png->clear();
147 162
148 gfx::NativeWindow native_window = browser->window()->GetNativeHandle(); 163 gfx::NativeWindow native_window = browser->window()->GetNativeHandle();
149 gfx::Rect snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); 164 gfx::Rect snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size());
150 bool success = browser::GrabWindowSnapshot(native_window, 165 bool success = browser::GrabWindowSnapshot(native_window,
151 last_screenshot_png, 166 last_screenshot_png,
152 snapshot_bounds); 167 snapshot_bounds);
153 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); 168 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect());
154 169
155 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) + 170 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) +
156 "#" + base::IntToString(browser->active_index()) + 171 "#" + base::IntToString(browser->active_index()) + "?" +
157 "?description=" + net::EscapeUrlEncodedData(description_template, false) + 172 kDescriptionParameter +
158 "&categoryTag=" + net::EscapeUrlEncodedData(category_tag, false); 173 net::EscapeUrlEncodedData(description_template, false) + "&" +
174 kCategoryTagParameter + net::EscapeUrlEncodedData(category_tag, false);
175
176 #if defined(OS_CHROMEOS)
177 feedback_url = feedback_url + "&" + kTimestampParameter +
178 net::EscapeUrlEncodedData(timestamp, false);
179 #endif
159 browser->ShowSingletonTab(GURL(feedback_url)); 180 browser->ShowSingletonTab(GURL(feedback_url));
160 } 181 }
161 182
162 } // namespace browser 183 } // namespace browser
163 184
164 // The handler for Javascript messages related to the "bug report" dialog 185 // The handler for Javascript messages related to the "bug report" dialog
165 class FeedbackHandler : public WebUIMessageHandler, 186 class FeedbackHandler : public WebUIMessageHandler,
166 public base::SupportsWeakPtr<FeedbackHandler> { 187 public base::SupportsWeakPtr<FeedbackHandler> {
167 public: 188 public:
168 explicit FeedbackHandler(content::WebContents* tab); 189 explicit FeedbackHandler(content::WebContents* tab);
(...skipping 23 matching lines...) Expand all
192 213
193 WebContents* tab_; 214 WebContents* tab_;
194 ScreenshotSource* screenshot_source_; 215 ScreenshotSource* screenshot_source_;
195 216
196 FeedbackData* feedback_data_; 217 FeedbackData* feedback_data_;
197 std::string target_tab_url_; 218 std::string target_tab_url_;
198 #if defined(OS_CHROMEOS) 219 #if defined(OS_CHROMEOS)
199 // Variables to track SyslogsProvider::RequestSyslogs callback. 220 // Variables to track SyslogsProvider::RequestSyslogs callback.
200 chromeos::system::SyslogsProvider::Handle syslogs_handle_; 221 chromeos::system::SyslogsProvider::Handle syslogs_handle_;
201 CancelableRequestConsumer syslogs_consumer_; 222 CancelableRequestConsumer syslogs_consumer_;
223
224 // Timestamp of when the feedback request was initiated
225 std::string timestamp_;
202 #endif 226 #endif
203 227
204 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler); 228 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler);
205 }; 229 };
206 230
207 ChromeWebUIDataSource* CreateFeedbackUIHTMLSource(bool successful_init) { 231 ChromeWebUIDataSource* CreateFeedbackUIHTMLSource(bool successful_init) {
208 ChromeWebUIDataSource* source = 232 ChromeWebUIDataSource* source =
209 new ChromeWebUIDataSource(chrome::kChromeUIFeedbackHost); 233 new ChromeWebUIDataSource(chrome::kChromeUIFeedbackHost);
210 234
211 source->AddLocalizedString("title", IDS_FEEDBACK_TITLE); 235 source->AddLocalizedString("title", IDS_FEEDBACK_TITLE);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 321 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
298 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); 322 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_);
299 } 323 }
300 324
301 bool FeedbackHandler::Init() { 325 bool FeedbackHandler::Init() {
302 std::string page_url; 326 std::string page_url;
303 if (tab_->GetController().GetActiveEntry()) { 327 if (tab_->GetController().GetActiveEntry()) {
304 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); 328 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec();
305 } 329 }
306 330
307 std::string params = page_url.substr(strlen(chrome::kChromeUIFeedbackURL)); 331 url_parse::Parsed parts;
308 // Erase the # - the first character. 332 ParseStandardURL(page_url.c_str(), page_url.length(), &parts);
309 if (params.length())
310 params.erase(params.begin(), params.begin() + 1);
311 333
312 size_t additional_params_pos = params.find('?'); 334 size_t params_start = page_url.find("?");
313 if (additional_params_pos != std::string::npos) 335 std::string index_str = page_url.substr(parts.ref.begin,
314 params.erase(params.begin() + additional_params_pos, params.end()); 336 params_start - parts.ref.begin);
337 std::string query = page_url.substr(params_start + 1);
315 338
316 int index = 0; 339 int index = 0;
317 if (!base::StringToInt(params, &index)) 340 if (!base::StringToInt(index_str, &index))
318 return false; 341 return false;
319 342
343 #if defined(OS_CHROMEOS)
344 std::vector<std::string> params;
345 if (Tokenize(query, std::string("&"), &params)) {
346 for (std::vector<std::string>::iterator it = params.begin();
347 it != params.end(); ++it) {
348 if (StartsWithASCII(*it, std::string(kTimestampParameter), true)) {
349 timestamp_ = *it;
350 ReplaceFirstSubstringAfterOffset(&timestamp_,
351 0,
352 kTimestampParameter,
353 "");
354 break;
355 }
356 }
357 }
358 #endif
359
320 Browser* browser = BrowserList::GetLastActive(); 360 Browser* browser = BrowserList::GetLastActive();
321 // Sanity checks. 361 // Sanity checks.
322 if (((index == 0) && (params != "0")) || !browser || 362 if (((index == 0) && (index_str != "0")) || !browser ||
323 index >= browser->tab_count()) { 363 index >= browser->tab_count()) {
324 return false; 364 return false;
325 } 365 }
326 366
327 WebContents* target_tab = 367 WebContents* target_tab =
328 browser->GetTabContentsWrapperAt(index)->web_contents(); 368 browser->GetTabContentsWrapperAt(index)->web_contents();
329 if (target_tab) { 369 if (target_tab) {
330 target_tab_url_ = target_tab->GetURL().spec(); 370 target_tab_url_ = target_tab->GetURL().spec();
331 } 371 }
332 372
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) 502 feedback_data_->UpdateData(Profile::FromWebUI(web_ui())
463 , target_tab_url_ 503 , target_tab_url_
464 , std::string() 504 , std::string()
465 , page_url 505 , page_url
466 , description 506 , description
467 , image_ptr 507 , image_ptr
468 #if defined(OS_CHROMEOS) 508 #if defined(OS_CHROMEOS)
469 , user_email 509 , user_email
470 , send_sys_info 510 , send_sys_info
471 , false // sent_report 511 , false // sent_report
512 , timestamp_
472 #endif 513 #endif
473 ); 514 );
474 515
475 #if defined(OS_CHROMEOS) 516 #if defined(OS_CHROMEOS)
476 // If we don't require sys_info, or we have it, or we never requested it 517 // If we don't require sys_info, or we have it, or we never requested it
477 // (because libcros failed to load), then send the report now. 518 // (because libcros failed to load), then send the report now.
478 // Otherwise, the report will get sent when we receive sys_info. 519 // Otherwise, the report will get sent when we receive sys_info.
479 if (!send_sys_info || feedback_data_->sys_info() != NULL || 520 if (!send_sys_info || feedback_data_->sys_info() != NULL ||
480 syslogs_handle_ == 0) { 521 syslogs_handle_ == 0) {
481 feedback_data_->SendReport(); 522 feedback_data_->SendReport();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 web_ui->AddMessageHandler(handler); 576 web_ui->AddMessageHandler(handler);
536 577
537 // The handler's init will determine whether we show the error html page. 578 // The handler's init will determine whether we show the error html page.
538 ChromeWebUIDataSource* html_source = 579 ChromeWebUIDataSource* html_source =
539 CreateFeedbackUIHTMLSource(handler->Init()); 580 CreateFeedbackUIHTMLSource(handler->Init());
540 581
541 // Set up the chrome://feedback/ source. 582 // Set up the chrome://feedback/ source.
542 Profile* profile = Profile::FromWebUI(web_ui); 583 Profile* profile = Profile::FromWebUI(web_ui);
543 profile->GetChromeURLDataManager()->AddDataSource(html_source); 584 profile->GetChromeURLDataManager()->AddDataSource(html_source);
544 } 585 }
OLDNEW
« chrome/browser/feedback/feedback_data.h ('K') | « chrome/browser/ui/views/accelerator_table.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698