1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ 6 #define CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/string16.h" 12 #include "chrome/browser/history/history.h" 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 14 #include "content/browser/cancelable_request.h" 15 #include "content/browser/webui/web_ui.h" 16 17 class GURL; 18 19 class HistoryUIHTMLSource : public ChromeURLDataManager::DataSource { 20 public: 21 HistoryUIHTMLSource(); 22 23 // Called when the network layer has requested a resource underneath 24 // the path we registered. 25 virtual void StartDataRequest(const std::string& path, 26 bool is_incognito, 27 int request_id); 28 virtual std::string GetMimeType(const std::string&) const; 29 30 private: ~HistoryUIHTMLSource()31 ~HistoryUIHTMLSource() {} 32 33 DISALLOW_COPY_AND_ASSIGN(HistoryUIHTMLSource); 34 }; 35 36 // The handler for Javascript messages related to the "history" view. 37 class BrowsingHistoryHandler : public WebUIMessageHandler { 38 public: 39 BrowsingHistoryHandler(); 40 virtual ~BrowsingHistoryHandler(); 41 42 // WebUIMessageHandler implementation. 43 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 44 virtual void RegisterMessages(); 45 46 // Callback for the "getHistory" message. 47 void HandleGetHistory(const ListValue* args); 48 49 // Callback for the "searchHistory" message. 50 void HandleSearchHistory(const ListValue* args); 51 52 // Callback for the "removeURLsOnOneDay" message. 53 void HandleRemoveURLsOnOneDay(const ListValue* args); 54 55 // Handle for "clearBrowsingData" message. 56 void HandleClearBrowsingData(const ListValue* args); 57 58 private: 59 // Callback from the history system when the history list is available. 60 void QueryComplete(HistoryService::Handle request_handle, 61 history::QueryResults* results); 62 63 // Callback from the history system when visits were deleted. 64 void RemoveComplete(); 65 66 // Extract the arguments from the call to HandleSearchHistory. 67 void ExtractSearchHistoryArguments(const ListValue* args, 68 int* month, 69 string16* query); 70 71 // Figure out the query options for a month-wide query. 72 history::QueryOptions CreateMonthQueryOptions(int month); 73 74 // Current search text. 75 string16 search_text_; 76 77 // Our consumer for search requests to the history service. 78 CancelableRequestConsumerT<int, 0> cancelable_search_consumer_; 79 80 // Our consumer for delete requests to the history service. 81 CancelableRequestConsumerT<int, 0> cancelable_delete_consumer_; 82 83 DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler); 84 }; 85 86 class HistoryUI : public WebUI { 87 public: 88 explicit HistoryUI(TabContents* contents); 89 90 // Return the URL for a given search term. 91 static const GURL GetHistoryURLWithSearchText(const string16& text); 92 93 static RefCountedMemory* GetFaviconResourceBytes(); 94 95 private: 96 DISALLOW_COPY_AND_ASSIGN(HistoryUI); 97 }; 98 99 #endif // CHROME_BROWSER_UI_WEBUI_HISTORY_UI_H_ 100