summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 16:53:18 +0000
committermihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 16:53:18 +0000
commit4c14ce487f93032da0ccc0d93ef42dd31303e0e6 (patch)
tree5e1f35c0846ae5b417418f4d8e32b136978d9503 /chrome
parentafb77faa1a2d3c98176c90e5ca76061b23cf8c13 (diff)
downloadchromium_src-4c14ce487f93032da0ccc0d93ef42dd31303e0e6.zip
chromium_src-4c14ce487f93032da0ccc0d93ef42dd31303e0e6.tar.gz
chromium_src-4c14ce487f93032da0ccc0d93ef42dd31303e0e6.tar.bz2
Remove obsolete code from UserScriptMaster.
Remove user script directory support from UserScriptMaster and other classes since it has been disabled since r32987. Remove support for the EXTENSION_USER_SCRIPTS_UPDATED notification, since it's no longer being sent (as of r80213). BUG=none TEST=no R=mpcomplete@chromium.org Review URL: http://codereview.chromium.org/7027019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/content_settings/host_content_settings_map.cc3
-rw-r--r--chrome/browser/extensions/extension_protocols.cc37
-rw-r--r--chrome/browser/extensions/extension_protocols.h5
-rw-r--r--chrome/browser/extensions/user_script_master.cc142
-rw-r--r--chrome/browser/extensions/user_script_master.h62
-rw-r--r--chrome/browser/extensions/user_script_master_unittest.cc69
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc1
-rw-r--r--chrome/browser/net/chrome_url_request_context.h12
-rw-r--r--chrome/browser/profiles/profile_impl.cc5
-rw-r--r--chrome/browser/profiles/profile_io_data.cc13
-rw-r--r--chrome/browser/profiles/profile_io_data.h1
-rw-r--r--chrome/common/extensions/user_script_unittest.cc6
12 files changed, 91 insertions, 265 deletions
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index f253ae7..5722d64 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -37,8 +37,7 @@ static bool ShouldAllowAllContent(const GURL& url) {
return url.SchemeIs(chrome::kChromeDevToolsScheme) ||
url.SchemeIs(chrome::kChromeInternalScheme) ||
url.SchemeIs(chrome::kChromeUIScheme) ||
- url.SchemeIs(chrome::kExtensionScheme) ||
- url.SchemeIs(chrome::kUserScriptScheme);
+ url.SchemeIs(chrome::kExtensionScheme);
}
typedef linked_ptr<content_settings::DefaultProviderInterface>
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index d7eac2f8..5c7b47e 100644
--- a/chrome/browser/extensions/extension_protocols.cc
+++ b/chrome/browser/extensions/extension_protocols.cc
@@ -233,36 +233,6 @@ ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const {
content_security_policy);
}
-class UserScriptProtocolHandler
- : public net::URLRequestJobFactory::ProtocolHandler {
- public:
- UserScriptProtocolHandler(const FilePath& user_script_dir_path,
- ExtensionInfoMap* extension_info_map)
- : user_script_dir_path_(user_script_dir_path),
- extension_info_map_(extension_info_map) {}
-
- virtual ~UserScriptProtocolHandler() {}
-
- virtual net::URLRequestJob* MaybeCreateJob(
- net::URLRequest* request) const OVERRIDE;
-
- private:
- const FilePath user_script_dir_path_;
- ExtensionInfoMap* const extension_info_map_;
-};
-
-// Factory registered with net::URLRequest to create URLRequestJobs for
-// chrome-user-script:/ URLs.
-net::URLRequestJob* UserScriptProtocolHandler::MaybeCreateJob(
- net::URLRequest* request) const {
- // chrome-user-script:/user-script-name.user.js
- ExtensionResource resource(
- request->url().host(), user_script_dir_path_,
- extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
-
- return new net::URLRequestFileJob(request, resource.GetFilePath());
-}
-
} // namespace
net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
@@ -270,10 +240,3 @@ net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
ExtensionInfoMap* extension_info_map) {
return new ExtensionProtocolHandler(is_incognito, extension_info_map);
}
-
-net::URLRequestJobFactory::ProtocolHandler* CreateUserScriptProtocolHandler(
- const FilePath& user_script_dir_path,
- ExtensionInfoMap* extension_info_map) {
- return new UserScriptProtocolHandler(
- user_script_dir_path, extension_info_map);
-}
diff --git a/chrome/browser/extensions/extension_protocols.h b/chrome/browser/extensions/extension_protocols.h
index 06ff2de..fb69492 100644
--- a/chrome/browser/extensions/extension_protocols.h
+++ b/chrome/browser/extensions/extension_protocols.h
@@ -16,9 +16,4 @@ net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
bool is_incognito,
ExtensionInfoMap* extension_info_map);
-// Creates the handlers for the chrome-user-script:// scheme.
-net::URLRequestJobFactory::ProtocolHandler* CreateUserScriptProtocolHandler(
- const FilePath& user_script_dir_path,
- ExtensionInfoMap* extension_info_map);
-
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROTOCOLS_H_
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index ba772b6..797fe59 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -9,7 +9,6 @@
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/path_service.h"
#include "base/pickle.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
@@ -20,11 +19,8 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_resource.h"
-#include "chrome/common/url_constants.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/common/notification_service.h"
-#include "net/base/net_util.h"
-
// Helper function to parse greasesmonkey headers
static bool GetDeclarationValue(const base::StringPiece& line,
@@ -139,16 +135,15 @@ bool UserScriptMaster::ScriptReloader::ParseMetadataHeader(
return true;
}
-void UserScriptMaster::ScriptReloader::StartScan(
- const FilePath& script_dir, const UserScriptList& lone_scripts) {
+void UserScriptMaster::ScriptReloader::StartLoad(
+ const UserScriptList& user_scripts) {
// Add a reference to ourselves to keep ourselves alive while we're running.
// Balanced by NotifyMaster().
AddRef();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
- this, &UserScriptMaster::ScriptReloader::RunScan, script_dir,
- lone_scripts));
+ this, &UserScriptMaster::ScriptReloader::RunLoad, user_scripts));
}
void UserScriptMaster::ScriptReloader::NotifyMaster(
@@ -160,7 +155,7 @@ void UserScriptMaster::ScriptReloader::NotifyMaster(
master_->NewScriptsAvailable(memory);
// Drop our self-reference.
- // Balances StartScan().
+ // Balances StartLoad().
Release();
}
@@ -185,46 +180,10 @@ static bool LoadScriptContent(UserScript::File* script_file) {
}
// static
-void UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
- const FilePath& script_dir, UserScriptList* result) {
- // Clear the list. We will populate it with the scripts found in script_dir.
- result->clear();
-
- // Find all the scripts in |script_dir|.
- if (!script_dir.value().empty()) {
- // Create the "<Profile>/User Scripts" directory if it doesn't exist
- if (!file_util::DirectoryExists(script_dir))
- file_util::CreateDirectory(script_dir);
-
- file_util::FileEnumerator enumerator(script_dir, false,
- file_util::FileEnumerator::FILES,
- FILE_PATH_LITERAL("*.user.js"));
- for (FilePath file = enumerator.Next(); !file.value().empty();
- file = enumerator.Next()) {
- result->push_back(UserScript());
- UserScript& user_script = result->back();
-
- // We default standalone user scripts to document-end for better
- // Greasemonkey compatibility.
- user_script.set_run_location(UserScript::DOCUMENT_END);
-
- // Push single js file in this UserScript.
- GURL url(std::string(chrome::kUserScriptScheme) + ":/" +
- net::FilePathToFileURL(file).ExtractFileName());
- user_script.js_scripts().push_back(UserScript::File(
- script_dir, file.BaseName(), url));
- UserScript::File& script_file = user_script.js_scripts().back();
- if (!LoadScriptContent(&script_file))
- result->pop_back();
- else
- ParseMetadataHeader(script_file.GetContent(), &user_script);
- }
- }
-}
-
-static void LoadLoneScripts(UserScriptList* lone_scripts) {
- for (size_t i = 0; i < lone_scripts->size(); ++i) {
- UserScript& script = lone_scripts->at(i);
+void UserScriptMaster::ScriptReloader::LoadUserScripts(
+ UserScriptList* user_scripts) {
+ for (size_t i = 0; i < user_scripts->size(); ++i) {
+ UserScript& script = user_scripts->at(i);
for (size_t k = 0; k < script.js_scripts().size(); ++k) {
UserScript::File& script_file = script.js_scripts()[k];
if (script_file.GetContent().empty())
@@ -273,19 +232,8 @@ static base::SharedMemory* Serialize(const UserScriptList& scripts) {
}
// This method will be called from the file thread
-void UserScriptMaster::ScriptReloader::RunScan(
- const FilePath script_dir, UserScriptList lone_script) {
- UserScriptList scripts;
- // Get list of user scripts.
- if (!script_dir.empty())
- LoadScriptsFromDirectory(script_dir, &scripts);
-
- LoadLoneScripts(&lone_script);
-
- // Merge with the explicit scripts
- scripts.reserve(scripts.size() + lone_script.size());
- scripts.insert(scripts.end(),
- lone_script.begin(), lone_script.end());
+void UserScriptMaster::ScriptReloader::RunLoad(UserScriptList user_scripts) {
+ LoadUserScripts(&user_scripts);
// Scripts now contains list of up-to-date scripts. Load the content in the
// shared memory and let the master know it's ready. We need to post the task
@@ -293,14 +241,13 @@ void UserScriptMaster::ScriptReloader::RunScan(
BrowserThread::PostTask(
master_thread_id_, FROM_HERE,
NewRunnableMethod(
- this, &ScriptReloader::NotifyMaster, Serialize(scripts)));
+ this, &ScriptReloader::NotifyMaster, Serialize(user_scripts)));
}
-UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile)
- : user_script_dir_(script_dir),
- extensions_service_ready_(false),
- pending_scan_(false),
+UserScriptMaster::UserScriptMaster(Profile* profile)
+ : extensions_service_ready_(false),
+ pending_load_(false),
profile_(profile) {
registrar_.Add(this, NotificationType::EXTENSIONS_READY,
Source<Profile>(profile_));
@@ -308,8 +255,6 @@ UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile)
Source<Profile>(profile_));
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
Source<Profile>(profile_));
- registrar_.Add(this, NotificationType::EXTENSION_USER_SCRIPTS_UPDATED,
- Source<Profile>(profile_));
registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
NotificationService::AllSources());
}
@@ -323,13 +268,13 @@ void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) {
// Ensure handle is deleted or released.
scoped_ptr<base::SharedMemory> handle_deleter(handle);
- if (pending_scan_) {
- // While we were scanning, there were further changes. Don't bother
- // notifying about these scripts and instead just immediately rescan.
- pending_scan_ = false;
- StartScan();
+ if (pending_load_) {
+ // While we were loading, there were further changes. Don't bother
+ // notifying about these scripts and instead just immediately reload.
+ pending_load_ = false;
+ StartLoad();
} else {
- // We're no longer scanning.
+ // We're no longer loading.
script_reloader_ = NULL;
// We've got scripts ready to go.
shared_memory_.swap(handle_deleter);
@@ -349,10 +294,11 @@ void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) {
void UserScriptMaster::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
+ bool should_start_load = false;
switch (type.value) {
case NotificationType::EXTENSIONS_READY:
extensions_service_ready_ = true;
- StartScan();
+ should_start_load = true;
break;
case NotificationType::EXTENSION_LOADED: {
// Add any content scripts inside the extension.
@@ -362,45 +308,31 @@ void UserScriptMaster::Observe(NotificationType type,
const UserScriptList& scripts = extension->content_scripts();
for (UserScriptList::const_iterator iter = scripts.begin();
iter != scripts.end(); ++iter) {
- lone_scripts_.push_back(*iter);
- lone_scripts_.back().set_incognito_enabled(incognito_enabled);
+ user_scripts_.push_back(*iter);
+ user_scripts_.back().set_incognito_enabled(incognito_enabled);
}
if (extensions_service_ready_)
- StartScan();
+ should_start_load = true;
break;
}
case NotificationType::EXTENSION_UNLOADED: {
// Remove any content scripts.
const Extension* extension =
Details<UnloadedExtensionInfo>(details)->extension;
- UserScriptList new_lone_scripts;
- for (UserScriptList::iterator iter = lone_scripts_.begin();
- iter != lone_scripts_.end(); ++iter) {
+ UserScriptList new_user_scripts;
+ for (UserScriptList::iterator iter = user_scripts_.begin();
+ iter != user_scripts_.end(); ++iter) {
if (iter->extension_id() != extension->id())
- new_lone_scripts.push_back(*iter);
+ new_user_scripts.push_back(*iter);
}
- lone_scripts_ = new_lone_scripts;
- StartScan();
+ user_scripts_ = new_user_scripts;
+ should_start_load = true;
// TODO(aa): Do we want to do something smarter for the scripts that have
// already been injected?
break;
}
- case NotificationType::EXTENSION_USER_SCRIPTS_UPDATED: {
- const Extension* extension = Details<const Extension>(details).ptr();
- UserScriptList new_lone_scripts;
- bool incognito_enabled = profile_->GetExtensionService()->
- IsIncognitoEnabled(extension->id());
- for (UserScriptList::iterator iter = lone_scripts_.begin();
- iter != lone_scripts_.end(); ++iter) {
- if (iter->extension_id() == extension->id()) {
- iter->set_incognito_enabled(incognito_enabled);
- }
- }
- StartScan();
- break;
- }
case NotificationType::RENDERER_PROCESS_CREATED: {
RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
if (ScriptsReady())
@@ -410,13 +342,21 @@ void UserScriptMaster::Observe(NotificationType type,
default:
DCHECK(false);
}
+
+ if (should_start_load) {
+ if (script_reloader_) {
+ pending_load_ = true;
+ } else {
+ StartLoad();
+ }
+ }
}
-void UserScriptMaster::StartScan() {
+void UserScriptMaster::StartLoad() {
if (!script_reloader_)
script_reloader_ = new ScriptReloader(this);
- script_reloader_->StartScan(user_script_dir_, lone_scripts_);
+ script_reloader_->StartLoad(user_scripts_);
}
void UserScriptMaster::SendUpdate(RenderProcessHost* process,
diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h
index 4a21eb0..fe9f39b 100644
--- a/chrome/browser/extensions/user_script_master.h
+++ b/chrome/browser/extensions/user_script_master.h
@@ -27,13 +27,11 @@ class RenderProcessHost;
class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
public NotificationObserver {
public:
- // For testability, the constructor takes the path the scripts live in.
- // This is normally a directory inside the profile.
- explicit UserScriptMaster(const FilePath& script_dir, Profile* profile);
+ explicit UserScriptMaster(Profile* profile);
// Kicks off a process on the file thread to reload scripts from disk
// into a new chunk of shared memory and notify renderers.
- virtual void StartScan();
+ virtual void StartLoad();
// Gets the segment of shared memory for the scripts.
base::SharedMemory* GetSharedMemory() const {
@@ -46,27 +44,16 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
// Return true if we have any scripts ready.
bool ScriptsReady() const { return shared_memory_.get() != NULL; }
- // Returns the path to the directory user scripts are stored in.
- FilePath user_script_dir() const { return user_script_dir_; }
-
protected:
friend class base::RefCountedThreadSafe<UserScriptMaster>;
virtual ~UserScriptMaster();
- private:
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse1);
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse2);
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse3);
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse4);
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse5);
- FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, Parse6);
-
public:
// We reload user scripts on the file thread to prevent blocking the UI.
// ScriptReloader lives on the file thread and does the reload
// work, and then sends a message back to its master with a new SharedMemory*.
- // ScriptReloader is the worker that manages running the script scan
+ // ScriptReloader is the worker that manages running the script load
// on the file thread. It must be created on, and its public API must only be
// called from, the master's thread.
class ScriptReloader
@@ -76,15 +63,11 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
static bool ParseMetadataHeader(const base::StringPiece& script_text,
UserScript* script);
- static void LoadScriptsFromDirectory(const FilePath& script_dir,
- UserScriptList* result);
-
explicit ScriptReloader(UserScriptMaster* master);
- // Start a scan for scripts.
+ // Start loading of scripts.
// Will always send a message to the master upon completion.
- void StartScan(const FilePath& script_dir,
- const UserScriptList& external_scripts);
+ void StartLoad(const UserScriptList& external_scripts);
// The master is going away; don't call it back.
void DisownMaster() {
@@ -92,26 +75,30 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
}
private:
+ private:
+ FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, SkipBOMAtTheBeginning);
+ FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, LeaveBOMNotAtTheBeginning);
friend class base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader>;
~ScriptReloader() {}
// Where functions are run:
// master file
- // StartScan -> RunScan
- // LoadScriptsFromDirectory()
- // LoadLoneScripts()
- // NotifyMaster <- RunScan
+ // StartLoad -> RunLoad
+ // LoadUserScripts()
+ // NotifyMaster <- RunLoad
// Runs on the master thread.
// Notify the master that new scripts are available.
void NotifyMaster(base::SharedMemory* memory);
// Runs on the File thread.
- // Scan the specified directory and lone scripts, calling NotifyMaster when
- // done. The parameters are intentionally passed by value so their lifetimes
- // aren't tied to the caller.
- void RunScan(const FilePath script_dir, UserScriptList lone_scripts);
+ // Load the specified user scripts, calling NotifyMaster when done.
+ // |user_scripts| is intentionally passed by value so its lifetime isn't
+ // tied to the caller.
+ void RunLoad(UserScriptList user_scripts);
+
+ static void LoadUserScripts(UserScriptList* user_scripts);
// A pointer back to our master.
// May be NULL if DisownMaster() is called.
@@ -137,26 +124,23 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
// Manages our notification registrations.
NotificationRegistrar registrar_;
- // The directories containing user scripts.
- FilePath user_script_dir_;
-
// We hang on to our pointer to know if we've already got one running.
scoped_refptr<ScriptReloader> script_reloader_;
// Contains the scripts that were found the last time scripts were updated.
scoped_ptr<base::SharedMemory> shared_memory_;
- // List of scripts outside of script directories we should also load.
- UserScriptList lone_scripts_;
+ // List of scripts from currently-installed extensions we should load.
+ UserScriptList user_scripts_;
// If the extensions service has finished loading its initial set of
// extensions.
bool extensions_service_ready_;
- // If the script directory is modified while we're rescanning it, we note
- // that we're currently mid-scan and then start over again once the scan
- // finishes. This boolean tracks whether another scan is pending.
- bool pending_scan_;
+ // If list of user scripts is modified while we're loading it, we note
+ // that we're currently mid-load and then start over again once the load
+ // finishes. This boolean tracks whether another load is pending.
+ bool pending_load_;
// The profile for which the scripts managed here are installed.
Profile* profile_;
diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc
index 84d6a64..c38f7f6 100644
--- a/chrome/browser/extensions/user_script_master_unittest.cc
+++ b/chrome/browser/extensions/user_script_master_unittest.cc
@@ -77,28 +77,8 @@ class UserScriptMasterTest : public testing::Test,
// Test that we get notified even when there are no scripts.
TEST_F(UserScriptMasterTest, NoScripts) {
TestingProfile profile;
- scoped_refptr<UserScriptMaster> master(new UserScriptMaster(temp_dir_.path(),
- &profile));
- master->StartScan();
- message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
- message_loop_.Run();
-
- ASSERT_TRUE(shared_memory_ != NULL);
-}
-
-// Test that we get notified about scripts if they're already in the test dir.
-TEST_F(UserScriptMasterTest, ExistingScripts) {
- TestingProfile profile;
- FilePath path = temp_dir_.path().AppendASCII("script.user.js");
-
- const char content[] = "some content";
- size_t written = file_util::WriteFile(path, content, sizeof(content));
- ASSERT_EQ(written, sizeof(content));
-
- scoped_refptr<UserScriptMaster> master(new UserScriptMaster(temp_dir_.path(),
- &profile));
- master->StartScan();
-
+ scoped_refptr<UserScriptMaster> master(new UserScriptMaster(&profile));
+ master->StartLoad();
message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
message_loop_.Run();
@@ -218,42 +198,37 @@ TEST_F(UserScriptMasterTest, Parse7) {
TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
FilePath path = temp_dir_.path().AppendASCII("script.user.js");
-
- const std::string content(
- "\xEF\xBB\xBF// ==UserScript==\n"
- "// @match http://*.mail.google.com/*\n"
- "// ==/UserScript==\n");
+ const std::string content("\xEF\xBB\xBF alert('hello');");
size_t written = file_util::WriteFile(path, content.c_str(), content.size());
ASSERT_EQ(written, content.size());
- UserScriptList script_list;
- UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
- temp_dir_.path(), &script_list);
- ASSERT_EQ(1U, script_list.size());
+ UserScript user_script;
+ user_script.js_scripts().push_back(UserScript::File(
+ temp_dir_.path(), path.BaseName(), GURL()));
+
+ UserScriptList user_scripts;
+ user_scripts.push_back(user_script);
+
+ UserScriptMaster::ScriptReloader::LoadUserScripts(&user_scripts);
EXPECT_EQ(content.substr(3),
- script_list[0].js_scripts()[0].GetContent().as_string());
- EXPECT_EQ("http://*.mail.google.com/*",
- script_list[0].url_patterns()[0].GetAsString());
+ user_scripts[0].js_scripts()[0].GetContent().as_string());
}
TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
FilePath path = temp_dir_.path().AppendASCII("script.user.js");
-
- const std::string content(
- "// ==UserScript==\n"
- "// @match http://*.mail.google.com/*\n"
- "// ==/UserScript==\n"
- "// @bom \xEF\xBB\xBF");
+ const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');");
size_t written = file_util::WriteFile(path, content.c_str(), content.size());
ASSERT_EQ(written, content.size());
- UserScriptList script_list;
- UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
- temp_dir_.path(), &script_list);
- ASSERT_EQ(1U, script_list.size());
+ UserScript user_script;
+ user_script.js_scripts().push_back(UserScript::File(
+ temp_dir_.path(), path.BaseName(), GURL()));
- EXPECT_EQ(content, script_list[0].js_scripts()[0].GetContent().as_string());
- EXPECT_EQ("http://*.mail.google.com/*",
- script_list[0].url_patterns()[0].GetAsString());
+ UserScriptList user_scripts;
+ user_scripts.push_back(user_script);
+
+ UserScriptMaster::ScriptReloader::LoadUserScripts(&user_scripts);
+
+ EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string());
}
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 1f8dc03..2bb2c76 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -360,7 +360,6 @@ void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) {
URLRequestContext::CopyFrom(other);
// Copy ChromeURLRequestContext parameters.
- set_user_script_dir_path(other->user_script_dir_path());
set_appcache_service(other->appcache_service());
set_blob_storage_context(other->blob_storage_context());
set_file_system_context(other->file_system_context());
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index b231c59..623ddca 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -49,11 +49,6 @@ class ChromeURLRequestContext : public net::URLRequestContext {
// Copies the state from |other| into this context.
void CopyFrom(ChromeURLRequestContext* other);
- // Gets the path to the directory user scripts are stored in.
- FilePath user_script_dir_path() const {
- return user_script_dir_path_;
- }
-
// Gets the appcache service to be used for requests in this context.
// May be NULL if requests for this context aren't subject to appcaching.
ChromeAppCacheService* appcache_service() const {
@@ -84,10 +79,6 @@ class ChromeURLRequestContext : public net::URLRequestContext {
// move completely to ProfileIOData.
ChromeURLDataManagerBackend* chrome_url_data_manager_backend() const;
- // Setters to simplify initializing from factory objects.
- void set_user_script_dir_path(const FilePath& path) {
- user_script_dir_path_ = path;
- }
void set_is_incognito(bool is_incognito) {
is_incognito_ = is_incognito;
}
@@ -121,9 +112,6 @@ class ChromeURLRequestContext : public net::URLRequestContext {
// be added to CopyFrom.
// ---------------------------------------------------------------------------
- // Path to the directory user scripts are stored in.
- FilePath user_script_dir_path_;
-
// TODO(willchan): Make these non-refcounted.
scoped_refptr<ChromeAppCacheService> appcache_service_;
scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 2e0396f..507996b 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -447,10 +447,7 @@ void ProfileImpl::InitExtensions(bool extensions_enabled) {
ExtensionErrorReporter::Init(true); // allow noisy errors.
- FilePath script_dir; // Don't look for user scripts in any directory.
- // TODO(aa): We should just remove this functionality,
- // since it isn't used anymore.
- user_script_master_ = new UserScriptMaster(script_dir, this);
+ user_script_master_ = new UserScriptMaster(this);
bool autoupdate_enabled = true;
#if defined(OS_CHROMEOS)
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index c49efc2..3b53944 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -241,12 +241,6 @@ void ProfileIOData::InitializeProfileParams(Profile* profile) {
params->host_content_settings_map = profile->GetHostContentSettingsMap();
params->host_zoom_map = profile->GetHostZoomMap();
params->transport_security_state = profile->GetTransportSecurityState();
-
- if (profile->GetUserScriptMaster()) {
- params->user_script_dir_path =
- profile->GetUserScriptMaster()->user_script_dir();
- }
-
params->ssl_config_service = profile->GetSSLConfigService();
params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile);
params->database_tracker = profile->GetDatabaseTracker();
@@ -299,7 +293,6 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
DCHECK_EQ(scheme, StringToLowerASCII(scheme));
static const char* const kProtocolList[] = {
chrome::kExtensionScheme,
- chrome::kUserScriptScheme,
chrome::kChromeUIScheme,
chrome::kChromeDevToolsScheme,
#if defined(OS_CHROMEOS)
@@ -430,11 +423,6 @@ void ProfileIOData::LazyInitialize() const {
profile_params_->extension_info_map));
DCHECK(set_protocol);
set_protocol = job_factory_->SetProtocolHandler(
- chrome::kUserScriptScheme,
- CreateUserScriptProtocolHandler(profile_params_->user_script_dir_path,
- profile_params_->extension_info_map));
- DCHECK(set_protocol);
- set_protocol = job_factory_->SetProtocolHandler(
chrome::kChromeUIScheme,
ChromeURLDataManagerBackend::CreateProtocolHandler(
chrome_url_data_manager_backend_.get(),
@@ -504,7 +492,6 @@ void ProfileIOData::ApplyProfileParamsToContext(
context->set_accept_language(profile_params_->accept_language);
context->set_accept_charset(profile_params_->accept_charset);
context->set_referrer_charset(profile_params_->referrer_charset);
- context->set_user_script_dir_path(profile_params_->user_script_dir_path);
context->set_transport_security_state(
profile_params_->transport_security_state);
context->set_ssl_config_service(profile_params_->ssl_config_service);
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index b8ea39b..08b8aba 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -116,7 +116,6 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
std::string accept_language;
std::string accept_charset;
std::string referrer_charset;
- FilePath user_script_dir_path;
IOThread* io_thread;
scoped_refptr<HostContentSettingsMap> host_content_settings_map;
scoped_refptr<HostZoomMap> host_zoom_map;
diff --git a/chrome/common/extensions/user_script_unittest.cc b/chrome/common/extensions/user_script_unittest.cc
index d947e37..47cec8f 100644
--- a/chrome/common/extensions/user_script_unittest.cc
+++ b/chrome/common/extensions/user_script_unittest.cc
@@ -175,15 +175,15 @@ TEST(ExtensionUserScriptTest, Pickle) {
script1.js_scripts().push_back(UserScript::File(
FilePath(FILE_PATH_LITERAL("c:\\foo\\")),
FilePath(FILE_PATH_LITERAL("foo.user.js")),
- GURL("chrome-user-script:/foo.user.js")));
+ GURL("chrome-extension://abc/foo.user.js")));
script1.css_scripts().push_back(UserScript::File(
FilePath(FILE_PATH_LITERAL("c:\\foo\\")),
FilePath(FILE_PATH_LITERAL("foo.user.css")),
- GURL("chrome-user-script:/foo.user.css")));
+ GURL("chrome-extension://abc/foo.user.css")));
script1.css_scripts().push_back(UserScript::File(
FilePath(FILE_PATH_LITERAL("c:\\foo\\")),
FilePath(FILE_PATH_LITERAL("foo2.user.css")),
- GURL("chrome-user-script:/foo2.user.css")));
+ GURL("chrome-extension://abc/foo2.user.css")));
script1.set_run_location(UserScript::DOCUMENT_START);
script1.add_url_pattern(pattern1);