Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/ui/webui/feedback_ui.cc

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/ui/webui/feedback_ui.h" 5 #include "chrome/browser/ui/webui/feedback_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // TODO(rkc): Once there is a method to 'remove' a source, change this code 378 // TODO(rkc): Once there is a method to 'remove' a source, change this code
379 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 379 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
380 ChromeURLDataManager::AddDataSource(profile, 380 ChromeURLDataManager::AddDataSource(profile,
381 new ScreenshotSource(NULL, profile)); 381 new ScreenshotSource(NULL, profile));
382 382
383 FeedbackUtil::ClearScreenshotPng(); 383 FeedbackUtil::ClearScreenshotPng();
384 } 384 }
385 385
386 void FeedbackHandler::SetupScreenshotsSource() { 386 void FeedbackHandler::SetupScreenshotsSource() {
387 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 387 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
388 // If we don't already have a screenshot source object created, create one. 388 screenshot_source_ =
389 if (!screenshot_source_) { 389 new ScreenshotSource(FeedbackUtil::GetScreenshotPng(), profile);
390 screenshot_source_ =
391 new ScreenshotSource(FeedbackUtil::GetScreenshotPng(), profile);
392 }
393 // Add the source to the data manager. 390 // Add the source to the data manager.
394 ChromeURLDataManager::AddDataSource(profile, screenshot_source_); 391 ChromeURLDataManager::AddDataSource(profile, screenshot_source_);
395 } 392 }
396 393
397 bool FeedbackHandler::Init() { 394 bool FeedbackHandler::Init() {
398 std::string page_url; 395 std::string page_url;
399 if (tab_->GetController().GetActiveEntry()) { 396 if (tab_->GetController().GetActiveEntry()) {
400 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); 397 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec();
401 } 398 }
402 399
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 // case we don't actually have a screenshot anyway. 465 // case we don't actually have a screenshot anyway.
469 SetupScreenshotsSource(); 466 SetupScreenshotsSource();
470 } else { 467 } else {
471 target_tab_url_ = custom_page_url; 468 target_tab_url_ = custom_page_url;
472 } 469 }
473 470
474 return true; 471 return true;
475 } 472 }
476 473
477 void FeedbackHandler::RegisterMessages() { 474 void FeedbackHandler::RegisterMessages() {
478 SetupScreenshotsSource();
479
480 web_ui()->RegisterMessageCallback("getDialogDefaults", 475 web_ui()->RegisterMessageCallback("getDialogDefaults",
481 base::Bind(&FeedbackHandler::HandleGetDialogDefaults, 476 base::Bind(&FeedbackHandler::HandleGetDialogDefaults,
482 base::Unretained(this))); 477 base::Unretained(this)));
483 web_ui()->RegisterMessageCallback("refreshCurrentScreenshot", 478 web_ui()->RegisterMessageCallback("refreshCurrentScreenshot",
484 base::Bind(&FeedbackHandler::HandleRefreshCurrentScreenshot, 479 base::Bind(&FeedbackHandler::HandleRefreshCurrentScreenshot,
485 base::Unretained(this))); 480 base::Unretained(this)));
486 #if defined(OS_CHROMEOS) 481 #if defined(OS_CHROMEOS)
487 web_ui()->RegisterMessageCallback("refreshSavedScreenshots", 482 web_ui()->RegisterMessageCallback("refreshSavedScreenshots",
488 base::Bind(&FeedbackHandler::HandleRefreshSavedScreenshots, 483 base::Bind(&FeedbackHandler::HandleRefreshSavedScreenshots,
489 base::Unretained(this))); 484 base::Unretained(this)));
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 : WebDialogUI(web_ui) { 718 : WebDialogUI(web_ui) {
724 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents()); 719 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents());
725 web_ui->AddMessageHandler(handler); 720 web_ui->AddMessageHandler(handler);
726 721
727 // The handler's init will determine whether we show the error html page. 722 // The handler's init will determine whether we show the error html page.
728 ChromeWebUIDataSource* html_source = 723 ChromeWebUIDataSource* html_source =
729 CreateFeedbackUIHTMLSource(handler->Init()); 724 CreateFeedbackUIHTMLSource(handler->Init());
730 725
731 // Set up the chrome://feedback/ source. 726 // Set up the chrome://feedback/ source.
732 Profile* profile = Profile::FromWebUI(web_ui); 727 Profile* profile = Profile::FromWebUI(web_ui);
733 ChromeURLDataManager::AddDataSource(profile, html_source); 728 ChromeURLDataManager::AddDataSourceImpl(profile, html_source);
734 } 729 }
735 730
736 #if defined(OS_CHROMEOS) 731 #if defined(OS_CHROMEOS)
737 // static 732 // static
738 void FeedbackUI::GetMostRecentScreenshots( 733 void FeedbackUI::GetMostRecentScreenshots(
739 const FilePath& filepath, 734 const FilePath& filepath,
740 std::vector<std::string>* saved_screenshots, 735 std::vector<std::string>* saved_screenshots,
741 size_t max_saved) { 736 size_t max_saved) {
742 std::string pattern = 737 std::string pattern =
743 std::string(ScreenshotSource::kScreenshotPrefix) + "*" + 738 std::string(ScreenshotSource::kScreenshotPrefix) + "*" +
(...skipping 14 matching lines...) Expand all
758 screenshot_filepaths.begin() + sort_size, 753 screenshot_filepaths.begin() + sort_size,
759 screenshot_filepaths.end(), 754 screenshot_filepaths.end(),
760 ScreenshotTimestampComp); 755 ScreenshotTimestampComp);
761 for (size_t i = 0; i < sort_size; ++i) 756 for (size_t i = 0; i < sort_size; ++i)
762 saved_screenshots->push_back( 757 saved_screenshots->push_back(
763 std::string(ScreenshotSource::kScreenshotUrlRoot) + 758 std::string(ScreenshotSource::kScreenshotUrlRoot) +
764 std::string(ScreenshotSource::kScreenshotSaved) + 759 std::string(ScreenshotSource::kScreenshotSaved) +
765 screenshot_filepaths[i]); 760 screenshot_filepaths[i]);
766 } 761 }
767 #endif 762 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698