diff options
| author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-06 16:41:13 +0000 |
|---|---|---|
| committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-06 16:41:13 +0000 |
| commit | 1c9ac92646f4ab04e244a550974243aa512e40e6 (patch) | |
| tree | 471ff35a6f86abe2f5c84d010a6e25ef0a354f7f | |
| parent | 3b48dbc794dd45719eb6047968eb1946d39fe59e (diff) | |
| download | chromium_src-1c9ac92646f4ab04e244a550974243aa512e40e6.zip chromium_src-1c9ac92646f4ab04e244a550974243aa512e40e6.tar.gz chromium_src-1c9ac92646f4ab04e244a550974243aa512e40e6.tar.bz2 | |
Get rid of the need to have ChromeWebUI. This was added originally so that we can keep the knowledge about whether or not we can show bookmarks bars out of content since content shouldn't know about chrome ui. But now that we're creating an API around content, we can't have chrome code derive from content implementation classes. This is the first step in doing this (after that we'll make chrome webui classes not derive from WebUI at all).
BUG=98716
Review URL: http://codereview.chromium.org/9111040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116672 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/ui/bookmarks/bookmark_tab_helper.cc | 6 | ||||
| -rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui.h | 4 | ||||
| -rw-r--r-- | chrome/browser/ui/webui/ntp/new_tab_ui.cc | 30 | ||||
| -rw-r--r-- | chrome/browser/ui/webui/ntp/new_tab_ui.h | 21 |
5 files changed, 39 insertions, 26 deletions
diff --git a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc index e4b5e7a..b0316fd 100644 --- a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc +++ b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc @@ -10,6 +10,7 @@ #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/chrome_web_ui.h" +#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" @@ -18,7 +19,10 @@ namespace { bool CanShowBookmarkBar(WebUI* ui) { - return ui && static_cast<ChromeWebUI*>(ui)->CanShowBookmarkBar(); + if (!ui) + return false; + NewTabUI* new_tab = NewTabUI::FromWebUI(ui); + return new_tab && new_tab->CanShowBookmarkBar(); } } // namespace diff --git a/chrome/browser/ui/webui/chrome_web_ui.cc b/chrome/browser/ui/webui/chrome_web_ui.cc index 9efe482..7a53bb2 100644 --- a/chrome/browser/ui/webui/chrome_web_ui.cc +++ b/chrome/browser/ui/webui/chrome_web_ui.cc @@ -34,10 +34,6 @@ Profile* ChromeWebUI::GetProfile() const { return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); } -bool ChromeWebUI::CanShowBookmarkBar() const { - return false; -} - void ChromeWebUI::RenderViewCreated(RenderViewHost* render_view_host) { WebUI::RenderViewCreated(render_view_host); diff --git a/chrome/browser/ui/webui/chrome_web_ui.h b/chrome/browser/ui/webui/chrome_web_ui.h index 5516a30..b95aa70 100644 --- a/chrome/browser/ui/webui/chrome_web_ui.h +++ b/chrome/browser/ui/webui/chrome_web_ui.h @@ -18,10 +18,6 @@ class ChromeWebUI : public WebUI { // Returns the profile for this WebUI. Profile* GetProfile() const; - // Returns true if the bookmark bar can be displayed over this webui, - // detached from the location bar. - virtual bool CanShowBookmarkBar() const; - // Overridden from WebUI: virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 971b74a..6a4ec18 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -6,10 +6,13 @@ #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" +#include <set> + #include "base/bind.h" #include "base/bind_helpers.h" #include "base/command_line.h" #include "base/i18n/rtl.h" +#include "base/lazy_instance.h" #include "base/memory/singleton.h" #include "base/metrics/histogram.h" #include "base/string_number_conversions.h" @@ -64,6 +67,8 @@ const int kTimeoutMs = 2000; const char kRTLHtmlTextDirection[] = "rtl"; const char kLTRHtmlTextDirection[] = "ltr"; +static base::LazyInstance<std::set<const WebUI*> > g_live_new_tabs; + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -71,6 +76,7 @@ const char kLTRHtmlTextDirection[] = "ltr"; NewTabUI::NewTabUI(WebContents* contents) : ChromeWebUI(contents) { + g_live_new_tabs.Pointer()->insert(this); // Override some options on the Web UI. hide_favicon_ = true; @@ -119,6 +125,7 @@ NewTabUI::NewTabUI(WebContents* contents) } NewTabUI::~NewTabUI() { + g_live_new_tabs.Pointer()->erase(this); } // The timer callback. If enough time has elapsed since the last paint @@ -155,6 +162,14 @@ void NewTabUI::StartTimingPaint(RenderViewHost* render_view_host) { } +bool NewTabUI::CanShowBookmarkBar() const { + PrefService* prefs = GetProfile()->GetPrefs(); + bool disabled_by_policy = + prefs->IsManagedPreference(prefs::kShowBookmarkBar) && + !prefs->GetBoolean(prefs::kShowBookmarkBar); + return browser_defaults::bookmarks_enabled && !disabled_by_policy; +} + void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { StartTimingPaint(render_view_host); ChromeWebUI::RenderViewCreated(render_view_host); @@ -165,14 +180,6 @@ void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { ChromeWebUI::RenderViewReused(render_view_host); } -bool NewTabUI::CanShowBookmarkBar() const { - PrefService* prefs = GetProfile()->GetPrefs(); - bool disabled_by_policy = - prefs->IsManagedPreference(prefs::kShowBookmarkBar) && - !prefs->GetBoolean(prefs::kShowBookmarkBar); - return browser_defaults::bookmarks_enabled && !disabled_by_policy; -} - void NewTabUI::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -245,6 +252,13 @@ void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, dictionary->SetString("direction", direction); } +// static +NewTabUI* NewTabUI::FromWebUI(WebUI* ui) { + if (!g_live_new_tabs.Pointer()->count(ui)) + return NULL; + return static_cast<NewTabUI*>(ui); +} + /////////////////////////////////////////////////////////////////////////////// // NewTabHTMLSource diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chrome/browser/ui/webui/ntp/new_tab_ui.h index 401b687..05e9e6f 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.h +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.h @@ -28,11 +28,6 @@ class NewTabUI : public ChromeWebUI, explicit NewTabUI(content::WebContents* manager); virtual ~NewTabUI(); - // Override WebUI methods so we can hook up the paint timer to the render - // view host. - virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; - virtual void RenderViewReused(RenderViewHost* render_view_host) OVERRIDE; - static void RegisterUserPrefs(PrefService* prefs); // Adds "url", "title", and "direction" keys on incoming dictionary, setting @@ -41,9 +36,21 @@ class NewTabUI : public ChromeWebUI, const string16& title, const GURL& gurl); + // Returns a pointer to a NewTabUI if the WebUI object is a new tab page. + static NewTabUI* FromWebUI(WebUI* ui); + // The current preference version. static int current_pref_version() { return current_pref_version_; } + // Override WebUI methods so we can hook up the paint timer to the render + // view host. + virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; + virtual void RenderViewReused(RenderViewHost* render_view_host) OVERRIDE; + + // Returns true if the bookmark bar can be displayed over this webui, detached + // from the location bar. + bool CanShowBookmarkBar() const; + class NewTabHTMLSource : public ChromeURLDataManager::DataSource { public: explicit NewTabHTMLSource(Profile* profile); @@ -80,10 +87,6 @@ class NewTabUI : public ChromeWebUI, void StartTimingPaint(RenderViewHost* render_view_host); void PaintTimeout(); - // Overridden from ChromeWebUI. Determines if the bookmarks bar can be shown - // detached from the location bar. - virtual bool CanShowBookmarkBar() const OVERRIDE; - content::NotificationRegistrar registrar_; // The time when we started benchmarking. |
