summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 22:09:59 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 22:09:59 +0000
commitb17d41c88c2750bc9ef72d199246b672c7ec12cc (patch)
tree6625894ccb07f4f72b8d6f2bfd61101577366dd5 /chrome/browser/dom_ui
parentcbfd6e11dae35a249f0c4b76496be96e528584c4 (diff)
downloadchromium_src-b17d41c88c2750bc9ef72d199246b672c7ec12cc.zip
chromium_src-b17d41c88c2750bc9ef72d199246b672c7ec12cc.tar.gz
chromium_src-b17d41c88c2750bc9ef72d199246b672c7ec12cc.tar.bz2
WebUI: Move more files from chrome/browser/dom_ui to chrome/browser/webui. Part 2.
BUG=59945, 59946 TEST=trybots Review URL: http://codereview.chromium.org/6531028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/bug_report_ui.cc745
-rw-r--r--chrome/browser/dom_ui/bug_report_ui.h31
-rw-r--r--chrome/browser/dom_ui/gpu_internals_ui.cc372
-rw-r--r--chrome/browser/dom_ui/gpu_internals_ui.h20
-rw-r--r--chrome/browser/dom_ui/history2_ui.cc413
-rw-r--r--chrome/browser/dom_ui/history2_ui.h112
-rw-r--r--chrome/browser/dom_ui/history_ui.cc401
-rw-r--r--chrome/browser/dom_ui/history_ui.h108
-rw-r--r--chrome/browser/dom_ui/keyboard_ui.cc50
-rw-r--r--chrome/browser/dom_ui/keyboard_ui.h42
-rw-r--r--chrome/browser/dom_ui/web_ui_factory.cc10
11 files changed, 5 insertions, 2299 deletions
diff --git a/chrome/browser/dom_ui/bug_report_ui.cc b/chrome/browser/dom_ui/bug_report_ui.cc
deleted file mode 100644
index 8423877..0000000
--- a/chrome/browser/dom_ui/bug_report_ui.cc
+++ /dev/null
@@ -1,745 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/bug_report_ui.h"
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/singleton.h"
-#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "base/weak_ptr.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/bug_report_data.h"
-#include "chrome/browser/bug_report_util.h"
-#include "chrome/browser/dom_ui/web_ui_screenshot_source.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/url_constants.h"
-#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/rect.h"
-
-#if defined(OS_CHROMEOS)
-#include "base/file_util.h"
-#include "base/path_service.h"
-#include "base/synchronization/waitable_event.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/syslogs_library.h"
-#include "chrome/browser/chromeos/login/user_manager.h"
-#endif
-
-namespace {
-
-const char kScreenshotBaseUrl[] = "chrome://screenshots/";
-const char kCurrentScreenshotUrl[] = "chrome://screenshots/current";
-#if defined(OS_CHROMEOS)
-const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/";
-
-const char kScreenshotPattern[] = "*.png";
-const char kScreenshotsRelativePath[] = "/Screenshots";
-
-const size_t kMaxSavedScreenshots = 2;
-#endif
-
-#if defined(OS_CHROMEOS)
-
-void GetSavedScreenshots(std::vector<std::string>* saved_screenshots,
- base::WaitableEvent* done) {
- saved_screenshots->clear();
-
- FilePath fileshelf_path;
- if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS,
- &fileshelf_path)) {
- done->Signal();
- return;
- }
-
- // TODO(rkc): Change this to use FilePath.Append() once the cros
- // issue with it is fixed
- FilePath screenshots_path(fileshelf_path.value() +
- std::string(kScreenshotsRelativePath));
- file_util::FileEnumerator screenshots(screenshots_path, false,
- file_util::FileEnumerator::FILES,
- std::string(kScreenshotPattern));
- FilePath screenshot = screenshots.Next();
- while (!screenshot.empty()) {
- saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) +
- screenshot.BaseName().value());
- if (saved_screenshots->size() >= kMaxSavedScreenshots)
- break;
-
- screenshot = screenshots.Next();
- }
- done->Signal();
-}
-
-// This fuction posts a task to the file thread to create/list all the current
-// and saved screenshots.
-void GetScreenshotUrls(std::vector<std::string>* saved_screenshots) {
- base::WaitableEvent done(true, false);
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- NewRunnableFunction(&GetSavedScreenshots,
- saved_screenshots, &done));
- done.Wait();
-}
-
-std::string GetUserEmail() {
- chromeos::UserManager* manager = chromeos::UserManager::Get();
- if (!manager)
- return std::string();
- else
- return manager->logged_in_user().email();
-}
-#endif
-
-// Returns the index of the feedback tab if already open, -1 otherwise
-int GetIndexOfFeedbackTab(Browser* browser) {
- GURL bug_report_url(chrome::kChromeUIBugReportURL);
- for (int i = 0; i < browser->tab_count(); ++i) {
- TabContents* tab = browser->GetTabContentsAt(i);
- if (tab && tab->GetURL().GetWithEmptyPath() == bug_report_url)
- return i;
- }
-
- return -1;
-}
-
-} // namespace
-
-
-namespace browser {
-
-// TODO(rkc): Eventually find a better way to do this
-std::vector<unsigned char>* last_screenshot_png = 0;
-gfx::Rect screen_size;
-
-void RefreshLastScreenshot(Browser* browser) {
- if (last_screenshot_png)
- last_screenshot_png->clear();
- else
- last_screenshot_png = new std::vector<unsigned char>;
-
- gfx::NativeWindow native_window = browser->window()->GetNativeHandle();
- screen_size = browser::GrabWindowSnapshot(native_window, last_screenshot_png);
-}
-
-void ShowHtmlBugReportView(Browser* browser) {
- // First check if we're already open (we cannot depend on ShowSingletonTab
- // for this functionality since we need to make *sure* we never get
- // instantiated again while we are open - with singleton tabs, that can
- // happen)
- int feedback_tab_index = GetIndexOfFeedbackTab(browser);
- if (feedback_tab_index >=0) {
- // Do not refresh screenshot, do not create a new tab
- browser->SelectTabContentsAt(feedback_tab_index, true);
- return;
- }
-
- RefreshLastScreenshot(browser);
- std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) +
- "#" + base::IntToString(browser->selected_index());
- browser->ShowSingletonTab(GURL(bug_report_url), false);
-}
-
-} // namespace browser
-
-
-class BugReportUIHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- explicit BugReportUIHTMLSource(base::StringPiece html);
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const {
- return "text/html";
- }
-
- private:
- base::StringPiece bug_report_html_;
- ~BugReportUIHTMLSource() {}
-
- DISALLOW_COPY_AND_ASSIGN(BugReportUIHTMLSource);
-};
-
-// The handler for Javascript messages related to the "bug report" dialog
-class BugReportHandler : public WebUIMessageHandler,
- public base::SupportsWeakPtr<BugReportHandler> {
- public:
- explicit BugReportHandler(TabContents* tab);
- virtual ~BugReportHandler();
-
- // Init work after Attach.
- base::StringPiece Init();
-
- // WebUIMessageHandler implementation.
- virtual WebUIMessageHandler* Attach(WebUI* web_ui);
- virtual void RegisterMessages();
-
- private:
- void HandleGetDialogDefaults(const ListValue* args);
- void HandleRefreshCurrentScreenshot(const ListValue* args);
-#if defined(OS_CHROMEOS)
- void HandleRefreshSavedScreenshots(const ListValue* args);
-#endif
- void HandleSendReport(const ListValue* args);
- void HandleCancel(const ListValue* args);
- void HandleOpenSystemTab(const ListValue* args);
-
- void SetupScreenshotsSource();
- void ClobberScreenshotsSource();
-
- void CancelFeedbackCollection();
- void CloseFeedbackTab();
-
- TabContents* tab_;
- WebUIScreenshotSource* screenshot_source_;
-
- BugReportData* bug_report_;
- std::string target_tab_url_;
-#if defined(OS_CHROMEOS)
- // Variables to track SyslogsLibrary::RequestSyslogs callback.
- chromeos::SyslogsLibrary::Handle syslogs_handle_;
- CancelableRequestConsumer syslogs_consumer_;
-#endif
-
- DISALLOW_COPY_AND_ASSIGN(BugReportHandler);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BugReportHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-BugReportUIHTMLSource::BugReportUIHTMLSource(base::StringPiece html)
- : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) {
- bug_report_html_ = html;
-}
-
-void BugReportUIHTMLSource::StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) {
- DictionaryValue localized_strings;
- localized_strings.SetString(std::string("title"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE));
- localized_strings.SetString(std::string("page-title"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_PAGE_TITLE));
- localized_strings.SetString(std::string("issue-with"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH));
- localized_strings.SetString(std::string("page-url"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL));
- localized_strings.SetString(std::string("description"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL));
- localized_strings.SetString(std::string("current-screenshot"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL));
- localized_strings.SetString(std::string("saved-screenshot"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOT_LABEL));
-#if defined(OS_CHROMEOS)
- localized_strings.SetString(std::string("user-email"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL));
- localized_strings.SetString(std::string("sysinfo"),
- l10n_util::GetStringUTF8(
- IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX));
-
- localized_strings.SetString(std::string("currentscreenshots"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS));
- localized_strings.SetString(std::string("savedscreenshots"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS));
-
- localized_strings.SetString(std::string("choose-different-screenshot"),
- l10n_util::GetStringUTF8(
- IDS_BUGREPORT_CHOOSE_DIFFERENT_SCREENSHOT));
- localized_strings.SetString(std::string("choose-original-screenshot"),
- l10n_util::GetStringUTF8(
- IDS_BUGREPORT_CHOOSE_ORIGINAL_SCREENSHOT));
-#else
- localized_strings.SetString(std::string("currentscreenshots"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE));
-#endif
- localized_strings.SetString(std::string("noscreenshot"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT));
-
- localized_strings.SetString(std::string("send-report"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT));
- localized_strings.SetString(std::string("cancel"),
- l10n_util::GetStringUTF8(IDS_CANCEL));
-
- // Option strings for the "issue with" drop-down.
- localized_strings.SetString(std::string("issue-choose"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE));
-
- localized_strings.SetString(std::string("no-issue-selected"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED));
-
- localized_strings.SetString(std::string("no-description"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_DESCRIPTION));
-
- localized_strings.SetString(std::string("no-saved-screenshots"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_SAVED_SCREENSHOTS_HELP));
-
- localized_strings.SetString(std::string("privacy-note"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PRIVACY_NOTE));
-
- // TODO(rkc): Find some way to ensure this order of dropdowns is in sync
- // with the order in the userfeedback ChromeData proto buffer
-#if defined(OS_CHROMEOS)
- // Dropdown for ChromeOS:
- //
- // Connectivity
- // Sync
- // Crash
- // Page Formatting
- // Extensions or Apps
- // Standby or Resume
- // Phishing Page
- // General Feedback/Other
-
- localized_strings.SetString(std::string("issue-connectivity"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_CONNECTIVITY));
- localized_strings.SetString(std::string("issue-sync"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SYNC));
- localized_strings.SetString(std::string("issue-crashes"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_CRASHES));
- localized_strings.SetString(std::string("issue-page-formatting"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_FORMATTING));
- localized_strings.SetString(std::string("issue-extensions"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_EXTENSIONS));
- localized_strings.SetString(std::string("issue-standby"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_STANDBY_RESUME));
- localized_strings.SetString(std::string("issue-phishing"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PHISHING_PAGE));
- localized_strings.SetString(std::string("issue-other"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_GENERAL));
-#else
- // Dropdown for Chrome:
- //
- // Page formatting or layout
- // Pages not loading
- // Plug-ins (e.g. Adobe Flash Player, Quicktime, etc)
- // Tabs or windows
- // Synced preferences
- // Crashes
- // Extensions or apps
- // Phishing
- // Other
-
- localized_strings.SetString(std::string("issue-page-formatting"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_FORMATTING));
- localized_strings.SetString(std::string("issue-page-load"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_LOAD));
- localized_strings.SetString(std::string("issue-plugins"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PLUGINS));
- localized_strings.SetString(std::string("issue-tabs"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_TABS));
- localized_strings.SetString(std::string("issue-sync"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_SYNC));
- localized_strings.SetString(std::string("issue-crashes"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_CRASHES));
- localized_strings.SetString(std::string("issue-extensions"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_EXTENSIONS));
- localized_strings.SetString(std::string("issue-phishing"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_PHISHING_PAGE));
- localized_strings.SetString(std::string("issue-other"),
- l10n_util::GetStringUTF8(IDS_BUGREPORT_OTHER));
-#endif
-
- SetFontAndTextDirection(&localized_strings);
-
- const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
- bug_report_html_, &localized_strings);
-
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(full_html.size());
- std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
-
- SendResponse(request_id, html_bytes);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BugReportData
-//
-////////////////////////////////////////////////////////////////////////////////
-void BugReportData::SendReport() {
-#if defined(OS_CHROMEOS)
- // In case we already got the syslogs and sent the report, leave
- if (sent_report_) return;
- // Set send_report_ so that no one else processes SendReport
- sent_report_ = true;
-#endif
-
- int image_data_size = image_.size();
- char* image_data = image_data_size ?
- reinterpret_cast<char*>(&(image_.front())) : NULL;
- BugReportUtil::SendReport(profile_
- , problem_type_
- , page_url_
- , description_
- , image_data
- , image_data_size
- , browser::screen_size.width()
- , browser::screen_size.height()
-#if defined(OS_CHROMEOS)
- , user_email_
- , zip_content_ ? zip_content_->c_str() : NULL
- , zip_content_ ? zip_content_->length() : 0
- , send_sys_info_ ? sys_info_ : NULL
-#endif
- );
-
-#if defined(OS_CHROMEOS)
- if (sys_info_) {
- delete sys_info_;
- sys_info_ = NULL;
- }
- if (zip_content_) {
- delete zip_content_;
- zip_content_ = NULL;
- }
-#endif
-
- // Once the report has been sent, this object has no purpose in life, delete
- // ourselves.
- delete this;
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BugReportHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-BugReportHandler::BugReportHandler(TabContents* tab)
- : tab_(tab),
- screenshot_source_(NULL),
- bug_report_(NULL)
-#if defined(OS_CHROMEOS)
- , syslogs_handle_(0)
-#endif
-{
-}
-
-BugReportHandler::~BugReportHandler() {
- // Just in case we didn't send off bug_report_ to SendReport
- if (bug_report_) {
- // If we're deleting the report object, cancel feedback collection first
- CancelFeedbackCollection();
- delete bug_report_;
- }
-}
-
-void BugReportHandler::ClobberScreenshotsSource() {
- // Re-create our screenshots data source (this clobbers the last source)
- // setting the screenshot to NULL, effectively disabling the source
- // TODO(rkc): Once there is a method to 'remove' a source, change this code
- tab_->profile()->GetChromeURLDataManager()->AddDataSource(
- new WebUIScreenshotSource(NULL));
-
- // clobber last screenshot
- if (browser::last_screenshot_png)
- browser::last_screenshot_png->clear();
-}
-
-void BugReportHandler::SetupScreenshotsSource() {
- // If we don't already have a screenshot source object created, create one.
- if (!screenshot_source_)
- screenshot_source_ = new WebUIScreenshotSource(
- browser::last_screenshot_png);
-
- // Add the source to the data manager.
- tab_->profile()->GetChromeURLDataManager()->AddDataSource(screenshot_source_);
-}
-
-WebUIMessageHandler* BugReportHandler::Attach(WebUI* web_ui) {
- SetupScreenshotsSource();
- return WebUIMessageHandler::Attach(web_ui);
-}
-
-base::StringPiece BugReportHandler::Init() {
- std::string page_url;
- if (tab_->controller().GetActiveEntry()) {
- page_url = tab_->controller().GetActiveEntry()->url().spec();
- }
-
- std::string params = page_url.substr(strlen(chrome::kChromeUIBugReportURL));
- // Erase the # - the first character.
- if (params.length())
- params.erase(params.begin(), params.begin() + 1);
-
- int index = 0;
- if (!base::StringToInt(params, &index)) {
- return base::StringPiece(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_BUGREPORT_HTML_INVALID));
- }
-
- Browser* browser = BrowserList::GetLastActive();
- // Sanity checks.
- if (((index == 0) && (params != "0")) || !browser ||
- index >= browser->tab_count()) {
- return base::StringPiece(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_BUGREPORT_HTML_INVALID));
- }
-
- TabContents* target_tab = browser->GetTabContentsAt(index);
- if (target_tab) {
- target_tab_url_ = target_tab->GetURL().spec();
- }
-
- // Setup the screenshot source after we've verified input is legit.
- SetupScreenshotsSource();
-
- return base::StringPiece(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_BUGREPORT_HTML));
-}
-
-void BugReportHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback("getDialogDefaults",
- NewCallback(this, &BugReportHandler::HandleGetDialogDefaults));
- web_ui_->RegisterMessageCallback("refreshCurrentScreenshot",
- NewCallback(this, &BugReportHandler::HandleRefreshCurrentScreenshot));
-#if defined(OS_CHROMEOS)
- web_ui_->RegisterMessageCallback("refreshSavedScreenshots",
- NewCallback(this, &BugReportHandler::HandleRefreshSavedScreenshots));
-#endif
- web_ui_->RegisterMessageCallback("sendReport",
- NewCallback(this, &BugReportHandler::HandleSendReport));
- web_ui_->RegisterMessageCallback("cancel",
- NewCallback(this, &BugReportHandler::HandleCancel));
- web_ui_->RegisterMessageCallback("openSystemTab",
- NewCallback(this, &BugReportHandler::HandleOpenSystemTab));
-}
-
-void BugReportHandler::HandleGetDialogDefaults(const ListValue*) {
- bug_report_ = new BugReportData();
-
- // send back values which the dialog js needs initially
- ListValue dialog_defaults;
-
- // 0: current url
- if (target_tab_url_.length())
- dialog_defaults.Append(new StringValue(target_tab_url_));
- else
- dialog_defaults.Append(new StringValue(""));
-
-#if defined(OS_CHROMEOS)
- // 1: about:system
- dialog_defaults.Append(new StringValue(chrome::kChromeUISystemInfoURL));
- // Trigger the request for system information here.
- chromeos::SyslogsLibrary* syslogs_lib =
- chromeos::CrosLibrary::Get()->GetSyslogsLibrary();
- if (syslogs_lib) {
- syslogs_handle_ = syslogs_lib->RequestSyslogs(
- true, true, &syslogs_consumer_,
- NewCallback(bug_report_, &BugReportData::SyslogsComplete));
- }
- // 2: user e-mail
- dialog_defaults.Append(new StringValue(GetUserEmail()));
-#endif
-
- web_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults);
-}
-
-void BugReportHandler::HandleRefreshCurrentScreenshot(const ListValue*) {
- std::string current_screenshot(kCurrentScreenshotUrl);
- StringValue screenshot(current_screenshot);
- web_ui_->CallJavascriptFunction(L"setupCurrentScreenshot", screenshot);
-}
-
-
-#if defined(OS_CHROMEOS)
-void BugReportHandler::HandleRefreshSavedScreenshots(const ListValue*) {
- std::vector<std::string> saved_screenshots;
- GetScreenshotUrls(&saved_screenshots);
-
- ListValue screenshots_list;
- for (size_t i = 0; i < saved_screenshots.size(); ++i)
- screenshots_list.Append(new StringValue(saved_screenshots[i]));
- web_ui_->CallJavascriptFunction(L"setupSavedScreenshots", screenshots_list);
-}
-#endif
-
-
-void BugReportHandler::HandleSendReport(const ListValue* list_value) {
- if (!bug_report_) {
- LOG(ERROR) << "Bug report hasn't been intialized yet.";
- return;
- }
-
- ListValue::const_iterator i = list_value->begin();
- if (i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #0 - Problem type.
- int problem_type;
- std::string problem_type_str;
- (*i)->GetAsString(&problem_type_str);
- if (!base::StringToInt(problem_type_str, &problem_type)) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
- if (++i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #1 - Page url.
- std::string page_url;
- (*i)->GetAsString(&page_url);
- if (++i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #2 - Description.
- std::string description;
- (*i)->GetAsString(&description);
- if (++i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #3 - Screenshot to send.
- std::string screenshot_path;
- (*i)->GetAsString(&screenshot_path);
- screenshot_path.erase(0, strlen(kScreenshotBaseUrl));
-
- // Get the image to send in the report.
- std::vector<unsigned char> image;
- if (screenshot_path.size() > 0) {
- image = screenshot_source_->GetScreenshot(screenshot_path);
- }
-
-#if defined(OS_CHROMEOS)
- if (++i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #4 - User e-mail
- std::string user_email;
- (*i)->GetAsString(&user_email);
- if (++i == list_value->end()) {
- LOG(ERROR) << "Incorrect data passed to sendReport.";
- return;
- }
-
- // #5 - System info checkbox.
- std::string sys_info_checkbox;
- (*i)->GetAsString(&sys_info_checkbox);
- bool send_sys_info = (sys_info_checkbox == "true");
-
- // If we aren't sending the sys_info, cancel the gathering of the syslogs.
- if (!send_sys_info)
- CancelFeedbackCollection();
-#endif
-
- // Update the data in bug_report_ so it can be sent
- bug_report_->UpdateData(web_ui_->GetProfile()
- , target_tab_url_
- , problem_type
- , page_url
- , description
- , image
-#if defined(OS_CHROMEOS)
- , user_email
- , send_sys_info
- , false // sent_report
-#endif
- );
-
-#if defined(OS_CHROMEOS)
- // If we don't require sys_info, or we have it, or we never requested it
- // (because libcros failed to load), then send the report now.
- // Otherwise, the report will get sent when we receive sys_info.
- if (!send_sys_info || bug_report_->sys_info() != NULL ||
- syslogs_handle_ == 0) {
- bug_report_->SendReport();
- }
-#else
- bug_report_->SendReport();
-#endif
- // Lose the pointer to the BugReportData object; the object will delete itself
- // from SendReport, whether we called it, or will be called by the log
- // completion routine.
- bug_report_ = NULL;
-
- // Whether we sent the report, or if it will be sent by the Syslogs complete
- // function, close our feedback tab anyway, we have no more use for it.
- CloseFeedbackTab();
-}
-
-void BugReportHandler::HandleCancel(const ListValue*) {
- CloseFeedbackTab();
-}
-
-void BugReportHandler::HandleOpenSystemTab(const ListValue* args) {
-#if defined(OS_CHROMEOS)
- BrowserList::GetLastActive()->OpenSystemTabAndActivate();
-#endif
-}
-
-void BugReportHandler::CancelFeedbackCollection() {
-#if defined(OS_CHROMEOS)
- if (syslogs_handle_ != 0) {
- chromeos::SyslogsLibrary* syslogs_lib =
- chromeos::CrosLibrary::Get()->GetSyslogsLibrary();
- if (syslogs_lib)
- syslogs_lib->CancelRequest(syslogs_handle_);
- }
-#endif
-}
-
-void BugReportHandler::CloseFeedbackTab() {
- Browser* browser = BrowserList::GetLastActive();
- if (browser) {
- browser->CloseTabContents(tab_);
- } else {
- LOG(FATAL) << "Failed to get last active browser.";
- }
- ClobberScreenshotsSource();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BugReportUI
-//
-////////////////////////////////////////////////////////////////////////////////
-BugReportUI::BugReportUI(TabContents* tab) : HtmlDialogUI(tab) {
- BugReportHandler* handler = new BugReportHandler(tab);
- AddMessageHandler((handler)->Attach(this));
-
- // The handler's init will specify which html
- // resource we'll display to the user
- BugReportUIHTMLSource* html_source =
- new BugReportUIHTMLSource(handler->Init());
- // Set up the chrome://bugreport/ source.
- tab->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
diff --git a/chrome/browser/dom_ui/bug_report_ui.h b/chrome/browser/dom_ui/bug_report_ui.h
deleted file mode 100644
index 83835aa..0000000
--- a/chrome/browser/dom_ui/bug_report_ui.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_DOM_UI_BUG_REPORT_UI_H_
-#define CHROME_BROWSER_DOM_UI_BUG_REPORT_UI_H_
-
-#include "chrome/browser/dom_ui/html_dialog_ui.h"
-#include "chrome/browser/ui/views/window.h"
-
-namespace gfx {
-class Rect;
-} // namespace gfx
-
-class Browser;
-class NSWindow;
-class TabContents;
-
-namespace browser {
-void ShowHtmlBugReportView(Browser* browser);
-} // namespace browser
-
-class BugReportUI : public HtmlDialogUI {
- public:
- explicit BugReportUI(TabContents* contents);
- private:
-
- DISALLOW_COPY_AND_ASSIGN(BugReportUI);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_BUG_REPORT_UI_H_
diff --git a/chrome/browser/dom_ui/gpu_internals_ui.cc b/chrome/browser/dom_ui/gpu_internals_ui.cc
deleted file mode 100644
index 1dcc3d8..0000000
--- a/chrome/browser/dom_ui/gpu_internals_ui.cc
+++ /dev/null
@@ -1,372 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/gpu_internals_ui.h"
-
-#include <algorithm>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/command_line.h"
-#include "base/file_util.h"
-#include "base/message_loop.h"
-#include "base/path_service.h"
-#include "base/singleton.h"
-#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/gpu_process_host.h"
-#include "chrome/browser/gpu_process_host_ui_shim.h"
-#include "chrome/browser/io_thread.h"
-#include "chrome/browser/net/chrome_net_log.h"
-#include "chrome/browser/net/connection_tester.h"
-#include "chrome/browser/net/passive_log_collector.h"
-#include "chrome/browser/net/url_fixer_upper.h"
-#include "chrome/browser/platform_util.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_version_info.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/net/url_request_context_getter.h"
-#include "chrome/common/url_constants.h"
-#include "grit/browser_resources.h"
-#include "grit/generated_resources.h"
-#include "net/base/escape.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-namespace {
-
-class GpuHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- GpuHTMLSource();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const;
-
- private:
- ~GpuHTMLSource() {}
- DISALLOW_COPY_AND_ASSIGN(GpuHTMLSource);
-};
-
-// This class receives javascript messages from the renderer.
-// Note that the WebUI infrastructure runs on the UI thread, therefore all of
-// this class's methods are expected to run on the UI thread.
-class GpuMessageHandler
- : public WebUIMessageHandler,
- public base::SupportsWeakPtr<GpuMessageHandler> {
- public:
- GpuMessageHandler();
- virtual ~GpuMessageHandler();
-
- // WebUIMessageHandler implementation.
- virtual WebUIMessageHandler* Attach(WebUI* web_ui);
- virtual void RegisterMessages();
-
- // Mesages
- void OnCallAsync(const ListValue* list);
-
- // Submessages dispatched from OnCallAsync
- Value* OnRequestGpuInfo(const ListValue* list);
- Value* OnRequestClientInfo(const ListValue* list);
- Value* OnRequestLogMessages(const ListValue* list);
-
- // Executes the javascript function |function_name| in the renderer, passing
- // it the argument |value|.
- void CallJavascriptFunction(const std::wstring& function_name,
- const Value* value);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// GpuHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-GpuHTMLSource::GpuHTMLSource()
- : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) {
-}
-
-void GpuHTMLSource::StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) {
- DictionaryValue localized_strings;
- SetFontAndTextDirection(&localized_strings);
-
- base::StringPiece gpu_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_GPU_INTERNALS_HTML));
- std::string full_html(gpu_html.data(), gpu_html.size());
- jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html);
- jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html);
- jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html);
- jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
-
-
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(full_html.size());
- std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
-
- SendResponse(request_id, html_bytes);
-}
-
-std::string GpuHTMLSource::GetMimeType(const std::string&) const {
- return "text/html";
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// GpuMessageHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-
-GpuMessageHandler::GpuMessageHandler() {
-}
-
-GpuMessageHandler::~GpuMessageHandler() {}
-
-WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui);
- return result;
-}
-
-/* BrowserBridge.callAsync prepends a requestID to these messages. */
-void GpuMessageHandler::RegisterMessages() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- web_ui_->RegisterMessageCallback(
- "callAsync",
- NewCallback(this, &GpuMessageHandler::OnCallAsync));
-}
-
-void GpuMessageHandler::OnCallAsync(const ListValue* args) {
- DCHECK_GE(args->GetSize(), static_cast<size_t>(2));
- // unpack args into requestId, submessage and submessageArgs
- bool ok;
- Value* requestId;
- ok = args->Get(0, &requestId);
- DCHECK(ok);
-
- std::string submessage;
- ok = args->GetString(1, &submessage);
- DCHECK(ok);
-
- ListValue* submessageArgs = new ListValue();
- for (size_t i = 2; i < args->GetSize(); ++i) {
- Value* arg;
- ok = args->Get(i, &arg);
- DCHECK(ok);
-
- Value* argCopy = arg->DeepCopy();
- submessageArgs->Append(argCopy);
- }
-
- // call the submessage handler
- Value* ret = NULL;
- if (submessage == "requestGpuInfo") {
- ret = OnRequestGpuInfo(submessageArgs);
- } else if (submessage == "requestClientInfo") {
- ret = OnRequestClientInfo(submessageArgs);
- } else if (submessage == "requestLogMessages") {
- ret = OnRequestLogMessages(submessageArgs);
- } else { // unrecognized submessage
- NOTREACHED();
- delete submessageArgs;
- return;
- }
- delete submessageArgs;
-
- // call BrowserBridge.onCallAsyncReply with result
- if (ret) {
- web_ui_->CallJavascriptFunction(L"browserBridge.onCallAsyncReply",
- *requestId,
- *ret);
- delete ret;
- } else {
- web_ui_->CallJavascriptFunction(L"browserBridge.onCallAsyncReply",
- *requestId);
- }
-}
-
-Value* GpuMessageHandler::OnRequestClientInfo(const ListValue* list) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- DictionaryValue* dict = new DictionaryValue();
-
- chrome::VersionInfo version_info;
-
- if (!version_info.is_valid()) {
- DLOG(ERROR) << "Unable to create chrome::VersionInfo";
- } else {
- // We have everything we need to send the right values.
- dict->SetString("version", version_info.Version());
- dict->SetString("cl", version_info.LastChange());
- dict->SetString("version_mod",
- platform_util::GetVersionStringModifier());
- dict->SetString("official",
- l10n_util::GetStringUTF16(
- version_info.IsOfficialBuild() ?
- IDS_ABOUT_VERSION_OFFICIAL
- : IDS_ABOUT_VERSION_UNOFFICIAL));
-
- dict->SetString("command_line",
- CommandLine::ForCurrentProcess()->command_line_string());
- }
-
- return dict;
-}
-
-DictionaryValue* NewDescriptionValuePair(const std::string& desc,
- const std::string& value) {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString("description", desc);
- dict->SetString("value", value);
- return dict;
-}
-
-DictionaryValue* NewDescriptionValuePair(const std::string& desc,
- Value* value) {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString("description", desc);
- dict->Set("value", value);
- return dict;
-}
-
-#if defined(OS_WIN)
-// Output DxDiagNode tree as nested array of {description,value} pairs
-ListValue* DxDiagNodeToList(const DxDiagNode& node) {
- ListValue* list = new ListValue();
- for (std::map<std::string, std::string>::const_iterator it =
- node.values.begin();
- it != node.values.end();
- ++it) {
- list->Append(NewDescriptionValuePair(it->first, it->second));
- }
-
- for (std::map<std::string, DxDiagNode>::const_iterator it =
- node.children.begin();
- it != node.children.end();
- ++it) {
- ListValue* sublist = DxDiagNodeToList(it->second);
- list->Append(NewDescriptionValuePair(it->first, sublist));
- }
- return list;
-}
-
-#endif // OS_WIN
-
-std::string VersionNumberToString(uint32 value) {
- int hi = (value >> 8) & 0xff;
- int low = value & 0xff;
- return base::IntToString(hi) + "." + base::IntToString(low);
-}
-
-DictionaryValue* GpuInfoToDict(const GPUInfo& gpu_info) {
- ListValue* basic_info = new ListValue();
- basic_info->Append(NewDescriptionValuePair("Initialization time",
- base::Int64ToString(gpu_info.initialization_time().InMilliseconds())));
- basic_info->Append(NewDescriptionValuePair("Vendor Id",
- base::StringPrintf("0x%04x", gpu_info.vendor_id())));
- basic_info->Append(NewDescriptionValuePair("Device Id",
- base::StringPrintf("0x%04x", gpu_info.device_id())));
- basic_info->Append(NewDescriptionValuePair("Driver vendor",
- gpu_info.driver_vendor()));
- basic_info->Append(NewDescriptionValuePair("Driver version",
- gpu_info.driver_version()));
- basic_info->Append(NewDescriptionValuePair("Pixel shader version",
- VersionNumberToString(gpu_info.pixel_shader_version())));
- basic_info->Append(NewDescriptionValuePair("Vertex shader version",
- VersionNumberToString(gpu_info.vertex_shader_version())));
- basic_info->Append(NewDescriptionValuePair("GL version",
- VersionNumberToString(gpu_info.gl_version())));
- basic_info->Append(NewDescriptionValuePair("GL_VENDOR",
- gpu_info.gl_vendor()));
- basic_info->Append(NewDescriptionValuePair("GL_RENDERER",
- gpu_info.gl_renderer()));
- basic_info->Append(NewDescriptionValuePair("GL_VERSION",
- gpu_info.gl_version_string()));
- basic_info->Append(NewDescriptionValuePair("GL_EXTENSIONS",
- gpu_info.gl_extensions()));
-
- DictionaryValue* info = new DictionaryValue();
- info->Set("basic_info", basic_info);
-
- if (gpu_info.level() == GPUInfo::kPartial) {
- info->SetString("level", "partial");
- } else if (gpu_info.level() == GPUInfo::kCompleting) {
- info->SetString("level", "completing");
- } else if (gpu_info.level() == GPUInfo::kComplete) {
- info->SetString("level", "complete");
- } else {
- DCHECK(false) << "Unrecognized GPUInfo::Level value";
- info->SetString("level", "");
- }
-
-#if defined(OS_WIN)
- if (gpu_info.level() == GPUInfo::kComplete) {
- ListValue* dx_info = DxDiagNodeToList(gpu_info.dx_diagnostics());
- info->Set("diagnostics", dx_info);
- }
-#endif
-
- return info;
-}
-
-Value* GpuMessageHandler::OnRequestGpuInfo(const ListValue* list) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- // Get GPU Info.
- GPUInfo gpu_info = GpuProcessHostUIShim::GetInstance()->gpu_info();
-
- std::string html;
- if (gpu_info.level() != GPUInfo::kComplete) {
- GpuProcessHostUIShim::GetInstance()->CollectGraphicsInfoAsynchronously(
- GPUInfo::kComplete);
- }
-
- if (gpu_info.level() != GPUInfo::kUninitialized) {
- return GpuInfoToDict(gpu_info);
- } else {
- return NULL;
- }
-}
-
-Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return GpuProcessHostUIShim::GetInstance()->logMessages();
-}
-
-} // namespace
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// GpuInternalsUI
-//
-////////////////////////////////////////////////////////////////////////////////
-
-GpuInternalsUI::GpuInternalsUI(TabContents* contents) : WebUI(contents) {
- AddMessageHandler((new GpuMessageHandler())->Attach(this));
-
- GpuHTMLSource* html_source = new GpuHTMLSource();
-
- // Set up the chrome://gpu/ source.
- contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
-
diff --git a/chrome/browser/dom_ui/gpu_internals_ui.h b/chrome/browser/dom_ui/gpu_internals_ui.h
deleted file mode 100644
index 1930827..0000000
--- a/chrome/browser/dom_ui/gpu_internals_ui.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_DOM_UI_GPU_INTERNALS_UI_H_
-#define CHROME_BROWSER_DOM_UI_GPU_INTERNALS_UI_H_
-#pragma once
-
-#include "chrome/browser/dom_ui/web_ui.h"
-
-class GpuInternalsUI : public WebUI {
- public:
- explicit GpuInternalsUI(TabContents* contents);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GpuInternalsUI);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_GPU_INTERNALS_UI_H_
-
diff --git a/chrome/browser/dom_ui/history2_ui.cc b/chrome/browser/dom_ui/history2_ui.cc
deleted file mode 100644
index ceb754f..0000000
--- a/chrome/browser/dom_ui/history2_ui.cc
+++ /dev/null
@@ -1,413 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/history2_ui.h"
-
-#include <algorithm>
-#include <set>
-
-#include "base/callback.h"
-#include "base/i18n/time_formatting.h"
-#include "base/message_loop.h"
-#include "base/singleton.h"
-#include "base/string16.h"
-#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "base/threading/thread.h"
-#include "base/time.h"
-#include "base/values.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/dom_ui/web_ui_favicon_source.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/history/history_types.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_delegate.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/notification_source.h"
-#include "chrome/common/time_format.h"
-#include "chrome/common/url_constants.h"
-#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "net/base/escape.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-// Maximum number of search results to return in a given search. We should
-// eventually remove this.
-static const int kMaxSearchResults = 100;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-HistoryUIHTMLSource2::HistoryUIHTMLSource2()
- : DataSource(chrome::kChromeUIHistory2Host, MessageLoop::current()) {
-}
-
-void HistoryUIHTMLSource2::StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) {
- DictionaryValue localized_strings;
- localized_strings.SetString("loading",
- l10n_util::GetStringUTF16(IDS_HISTORY_LOADING));
- localized_strings.SetString("title",
- l10n_util::GetStringUTF16(IDS_HISTORY_TITLE));
- localized_strings.SetString("loading",
- l10n_util::GetStringUTF16(IDS_HISTORY_LOADING));
- localized_strings.SetString("newest",
- l10n_util::GetStringUTF16(IDS_HISTORY_NEWEST));
- localized_strings.SetString("newer",
- l10n_util::GetStringUTF16(IDS_HISTORY_NEWER));
- localized_strings.SetString("older",
- l10n_util::GetStringUTF16(IDS_HISTORY_OLDER));
- localized_strings.SetString("searchresultsfor",
- l10n_util::GetStringUTF16(IDS_HISTORY_SEARCHRESULTSFOR));
- localized_strings.SetString("history",
- l10n_util::GetStringUTF16(IDS_HISTORY_BROWSERESULTS));
- localized_strings.SetString("cont",
- l10n_util::GetStringUTF16(IDS_HISTORY_CONTINUED));
- localized_strings.SetString("searchbutton",
- l10n_util::GetStringUTF16(IDS_HISTORY_SEARCH_BUTTON));
- localized_strings.SetString("noresults",
- l10n_util::GetStringUTF16(IDS_HISTORY_NO_RESULTS));
- localized_strings.SetString("noitems",
- l10n_util::GetStringUTF16(IDS_HISTORY_NO_ITEMS));
- localized_strings.SetString("edithistory",
- l10n_util::GetStringUTF16(IDS_HISTORY_START_EDITING_HISTORY));
- localized_strings.SetString("doneediting",
- l10n_util::GetStringUTF16(IDS_HISTORY_STOP_EDITING_HISTORY));
- localized_strings.SetString("removeselected",
- l10n_util::GetStringUTF16(IDS_HISTORY_REMOVE_SELECTED_ITEMS));
- localized_strings.SetString("clearallhistory",
- l10n_util::GetStringUTF16(IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG));
- localized_strings.SetString("deletewarning",
- l10n_util::GetStringUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING));
-
- SetFontAndTextDirection(&localized_strings);
-
- static const base::StringPiece history_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_HISTORY2_HTML));
- const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
- history_html, &localized_strings);
-
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(full_html.size());
- std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
-
- SendResponse(request_id, html_bytes);
-}
-
-std::string HistoryUIHTMLSource2::GetMimeType(const std::string&) const {
- return "text/html";
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-BrowsingHistoryHandler2::BrowsingHistoryHandler2()
- : search_text_() {
-}
-
-BrowsingHistoryHandler2::~BrowsingHistoryHandler2() {
- cancelable_search_consumer_.CancelAllRequests();
- cancelable_delete_consumer_.CancelAllRequests();
-}
-
-WebUIMessageHandler* BrowsingHistoryHandler2::Attach(WebUI* web_ui) {
- // Create our favicon data source.
- Profile* profile = web_ui->GetProfile();
- profile->GetChromeURLDataManager()->AddDataSource(
- new WebUIFavIconSource(profile));
-
- // Get notifications when history is cleared.
- registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(web_ui->GetProfile()->GetOriginalProfile()));
- return WebUIMessageHandler::Attach(web_ui);
-}
-
-void BrowsingHistoryHandler2::RegisterMessages() {
- web_ui_->RegisterMessageCallback("getHistory",
- NewCallback(this, &BrowsingHistoryHandler2::HandleGetHistory));
- web_ui_->RegisterMessageCallback("searchHistory",
- NewCallback(this, &BrowsingHistoryHandler2::HandleSearchHistory));
- web_ui_->RegisterMessageCallback("removeURLsOnOneDay",
- NewCallback(this, &BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay));
- web_ui_->RegisterMessageCallback("clearBrowsingData",
- NewCallback(this, &BrowsingHistoryHandler2::HandleClearBrowsingData));
-}
-
-void BrowsingHistoryHandler2::HandleGetHistory(const ListValue* args) {
- // Anything in-flight is invalid.
- cancelable_search_consumer_.CancelAllRequests();
-
- // Get arguments (if any).
- int day = 0;
- ExtractIntegerValue(args, &day);
-
- // Set our query options.
- history::QueryOptions options;
- options.begin_time = base::Time::Now().LocalMidnight();
- options.begin_time -= base::TimeDelta::FromDays(day);
- options.end_time = base::Time::Now().LocalMidnight();
- options.end_time -= base::TimeDelta::FromDays(day - 1);
-
- // Need to remember the query string for our results.
- search_text_ = string16();
-
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->QueryHistory(search_text_,
- options,
- &cancelable_search_consumer_,
- NewCallback(this, &BrowsingHistoryHandler2::QueryComplete));
-}
-
-void BrowsingHistoryHandler2::HandleSearchHistory(const ListValue* args) {
- // Anything in-flight is invalid.
- cancelable_search_consumer_.CancelAllRequests();
-
- // Get arguments (if any).
- int month = 0;
- string16 query;
- ExtractSearchHistoryArguments(args, &month, &query);
-
- // Set the query ranges for the given month.
- history::QueryOptions options = CreateMonthQueryOptions(month);
-
- // When searching, limit the number of results returned.
- options.max_count = kMaxSearchResults;
-
- // Need to remember the query string for our results.
- search_text_ = query;
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->QueryHistory(search_text_,
- options,
- &cancelable_search_consumer_,
- NewCallback(this, &BrowsingHistoryHandler2::QueryComplete));
-}
-
-void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const ListValue* args) {
- if (cancelable_delete_consumer_.HasPendingRequests()) {
- web_ui_->CallJavascriptFunction(L"deleteFailed");
- return;
- }
-
- // Get day to delete data from.
- int visit_time = 0;
- ExtractIntegerValue(args, &visit_time);
- base::Time::Exploded exploded;
- base::Time::FromTimeT(
- static_cast<time_t>(visit_time)).LocalExplode(&exploded);
- exploded.hour = exploded.minute = exploded.second = exploded.millisecond = 0;
- base::Time begin_time = base::Time::FromLocalExploded(exploded);
- base::Time end_time = begin_time + base::TimeDelta::FromDays(1);
-
- // Get URLs.
- std::set<GURL> urls;
- for (ListValue::const_iterator v = args->begin() + 1;
- v != args->end(); ++v) {
- if ((*v)->GetType() != Value::TYPE_STRING)
- continue;
- const StringValue* string_value = static_cast<const StringValue*>(*v);
- string16 string16_value;
- if (!string_value->GetAsString(&string16_value))
- continue;
- urls.insert(GURL(string16_value));
- }
-
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->ExpireHistoryBetween(
- urls, begin_time, end_time, &cancelable_delete_consumer_,
- NewCallback(this, &BrowsingHistoryHandler2::RemoveComplete));
-}
-
-void BrowsingHistoryHandler2::HandleClearBrowsingData(const ListValue* args) {
- // TODO(beng): This is an improper direct dependency on Browser. Route this
- // through some sort of delegate.
- Browser* browser = BrowserList::FindBrowserWithProfile(web_ui_->GetProfile());
- if (browser)
- browser->OpenClearBrowsingDataDialog();
-}
-
-void BrowsingHistoryHandler2::QueryComplete(
- HistoryService::Handle request_handle,
- history::QueryResults* results) {
-
- ListValue results_value;
- base::Time midnight_today = base::Time::Now().LocalMidnight();
-
- for (size_t i = 0; i < results->size(); ++i) {
- history::URLResult const &page = (*results)[i];
- DictionaryValue* page_value = new DictionaryValue();
- SetURLAndTitle(page_value, page.title(), page.url());
-
- // Need to pass the time in epoch time (fastest JS conversion).
- page_value->SetInteger("time",
- static_cast<int>(page.visit_time().ToTimeT()));
-
- // Until we get some JS i18n infrastructure, we also need to
- // pass the dates in as strings. This could use some
- // optimization.
-
- // Only pass in the strings we need (search results need a shortdate
- // and snippet, browse results need day and time information).
- if (search_text_.empty()) {
- // Figure out the relative date string.
- string16 date_str = TimeFormat::RelativeDate(page.visit_time(),
- &midnight_today);
- if (date_str.empty()) {
- date_str = base::TimeFormatFriendlyDate(page.visit_time());
- } else {
- date_str = l10n_util::GetStringFUTF16(
- IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
- date_str,
- base::TimeFormatFriendlyDate(page.visit_time()));
- }
- page_value->SetString("dateRelativeDay", date_str);
- page_value->SetString("dateTimeOfDay",
- base::TimeFormatTimeOfDay(page.visit_time()));
- } else {
- page_value->SetString("dateShort",
- base::TimeFormatShortDate(page.visit_time()));
- page_value->SetString("snippet", page.snippet().text());
- }
- page_value->SetBoolean("starred",
- web_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url()));
- results_value.Append(page_value);
- }
-
- DictionaryValue info_value;
- info_value.SetString("term", search_text_);
- info_value.SetBoolean("finished", results->reached_beginning());
-
- web_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value);
-}
-
-void BrowsingHistoryHandler2::RemoveComplete() {
- // Some Visits were deleted from history. Reload the list.
- web_ui_->CallJavascriptFunction(L"deleteComplete");
-}
-
-void BrowsingHistoryHandler2::ExtractSearchHistoryArguments(
- const ListValue* args,
- int* month,
- string16* query) {
- *month = 0;
- Value* list_member;
-
- // Get search string.
- if (args->Get(0, &list_member) &&
- list_member->GetType() == Value::TYPE_STRING) {
- const StringValue* string_value =
- static_cast<const StringValue*>(list_member);
- string_value->GetAsString(query);
- }
-
- // Get search month.
- if (args->Get(1, &list_member) &&
- list_member->GetType() == Value::TYPE_STRING) {
- const StringValue* string_value =
- static_cast<const StringValue*>(list_member);
- string16 string16_value;
- string_value->GetAsString(&string16_value);
- base::StringToInt(string16_value, month);
- }
-}
-
-history::QueryOptions BrowsingHistoryHandler2::CreateMonthQueryOptions(
- int month) {
- history::QueryOptions options;
-
- // Configure the begin point of the search to the start of the
- // current month.
- base::Time::Exploded exploded;
- base::Time::Now().LocalMidnight().LocalExplode(&exploded);
- exploded.day_of_month = 1;
-
- if (month == 0) {
- options.begin_time = base::Time::FromLocalExploded(exploded);
-
- // Set the end time of this first search to null (which will
- // show results from the future, should the user's clock have
- // been set incorrectly).
- options.end_time = base::Time();
- } else {
- // Set the end-time of this search to the end of the month that is
- // |depth| months before the search end point. The end time is not
- // inclusive, so we should feel free to set it to midnight on the
- // first day of the following month.
- exploded.month -= month - 1;
- while (exploded.month < 1) {
- exploded.month += 12;
- exploded.year--;
- }
- options.end_time = base::Time::FromLocalExploded(exploded);
-
- // Set the begin-time of the search to the start of the month
- // that is |depth| months prior to search_start_.
- if (exploded.month > 1) {
- exploded.month--;
- } else {
- exploded.month = 12;
- exploded.year--;
- }
- options.begin_time = base::Time::FromLocalExploded(exploded);
- }
-
- return options;
-}
-
-void BrowsingHistoryHandler2::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type != NotificationType::HISTORY_URLS_DELETED) {
- NOTREACHED();
- return;
- }
-
- // Some URLs were deleted from history. Reload the list.
- web_ui_->CallJavascriptFunction(L"historyDeleted");
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryUIContents
-//
-////////////////////////////////////////////////////////////////////////////////
-
-HistoryUI2::HistoryUI2(TabContents* contents) : WebUI(contents) {
- AddMessageHandler((new BrowsingHistoryHandler2())->Attach(this));
-
- HistoryUIHTMLSource2* html_source = new HistoryUIHTMLSource2();
-
- // Set up the chrome://history2/ source.
- contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
-
-// static
-const GURL HistoryUI2::GetHistoryURLWithSearchText(const string16& text) {
- return GURL(std::string(chrome::kChromeUIHistory2URL) + "#q=" +
- EscapeQueryParamValue(UTF16ToUTF8(text), true));
-}
-
-// static
-RefCountedMemory* HistoryUI2::GetFaviconResourceBytes() {
- return ResourceBundle::GetSharedInstance().
- LoadDataResourceBytes(IDR_HISTORY_FAVICON);
-}
diff --git a/chrome/browser/dom_ui/history2_ui.h b/chrome/browser/dom_ui/history2_ui.h
deleted file mode 100644
index 9eda410..0000000
--- a/chrome/browser/dom_ui/history2_ui.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_DOM_UI_HISTORY2_UI_H_
-#define CHROME_BROWSER_DOM_UI_HISTORY2_UI_H_
-#pragma once
-
-#include <string>
-
-#include "base/string16.h"
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/dom_ui/web_ui.h"
-#include "chrome/browser/cancelable_request.h"
-#include "chrome/browser/history/history.h"
-#include "chrome/common/notification_registrar.h"
-
-class GURL;
-
-// Temporary fork for development of new history UI.
-// TODO(pamg): merge back in when new UI is complete.
-
-class HistoryUIHTMLSource2 : public ChromeURLDataManager::DataSource {
- public:
- HistoryUIHTMLSource2();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id);
-
- virtual std::string GetMimeType(const std::string&) const;
-
- private:
- ~HistoryUIHTMLSource2() {}
-
- DISALLOW_COPY_AND_ASSIGN(HistoryUIHTMLSource2);
-};
-
-// The handler for Javascript messages related to the "history" view.
-class BrowsingHistoryHandler2 : public WebUIMessageHandler,
- public NotificationObserver {
- public:
- BrowsingHistoryHandler2();
- virtual ~BrowsingHistoryHandler2();
-
- // WebUIMessageHandler implementation.
- virtual WebUIMessageHandler* Attach(WebUI* web_ui);
- virtual void RegisterMessages();
-
- // Callback for the "getHistory" message.
- void HandleGetHistory(const ListValue* args);
-
- // Callback for the "searchHistory" message.
- void HandleSearchHistory(const ListValue* args);
-
- // Callback for the "removeURLsOnOneDay" message.
- void HandleRemoveURLsOnOneDay(const ListValue* args);
-
- // Handle for "clearBrowsingData" message.
- void HandleClearBrowsingData(const ListValue* args);
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- private:
- // Callback from the history system when the history list is available.
- void QueryComplete(HistoryService::Handle request_handle,
- history::QueryResults* results);
-
- // Callback from the history system when visits were deleted.
- void RemoveComplete();
-
- // Extract the arguments from the call to HandleSearchHistory.
- void ExtractSearchHistoryArguments(const ListValue* args,
- int* month,
- string16* query);
-
- // Figure out the query options for a month-wide query.
- history::QueryOptions CreateMonthQueryOptions(int month);
-
- NotificationRegistrar registrar_;
-
- // Current search text.
- string16 search_text_;
-
- // Our consumer for search requests to the history service.
- CancelableRequestConsumerT<int, 0> cancelable_search_consumer_;
-
- // Our consumer for delete requests to the history service.
- CancelableRequestConsumerT<int, 0> cancelable_delete_consumer_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler2);
-};
-
-class HistoryUI2 : public WebUI {
- public:
- explicit HistoryUI2(TabContents* contents);
-
- // Return the URL for a given search term.
- static const GURL GetHistoryURLWithSearchText(const string16& text);
-
- static RefCountedMemory* GetFaviconResourceBytes();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(HistoryUI2);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_HISTORY2_UI_H_
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc
deleted file mode 100644
index 680ada9..0000000
--- a/chrome/browser/dom_ui/history_ui.cc
+++ /dev/null
@@ -1,401 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/history_ui.h"
-
-#include <algorithm>
-#include <set>
-
-#include "base/callback.h"
-#include "base/i18n/time_formatting.h"
-#include "base/message_loop.h"
-#include "base/singleton.h"
-#include "base/string16.h"
-#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
-#include "base/threading/thread.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/dom_ui/web_ui_favicon_source.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/history/history_types.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_contents_delegate.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/notification_source.h"
-#include "chrome/common/time_format.h"
-#include "chrome/common/url_constants.h"
-#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "net/base/escape.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-// Maximum number of search results to return in a given search. We should
-// eventually remove this.
-static const int kMaxSearchResults = 100;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-HistoryUIHTMLSource::HistoryUIHTMLSource()
- : DataSource(chrome::kChromeUIHistoryHost, MessageLoop::current()) {
-}
-
-void HistoryUIHTMLSource::StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) {
- DictionaryValue localized_strings;
- localized_strings.SetString("loading",
- l10n_util::GetStringUTF16(IDS_HISTORY_LOADING));
- localized_strings.SetString("title",
- l10n_util::GetStringUTF16(IDS_HISTORY_TITLE));
- localized_strings.SetString("loading",
- l10n_util::GetStringUTF16(IDS_HISTORY_LOADING));
- localized_strings.SetString("newest",
- l10n_util::GetStringUTF16(IDS_HISTORY_NEWEST));
- localized_strings.SetString("newer",
- l10n_util::GetStringUTF16(IDS_HISTORY_NEWER));
- localized_strings.SetString("older",
- l10n_util::GetStringUTF16(IDS_HISTORY_OLDER));
- localized_strings.SetString("searchresultsfor",
- l10n_util::GetStringUTF16(IDS_HISTORY_SEARCHRESULTSFOR));
- localized_strings.SetString("history",
- l10n_util::GetStringUTF16(IDS_HISTORY_BROWSERESULTS));
- localized_strings.SetString("cont",
- l10n_util::GetStringUTF16(IDS_HISTORY_CONTINUED));
- localized_strings.SetString("searchbutton",
- l10n_util::GetStringUTF16(IDS_HISTORY_SEARCH_BUTTON));
- localized_strings.SetString("noresults",
- l10n_util::GetStringUTF16(IDS_HISTORY_NO_RESULTS));
- localized_strings.SetString("noitems",
- l10n_util::GetStringUTF16(IDS_HISTORY_NO_ITEMS));
- localized_strings.SetString("edithistory",
- l10n_util::GetStringUTF16(IDS_HISTORY_START_EDITING_HISTORY));
- localized_strings.SetString("doneediting",
- l10n_util::GetStringUTF16(IDS_HISTORY_STOP_EDITING_HISTORY));
- localized_strings.SetString("removeselected",
- l10n_util::GetStringUTF16(IDS_HISTORY_REMOVE_SELECTED_ITEMS));
- localized_strings.SetString("clearallhistory",
- l10n_util::GetStringUTF16(IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG));
- localized_strings.SetString("deletewarning",
- l10n_util::GetStringUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING));
-
- SetFontAndTextDirection(&localized_strings);
-
- static const base::StringPiece history_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_HISTORY_HTML));
- const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
- history_html, &localized_strings);
-
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(full_html.size());
- std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
-
- SendResponse(request_id, html_bytes);
-}
-
-std::string HistoryUIHTMLSource::GetMimeType(const std::string&) const {
- return "text/html";
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-BrowsingHistoryHandler::BrowsingHistoryHandler()
- : search_text_() {
-}
-
-BrowsingHistoryHandler::~BrowsingHistoryHandler() {
- cancelable_search_consumer_.CancelAllRequests();
- cancelable_delete_consumer_.CancelAllRequests();
-}
-
-WebUIMessageHandler* BrowsingHistoryHandler::Attach(WebUI* web_ui) {
- // Create our favicon data source.
- Profile* profile = web_ui->GetProfile();
- profile->GetChromeURLDataManager()->AddDataSource(
- new WebUIFavIconSource(profile));
-
- // Get notifications when history is cleared.
- registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(profile->GetOriginalProfile()));
- return WebUIMessageHandler::Attach(web_ui);
-}
-
-void BrowsingHistoryHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback("getHistory",
- NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory));
- web_ui_->RegisterMessageCallback("searchHistory",
- NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory));
- web_ui_->RegisterMessageCallback("removeURLsOnOneDay",
- NewCallback(this, &BrowsingHistoryHandler::HandleRemoveURLsOnOneDay));
- web_ui_->RegisterMessageCallback("clearBrowsingData",
- NewCallback(this, &BrowsingHistoryHandler::HandleClearBrowsingData));
-}
-
-void BrowsingHistoryHandler::HandleGetHistory(const ListValue* args) {
- // Anything in-flight is invalid.
- cancelable_search_consumer_.CancelAllRequests();
-
- // Get arguments (if any).
- int day = 0;
- ExtractIntegerValue(args, &day);
-
- // Set our query options.
- history::QueryOptions options;
- options.begin_time = base::Time::Now().LocalMidnight();
- options.begin_time -= base::TimeDelta::FromDays(day);
- options.end_time = base::Time::Now().LocalMidnight();
- options.end_time -= base::TimeDelta::FromDays(day - 1);
-
- // Need to remember the query string for our results.
- search_text_ = string16();
-
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->QueryHistory(search_text_,
- options,
- &cancelable_search_consumer_,
- NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
-}
-
-void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) {
- // Anything in-flight is invalid.
- cancelable_search_consumer_.CancelAllRequests();
-
- // Get arguments (if any).
- int month = 0;
- string16 query;
- ExtractSearchHistoryArguments(args, &month, &query);
-
- // Set the query ranges for the given month.
- history::QueryOptions options = CreateMonthQueryOptions(month);
-
- // When searching, limit the number of results returned.
- options.max_count = kMaxSearchResults;
-
- // Need to remember the query string for our results.
- search_text_ = query;
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->QueryHistory(search_text_,
- options,
- &cancelable_search_consumer_,
- NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
-}
-
-void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) {
- if (cancelable_delete_consumer_.HasPendingRequests()) {
- web_ui_->CallJavascriptFunction(L"deleteFailed");
- return;
- }
-
- // Get day to delete data from.
- int visit_time = 0;
- ExtractIntegerValue(args, &visit_time);
- base::Time::Exploded exploded;
- base::Time::FromTimeT(
- static_cast<time_t>(visit_time)).LocalExplode(&exploded);
- exploded.hour = exploded.minute = exploded.second = exploded.millisecond = 0;
- base::Time begin_time = base::Time::FromLocalExploded(exploded);
- base::Time end_time = begin_time + base::TimeDelta::FromDays(1);
-
- // Get URLs.
- std::set<GURL> urls;
- for (ListValue::const_iterator v = args->begin() + 1;
- v != args->end(); ++v) {
- if ((*v)->GetType() != Value::TYPE_STRING)
- continue;
- const StringValue* string_value = static_cast<const StringValue*>(*v);
- string16 string16_value;
- if (!string_value->GetAsString(&string16_value))
- continue;
- urls.insert(GURL(string16_value));
- }
-
- HistoryService* hs =
- web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- hs->ExpireHistoryBetween(
- urls, begin_time, end_time, &cancelable_delete_consumer_,
- NewCallback(this, &BrowsingHistoryHandler::RemoveComplete));
-}
-
-void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) {
- // TODO(beng): This is an improper direct dependency on Browser. Route this
- // through some sort of delegate.
- Browser* browser = BrowserList::FindBrowserWithProfile(web_ui_->GetProfile());
- if (browser)
- browser->OpenClearBrowsingDataDialog();
-}
-
-void BrowsingHistoryHandler::QueryComplete(
- HistoryService::Handle request_handle,
- history::QueryResults* results) {
-
- ListValue results_value;
- base::Time midnight_today = base::Time::Now().LocalMidnight();
-
- for (size_t i = 0; i < results->size(); ++i) {
- history::URLResult const &page = (*results)[i];
- DictionaryValue* page_value = new DictionaryValue();
- SetURLAndTitle(page_value, page.title(), page.url());
-
- // Need to pass the time in epoch time (fastest JS conversion).
- page_value->SetInteger("time",
- static_cast<int>(page.visit_time().ToTimeT()));
-
- // Until we get some JS i18n infrastructure, we also need to
- // pass the dates in as strings. This could use some
- // optimization.
-
- // Only pass in the strings we need (search results need a shortdate
- // and snippet, browse results need day and time information).
- if (search_text_.empty()) {
- // Figure out the relative date string.
- string16 date_str = TimeFormat::RelativeDate(page.visit_time(),
- &midnight_today);
- if (date_str.empty()) {
- date_str = base::TimeFormatFriendlyDate(page.visit_time());
- } else {
- date_str = l10n_util::GetStringFUTF16(
- IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
- date_str,
- base::TimeFormatFriendlyDate(page.visit_time()));
- }
- page_value->SetString("dateRelativeDay", date_str);
- page_value->SetString("dateTimeOfDay",
- base::TimeFormatTimeOfDay(page.visit_time()));
- } else {
- page_value->SetString("dateShort",
- base::TimeFormatShortDate(page.visit_time()));
- page_value->SetString("snippet", page.snippet().text());
- }
- page_value->SetBoolean("starred",
- web_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url()));
- results_value.Append(page_value);
- }
-
- DictionaryValue info_value;
- info_value.SetString("term", search_text_);
- info_value.SetBoolean("finished", results->reached_beginning());
-
- web_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value);
-}
-
-void BrowsingHistoryHandler::RemoveComplete() {
- // Some Visits were deleted from history. Reload the list.
- web_ui_->CallJavascriptFunction(L"deleteComplete");
-}
-
-void BrowsingHistoryHandler::ExtractSearchHistoryArguments(
- const ListValue* args,
- int* month,
- string16* query) {
- CHECK(args->GetSize() == 2);
- query->clear();
- CHECK(args->GetString(0, query));
-
- string16 string16_value;
- CHECK(args->GetString(1, &string16_value));
- *month = 0;
- base::StringToInt(string16_value, month);
-}
-
-history::QueryOptions BrowsingHistoryHandler::CreateMonthQueryOptions(
- int month) {
- history::QueryOptions options;
-
- // Configure the begin point of the search to the start of the
- // current month.
- base::Time::Exploded exploded;
- base::Time::Now().LocalMidnight().LocalExplode(&exploded);
- exploded.day_of_month = 1;
-
- if (month == 0) {
- options.begin_time = base::Time::FromLocalExploded(exploded);
-
- // Set the end time of this first search to null (which will
- // show results from the future, should the user's clock have
- // been set incorrectly).
- options.end_time = base::Time();
- } else {
- // Set the end-time of this search to the end of the month that is
- // |depth| months before the search end point. The end time is not
- // inclusive, so we should feel free to set it to midnight on the
- // first day of the following month.
- exploded.month -= month - 1;
- while (exploded.month < 1) {
- exploded.month += 12;
- exploded.year--;
- }
- options.end_time = base::Time::FromLocalExploded(exploded);
-
- // Set the begin-time of the search to the start of the month
- // that is |depth| months prior to search_start_.
- if (exploded.month > 1) {
- exploded.month--;
- } else {
- exploded.month = 12;
- exploded.year--;
- }
- options.begin_time = base::Time::FromLocalExploded(exploded);
- }
-
- return options;
-}
-
-void BrowsingHistoryHandler::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type != NotificationType::HISTORY_URLS_DELETED) {
- NOTREACHED();
- return;
- }
-
- // Some URLs were deleted from history. Reload the list.
- web_ui_->CallJavascriptFunction(L"historyDeleted");
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// HistoryUIContents
-//
-////////////////////////////////////////////////////////////////////////////////
-
-HistoryUI::HistoryUI(TabContents* contents) : WebUI(contents) {
- AddMessageHandler((new BrowsingHistoryHandler())->Attach(this));
-
- HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource();
-
- // Set up the chrome://history/ source.
- contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
-
-// static
-const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) {
- return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
- EscapeQueryParamValue(UTF16ToUTF8(text), true));
-}
-
-// static
-RefCountedMemory* HistoryUI::GetFaviconResourceBytes() {
- return ResourceBundle::GetSharedInstance().
- LoadDataResourceBytes(IDR_HISTORY_FAVICON);
-}
diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h
deleted file mode 100644
index f1788bd..0000000
--- a/chrome/browser/dom_ui/history_ui.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
-#define CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
-#pragma once
-
-#include <string>
-
-#include "base/string16.h"
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/dom_ui/web_ui.h"
-#include "chrome/browser/cancelable_request.h"
-#include "chrome/browser/history/history.h"
-#include "chrome/common/notification_registrar.h"
-
-class GURL;
-
-class HistoryUIHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- HistoryUIHTMLSource();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const;
-
- private:
- ~HistoryUIHTMLSource() {}
-
- DISALLOW_COPY_AND_ASSIGN(HistoryUIHTMLSource);
-};
-
-// The handler for Javascript messages related to the "history" view.
-class BrowsingHistoryHandler : public WebUIMessageHandler,
- public NotificationObserver {
- public:
- BrowsingHistoryHandler();
- virtual ~BrowsingHistoryHandler();
-
- // WebUIMessageHandler implementation.
- virtual WebUIMessageHandler* Attach(WebUI* web_ui);
- virtual void RegisterMessages();
-
- // Callback for the "getHistory" message.
- void HandleGetHistory(const ListValue* args);
-
- // Callback for the "searchHistory" message.
- void HandleSearchHistory(const ListValue* args);
-
- // Callback for the "removeURLsOnOneDay" message.
- void HandleRemoveURLsOnOneDay(const ListValue* args);
-
- // Handle for "clearBrowsingData" message.
- void HandleClearBrowsingData(const ListValue* args);
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- private:
- // Callback from the history system when the history list is available.
- void QueryComplete(HistoryService::Handle request_handle,
- history::QueryResults* results);
-
- // Callback from the history system when visits were deleted.
- void RemoveComplete();
-
- // Extract the arguments from the call to HandleSearchHistory.
- void ExtractSearchHistoryArguments(const ListValue* args,
- int* month,
- string16* query);
-
- // Figure out the query options for a month-wide query.
- history::QueryOptions CreateMonthQueryOptions(int month);
-
- NotificationRegistrar registrar_;
-
- // Current search text.
- string16 search_text_;
-
- // Our consumer for search requests to the history service.
- CancelableRequestConsumerT<int, 0> cancelable_search_consumer_;
-
- // Our consumer for delete requests to the history service.
- CancelableRequestConsumerT<int, 0> cancelable_delete_consumer_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
-};
-
-class HistoryUI : public WebUI {
- public:
- explicit HistoryUI(TabContents* contents);
-
- // Return the URL for a given search term.
- static const GURL GetHistoryURLWithSearchText(const string16& text);
-
- static RefCountedMemory* GetFaviconResourceBytes();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(HistoryUI);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
diff --git a/chrome/browser/dom_ui/keyboard_ui.cc b/chrome/browser/dom_ui/keyboard_ui.cc
deleted file mode 100644
index a85b92d..0000000
--- a/chrome/browser/dom_ui/keyboard_ui.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/keyboard_ui.h"
-
-#include "base/ref_counted_memory.h"
-#include "base/singleton.h"
-#include "base/string_piece.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/url_constants.h"
-#include "grit/browser_resources.h"
-#include "ui/base/resource/resource_bundle.h"
-
-///////////////////////////////////////////////////////////////////////////////
-// KeyboardUI
-
-KeyboardUI::KeyboardUI(TabContents* contents)
- : WebUI(contents) {
- KeyboardHTMLSource* html_source = new KeyboardHTMLSource();
- contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
-
-KeyboardUI::~KeyboardUI() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// KeyboardHTMLSource
-
-KeyboardUI::KeyboardHTMLSource::KeyboardHTMLSource()
- : DataSource(chrome::kChromeUIKeyboardHost, MessageLoop::current()) {
-}
-
-void KeyboardUI::KeyboardHTMLSource::StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id) {
- NOTREACHED() << "We should never get here since the extension should have"
- << "been triggered";
- SendResponse(request_id, NULL);
-}
-
-std::string KeyboardUI::KeyboardHTMLSource::GetMimeType(
- const std::string&) const {
- NOTREACHED() << "We should never get here since the extension should have"
- << "been triggered";
- return "text/html";
-}
diff --git a/chrome/browser/dom_ui/keyboard_ui.h b/chrome/browser/dom_ui/keyboard_ui.h
deleted file mode 100644
index 0448407..0000000
--- a/chrome/browser/dom_ui/keyboard_ui.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_DOM_UI_KEYBOARD_UI_H_
-#define CHROME_BROWSER_DOM_UI_KEYBOARD_UI_H_
-#pragma once
-
-#include <string>
-
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/dom_ui/web_ui.h"
-
-class Profile;
-
-// The TabContents used for the keyboard page.
-class KeyboardUI : public WebUI {
- public:
- explicit KeyboardUI(TabContents* manager);
- ~KeyboardUI();
-
- class KeyboardHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- KeyboardHTMLSource();
-
- // Overrides from DataSource
- virtual void StartDataRequest(const std::string& path,
- bool is_off_the_record,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const;
-
- private:
- virtual ~KeyboardHTMLSource() {}
-
- DISALLOW_COPY_AND_ASSIGN(KeyboardHTMLSource);
- };
-
- private:
- DISALLOW_COPY_AND_ASSIGN(KeyboardUI);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_KEYBOARD_UI_H_
diff --git a/chrome/browser/dom_ui/web_ui_factory.cc b/chrome/browser/dom_ui/web_ui_factory.cc
index d69da41..6cedb8c 100644
--- a/chrome/browser/dom_ui/web_ui_factory.cc
+++ b/chrome/browser/dom_ui/web_ui_factory.cc
@@ -6,11 +6,7 @@
#include "base/command_line.h"
#include "chrome/browser/about_flags.h"
-#include "chrome/browser/dom_ui/bug_report_ui.h"
#include "chrome/browser/dom_ui/constrained_html_ui.h"
-#include "chrome/browser/dom_ui/gpu_internals_ui.h"
-#include "chrome/browser/dom_ui/history2_ui.h"
-#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
#include "chrome/browser/dom_ui/net_internals_ui.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
@@ -28,9 +24,13 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/webui/bookmarks_ui.h"
+#include "chrome/browser/webui/bug_report_ui.h"
#include "chrome/browser/webui/devtools_ui.h"
#include "chrome/browser/webui/downloads_ui.h"
#include "chrome/browser/webui/flags_ui.h"
+#include "chrome/browser/webui/gpu_internals_ui.h"
+#include "chrome/browser/webui/history2_ui.h"
+#include "chrome/browser/webui/history_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"
@@ -50,7 +50,7 @@
#endif
#if defined(TOUCH_UI)
-#include "chrome/browser/dom_ui/keyboard_ui.h"
+#include "chrome/browser/webui/keyboard_ui.h"
#endif
#if defined(TOUCH_UI) && defined(OS_CHROMEOS)