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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ 6 #define CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/files/file_path.h" 12 #include "chrome/browser/feedback/feedback_data.h" 13 #include "chrome/browser/feedback/proto/common.pb.h" 14 #include "chrome/browser/feedback/proto/dom.pb.h" 15 #include "chrome/browser/feedback/proto/extension.pb.h" 16 #include "chrome/browser/feedback/proto/math.pb.h" 17 #include "chrome/browser/ui/webui/screenshot_source.h" 18 #include "ui/gfx/rect.h" 19 20 #if defined(OS_MACOSX) 21 #include "base/sys_info.h" 22 #elif defined(OS_WIN) 23 #include "base/win/windows_version.h" 24 #endif 25 26 class Profile; 27 28 namespace content { 29 class WebContents; 30 } 31 32 namespace chrome { 33 extern const char kAppLauncherCategoryTag[]; 34 } // namespace chrome 35 36 class FeedbackUtil { 37 public: 38 39 #if defined(OS_MACOSX) 40 enum BugType { 41 PAGE_WONT_LOAD = 0, 42 PAGE_LOOKS_ODD, 43 PHISHING_PAGE, 44 CANT_SIGN_IN, 45 CHROME_MISBEHAVES, 46 SOMETHING_MISSING, 47 BROWSER_CRASH, 48 OTHER_PROBLEM 49 }; 50 #endif 51 52 53 // SetOSVersion copies the maj.minor.build + servicePack_string 54 // into a string. We currently have: 55 // base::win::GetVersion returns WinVersion, which is just 56 // an enum of 2000, XP, 2003, or VISTA. Not enough detail for 57 // bug reports. 58 // base::SysInfo::OperatingSystemVersion returns an std::string 59 // but doesn't include the build or service pack. That function 60 // is probably the right one to extend, but will require changing 61 // all the call sites or making it a wrapper around another util. 62 static void SetOSVersion(std::string *os_version); 63 64 // Send the feedback report after the specified delay 65 static void DispatchFeedback(Profile* profile, 66 std::string* feedback_data, 67 int64 delay); 68 69 // Generates bug report data. 70 static void SendReport(scoped_refptr<FeedbackData> data); 71 // Redirects the user to Google's phishing reporting page. 72 static void ReportPhishing(content::WebContents* current_tab, 73 const std::string& phishing_url); 74 // Maintains a single vector of bytes to store the last screenshot taken. 75 static std::vector<unsigned char>* GetScreenshotPng(); 76 static void ClearScreenshotPng(); 77 static void SetScreenshotSize(const gfx::Rect& rect); 78 static gfx::Rect& GetScreenshotSize(); 79 static bool ZipString(const std::string& logs, std::string* compressed_logs); 80 81 class PostCleanup; 82 83 private: 84 // Add a key value pair to the feedback object 85 static void AddFeedbackData( 86 userfeedback::ExtensionSubmit* feedback_data, 87 const std::string& key, const std::string& value); 88 89 // Send the feedback report 90 static void SendFeedback(Profile* profile, 91 std::string* feedback_data, 92 int64 previous_delay); 93 94 #if defined(OS_CHROMEOS) 95 static bool ValidFeedbackSize(const std::string& content); 96 #endif 97 98 DISALLOW_IMPLICIT_CONSTRUCTORS(FeedbackUtil); 99 }; 100 101 #endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ 102