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/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "content/public/browser/url_data_source_delegate.h" |
15 | 16 |
16 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
17 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 18 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
19 #include "chrome/browser/google_apis/gdata_errorcode.h" | 20 #include "chrome/browser/google_apis/gdata_errorcode.h" |
20 #endif | 21 #endif |
21 | 22 |
22 typedef std::vector<unsigned char> ScreenshotData; | 23 typedef std::vector<unsigned char> ScreenshotData; |
23 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; | 24 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; |
24 | 25 |
25 class FilePath; | 26 class FilePath; |
26 class Profile; | 27 class Profile; |
27 | 28 |
28 // ScreenshotSource is the data source that serves screenshots (saved | 29 // ScreenshotSource is the data source that serves screenshots (saved |
29 // or current) to the bug report html ui. | 30 // or current) to the bug report html ui. |
30 class ScreenshotSource : public ChromeURLDataManager::DataSource { | 31 class ScreenshotSource : public content::URLDataSourceDelegate { |
31 public: | 32 public: |
32 explicit ScreenshotSource( | 33 explicit ScreenshotSource( |
33 std::vector<unsigned char>* current_screenshot, | 34 std::vector<unsigned char>* current_screenshot, |
34 Profile* profile); | 35 Profile* profile); |
35 | 36 |
36 #if defined(USE_ASH) | 37 #if defined(USE_ASH) |
37 | 38 |
38 // Queries the browser process to determine if screenshots are disabled. | 39 // Queries the browser process to determine if screenshots are disabled. |
39 static bool AreScreenshotsDisabled(); | 40 static bool AreScreenshotsDisabled(); |
40 | 41 |
41 // Common access for the screenshot directory, parameter is set to the | 42 // Common access for the screenshot directory, parameter is set to the |
42 // requested directory and return value of true is given upon success. | 43 // requested directory and return value of true is given upon success. |
43 static bool GetScreenshotDirectory(FilePath* directory); | 44 static bool GetScreenshotDirectory(FilePath* directory); |
44 #endif | 45 #endif |
45 | 46 |
46 // Get the basefilename for screenshots | 47 // Get the basefilename for screenshots |
47 static std::string GetScreenshotBaseFilename(); | 48 static std::string GetScreenshotBaseFilename(); |
48 | 49 |
49 // Called when the network layer has requested a resource underneath | 50 // content::URLDataSourceDelegate implementation. |
50 // the path we registered. | 51 virtual std::string GetSource() OVERRIDE; |
51 virtual void StartDataRequest(const std::string& path, | 52 virtual void StartDataRequest(const std::string& path, |
52 bool is_incognito, | 53 bool is_incognito, |
53 int request_id) OVERRIDE; | 54 int request_id) OVERRIDE; |
54 | |
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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Profile* profile_; | 110 Profile* profile_; |
111 | 111 |
112 // Key: Relative path to the screenshot (including filename) | 112 // Key: Relative path to the screenshot (including filename) |
113 // Value: Pointer to the screenshot data associated with the path. | 113 // Value: Pointer to the screenshot data associated with the path. |
114 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; | 114 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); | 116 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); |
117 }; | 117 }; |
118 | 118 |
119 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 119 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
OLD | NEW |