blob: d029b4fa39abf55af1603978a7333666aaf90c7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// 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_
#pragma once
#include "base/file_path.h"
#include "base/logging.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/file_watcher.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.
class UserStyleSheetWatcher
: public base::RefCountedThreadSafe<UserStyleSheetWatcher,
ChromeThread::DeleteOnUIThread>,
public NotificationObserver,
public FileWatcher::Delegate {
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);
// FileWatcher::Delegate interface
virtual void OnFileChanged(const FilePath& path);
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 User StyleSheets/Custom.css.
FilePath profile_path_;
// The user style sheet as a base64 data:// URL.
GURL user_style_sheet_;
// Watches for changes to the css file so we can reload the style sheet.
scoped_ptr<FileWatcher> file_watcher_;
NotificationRegistrar registrar_;
bool has_loaded_;
DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher);
};
#endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_
|