OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/bug_report_ui.h" | 5 #include "chrome/browser/dom_ui/bug_report_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 done.Wait(); | 109 done.Wait(); |
110 } | 110 } |
111 | 111 |
112 std::string GetUserEmail() { | 112 std::string GetUserEmail() { |
113 chromeos::UserManager* manager = chromeos::UserManager::Get(); | 113 chromeos::UserManager* manager = chromeos::UserManager::Get(); |
114 if (!manager) | 114 if (!manager) |
115 return std::string(); | 115 return std::string(); |
116 else | 116 else |
117 return manager->logged_in_user().email(); | 117 return manager->logged_in_user().email(); |
118 } | 118 } |
119 #endif | |
119 | 120 |
120 #endif | 121 // Returns the index of the feedback tab if already open, -1 otherwise |
121 } // namespace | 122 int GetIndexOfFeedbackTab(Browser* browser) { |
123 GURL bug_report_url(chrome::kChromeUIBugReportURL); | |
124 for (int i = 0; i < browser->tab_count(); ++i) { | |
125 TabContents* tab = browser->GetTabContentsAt(i); | |
126 if (tab) | |
127 if (bug_report_url == tab->GetURL().GetWithEmptyPath()) | |
oshima
2010/12/02 18:03:30
if (tab && tab->GetURL().GetWithEmptyPath() == bug
rkc
2010/12/02 19:54:04
Done.
| |
128 return i; | |
129 } | |
130 | |
131 return -1; | |
132 } | |
133 | |
134 } // namespace | |
122 | 135 |
123 | 136 |
124 namespace browser { | 137 namespace browser { |
125 | 138 |
126 // TODO(rkc): Eventually find a better way to do this | 139 // TODO(rkc): Eventually find a better way to do this |
127 std::vector<unsigned char>* last_screenshot_png = 0; | 140 std::vector<unsigned char>* last_screenshot_png = 0; |
128 gfx::Rect screen_size; | 141 gfx::Rect screen_size; |
129 | 142 |
143 // Get bounds in different ways for different OS's; | |
144 #if defined(TOOLKIT_VIEWS) | |
145 // Windows/ChromeOS support Views - so we get dimensions from the | |
146 // views::Window object | |
130 void RefreshLastScreenshot(views::Window* parent) { | 147 void RefreshLastScreenshot(views::Window* parent) { |
148 gfx::NativeWindow window = parent->GetNativeWindow(); | |
149 int width = parent->GetBounds().width(); | |
150 int height = parent->GetBounds().height(); | |
151 #elif defined(OS_LINUX) | |
152 // Linux provides its bounds and a native window handle to the screen | |
153 void RefreshLastScreenshot(gfx::NativeWindow window, | |
154 const gfx::Rect& bounds) { | |
155 int width = bounds.width(); | |
156 int height = bounds.height(); | |
157 #elif defined(OS_MACOSX) | |
158 // Mac gets its bounds from the GrabWindowSnapshot function | |
159 void RefreshLastScreenshot(NSWindow* window) { | |
160 int width = 0; | |
161 int height = 0; | |
162 #endif | |
163 | |
131 // Grab an exact snapshot of the window that the user is seeing (i.e. as | 164 // Grab an exact snapshot of the window that the user is seeing (i.e. as |
132 // rendered--do not re-render, and include windowed plugins). | 165 // rendered--do not re-render, and include windowed plugins). |
133 if (last_screenshot_png) | 166 if (last_screenshot_png) |
134 last_screenshot_png->clear(); | 167 last_screenshot_png->clear(); |
135 else | 168 else |
136 last_screenshot_png = new std::vector<unsigned char>; | 169 last_screenshot_png = new std::vector<unsigned char>; |
137 | 170 |
138 #if defined(USE_X11) | 171 #if defined(USE_X11) |
139 screen_size = parent->GetBounds(); | 172 x11_util::GrabWindowSnapshot(window, last_screenshot_png); |
140 x11_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png); | |
141 #elif defined(OS_MACOSX) | 173 #elif defined(OS_MACOSX) |
142 int width = 0, height = 0; | 174 mac_util::GrabWindowSnapshot(window, last_screenshot_png, &width, &height); |
143 mac_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png, | |
144 &width, &height); | |
145 #elif defined(OS_WIN) | 175 #elif defined(OS_WIN) |
146 screen_size = parent->GetBounds(); | 176 win_util::GrabWindowSnapshot(window, last_screenshot_png); |
147 win_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png); | |
148 #endif | 177 #endif |
178 | |
179 screen_size.set_width(width); | |
180 screen_size.set_height(height); | |
149 } | 181 } |
150 | 182 |
151 // Global "display this dialog" function declared in browser_dialogs.h. | 183 #if defined(TOOLKIT_VIEWS) |
152 void ShowHtmlBugReportView(views::Window* parent, Browser* browser) { | 184 void ShowHtmlBugReportView(views::Window* parent, Browser* browser) { |
185 #elif defined(OS_LINUX) | |
186 void ShowHtmlBugReportView(gfx::NativeWindow window, const gfx::Rect& bounds, | |
187 Browser* browser) { | |
188 #elif defined(OS_MACOSX) | |
189 void ShowHtmlBugReportView(NSWindow* window, Browser* browser) { | |
190 #endif | |
191 | |
192 // First check if we're already open (we cannot depend on ShowSingletonTab | |
193 // for this functionality since we need to make *sure* we never get | |
194 // instantiated again while we are open - with singleton tabs, that can | |
195 // happen) | |
196 int feedback_tab_index = GetIndexOfFeedbackTab(browser); | |
197 if (feedback_tab_index >=0) { | |
198 // Do not refresh screenshot, do not create a new tab | |
199 browser->SelectTabContentsAt(feedback_tab_index, true); | |
200 } | |
201 | |
202 // now for refreshing the last screenshot | |
203 #if defined(TOOLKIT_VIEWS) | |
204 RefreshLastScreenshot(parent); | |
205 #elif defined(OS_LINUX) | |
206 RefreshLastScreenshot(window, bounds); | |
207 #elif defined(OS_MACOSX) | |
208 RefreshLastScreenshot(window); | |
209 #endif | |
210 | |
153 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + | 211 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + |
154 "#" + base::IntToString(browser->selected_index()); | 212 "#" + base::IntToString(browser->selected_index()); |
155 | |
156 RefreshLastScreenshot(parent); | |
157 browser->ShowSingletonTab(GURL(bug_report_url), false); | 213 browser->ShowSingletonTab(GURL(bug_report_url), false); |
158 } | 214 } |
159 | 215 |
160 } // namespace browser | 216 } // namespace browser |
oshima
2010/12/02 18:03:30
two spaces before //
rkc
2010/12/02 19:54:04
Done.
| |
161 | 217 |
162 | 218 |
163 class BugReportUIHTMLSource : public ChromeURLDataManager::DataSource { | 219 class BugReportUIHTMLSource : public ChromeURLDataManager::DataSource { |
164 public: | 220 public: |
165 explicit BugReportUIHTMLSource(base::StringPiece html); | 221 explicit BugReportUIHTMLSource(base::StringPiece html); |
166 | 222 |
167 // Called when the network layer has requested a resource underneath | 223 // Called when the network layer has requested a resource underneath |
168 // the path we registered. | 224 // the path we registered. |
169 virtual void StartDataRequest(const std::string& path, | 225 virtual void StartDataRequest(const std::string& path, |
170 bool is_off_the_record, | 226 bool is_off_the_record, |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 711 } |
656 | 712 |
657 // #5 - System info checkbox. | 713 // #5 - System info checkbox. |
658 std::string sys_info_checkbox; | 714 std::string sys_info_checkbox; |
659 (*i)->GetAsString(&sys_info_checkbox); | 715 (*i)->GetAsString(&sys_info_checkbox); |
660 bool send_sys_info = (sys_info_checkbox == "true"); | 716 bool send_sys_info = (sys_info_checkbox == "true"); |
661 | 717 |
662 // If we aren't sending the sys_info, cancel the gathering of the syslogs. | 718 // If we aren't sending the sys_info, cancel the gathering of the syslogs. |
663 if (!send_sys_info) | 719 if (!send_sys_info) |
664 CancelFeedbackCollection(); | 720 CancelFeedbackCollection(); |
721 #endif | |
665 | 722 |
666 // Update the data in bug_report_ so it can be sent | 723 // Update the data in bug_report_ so it can be sent |
667 bug_report_->UpdateData(dom_ui_->GetProfile() | 724 bug_report_->UpdateData(dom_ui_->GetProfile() |
668 , target_tab_url_ | 725 , target_tab_url_ |
669 , target_tab_title_ | 726 , target_tab_title_ |
670 , problem_type | 727 , problem_type |
671 , page_url | 728 , page_url |
672 , description | 729 , description |
673 , image | 730 , image |
674 #if defined(OS_CHROMEOS) | 731 #if defined(OS_CHROMEOS) |
675 , user_email | 732 , user_email |
676 , send_sys_info | 733 , send_sys_info |
677 , false // sent_report | 734 , false // sent_report |
678 #endif | 735 #endif |
679 ); | 736 ); |
680 | 737 |
738 #if defined(OS_CHROMEOS) | |
681 // If we don't require sys_info, or we have it, or we never requested it | 739 // If we don't require sys_info, or we have it, or we never requested it |
682 // (because libcros failed to load), then send the report now. | 740 // (because libcros failed to load), then send the report now. |
683 // Otherwise, the report will get sent when we receive sys_info. | 741 // Otherwise, the report will get sent when we receive sys_info. |
684 if (!send_sys_info || bug_report_->sys_info() != NULL || | 742 if (!send_sys_info || bug_report_->sys_info() != NULL || |
685 syslogs_handle_ == 0) { | 743 syslogs_handle_ == 0) { |
686 bug_report_->SendReport(); | 744 bug_report_->SendReport(); |
687 } | 745 } |
688 #else | 746 #else |
689 bug_report_->SendReport(); | 747 bug_report_->SendReport(); |
690 #endif | 748 #endif |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 BugReportUIHTMLSource* html_source = | 801 BugReportUIHTMLSource* html_source = |
744 new BugReportUIHTMLSource(handler->Init()); | 802 new BugReportUIHTMLSource(handler->Init()); |
745 // Set up the chrome://bugreport/ source. | 803 // Set up the chrome://bugreport/ source. |
746 BrowserThread::PostTask( | 804 BrowserThread::PostTask( |
747 BrowserThread::IO, FROM_HERE, | 805 BrowserThread::IO, FROM_HERE, |
748 NewRunnableMethod( | 806 NewRunnableMethod( |
749 Singleton<ChromeURLDataManager>::get(), | 807 Singleton<ChromeURLDataManager>::get(), |
750 &ChromeURLDataManager::AddDataSource, | 808 &ChromeURLDataManager::AddDataSource, |
751 make_scoped_refptr(html_source))); | 809 make_scoped_refptr(html_source))); |
752 } | 810 } |
OLD | NEW |