| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/timer.h" | 13 #include "base/timer.h" |
| 14 #include "chrome/browser/sessions/tab_restore_service.h" | 14 #include "chrome/browser/sessions/tab_restore_service.h" |
| 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 16 #include "content/browser/webui/web_ui.h" | 16 #include "content/browser/webui/web_ui.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_ui_controller.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 class PrefService; | 22 class PrefService; |
| 22 class Profile; | 23 class Profile; |
| 23 | 24 |
| 24 // The TabContents used for the New Tab page. | 25 // The TabContents used for the New Tab page. |
| 25 class NewTabUI : public WebUI, | 26 class NewTabUI : public WebUI, public content::WebUIController, |
| 26 public content::NotificationObserver { | 27 public content::NotificationObserver { |
| 27 public: | 28 public: |
| 28 explicit NewTabUI(content::WebContents* manager); | 29 explicit NewTabUI(content::WebContents* manager); |
| 29 virtual ~NewTabUI(); | 30 virtual ~NewTabUI(); |
| 30 | 31 |
| 31 static void RegisterUserPrefs(PrefService* prefs); | 32 static void RegisterUserPrefs(PrefService* prefs); |
| 32 | 33 |
| 33 // Adds "url", "title", and "direction" keys on incoming dictionary, setting | 34 // Adds "url", "title", and "direction" keys on incoming dictionary, setting |
| 34 // title as the url as a fallback on empty title. | 35 // title as the url as a fallback on empty title. |
| 35 static void SetURLTitleAndDirection(base::DictionaryValue* dictionary, | 36 static void SetURLTitleAndDirection(base::DictionaryValue* dictionary, |
| 36 const string16& title, | 37 const string16& title, |
| 37 const GURL& gurl); | 38 const GURL& gurl); |
| 38 | 39 |
| 39 // Returns a pointer to a NewTabUI if the WebUI object is a new tab page. | 40 // Returns a pointer to a NewTabUI if the WebUI object is a new tab page. |
| 40 static NewTabUI* FromWebUI(WebUI* ui); | 41 static NewTabUI* FromWebUI(WebUI* ui); |
| 41 | 42 |
| 42 // The current preference version. | 43 // The current preference version. |
| 43 static int current_pref_version() { return current_pref_version_; } | 44 static int current_pref_version() { return current_pref_version_; } |
| 44 | 45 |
| 45 // Override WebUI methods so we can hook up the paint timer to the render | 46 // WebUIController implementation: |
| 46 // view host. | |
| 47 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; | 47 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; |
| 48 virtual void RenderViewReused(RenderViewHost* render_view_host) OVERRIDE; | 48 virtual void RenderViewReused(RenderViewHost* render_view_host) OVERRIDE; |
| 49 | 49 |
| 50 // Returns true if the bookmark bar can be displayed over this webui, detached | 50 // Returns true if the bookmark bar can be displayed over this webui, detached |
| 51 // from the location bar. | 51 // from the location bar. |
| 52 bool CanShowBookmarkBar() const; | 52 bool CanShowBookmarkBar() const; |
| 53 | 53 |
| 54 class NewTabHTMLSource : public ChromeURLDataManager::DataSource { | 54 class NewTabHTMLSource : public ChromeURLDataManager::DataSource { |
| 55 public: | 55 public: |
| 56 explicit NewTabHTMLSource(Profile* profile); | 56 explicit NewTabHTMLSource(Profile* profile); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 base::TimeTicks last_paint_; | 97 base::TimeTicks last_paint_; |
| 98 // Scoping so we can be sure our timeouts don't outlive us. | 98 // Scoping so we can be sure our timeouts don't outlive us. |
| 99 base::OneShotTimer<NewTabUI> timer_; | 99 base::OneShotTimer<NewTabUI> timer_; |
| 100 // The preference version. This used for migrating prefs of the NTP. | 100 // The preference version. This used for migrating prefs of the NTP. |
| 101 static const int current_pref_version_ = 3; | 101 static const int current_pref_version_ = 3; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(NewTabUI); | 103 DISALLOW_COPY_AND_ASSIGN(NewTabUI); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ | 106 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_ |
| OLD | NEW |