summaryrefslogtreecommitdiffstats
path: root/chrome/browser/user_style_sheet_watcher.h
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 05:18:06 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 05:18:06 +0000
commit6c32ce70d1b04d1b5982a5833ced60b92cda10fb (patch)
treea42fab74398b9b4d44eecc80326385a27d3664cd /chrome/browser/user_style_sheet_watcher.h
parent31e9bb2767ccded0fe3f2af5c8f105af0eb97a01 (diff)
downloadchromium_src-6c32ce70d1b04d1b5982a5833ced60b92cda10fb.zip
chromium_src-6c32ce70d1b04d1b5982a5833ced60b92cda10fb.tar.gz
chromium_src-6c32ce70d1b04d1b5982a5833ced60b92cda10fb.tar.bz2
First cut at custom user style sheets.
Enabled with the --enable-user-stylesheet flag which causes chrome to read <user-data-dir>/<profile>/User StyleSheet/Custom.css at startup and set it as the user style sheet. This version never reloads the user style sheet, I'll have to bring back FileWatcher for that. I also put the user stylesheet in a subdir because the implementation of FileWatcher will watch the parent dir (this is what the OS apis give me) and watching the profile dir will cause lots of activity. BUG=2393 Review URL: http://codereview.chromium.org/660349 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/user_style_sheet_watcher.h')
-rw-r--r--chrome/browser/user_style_sheet_watcher.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/user_style_sheet_watcher.h b/chrome/browser/user_style_sheet_watcher.h
new file mode 100644
index 0000000..87fa5ce
--- /dev/null
+++ b/chrome/browser/user_style_sheet_watcher.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2010 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_USER_STYLE_SHEET_WATCHER_H_
+#define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_
+
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/ref_counted.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+#include "googleurl/src/gurl.h"
+
+// This loads the user style sheet on the file thread and sends a notification
+// when the style sheet is loaded.
+// TODO(tony): Watch for file changes and send a notification of the update.
+class UserStyleSheetWatcher
+ : public base::RefCountedThreadSafe<UserStyleSheetWatcher,
+ ChromeThread::DeleteOnUIThread>,
+ public NotificationObserver {
+ public:
+ explicit UserStyleSheetWatcher(const FilePath& profile_path);
+ virtual ~UserStyleSheetWatcher() {}
+
+ void Init();
+
+ GURL user_style_sheet() const {
+ return user_style_sheet_;
+ }
+
+ // NotificationObserver interface
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ private:
+ // Load the user style sheet on the file thread and convert it to a
+ // base64 URL. Posts the base64 URL back to the UI thread.
+ void LoadStyleSheet(const FilePath& profile_path);
+
+ void SetStyleSheet(const GURL& url);
+
+ // The directory containing the User StyleSheet.
+ FilePath profile_path_;
+
+ // The user style sheet as a base64 data:// URL.
+ GURL user_style_sheet_;
+
+ NotificationRegistrar registrar_;
+ bool has_loaded_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher);
+};
+
+#endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_