| 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/views/bug_report_view.h" | 5 #include "chrome/browser/views/bug_report_view.h" |
| 6 | 6 |
| 7 #include "app/combobox_model.h" | 7 #include "app/combobox_model.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_version_info.h" | 11 #include "chrome/app/chrome_version_info.h" |
| 12 #include "chrome/browser/bug_report_util.h" | 12 #include "chrome/browser/bug_report_util.h" |
| 13 #include "chrome/browser/pref_service.h" | 13 #include "chrome/browser/pref_service.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/browser_list.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 16 #include "chrome/browser/tab_contents/navigation_controller.h" | 17 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 17 #include "chrome/browser/tab_contents/navigation_entry.h" | 18 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 19 #include "chrome/common/net/url_fetcher.h" | 20 #include "chrome/common/net/url_fetcher.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 #include "app/x11_util.h" | 36 #include "app/x11_util.h" |
| 36 #else | 37 #else |
| 37 #include "app/win_util.h" | 38 #include "app/win_util.h" |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 using views::ColumnSet; | 41 using views::ColumnSet; |
| 41 using views::GridLayout; | 42 using views::GridLayout; |
| 42 | 43 |
| 43 // Report a bug data version. | 44 // Report a bug data version. |
| 44 static const int kBugReportVersion = 1; | 45 static const int kBugReportVersion = 1; |
| 46 static const int kScreenImageRadioGroup = 2; |
| 47 |
| 45 | 48 |
| 46 // Number of lines description field can display at one time. | 49 // Number of lines description field can display at one time. |
| 47 static const int kDescriptionLines = 5; | 50 static const int kDescriptionLines = 5; |
| 48 | 51 |
| 49 class BugReportComboBoxModel : public ComboboxModel { | 52 class BugReportComboBoxModel : public ComboboxModel { |
| 50 public: | 53 public: |
| 51 BugReportComboBoxModel() {} | 54 BugReportComboBoxModel() {} |
| 52 | 55 |
| 53 // ComboboxModel interface. | 56 // ComboboxModel interface. |
| 54 virtual int GetItemCount() { | 57 virtual int GetItemCount() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Grab an exact snapshot of the window that the user is seeing (i.e. as | 101 // Grab an exact snapshot of the window that the user is seeing (i.e. as |
| 99 // rendered--do not re-render, and include windowed plugins). | 102 // rendered--do not re-render, and include windowed plugins). |
| 100 std::vector<unsigned char> *screenshot_png = new std::vector<unsigned char>; | 103 std::vector<unsigned char> *screenshot_png = new std::vector<unsigned char>; |
| 101 | 104 |
| 102 #if defined(OS_LINUX) | 105 #if defined(OS_LINUX) |
| 103 x11_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png); | 106 x11_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png); |
| 104 #else | 107 #else |
| 105 win_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png); | 108 win_util::GrabWindowSnapshot(parent->GetNativeWindow(), screenshot_png); |
| 106 #endif | 109 #endif |
| 107 | 110 |
| 111 // Get the size of the parent window to capture screenshot dimensions |
| 112 gfx::Rect screenshot_size = parent->GetBounds(); |
| 113 |
| 114 |
| 108 // The BugReportView takes ownership of the png data, and will dispose of | 115 // The BugReportView takes ownership of the png data, and will dispose of |
| 109 // it in its destructor. | 116 // it in its destructor. |
| 110 view->set_png_data(screenshot_png); | 117 view->set_png_data(screenshot_png); |
| 118 view->set_screenshot_size(screenshot_size); |
| 111 | 119 |
| 112 // Create and show the dialog. | 120 // Create and show the dialog. |
| 113 views::Window::CreateChromeWindow(parent->GetNativeWindow(), gfx::Rect(), | 121 views::Window::CreateChromeWindow(parent->GetNativeWindow(), gfx::Rect(), |
| 114 view)->Show(); | 122 view)->Show(); |
| 115 } | 123 } |
| 116 | 124 |
| 117 } // namespace browser | 125 } // namespace browser |
| 118 | 126 |
| 119 // BugReportView - create and submit a bug report from the user. | 127 // BugReportView - create and submit a bug report from the user. |
| 120 // This is separate from crash reporting, which is handled by Breakpad. | 128 // This is separate from crash reporting, which is handled by Breakpad. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 description_text_ = | 185 description_text_ = |
| 178 new views::Textfield(views::Textfield::STYLE_MULTILINE); | 186 new views::Textfield(views::Textfield::STYLE_MULTILINE); |
| 179 description_text_->SetHeightInLines(kDescriptionLines); | 187 description_text_->SetHeightInLines(kDescriptionLines); |
| 180 description_text_->SetAccessibleName(description_label_->GetText()); | 188 description_text_->SetAccessibleName(description_label_->GetText()); |
| 181 #endif | 189 #endif |
| 182 | 190 |
| 183 include_page_source_checkbox_ = new views::Checkbox( | 191 include_page_source_checkbox_ = new views::Checkbox( |
| 184 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_SOURCE_CHKBOX)); | 192 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_SOURCE_CHKBOX)); |
| 185 include_page_source_checkbox_->SetChecked(true); | 193 include_page_source_checkbox_->SetChecked(true); |
| 186 | 194 |
| 195 #if defined(OS_CHROMEOS) |
| 196 include_last_screen_image_radio_ = new views::RadioButton( |
| 197 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_LAST_SCREEN_IMAGE), |
| 198 kScreenImageRadioGroup); |
| 199 last_screenshot_iv_ = new views::ImageView(); |
| 200 |
| 201 include_new_screen_image_radio_ = new views::RadioButton( |
| 202 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE), |
| 203 kScreenImageRadioGroup); |
| 204 |
| 205 include_system_information_checkbox_ = new views::Checkbox( |
| 206 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); |
| 207 system_information_url_ = new views::Link( |
| 208 l10n_util::GetString(IDS_BUGREPORT_SYSTEM_INFORMATION_URL_TEXT)); |
| 209 system_information_url_->SetController(this); |
| 210 |
| 211 include_last_screen_image_radio_->SetChecked(true); |
| 212 include_system_information_checkbox_->SetChecked(true); |
| 213 #endif |
| 187 include_page_image_checkbox_ = new views::Checkbox( | 214 include_page_image_checkbox_ = new views::Checkbox( |
| 188 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_IMAGE_CHKBOX)); | 215 l10n_util::GetString(IDS_BUGREPORT_INCLUDE_PAGE_IMAGE_CHKBOX)); |
| 189 include_page_image_checkbox_->SetChecked(true); | 216 include_page_image_checkbox_->SetChecked(true); |
| 190 | 217 |
| 191 // Arranges controls by using GridLayout. | 218 // Arranges controls by using GridLayout. |
| 192 const int column_set_id = 0; | 219 const int column_set_id = 0; |
| 193 GridLayout* layout = CreatePanelGridLayout(this); | 220 GridLayout* layout = CreatePanelGridLayout(this); |
| 194 SetLayoutManager(layout); | 221 SetLayoutManager(layout); |
| 195 ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 222 ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
| 196 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 223 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 225 layout->AddView(description_text_, 1, 1, GridLayout::FILL, | 252 layout->AddView(description_text_, 1, 1, GridLayout::FILL, |
| 226 GridLayout::LEADING); | 253 GridLayout::LEADING); |
| 227 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | 254 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
| 228 | 255 |
| 229 // Checkboxes. | 256 // Checkboxes. |
| 230 // The include page source checkbox is hidden until we can make it work. | 257 // The include page source checkbox is hidden until we can make it work. |
| 231 // layout->StartRow(0, column_set_id); | 258 // layout->StartRow(0, column_set_id); |
| 232 // layout->SkipColumns(1); | 259 // layout->SkipColumns(1); |
| 233 // layout->AddView(include_page_source_checkbox_); | 260 // layout->AddView(include_page_source_checkbox_); |
| 234 // layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 261 // layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 262 layout->StartRow(0, column_set_id); |
| 263 layout->SkipColumns(1); |
| 264 #if defined(OS_CHROMEOS) |
| 265 // Radio boxes to select last screen shot or, |
| 266 layout->AddView(include_last_screen_image_radio_); |
| 267 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 268 // new screenshot |
| 269 layout->StartRow(0, column_set_id); |
| 270 layout->SkipColumns(1); |
| 271 layout->AddView(include_new_screen_image_radio_); |
| 272 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
| 273 |
| 274 // Checkbox for system information |
| 275 layout->StartRow(0, column_set_id); |
| 276 layout->SkipColumns(1); |
| 277 layout->AddView(include_system_information_checkbox_); |
| 278 |
| 279 // TODO(rkc): Add a link once we're pulling system info, to it |
| 280 #else |
| 235 if (include_page_image_checkbox_) { | 281 if (include_page_image_checkbox_) { |
| 236 layout->StartRow(0, column_set_id); | 282 layout->StartRow(0, column_set_id); |
| 237 layout->SkipColumns(1); | 283 layout->SkipColumns(1); |
| 238 layout->AddView(include_page_image_checkbox_); | 284 layout->AddView(include_page_image_checkbox_); |
| 239 } | 285 } |
| 286 #endif |
| 240 | 287 |
| 241 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | 288 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
| 242 } | 289 } |
| 243 | 290 |
| 244 gfx::Size BugReportView::GetPreferredSize() { | 291 gfx::Size BugReportView::GetPreferredSize() { |
| 245 return gfx::Size(views::Window::GetLocalizedContentsSize( | 292 return gfx::Size(views::Window::GetLocalizedContentsSize( |
| 246 IDS_BUGREPORT_DIALOG_WIDTH_CHARS, | 293 IDS_BUGREPORT_DIALOG_WIDTH_CHARS, |
| 247 IDS_BUGREPORT_DIALOG_HEIGHT_LINES)); | 294 IDS_BUGREPORT_DIALOG_HEIGHT_LINES)); |
| 248 } | 295 } |
| 249 | 296 |
| 297 |
| 298 void BugReportView::UpdateReportingControls(bool is_phishing_report) { |
| 299 // page source, screen/page images, system information |
| 300 // are not needed if it's a phishing report |
| 301 |
| 302 include_page_source_checkbox_->SetEnabled(!is_phishing_report); |
| 303 include_page_source_checkbox_->SetChecked(!is_phishing_report); |
| 304 |
| 305 #if defined(OS_CHROMEOS) |
| 306 include_last_screen_image_radio_->SetEnabled(!is_phishing_report); |
| 307 include_new_screen_image_radio_->SetEnabled(!is_phishing_report); |
| 308 |
| 309 include_system_information_checkbox_->SetEnabled(!is_phishing_report); |
| 310 include_system_information_checkbox_->SetChecked(!is_phishing_report); |
| 311 |
| 312 system_information_url_->SetEnabled(!is_phishing_report); |
| 313 #else |
| 314 if (include_page_image_checkbox_) { |
| 315 include_page_image_checkbox_->SetEnabled(!is_phishing_report); |
| 316 include_page_image_checkbox_->SetChecked(!is_phishing_report); |
| 317 } |
| 318 #endif |
| 319 } |
| 320 |
| 250 void BugReportView::ItemChanged(views::Combobox* combobox, | 321 void BugReportView::ItemChanged(views::Combobox* combobox, |
| 251 int prev_index, | 322 int prev_index, |
| 252 int new_index) { | 323 int new_index) { |
| 253 if (new_index == prev_index) | 324 if (new_index == prev_index) |
| 254 return; | 325 return; |
| 255 | 326 |
| 256 problem_type_ = new_index; | 327 problem_type_ = new_index; |
| 257 bool is_phishing_report = new_index == BugReportUtil::PHISHING_PAGE; | 328 bool is_phishing_report = new_index == BugReportUtil::PHISHING_PAGE; |
| 258 | 329 |
| 259 description_text_->SetEnabled(!is_phishing_report); | 330 description_text_->SetEnabled(!is_phishing_report); |
| 260 description_text_->SetReadOnly(is_phishing_report); | 331 description_text_->SetReadOnly(is_phishing_report); |
| 261 if (is_phishing_report) { | 332 if (is_phishing_report) { |
| 262 old_report_text_ = UTF16ToWide(description_text_->text()); | 333 old_report_text_ = UTF16ToWide(description_text_->text()); |
| 263 description_text_->SetText(string16()); | 334 description_text_->SetText(string16()); |
| 264 } else if (!old_report_text_.empty()) { | 335 } else if (!old_report_text_.empty()) { |
| 265 description_text_->SetText(WideToUTF16Hack(old_report_text_)); | 336 description_text_->SetText(WideToUTF16Hack(old_report_text_)); |
| 266 old_report_text_.clear(); | 337 old_report_text_.clear(); |
| 267 } | 338 } |
| 268 include_page_source_checkbox_->SetEnabled(!is_phishing_report); | 339 |
| 269 include_page_source_checkbox_->SetChecked(!is_phishing_report); | 340 UpdateReportingControls(is_phishing_report); |
| 270 if (include_page_image_checkbox_) { | |
| 271 include_page_image_checkbox_->SetEnabled(!is_phishing_report); | |
| 272 include_page_image_checkbox_->SetChecked(!is_phishing_report); | |
| 273 } | |
| 274 GetDialogClientView()->UpdateDialogButtons(); | 341 GetDialogClientView()->UpdateDialogButtons(); |
| 275 } | 342 } |
| 276 | 343 |
| 277 void BugReportView::ContentsChanged(views::Textfield* sender, | 344 void BugReportView::ContentsChanged(views::Textfield* sender, |
| 278 const string16& new_contents) { | 345 const string16& new_contents) { |
| 279 } | 346 } |
| 280 | 347 |
| 281 bool BugReportView::HandleKeystroke(views::Textfield* sender, | 348 bool BugReportView::HandleKeystroke(views::Textfield* sender, |
| 282 const views::Textfield::Keystroke& key) { | 349 const views::Textfield::Keystroke& key) { |
| 283 return false; | 350 return false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 if (IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { | 394 if (IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { |
| 328 if (problem_type_ == BugReportUtil::PHISHING_PAGE) | 395 if (problem_type_ == BugReportUtil::PHISHING_PAGE) |
| 329 BugReportUtil::ReportPhishing(tab_, | 396 BugReportUtil::ReportPhishing(tab_, |
| 330 UTF16ToUTF8(page_url_text_->text())); | 397 UTF16ToUTF8(page_url_text_->text())); |
| 331 else | 398 else |
| 332 BugReportUtil::SendReport(profile_, | 399 BugReportUtil::SendReport(profile_, |
| 333 WideToUTF8(page_title_text_->GetText()), | 400 WideToUTF8(page_title_text_->GetText()), |
| 334 problem_type_, | 401 problem_type_, |
| 335 UTF16ToUTF8(page_url_text_->text()), | 402 UTF16ToUTF8(page_url_text_->text()), |
| 336 UTF16ToUTF8(description_text_->text()), | 403 UTF16ToUTF8(description_text_->text()), |
| 404 #if defined(OS_CHROMEOS) |
| 405 include_new_screen_image_radio_->checked() && png_data_.get() ? |
| 406 #else |
| 337 include_page_image_checkbox_->checked() && png_data_.get() ? | 407 include_page_image_checkbox_->checked() && png_data_.get() ? |
| 408 #endif |
| 338 reinterpret_cast<const char *>(&((*png_data_.get())[0])) : NULL, | 409 reinterpret_cast<const char *>(&((*png_data_.get())[0])) : NULL, |
| 339 png_data_->size()); | 410 png_data_->size(), screenshot_size_.width(), |
| 411 screenshot_size_.height()); |
| 340 } | 412 } |
| 341 return true; | 413 return true; |
| 342 } | 414 } |
| 343 | 415 |
| 416 #if defined(OS_CHROMEOS) |
| 417 void BugReportView::LinkActivated(views::Link* source, |
| 418 int event_flags) { |
| 419 GURL url; |
| 420 if (source == system_information_url_) { |
| 421 url = GURL(l10n_util::GetStringUTF16(IDS_BUGREPORT_SYSTEM_INFORMATION_URL)); |
| 422 } else { |
| 423 NOTREACHED() << "Unknown link source"; |
| 424 return; |
| 425 } |
| 426 |
| 427 Browser* browser = BrowserList::GetLastActive(); |
| 428 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 429 } |
| 430 #endif |
| 431 |
| 432 |
| 344 views::View* BugReportView::GetContentsView() { | 433 views::View* BugReportView::GetContentsView() { |
| 345 return this; | 434 return this; |
| 346 } | 435 } |
| OLD | NEW |