OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/user_style_sheet_watcher.h" | 5 #include "chrome/browser/user_style_sheet_watcher.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 base::FilePath style_sheet_dir = style_sheet_file.DirName(); | 115 base::FilePath style_sheet_dir = style_sheet_file.DirName(); |
116 if (!base::DirectoryExists(style_sheet_dir)) { | 116 if (!base::DirectoryExists(style_sheet_dir)) { |
117 if (!file_util::CreateDirectory(style_sheet_dir)) | 117 if (!file_util::CreateDirectory(style_sheet_dir)) |
118 return; | 118 return; |
119 } | 119 } |
120 // Create the file if it doesn't exist. | 120 // Create the file if it doesn't exist. |
121 if (!base::PathExists(style_sheet_file)) | 121 if (!base::PathExists(style_sheet_file)) |
122 file_util::WriteFile(style_sheet_file, "", 0); | 122 file_util::WriteFile(style_sheet_file, "", 0); |
123 | 123 |
124 std::string css; | 124 std::string css; |
125 bool rv = file_util::ReadFileToString(style_sheet_file, &css); | 125 bool rv = base::ReadFileToString(style_sheet_file, &css); |
126 GURL style_sheet_url; | 126 GURL style_sheet_url; |
127 if (rv && !css.empty()) { | 127 if (rv && !css.empty()) { |
128 std::string css_base64; | 128 std::string css_base64; |
129 rv = base::Base64Encode(css, &css_base64); | 129 rv = base::Base64Encode(css, &css_base64); |
130 if (rv) { | 130 if (rv) { |
131 // WebKit knows about data urls, so convert the file to a data url. | 131 // WebKit knows about data urls, so convert the file to a data url. |
132 const char kDataUrlPrefix[] = "data:text/css;charset=utf-8;base64,"; | 132 const char kDataUrlPrefix[] = "data:text/css;charset=utf-8;base64,"; |
133 style_sheet_url = GURL(kDataUrlPrefix + css_base64); | 133 style_sheet_url = GURL(kDataUrlPrefix + css_base64); |
134 } | 134 } |
135 } | 135 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (profile_->IsSameProfile(Profile::FromBrowserContext( | 207 if (profile_->IsSameProfile(Profile::FromBrowserContext( |
208 content::Source<WebContents>(source)->GetBrowserContext()))) { | 208 content::Source<WebContents>(source)->GetBrowserContext()))) { |
209 loader_->NotifyLoaded(); | 209 loader_->NotifyLoaded(); |
210 registrar_.RemoveAll(); | 210 registrar_.RemoveAll(); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 void UserStyleSheetWatcher::ShutdownOnUIThread() { | 214 void UserStyleSheetWatcher::ShutdownOnUIThread() { |
215 registrar_.RemoveAll(); | 215 registrar_.RemoveAll(); |
216 } | 216 } |
OLD | NEW |