summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 01:07:42 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 01:07:42 +0000
commit4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f (patch)
tree69a1e9f78b3a5fa8b909cfab336826b09c44235f /chrome/browser/dom_ui
parent5085ee0b4bfbe4625e63ee6975bb95702e13e0aa (diff)
downloadchromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.zip
chromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.tar.gz
chromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.tar.bz2
This is the first pass at themes.
This CL is paired with http://codereview.chromium.org/67284 This CL (for commit purposes) includes http://codereview.chromium.org/67284 BUG=4463,11232,11233,11234,11235 Review URL: http://codereview.chromium.org/99030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15704 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/dom_ui.cc7
-rw-r--r--chrome/browser/dom_ui/dom_ui.h5
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.cc37
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.h30
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc6
5 files changed, 84 insertions, 1 deletions
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc
index f8e0405..ff49039 100644
--- a/chrome/browser/dom_ui/dom_ui.cc
+++ b/chrome/browser/dom_ui/dom_ui.cc
@@ -10,7 +10,10 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/values.h"
+#include "base/win_util.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
DOMUI::DOMUI(TabContents* contents)
: hide_favicon_(false),
@@ -79,6 +82,10 @@ void DOMUI::CallJavascriptFunction(
ExecuteJavascript(javascript);
}
+ThemeProvider* DOMUI::GetThemeProvider() const {
+ return tab_contents_->profile()->GetThemeProvider();
+}
+
void DOMUI::RegisterMessageCallback(const std::string &message,
MessageCallback *callback) {
message_callbacks_.insert(std::make_pair(message, callback));
diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h
index 3c2dc16..fadff05 100644
--- a/chrome/browser/dom_ui/dom_ui.h
+++ b/chrome/browser/dom_ui/dom_ui.h
@@ -21,6 +21,7 @@ class Profile;
class RenderViewHost;
class Value;
class TabContents;
+class ThemeProvider;
// A DOMUI sets up the datasources and message handlers for a given HTML-based
// UI. It is contained by a DOMUIManager.
@@ -44,7 +45,7 @@ class DOMUI {
bool hide_favicon() const {
return hide_favicon_;
}
-
+
// Returns true if the bookmark bar should be forced to being visible,
// overriding the user's preference.
bool force_bookmark_bar_visible() const {
@@ -89,6 +90,8 @@ class DOMUI {
const Value& arg1,
const Value& arg2);
+ ThemeProvider* GetThemeProvider() const;
+
TabContents* tab_contents() { return tab_contents_; }
Profile* GetProfile();
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc
new file mode 100644
index 0000000..31ff1f8
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2009 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/dom_ui_theme_source.h"
+
+#include "app/resource_bundle.h"
+#include "app/theme_provider.h"
+#include "base/gfx/png_encoder.h"
+#include "base/message_loop.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/theme_resources_util.h"
+#include "chrome/common/url_constants.h"
+#include "grit/theme_resources.h"
+
+DOMUIThemeSource::DOMUIThemeSource(Profile* profile)
+ : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()),
+ profile_(profile) {
+}
+
+void DOMUIThemeSource::StartDataRequest(const std::string& path,
+ int request_id) {
+ ThemeProvider* tp = profile_->GetThemeProvider();
+ if (tp) {
+ int id = ThemeResourcesUtil::GetId(path);
+ if (id != -1) {
+ SkBitmap* image = tp->GetBitmapNamed(id);
+ if (image) {
+ std::vector<unsigned char> png_bytes;
+ PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes);
+
+ scoped_refptr<RefCountedBytes> image_data = new RefCountedBytes(png_bytes);
+ SendResponse(request_id, image_data);
+ }
+ }
+ }
+}
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.h b/chrome/browser/dom_ui/dom_ui_theme_source.h
new file mode 100644
index 0000000..279042d
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2009 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_DOM_UI_THEME_SOURCE_H_
+#define CHROME_BROWSER_DOM_UI_DOM_UI_THEME_SOURCE_H_
+
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+
+class Profile;
+
+// ThumbnailSource is the gateway between network-level chrome:
+// requests for thumbnails and the history backend that serves these.
+class DOMUIThemeSource : public ChromeURLDataManager::DataSource {
+public:
+ explicit DOMUIThemeSource(Profile* profile);
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string& path) const {
+ return "image/png";
+ }
+
+private:
+ Profile* profile_;
+ DISALLOW_COPY_AND_ASSIGN(DOMUIThemeSource);
+};
+
+#endif // CHROME_BROWSER_DOM_UI_DOM_UI_THEME_SOURCE_H_
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index d4bdf97..b13fbb2 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
#include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h"
+#include "chrome/browser/dom_ui/dom_ui_theme_source.h"
#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -1165,6 +1166,11 @@ NewTabUI::NewTabUI(TabContents* contents)
// In testing mode there may not be an I/O thread.
if (g_browser_process->io_thread()) {
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(&chrome_url_data_manager,
+ &ChromeURLDataManager::AddDataSource,
+ new DOMUIThemeSource(GetProfile())));
+
NewTabHTMLSource* html_source = new NewTabHTMLSource();
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,