Get rid of user-level styles.
-The Apps codepath for this is just using the wrong thing. It should be using author-level styles like extensions do. -The user-stylesheet feature requires the user to put a CSS stylesheet in the right location in their user-data-dir. Extensions are a much better way of doing this. This is in preparation for simplifying the Blink style resolution code by removing the concept of user styles. Review URL: https://codereview.chromium.org/64843004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234007 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome
browser
chrome_content_browser_client.ccuser_style_sheet_watcher.ccuser_style_sheet_watcher.huser_style_sheet_watcher_factory.ccuser_style_sheet_watcher_factory.huser_style_sheet_watcher_unittest.cc
chrome_browser.gypichrome_tests_unit.gypiprofiles
ui
prefs
renderer
extensions
content
webkit/common
@ -86,8 +86,6 @@
|
||||
#include "chrome/browser/ui/sync/sync_promo_ui.h"
|
||||
#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
|
||||
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher_factory.h"
|
||||
#include "chrome/browser/validation_message_message_filter.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
@ -2250,21 +2248,6 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs(
|
||||
web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
|
||||
#endif
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
web_prefs->user_style_sheet_enabled = false;
|
||||
#else
|
||||
// The user stylesheet watcher may not exist in a testing profile.
|
||||
UserStyleSheetWatcher* user_style_sheet_watcher =
|
||||
UserStyleSheetWatcherFactory::GetForProfile(profile).get();
|
||||
if (user_style_sheet_watcher) {
|
||||
web_prefs->user_style_sheet_enabled = true;
|
||||
web_prefs->user_style_sheet_location =
|
||||
user_style_sheet_watcher->user_style_sheet();
|
||||
} else {
|
||||
web_prefs->user_style_sheet_enabled = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
web_prefs->asynchronous_spell_checking_enabled = true;
|
||||
web_prefs->unified_textchecker_enabled = true;
|
||||
|
||||
|
@ -51,7 +51,6 @@
|
||||
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
|
||||
#include "chrome/browser/ui/tabs/pinned_tab_service_factory.h"
|
||||
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher_factory.h"
|
||||
#include "chrome/browser/webdata/web_data_service_factory.h"
|
||||
|
||||
#if defined(ENABLE_EXTENSIONS)
|
||||
@ -371,9 +370,6 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
|
||||
TokenCacheServiceFactory::GetInstance();
|
||||
#endif
|
||||
TokenServiceFactory::GetInstance();
|
||||
#if !defined(OS_ANDROID)
|
||||
UserStyleSheetWatcherFactory::GetInstance();
|
||||
#endif
|
||||
WebDataServiceFactory::GetInstance();
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@
|
||||
#include "chrome/browser/sessions/session_service_factory.h"
|
||||
#include "chrome/browser/ui/startup/startup_browser_creator.h"
|
||||
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher.h"
|
||||
#include "chrome/browser/webdata/web_data_service.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "chrome/common/chrome_paths_internal.h"
|
||||
|
@ -15,8 +15,6 @@
|
||||
#include "chrome/browser/chrome_notification_types.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/renderer_preferences_util.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher_factory.h"
|
||||
#include "chrome/common/pref_font_webkit_names.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/common/pref_names_util.h"
|
||||
@ -342,15 +340,6 @@ PrefsTabHelper::PrefsTabHelper(WebContents* contents)
|
||||
renderer_preferences_util::UpdateFromSystemSettings(
|
||||
web_contents_->GetMutableRendererPrefs(), GetProfile());
|
||||
|
||||
#if !defined(OS_ANDROID)
|
||||
UserStyleSheetWatcher* uss =
|
||||
UserStyleSheetWatcherFactory::GetForProfile(GetProfile());
|
||||
if (uss) {
|
||||
style_sheet_subscription_ = uss->RegisterOnStyleSheetUpdatedCallback(
|
||||
base::Bind(&PrefsTabHelper::UpdateWebPreferences,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
#endif
|
||||
#if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES)
|
||||
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
|
||||
content::Source<ThemeService>(
|
||||
|
@ -1,215 +0,0 @@
|
||||
// Copyright (c) 2012 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/user_style_sheet_watcher.h"
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/file_util.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "content/public/browser/notification_service.h"
|
||||
#include "content/public/browser/notification_types.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
using ::base::FilePathWatcher;
|
||||
using content::BrowserThread;
|
||||
using content::WebContents;
|
||||
|
||||
namespace {
|
||||
|
||||
// The subdirectory of the profile that contains the style sheet.
|
||||
const char kStyleSheetDir[] = "User StyleSheets";
|
||||
// The filename of the stylesheet.
|
||||
const char kUserStyleSheetFile[] = "Custom.css";
|
||||
|
||||
} // namespace
|
||||
|
||||
// UserStyleSheetLoader is responsible for loading the user style sheet on the
|
||||
// file thread and sends a notification when the style sheet is loaded. It is
|
||||
// a helper to UserStyleSheetWatcher. The reference graph is as follows:
|
||||
//
|
||||
// .-----------------------. owns .-----------------.
|
||||
// | UserStyleSheetWatcher |----------->| FilePathWatcher |
|
||||
// '-----------------------' '-----------------'
|
||||
// | |
|
||||
// V |
|
||||
// .----------------------. |
|
||||
// | UserStyleSheetLoader |<--------------------'
|
||||
// '----------------------'
|
||||
//
|
||||
// FilePathWatcher's reference to UserStyleSheetLoader is used for delivering
|
||||
// the change notifications. Since they happen asynchronously,
|
||||
// UserStyleSheetWatcher and its FilePathWatcher may be destroyed while a
|
||||
// callback to UserStyleSheetLoader is in progress, in which case the
|
||||
// UserStyleSheetLoader object outlives the watchers.
|
||||
class UserStyleSheetLoader
|
||||
: public base::RefCountedThreadSafe<UserStyleSheetLoader> {
|
||||
public:
|
||||
UserStyleSheetLoader();
|
||||
|
||||
GURL user_style_sheet() const {
|
||||
return user_style_sheet_;
|
||||
}
|
||||
|
||||
// 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 base::FilePath& style_sheet_file);
|
||||
|
||||
// Register a callback to be called whenever the stylesheet gets updated.
|
||||
scoped_ptr<base::CallbackList<void(void)>::Subscription>
|
||||
RegisterOnStyleSheetUpdatedCallback(const base::Closure& callback);
|
||||
|
||||
// Send out a notification if the stylesheet has already been loaded.
|
||||
void NotifyLoaded();
|
||||
|
||||
// FilePathWatcher::Callback method:
|
||||
void NotifyPathChanged(const base::FilePath& path, bool error);
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<UserStyleSheetLoader>;
|
||||
~UserStyleSheetLoader();
|
||||
|
||||
// Called on the UI thread after the stylesheet has loaded.
|
||||
void SetStyleSheet(const GURL& url);
|
||||
|
||||
// The user style sheet as a base64 data:// URL.
|
||||
GURL user_style_sheet_;
|
||||
|
||||
// Whether the stylesheet has been loaded.
|
||||
bool has_loaded_;
|
||||
|
||||
base::CallbackList<void(void)> style_sheet_updated_callbacks_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UserStyleSheetLoader);
|
||||
};
|
||||
|
||||
UserStyleSheetLoader::UserStyleSheetLoader()
|
||||
: has_loaded_(false) {
|
||||
}
|
||||
|
||||
UserStyleSheetLoader::~UserStyleSheetLoader() {
|
||||
}
|
||||
|
||||
scoped_ptr<base::CallbackList<void(void)>::Subscription>
|
||||
UserStyleSheetLoader::RegisterOnStyleSheetUpdatedCallback(
|
||||
const base::Closure& callback) {
|
||||
return style_sheet_updated_callbacks_.Add(callback);
|
||||
}
|
||||
|
||||
void UserStyleSheetLoader::NotifyLoaded() {
|
||||
if (has_loaded_) {
|
||||
style_sheet_updated_callbacks_.Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void UserStyleSheetLoader::NotifyPathChanged(const base::FilePath& path,
|
||||
bool error) {
|
||||
if (!error)
|
||||
LoadStyleSheet(path);
|
||||
}
|
||||
|
||||
void UserStyleSheetLoader::LoadStyleSheet(
|
||||
const base::FilePath& style_sheet_file) {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
||||
// We keep the user style sheet in a subdir so we can watch for changes
|
||||
// to the file.
|
||||
base::FilePath style_sheet_dir = style_sheet_file.DirName();
|
||||
if (!base::DirectoryExists(style_sheet_dir)) {
|
||||
if (!file_util::CreateDirectory(style_sheet_dir))
|
||||
return;
|
||||
}
|
||||
// Create the file if it doesn't exist.
|
||||
if (!base::PathExists(style_sheet_file))
|
||||
file_util::WriteFile(style_sheet_file, "", 0);
|
||||
|
||||
std::string css;
|
||||
bool rv = base::ReadFileToString(style_sheet_file, &css);
|
||||
GURL style_sheet_url;
|
||||
if (rv && !css.empty()) {
|
||||
std::string css_base64;
|
||||
rv = base::Base64Encode(css, &css_base64);
|
||||
if (rv) {
|
||||
// WebKit knows about data urls, so convert the file to a data url.
|
||||
const char kDataUrlPrefix[] = "data:text/css;charset=utf-8;base64,";
|
||||
style_sheet_url = GURL(kDataUrlPrefix + css_base64);
|
||||
}
|
||||
}
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&UserStyleSheetLoader::SetStyleSheet, this,
|
||||
style_sheet_url));
|
||||
}
|
||||
|
||||
void UserStyleSheetLoader::SetStyleSheet(const GURL& url) {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
|
||||
has_loaded_ = true;
|
||||
user_style_sheet_ = url;
|
||||
NotifyLoaded();
|
||||
}
|
||||
|
||||
UserStyleSheetWatcher::UserStyleSheetWatcher(Profile* profile,
|
||||
const base::FilePath& profile_path)
|
||||
: RefcountedBrowserContextKeyedService(content::BrowserThread::UI),
|
||||
profile_(profile),
|
||||
profile_path_(profile_path),
|
||||
loader_(new UserStyleSheetLoader) {
|
||||
// Listen for when the first render view host is created. If we load
|
||||
// too fast, the first tab won't hear the notification and won't get
|
||||
// the user style sheet.
|
||||
registrar_.Add(this,
|
||||
content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
|
||||
content::NotificationService::AllBrowserContextsAndSources());
|
||||
}
|
||||
|
||||
UserStyleSheetWatcher::~UserStyleSheetWatcher() {
|
||||
}
|
||||
|
||||
void UserStyleSheetWatcher::Init() {
|
||||
// Make sure we run on the file thread.
|
||||
if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
|
||||
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
||||
base::Bind(&UserStyleSheetWatcher::Init, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file_watcher_.get()) {
|
||||
file_watcher_.reset(new FilePathWatcher);
|
||||
base::FilePath style_sheet_file = profile_path_.AppendASCII(kStyleSheetDir)
|
||||
.AppendASCII(kUserStyleSheetFile);
|
||||
if (!file_watcher_->Watch(
|
||||
style_sheet_file,
|
||||
false,
|
||||
base::Bind(&UserStyleSheetLoader::NotifyPathChanged,
|
||||
loader_.get()))) {
|
||||
LOG(ERROR) << "Failed to setup watch for " << style_sheet_file.value();
|
||||
}
|
||||
loader_->LoadStyleSheet(style_sheet_file);
|
||||
}
|
||||
}
|
||||
|
||||
GURL UserStyleSheetWatcher::user_style_sheet() const {
|
||||
return loader_->user_style_sheet();
|
||||
}
|
||||
|
||||
scoped_ptr<base::CallbackList<void(void)>::Subscription>
|
||||
UserStyleSheetWatcher::RegisterOnStyleSheetUpdatedCallback(
|
||||
const base::Closure& callback) {
|
||||
return loader_->RegisterOnStyleSheetUpdatedCallback(callback);
|
||||
}
|
||||
|
||||
void UserStyleSheetWatcher::Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED);
|
||||
if (profile_->IsSameProfile(Profile::FromBrowserContext(
|
||||
content::Source<WebContents>(source)->GetBrowserContext()))) {
|
||||
loader_->NotifyLoaded();
|
||||
registrar_.RemoveAll();
|
||||
}
|
||||
}
|
||||
|
||||
void UserStyleSheetWatcher::ShutdownOnUIThread() {
|
||||
registrar_.RemoveAll();
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
// Copyright (c) 2012 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/callback_list.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_path_watcher.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/sequenced_task_runner_helpers.h"
|
||||
#include "components/browser_context_keyed_service/refcounted_browser_context_keyed_service.h"
|
||||
#include "content/public/browser/notification_observer.h"
|
||||
#include "content/public/browser/notification_registrar.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
class Profile;
|
||||
class UserStyleSheetLoader;
|
||||
|
||||
// Watches the user style sheet file and triggers reloads on the file thread
|
||||
// whenever the file changes.
|
||||
class UserStyleSheetWatcher
|
||||
: public content::NotificationObserver,
|
||||
public RefcountedBrowserContextKeyedService {
|
||||
public:
|
||||
UserStyleSheetWatcher(Profile* profile, const base::FilePath& profile_path);
|
||||
|
||||
void Init();
|
||||
|
||||
GURL user_style_sheet() const;
|
||||
|
||||
// Register a callback to be called whenever the stylesheet gets updated.
|
||||
scoped_ptr<base::CallbackList<void(void)>::Subscription>
|
||||
RegisterOnStyleSheetUpdatedCallback(const base::Closure& callback);
|
||||
|
||||
// content::NotificationObserver interface
|
||||
virtual void Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) OVERRIDE;
|
||||
|
||||
// RefCountedProfileKeyedBase method override.
|
||||
virtual void ShutdownOnUIThread() OVERRIDE;
|
||||
|
||||
private:
|
||||
friend class base::DeleteHelper<UserStyleSheetWatcher>;
|
||||
|
||||
virtual ~UserStyleSheetWatcher();
|
||||
|
||||
// The profile owning us.
|
||||
Profile* profile_;
|
||||
|
||||
// The directory containing User StyleSheets/Custom.css.
|
||||
base::FilePath profile_path_;
|
||||
|
||||
// The loader object.
|
||||
scoped_refptr<UserStyleSheetLoader> loader_;
|
||||
|
||||
// Watches for changes to the css file so we can reload the style sheet.
|
||||
scoped_ptr<base::FilePathWatcher> file_watcher_;
|
||||
|
||||
content::NotificationRegistrar registrar_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_
|
@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2012 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/user_style_sheet_watcher_factory.h"
|
||||
|
||||
#include "chrome/browser/profiles/incognito_helpers.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/user_style_sheet_watcher.h"
|
||||
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
|
||||
|
||||
// static
|
||||
scoped_refptr<UserStyleSheetWatcher>
|
||||
UserStyleSheetWatcherFactory::GetForProfile(
|
||||
Profile* profile) {
|
||||
return static_cast<UserStyleSheetWatcher*>(
|
||||
GetInstance()->GetServiceForBrowserContext(profile, true).get());
|
||||
}
|
||||
|
||||
// static
|
||||
UserStyleSheetWatcherFactory* UserStyleSheetWatcherFactory::GetInstance() {
|
||||
return Singleton<UserStyleSheetWatcherFactory>::get();
|
||||
}
|
||||
|
||||
UserStyleSheetWatcherFactory::UserStyleSheetWatcherFactory()
|
||||
: RefcountedBrowserContextKeyedServiceFactory(
|
||||
"UserStyleSheetWatcher",
|
||||
BrowserContextDependencyManager::GetInstance()) {
|
||||
}
|
||||
|
||||
UserStyleSheetWatcherFactory::~UserStyleSheetWatcherFactory() {
|
||||
}
|
||||
|
||||
scoped_refptr<RefcountedBrowserContextKeyedService>
|
||||
UserStyleSheetWatcherFactory::BuildServiceInstanceFor(
|
||||
content::BrowserContext* context) const {
|
||||
Profile* profile = static_cast<Profile*>(context);
|
||||
scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher(
|
||||
new UserStyleSheetWatcher(profile, profile->GetPath()));
|
||||
user_style_sheet_watcher->Init();
|
||||
return user_style_sheet_watcher;
|
||||
}
|
||||
|
||||
content::BrowserContext* UserStyleSheetWatcherFactory::GetBrowserContextToUse(
|
||||
content::BrowserContext* context) const {
|
||||
return chrome::GetBrowserContextRedirectedInIncognito(context);
|
||||
}
|
||||
|
||||
bool UserStyleSheetWatcherFactory::ServiceIsNULLWhileTesting() const {
|
||||
return true;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
// Copyright (c) 2012 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_FACTORY_H_
|
||||
#define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_FACTORY_H_
|
||||
|
||||
#include "base/memory/singleton.h"
|
||||
#include "components/browser_context_keyed_service/refcounted_browser_context_keyed_service_factory.h"
|
||||
|
||||
class Profile;
|
||||
class UserStyleSheetWatcher;
|
||||
|
||||
// Singleton that owns all UserStyleSheetWatcher and associates them with
|
||||
// Profiles.
|
||||
class UserStyleSheetWatcherFactory
|
||||
: public RefcountedBrowserContextKeyedServiceFactory {
|
||||
public:
|
||||
static scoped_refptr<UserStyleSheetWatcher> GetForProfile(Profile* profile);
|
||||
|
||||
static UserStyleSheetWatcherFactory* GetInstance();
|
||||
|
||||
private:
|
||||
friend struct DefaultSingletonTraits<UserStyleSheetWatcherFactory>;
|
||||
|
||||
UserStyleSheetWatcherFactory();
|
||||
virtual ~UserStyleSheetWatcherFactory();
|
||||
|
||||
// BrowserContextKeyedServiceFactory:
|
||||
virtual scoped_refptr<RefcountedBrowserContextKeyedService>
|
||||
BuildServiceInstanceFor(content::BrowserContext* context) const OVERRIDE;
|
||||
virtual content::BrowserContext* GetBrowserContextToUse(
|
||||
content::BrowserContext* context) const OVERRIDE;
|
||||
virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcherFactory);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_FACTORY_H_
|
@ -1,57 +0,0 @@
|
||||
// Copyright (c) 2011 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/user_style_sheet_watcher.h"
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "base/file_util.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/test/base/testing_browser_process.h"
|
||||
#include "content/public/test/test_browser_thread.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
TEST(UserStyleSheetWatcherTest, StyleLoad) {
|
||||
base::ScopedTempDir dir;
|
||||
ASSERT_TRUE(dir.CreateUniqueTempDir());
|
||||
|
||||
std::string css_file_contents = "a { color: green; }";
|
||||
base::FilePath style_sheet_file = dir.path().AppendASCII("User StyleSheets")
|
||||
.AppendASCII("Custom.css");
|
||||
file_util::CreateDirectory(style_sheet_file.DirName());
|
||||
ASSERT_TRUE(file_util::WriteFile(style_sheet_file,
|
||||
css_file_contents.data(), css_file_contents.length()));
|
||||
|
||||
base::MessageLoop loop(base::MessageLoop::TYPE_UI);
|
||||
base::Thread io_thread("UserStyleSheetWatcherTestIOThread");
|
||||
base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
|
||||
ASSERT_TRUE(io_thread.StartWithOptions(options));
|
||||
content::TestBrowserThread browser_ui_thread(BrowserThread::UI, &loop);
|
||||
content::TestBrowserThread browser_file_thread(BrowserThread::FILE,
|
||||
io_thread.message_loop());
|
||||
|
||||
// It is important that the creation of |style_sheet_watcher| occur after the
|
||||
// creation of |browser_ui_thread| because UserStyleSheetWatchers are
|
||||
// restricted to being deleted only on UI browser threads.
|
||||
scoped_refptr<UserStyleSheetWatcher> style_sheet_watcher(
|
||||
new UserStyleSheetWatcher(NULL, dir.path()));
|
||||
style_sheet_watcher->Init();
|
||||
|
||||
io_thread.Stop();
|
||||
loop.RunUntilIdle();
|
||||
|
||||
GURL result_url = style_sheet_watcher->user_style_sheet();
|
||||
std::string result = result_url.spec();
|
||||
std::string prefix = "data:text/css;charset=utf-8;base64,";
|
||||
ASSERT_TRUE(StartsWithASCII(result, prefix, true));
|
||||
result = result.substr(prefix.length());
|
||||
std::string decoded;
|
||||
ASSERT_TRUE(base::Base64Decode(result, &decoded));
|
||||
ASSERT_EQ(css_file_contents, decoded);
|
||||
}
|
@ -2595,10 +2595,6 @@
|
||||
'browser/user_data_dir_extractor.h',
|
||||
'browser/user_data_dir_extractor_win.cc',
|
||||
'browser/user_data_dir_extractor_win.h',
|
||||
'browser/user_style_sheet_watcher.cc',
|
||||
'browser/user_style_sheet_watcher.h',
|
||||
'browser/user_style_sheet_watcher_factory.cc',
|
||||
'browser/user_style_sheet_watcher_factory.h',
|
||||
'browser/validation_message_message_filter.cc',
|
||||
'browser/validation_message_message_filter.h',
|
||||
'browser/value_store/leveldb_value_store.cc',
|
||||
@ -3310,12 +3306,6 @@
|
||||
'browser/upgrade_detector_impl.cc',
|
||||
'browser/upgrade_detector_impl.h',
|
||||
|
||||
# User Stylesheet unsupported on Android (crbug.com/236696)
|
||||
'browser/user_style_sheet_watcher.cc',
|
||||
'browser/user_style_sheet_watcher.h',
|
||||
'browser/user_style_sheet_watcher_factory.cc',
|
||||
'browser/user_style_sheet_watcher_factory.h',
|
||||
|
||||
# Not used by Android
|
||||
'browser/accessibility/accessibility_events.cc',
|
||||
'browser/accessibility/accessibility_extension_api_constants.cc',
|
||||
|
@ -1755,7 +1755,6 @@
|
||||
'browser/undo/bookmark_undo_service_test.cc',
|
||||
'browser/undo/undo_manager_test.cc',
|
||||
'browser/usb/usb_context_unittest.cc',
|
||||
'browser/user_style_sheet_watcher_unittest.cc',
|
||||
'browser/value_store/leveldb_value_store_unittest.cc',
|
||||
'browser/value_store/testing_value_store_unittest.cc',
|
||||
'browser/value_store/value_store_change_unittest.cc',
|
||||
@ -2649,8 +2648,6 @@
|
||||
'browser/sync_file_system/drive_backend/api_util_unittest.cc',
|
||||
'browser/sync_file_system/drive_backend/drive_file_sync_service_sync_unittest.cc',
|
||||
|
||||
'browser/user_style_sheet_watcher_unittest.cc',
|
||||
|
||||
# The autofill popup is implemented in mostly native code on
|
||||
# Android.
|
||||
'browser/ui/autofill/autofill_popup_controller_unittest.cc',
|
||||
|
@ -1274,7 +1274,7 @@ void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
|
||||
ReplaceFirstSubstringAfterOffset(&stylesheet, 0,
|
||||
"$FONTSIZE", system_font_size_);
|
||||
frame->document().insertUserStyleSheet(
|
||||
WebString::fromUTF8(stylesheet), WebDocument::UserStyleUserLevel);
|
||||
WebString::fromUTF8(stylesheet), WebDocument::UserStyleAuthorLevel);
|
||||
}
|
||||
|
||||
content_watcher_->DidCreateDocumentElement(frame);
|
||||
|
@ -110,8 +110,6 @@ IPC_STRUCT_TRAITS_BEGIN(WebPreferences)
|
||||
IPC_STRUCT_TRAITS_MEMBER(tabs_to_links)
|
||||
IPC_STRUCT_TRAITS_MEMBER(hyperlink_auditing_enabled)
|
||||
IPC_STRUCT_TRAITS_MEMBER(is_online)
|
||||
IPC_STRUCT_TRAITS_MEMBER(user_style_sheet_enabled)
|
||||
IPC_STRUCT_TRAITS_MEMBER(user_style_sheet_location)
|
||||
IPC_STRUCT_TRAITS_MEMBER(allow_universal_access_from_file_urls)
|
||||
IPC_STRUCT_TRAITS_MEMBER(allow_file_access_from_file_urls)
|
||||
IPC_STRUCT_TRAITS_MEMBER(webaudio_enabled)
|
||||
|
@ -146,10 +146,6 @@ void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
|
||||
settings->setUsesEncodingDetector(prefs.uses_universal_detector);
|
||||
settings->setTextAreasAreResizable(prefs.text_areas_are_resizable);
|
||||
settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
|
||||
if (prefs.user_style_sheet_enabled)
|
||||
settings->setUserStyleSheetLocation(prefs.user_style_sheet_location);
|
||||
else
|
||||
settings->setUserStyleSheetLocation(WebURL());
|
||||
settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
|
||||
settings->setJavaScriptCanAccessClipboard(
|
||||
prefs.javascript_can_access_clipboard);
|
||||
|
@ -47,7 +47,6 @@ void ExportLayoutTestSpecificPreferences(
|
||||
to->allow_file_access_from_file_urls = from.allowFileAccessFromFileURLs;
|
||||
to->javascript_can_open_windows_automatically =
|
||||
from.javaScriptCanOpenWindowsAutomatically;
|
||||
to->user_style_sheet_location = from.userStyleSheetLocation;
|
||||
}
|
||||
|
||||
// Applies settings that differ between layout tests and regular mode. Some
|
||||
@ -96,7 +95,6 @@ void ApplyLayoutTestDefaultPreferences(WebPreferences* prefs) {
|
||||
webkit_glue::kCommonScript] = ASCIIToUTF16("Helvetica");
|
||||
prefs->minimum_logical_font_size = 9;
|
||||
prefs->asynchronous_spell_checking_enabled = false;
|
||||
prefs->user_style_sheet_enabled = true;
|
||||
prefs->threaded_html_parser = true;
|
||||
prefs->accelerated_2d_canvas_enabled =
|
||||
command_line.HasSwitch(switches::kEnableAccelerated2DCanvas);
|
||||
|
@ -43,7 +43,6 @@ WebPreferences::WebPreferences()
|
||||
caret_browsing_enabled(false),
|
||||
hyperlink_auditing_enabled(true),
|
||||
is_online(true),
|
||||
user_style_sheet_enabled(false),
|
||||
allow_universal_access_from_file_urls(false),
|
||||
allow_file_access_from_file_urls(false),
|
||||
webaudio_enabled(false),
|
||||
|
@ -91,8 +91,6 @@ struct WEBKIT_COMMON_EXPORT WebPreferences {
|
||||
bool caret_browsing_enabled;
|
||||
bool hyperlink_auditing_enabled;
|
||||
bool is_online;
|
||||
bool user_style_sheet_enabled;
|
||||
GURL user_style_sheet_location;
|
||||
bool allow_universal_access_from_file_urls;
|
||||
bool allow_file_access_from_file_urls;
|
||||
bool webaudio_enabled;
|
||||
|
Reference in New Issue
Block a user