OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "content/public/browser/url_data_source_delegate.h" | 15 #include "content/public/browser/url_data_source.h" |
16 | 16 |
17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
18 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 18 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
19 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
20 #include "chrome/browser/google_apis/gdata_errorcode.h" | 20 #include "chrome/browser/google_apis/gdata_errorcode.h" |
21 #endif | 21 #endif |
22 | 22 |
23 typedef std::vector<unsigned char> ScreenshotData; | 23 typedef std::vector<unsigned char> ScreenshotData; |
24 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; | 24 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; |
25 | 25 |
26 class FilePath; | 26 class FilePath; |
27 class Profile; | 27 class Profile; |
28 | 28 |
29 // ScreenshotSource is the data source that serves screenshots (saved | 29 // ScreenshotSource is the data source that serves screenshots (saved |
30 // or current) to the bug report html ui. | 30 // or current) to the bug report html ui. |
31 class ScreenshotSource : public content::URLDataSourceDelegate { | 31 class ScreenshotSource : public content::URLDataSource { |
32 public: | 32 public: |
33 explicit ScreenshotSource( | 33 explicit ScreenshotSource( |
34 std::vector<unsigned char>* current_screenshot, | 34 std::vector<unsigned char>* current_screenshot, |
35 Profile* profile); | 35 Profile* profile); |
36 | 36 |
37 #if defined(USE_ASH) | 37 #if defined(USE_ASH) |
38 | |
39 // Queries the browser process to determine if screenshots are disabled. | 38 // Queries the browser process to determine if screenshots are disabled. |
40 static bool AreScreenshotsDisabled(); | 39 static bool AreScreenshotsDisabled(); |
41 | 40 |
42 // Common access for the screenshot directory, parameter is set to the | 41 // Common access for the screenshot directory, parameter is set to the |
43 // requested directory and return value of true is given upon success. | 42 // requested directory and return value of true is given upon success. |
44 static bool GetScreenshotDirectory(FilePath* directory); | 43 static bool GetScreenshotDirectory(FilePath* directory); |
45 #endif | 44 #endif |
46 | 45 |
47 // Get the basefilename for screenshots | 46 // Get the basefilename for screenshots |
48 static std::string GetScreenshotBaseFilename(); | 47 static std::string GetScreenshotBaseFilename(); |
49 | 48 |
50 // content::URLDataSourceDelegate implementation. | 49 // content::URLDataSource implementation. |
51 virtual std::string GetSource() OVERRIDE; | 50 virtual std::string GetSource() OVERRIDE; |
52 virtual void StartDataRequest(const std::string& path, | 51 virtual void StartDataRequest( |
53 bool is_incognito, | 52 const std::string& path, |
54 int request_id) OVERRIDE; | 53 bool is_incognito, |
| 54 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
55 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 55 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
56 | 56 |
57 // Get the screenshot specified by the given relative path that we've cached | 57 // Get the screenshot specified by the given relative path that we've cached |
58 // from a previous request to the screenshots source. | 58 // from a previous request to the screenshots source. |
59 // Note: This method strips the query string from the given path. | 59 // Note: This method strips the query string from the given path. |
60 ScreenshotDataPtr GetCachedScreenshot(const std::string& screenshot_path); | 60 ScreenshotDataPtr GetCachedScreenshot(const std::string& screenshot_path); |
61 | 61 |
62 // Url that represents the base directory for screenshots. | 62 // Url that represents the base directory for screenshots. |
63 static const char kScreenshotUrlRoot[]; | 63 static const char kScreenshotUrlRoot[]; |
64 // Identifier for the current screenshot | 64 // Identifier for the current screenshot |
65 // (relative to screenshot base directory). | 65 // (relative to screenshot base directory). |
66 static const char kScreenshotCurrent[]; | 66 static const char kScreenshotCurrent[]; |
67 // Path for directory where screenshots are saved | 67 // Path for directory where screenshots are saved |
68 // (relative to screenshot base directory). | 68 // (relative to screenshot base directory). |
69 static const char kScreenshotSaved[]; | 69 static const char kScreenshotSaved[]; |
70 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
71 // Common prefix to screenshot filenames. | 71 // Common prefix to screenshot filenames. |
72 static const char kScreenshotPrefix[]; | 72 static const char kScreenshotPrefix[]; |
73 // Common suffix to screenshot filenames. | 73 // Common suffix to screenshot filenames. |
74 static const char kScreenshotSuffix[]; | 74 static const char kScreenshotSuffix[]; |
75 #endif | 75 #endif |
76 | 76 |
77 private: | 77 private: |
78 virtual ~ScreenshotSource(); | 78 virtual ~ScreenshotSource(); |
79 | 79 |
80 // Send the screenshot specified by the given relative path to the requestor. | 80 // Send the screenshot specified by the given relative path to the requestor. |
81 // This is the ancestor for SendSavedScreenshot and CacheAndSendScreenshot. | 81 // This is the ancestor for SendSavedScreenshot and CacheAndSendScreenshot. |
82 // All calls to send a screenshot should only call this method. | 82 // All calls to send a screenshot should only call this method. |
83 // Note: This method strips the query string from the given path. | 83 // Note: This method strips the query string from the given path. |
84 void SendScreenshot(const std::string& screenshot_path, int request_id); | 84 void SendScreenshot(const std::string& screenshot_path, |
| 85 const content::URLDataSource::GotDataCallback& callback); |
85 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
86 // Send a saved screenshot image file specified by the given screenshot path | 87 // Send a saved screenshot image file specified by the given screenshot path |
87 // to the requestor. | 88 // to the requestor. |
88 void SendSavedScreenshot(const std::string& screenshot_path, | 89 void SendSavedScreenshot( |
89 int request_id, | 90 const std::string& screenshot_path, |
90 const FilePath& file); | 91 const content::URLDataSource::GotDataCallback& callback, |
| 92 const FilePath& file); |
91 | 93 |
92 // The callback for Drive's getting file method. | 94 // The callback for Drive's getting file method. |
93 void GetSavedScreenshotCallback(const std::string& screenshot_path, | 95 void GetSavedScreenshotCallback( |
94 int request_id, | 96 const std::string& screenshot_path, |
95 drive::DriveFileError error, | 97 const content::URLDataSource::GotDataCallback& callback, |
96 const FilePath& file, | 98 drive::DriveFileError error, |
97 const std::string& unused_mime_type, | 99 const FilePath& file, |
98 drive::DriveFileType file_type); | 100 const std::string& unused_mime_type, |
| 101 drive::DriveFileType file_type); |
99 | 102 |
100 #endif | 103 #endif |
101 // Sends the screenshot data to the requestor while caching it locally to the | 104 // Sends the screenshot data to the requestor while caching it locally to the |
102 // class instance, indexed by path. | 105 // class instance, indexed by path. |
103 void CacheAndSendScreenshot(const std::string& screenshot_path, | 106 void CacheAndSendScreenshot( |
104 int request_id, | 107 const std::string& screenshot_path, |
105 ScreenshotDataPtr bytes); | 108 const content::URLDataSource::GotDataCallback& callback, |
| 109 ScreenshotDataPtr bytes); |
106 | 110 |
107 // Pointer to the screenshot data for the current screenshot. | 111 // Pointer to the screenshot data for the current screenshot. |
108 ScreenshotDataPtr current_screenshot_; | 112 ScreenshotDataPtr current_screenshot_; |
109 | 113 |
110 Profile* profile_; | 114 Profile* profile_; |
111 | 115 |
112 // Key: Relative path to the screenshot (including filename) | 116 // Key: Relative path to the screenshot (including filename) |
113 // Value: Pointer to the screenshot data associated with the path. | 117 // Value: Pointer to the screenshot data associated with the path. |
114 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; | 118 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; |
115 | 119 |
116 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); | 120 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); |
117 }; | 121 }; |
118 | 122 |
119 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 123 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
OLD | NEW |