Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / new_tab_ui.h
blob79899a315fcdc0d13209f8f9a42b5f071b022483
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/url_data_source.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_ui_controller.h"
21 class GURL;
22 class Profile;
24 namespace base {
25 class DictionaryValue;
28 namespace user_prefs {
29 class PrefRegistrySyncable;
32 // The WebUIController used for the New Tab page.
33 class NewTabUI : public content::WebUIController,
34 public content::WebContentsObserver,
35 public content::NotificationObserver {
36 public:
37 explicit NewTabUI(content::WebUI* web_ui);
38 ~NewTabUI() override;
40 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
42 // Returns whether or not to show apps pages.
43 static bool ShouldShowApps();
45 // TODO(dbeam): why are these static |Set*()| methods on NewTabUI?
47 // Adds "url", "title", and "direction" keys on incoming dictionary, setting
48 // title as the url as a fallback on empty title.
49 static void SetUrlTitleAndDirection(base::DictionaryValue* dictionary,
50 const base::string16& title,
51 const GURL& gurl);
53 // Adds "full_name" and "full_name_direction" keys on incoming dictionary.
54 static void SetFullNameAndDirection(const base::string16& full_name,
55 base::DictionaryValue* dictionary);
57 // Returns a pointer to a NewTabUI if the WebUIController object is a new tab
58 // page.
59 static NewTabUI* FromWebUIController(content::WebUIController* ui);
61 // The current preference version.
62 static int current_pref_version() { return current_pref_version_; }
64 // WebUIController implementation:
65 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
66 void RenderViewReused(content::RenderViewHost* render_view_host) override;
68 // WebContentsObserver implementation:
69 void WasHidden() override;
71 bool showing_sync_bubble() { return showing_sync_bubble_; }
72 void set_showing_sync_bubble(bool showing) { showing_sync_bubble_ = showing; }
74 class NewTabHTMLSource : public content::URLDataSource {
75 public:
76 explicit NewTabHTMLSource(Profile* profile);
77 ~NewTabHTMLSource() override;
79 // content::URLDataSource implementation.
80 std::string GetSource() const override;
81 void StartDataRequest(
82 const std::string& path,
83 int render_process_id,
84 int render_frame_id,
85 const content::URLDataSource::GotDataCallback& callback) override;
86 std::string GetMimeType(const std::string&) const override;
87 bool ShouldReplaceExistingSource() const override;
88 bool ShouldAddContentSecurityPolicy() const override;
90 // Adds |resource| to the source. |resource_id| is resource id or 0,
91 // which means return empty data set. |mime_type| is mime type of the
92 // resource.
93 void AddResource(const char* resource,
94 const char* mime_type,
95 int resource_id);
97 private:
98 // Pointer back to the original profile.
99 Profile* profile_;
101 // Maps resource files to mime types an resource ids.
102 std::map<std::string, std::pair<std::string, int> > resource_map_;
104 DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource);
107 private:
108 FRIEND_TEST_ALL_PREFIXES(NewTabUITest, UpdateUserPrefsVersion);
110 // content::NotificationObserver implementation.
111 void Observe(int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) override;
115 // If |web_contents| has an NTP URL, emits a number of NTP statistics (like
116 // mouseovers counts) associated with |web_contents|, to be logged in UMA
117 // histograms.
118 void EmitNtpStatistics();
120 void OnShowBookmarkBarChanged();
122 void StartTimingPaint(content::RenderViewHost* render_view_host);
123 void PaintTimeout();
125 Profile* GetProfile() const;
127 content::NotificationRegistrar registrar_;
129 // The time when we started benchmarking.
130 base::TimeTicks start_;
131 // The last time we got a paint notification.
132 base::TimeTicks last_paint_;
133 // Scoping so we can be sure our timeouts don't outlive us.
134 base::OneShotTimer<NewTabUI> timer_;
135 // The preference version. This used for migrating prefs of the NTP.
136 static const int current_pref_version_ = 3;
138 // If the sync promo NTP bubble is being shown.
139 bool showing_sync_bubble_;
141 PrefChangeRegistrar pref_change_registrar_;
143 DISALLOW_COPY_AND_ASSIGN(NewTabUI);
146 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_