diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-05 22:51:54 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-05 22:51:54 +0000 |
commit | d2a69e2fccc65e8c74b770343cecad7a1136f9fd (patch) | |
tree | efc684e21d7ef65d72dcb31fba6a01184df8407b /chrome | |
parent | a60551c712b36d6241c234cd81ae2a847f323ec5 (diff) | |
download | chromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.zip chromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.tar.gz chromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.tar.bz2 |
Integrate URLPattern with Extension user scripts.
Also refactored the UserScript class in
UserScriptSlave and the UserScriptInfo structure
in UserScriptMaster into a common location.
Review URL: http://codereview.chromium.org/21070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension.cc | 22 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master.cc | 50 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master.h | 20 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master_unittest.cc | 28 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 12 | ||||
-rw-r--r-- | chrome/common/common.scons | 2 | ||||
-rw-r--r-- | chrome/common/common.vcproj | 8 | ||||
-rw-r--r-- | chrome/common/extensions/url_pattern.cc | 18 | ||||
-rw-r--r-- | chrome/common/extensions/url_pattern.h | 4 | ||||
-rw-r--r-- | chrome/common/extensions/user_script.cc | 69 | ||||
-rw-r--r-- | chrome/common/extensions/user_script.h | 74 | ||||
-rw-r--r-- | chrome/common/extensions/user_script_unittest.cc | 101 | ||||
-rw-r--r-- | chrome/renderer/user_script_slave.cc | 76 | ||||
-rw-r--r-- | chrome/renderer/user_script_slave.h | 61 | ||||
-rw-r--r-- | chrome/renderer/user_script_slave_unittest.cc | 43 | ||||
-rw-r--r-- | chrome/test/unit/unit_tests.scons | 2 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 24 |
18 files changed, 388 insertions, 242 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index f932eff..11cab38 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "net/base/net_util.h" +#include "chrome/common/extensions/user_script.h" const char kExtensionURLScheme[] = "chrome-extension"; const char kUserScriptURLScheme[] = "chrome-user-script"; @@ -262,16 +263,23 @@ bool Extension::InitFromValue(const DictionaryValue& source, return false; } - UserScriptInfo script_info; + UserScript script; for (size_t j = 0; j < matches->GetSize(); ++j) { - std::string match; - if (!matches->GetString(j, &match)) { + std::string match_str; + if (!matches->GetString(j, &match_str)) { *error = FormatErrorMessage(kInvalidMatchError, IntToString(i), IntToString(j)); return false; } - script_info.matches.push_back(match); + URLPattern pattern; + if (!pattern.Parse(match_str)) { + *error = FormatErrorMessage(kInvalidMatchError, IntToString(i), + IntToString(j)); + return false; + } + + script.add_url_pattern(pattern); } // TODO(aa): Support multiple files. @@ -281,10 +289,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, IntToString(0)); return false; } - script_info.path = Extension::GetResourcePath(path(), file); - script_info.url = Extension::GetResourceURL(url(), file); + script.set_path(Extension::GetResourcePath(path(), file)); + script.set_url(Extension::GetResourceURL(url(), file)); - user_scripts_.push_back(script_info); + user_scripts_.push_back(script); } } diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index ed86b6b..49e37a3 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -154,15 +154,17 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { Extension* extension = frontend->extensions()->at(0); const UserScriptList& scripts = extension->user_scripts(); ASSERT_EQ(2u, scripts.size()); - EXPECT_EQ(2u, scripts[0].matches.size()); - EXPECT_EQ("http://*.google.com/*", scripts[0].matches[0]); - EXPECT_EQ("https://*.google.com/*", scripts[0].matches[1]); + EXPECT_EQ(2u, scripts[0].url_patterns().size()); + EXPECT_EQ("http://*.google.com/*", + scripts[0].url_patterns()[0].GetAsString()); + EXPECT_EQ("https://*.google.com/*", + scripts[0].url_patterns()[1].GetAsString()); EXPECT_EQ(extension->path().AppendASCII("script1.js").value(), - scripts[0].path.value()); - EXPECT_EQ(1u, scripts[1].matches.size()); - EXPECT_EQ("http://*.yahoo.com/*", scripts[1].matches[0]); + scripts[0].path().value()); + EXPECT_EQ(1u, scripts[1].url_patterns().size()); + EXPECT_EQ("http://*.yahoo.com/*", scripts[1].url_patterns()[0].GetAsString()); EXPECT_EQ(extension->path().AppendASCII("script2.js").value(), - scripts[1].path.value()); + scripts[1].path().value()); EXPECT_EQ(std::string("com.google.myextension2"), frontend->extensions()->at(1)->id()); diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 3dafcbc..4ca10fb 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -22,7 +22,7 @@ extern const char kUserScriptURLScheme[]; // static void UserScriptMaster::ScriptReloader::ParseMetadataHeader( - const StringPiece& script_text, std::vector<std::string> *includes) { + const StringPiece& script_text, UserScript* script) { // http://wiki.greasespot.net/Metadata_block StringPiece line; size_t line_start = 0; @@ -57,7 +57,12 @@ void UserScriptMaster::ScriptReloader::ParseMetadataHeader( line.length() - kIncludeDeclaration.length()); std::string pattern_trimmed; TrimWhitespace(pattern, TRIM_ALL, &pattern_trimmed); - includes->push_back(pattern_trimmed); + + // We escape some characters that MatchPattern() considers special. + ReplaceSubstringsAfterOffset(&pattern_trimmed, 0, "\\", "\\\\"); + ReplaceSubstringsAfterOffset(&pattern_trimmed, 0, "?", "\\?"); + + script->add_glob(pattern_trimmed); } // TODO(aa): Handle more types of metadata. @@ -68,8 +73,8 @@ void UserScriptMaster::ScriptReloader::ParseMetadataHeader( // If no @include patterns were specified, default to @include *. // This is what Greasemonkey does. - if (includes->size() == 0) { - includes->push_back("*"); + if (script->globs().size() == 0) { + script->add_glob("*"); } } @@ -121,11 +126,11 @@ base::SharedMemory* UserScriptMaster::ScriptReloader::GetNewScripts( FILE_PATH_LITERAL("*.user.js")); for (FilePath file = enumerator.Next(); !file.value().empty(); file = enumerator.Next()) { - all_scripts.push_back(UserScriptInfo()); - UserScriptInfo& info = all_scripts.back(); - info.url = GURL(std::string(kUserScriptURLScheme) + ":/" + - net::FilePathToFileURL(file.ToWStringHack()).ExtractFileName()); - info.path = file; + all_scripts.push_back(UserScript()); + UserScript& info = all_scripts.back(); + info.set_url(GURL(std::string(kUserScriptURLScheme) + ":/" + + net::FilePathToFileURL(file.ToWStringHack()).ExtractFileName())); + info.set_path(file); } } @@ -137,21 +142,25 @@ base::SharedMemory* UserScriptMaster::ScriptReloader::GetNewScripts( lone_scripts.end()); // Load and pickle each script. Look for a metadata header if there are no - // matches specified already. + // url_patterns specified already. Pickle pickle; pickle.WriteSize(all_scripts.size()); for (UserScriptList::iterator iter = all_scripts.begin(); iter != all_scripts.end(); ++iter) { // TODO(aa): Support unicode script files. std::string contents; - file_util::ReadFileToString(iter->path.ToWStringHack(), &contents); + file_util::ReadFileToString(iter->path().ToWStringHack(), &contents); - if (iter->matches.empty()) { + if (iter->url_patterns().empty()) { // TODO(aa): Handle errors parsing header. - ParseMetadataHeader(contents, &iter->matches); + ParseMetadataHeader(contents, &(*iter)); } - PickleScriptData(*iter, contents, &pickle); + iter->Pickle(&pickle); + + // Write scripts as 'data' so that we can read it out in the slave without + // allocating a new string. + pickle.WriteData(contents.c_str(), contents.length()); } // Create the shared memory object. @@ -174,19 +183,6 @@ base::SharedMemory* UserScriptMaster::ScriptReloader::GetNewScripts( return shared_memory.release(); } -void UserScriptMaster::ScriptReloader::PickleScriptData( - const UserScriptInfo& script, const std::string& contents, Pickle* pickle) { - // Write scripts as 'data' so that we can read it out in the slave without - // allocating a new string. - pickle->WriteData(script.url.spec().c_str(), script.url.spec().length()); - pickle->WriteData(contents.c_str(), contents.length()); - pickle->WriteSize(script.matches.size()); - for (std::vector<std::string>::const_iterator iter = script.matches.begin(); - iter != script.matches.end(); ++iter) { - pickle->WriteString(*iter); - } -} - UserScriptMaster::UserScriptMaster(MessageLoop* worker_loop, const FilePath& script_dir) : user_script_dir_(script_dir), diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h index 1c1b095..8969281 100644 --- a/chrome/browser/extensions/user_script_master.h +++ b/chrome/browser/extensions/user_script_master.h @@ -12,17 +12,9 @@ #include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/string_piece.h" +#include "chrome/common/extensions/user_script.h" #include "googleurl/src/gurl.h" -class Pickle; - -struct UserScriptInfo { - GURL url; - FilePath path; - std::vector<std::string> matches; -}; -typedef std::vector<UserScriptInfo> UserScriptList; - // Manages a segment of shared memory that contains the user scripts the user // has installed. Lives on the UI thread. class UserScriptMaster : public base::RefCounted<UserScriptMaster>, @@ -35,7 +27,7 @@ class UserScriptMaster : public base::RefCounted<UserScriptMaster>, ~UserScriptMaster(); // Add a single user script that exists outside the script directory. - void AddLoneScript(const UserScriptInfo& script) { + void AddLoneScript(const UserScript& script) { lone_scripts_.push_back(script); } @@ -76,8 +68,8 @@ class UserScriptMaster : public base::RefCounted<UserScriptMaster>, : public base::RefCounted<UserScriptMaster::ScriptReloader> { public: // Parses the includes out of |script| and returns them in |includes|. - static void ParseMetadataHeader(const StringPiece& script, - std::vector<std::string>* includes); + static void ParseMetadataHeader(const StringPiece& script_text, + UserScript* script); ScriptReloader(UserScriptMaster* master) : master_(master), master_message_loop_(MessageLoop::current()) {} @@ -116,10 +108,6 @@ class UserScriptMaster : public base::RefCounted<UserScriptMaster>, base::SharedMemory* GetNewScripts(const FilePath& script_dir, const UserScriptList& lone_scripts); - // Serialize script metadata and contents into the specified pickle. - void PickleScriptData(const UserScriptInfo& script, - const std::string& contents, Pickle* pickle); - // A pointer back to our master. // May be NULL if DisownMaster() is called. UserScriptMaster* master_; diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc index af60cb8..8ce2391 100644 --- a/chrome/browser/extensions/user_script_master_unittest.cc +++ b/chrome/browser/extensions/user_script_master_unittest.cc @@ -139,21 +139,21 @@ TEST_F(UserScriptMasterTest, Parse1) { "\n" "alert('hoo!');\n"); - std::vector<std::string> includes; - UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &includes); - EXPECT_EQ(3U, includes.size()); - EXPECT_EQ("*mail.google.com*", includes[0]); - EXPECT_EQ("*mail.yahoo.com*", includes[1]); - EXPECT_EQ("*mail.msn.com*", includes[2]); + UserScript script; + UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script); + EXPECT_EQ(3U, script.globs().size()); + EXPECT_EQ("*mail.google.com*", script.globs()[0]); + EXPECT_EQ("*mail.yahoo.com*", script.globs()[1]); + EXPECT_EQ("*mail.msn.com*", script.globs()[2]); } TEST_F(UserScriptMasterTest, Parse2) { const std::string text("default to @include *"); - std::vector<std::string> includes; - UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &includes); - EXPECT_EQ(1U, includes.size()); - EXPECT_EQ("*", includes[0]); + UserScript script; + UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script); + EXPECT_EQ(1U, script.globs().size()); + EXPECT_EQ("*", script.globs()[0]); } TEST_F(UserScriptMasterTest, Parse3) { @@ -162,8 +162,8 @@ TEST_F(UserScriptMasterTest, Parse3) { "// @include *foo*\n" "// ==/UserScript=="); // no trailing newline - std::vector<std::string> includes; - UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &includes); - EXPECT_EQ(1U, includes.size()); - EXPECT_EQ("*foo*", includes[0]); + UserScript script; + UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script); + EXPECT_EQ(1U, script.globs().size()); + EXPECT_EQ("*foo*", script.globs()[0]); } diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index d98f232..2abc67f 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 3AEA44DB19C9D93B63D7A2E4 /* url_fetcher_protect.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0B7CC9C105E90E0665852528 /* url_fetcher_protect.cc */; }; 406DFE278638D6132B21B2C9 /* url_pattern.cc in Sources */ = {isa = PBXBuildFile; fileRef = 6447F24FADC63E58A44DB762 /* url_pattern.cc */; }; 475CAF858604B413561740C1 /* cache_manager_host.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF8520E9D4839009A6919 /* cache_manager_host.cc */; }; + 49C8AD19AA0094034F59B6F0 /* user_script.cc in Sources */ = {isa = PBXBuildFile; fileRef = 699499C4FBA07FB2D7B298A2 /* user_script.cc */; }; 4D175916B2FC058793051209 /* chrome_paths_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = C18F2A0A6FB6BEF75406511D /* chrome_paths_mac.cc */; }; 4D1F59FE0F2A6BBB0040C1E3 /* image_diff.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D1F59FD0F2A6BBB0040C1E3 /* image_diff.cc */; }; 4D1F5A060F2A6D170040C1E3 /* libbase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7BFDC70E9D525B009A6919 /* libbase.a */; }; @@ -236,6 +237,7 @@ 8570EB3F140C07ABF1957F12 /* url_pattern_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A9C335E39D39A7DE087850FC /* url_pattern_unittest.cc */; }; 8F51B73AAAF1772ECF9BD180 /* url_fetcher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 778D7927798B7E3FAA498D3D /* url_fetcher.cc */; }; 94542322A5E5A8F4FDDAB7F0 /* render_view_host_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = A76E42AD0F28EDB5009A7E88 /* render_view_host_manager.cc */; }; + A0EB956531B9DB1E40DAE980 /* user_script_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 37521A11B07C479E93A39D52 /* user_script_unittest.cc */; }; A54612DC0EE9958600A8EE5D /* extensions_service_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A54612DB0EE9958600A8EE5D /* extensions_service_unittest.cc */; }; A54612E20EE995F600A8EE5D /* extensions_service.cc in Sources */ = {isa = PBXBuildFile; fileRef = A54612D90EE9957000A8EE5D /* extensions_service.cc */; }; A572828F0F31156100384E1B /* unzip_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = E45076E80F153B06003BE099 /* unzip_unittest.cc */; }; @@ -250,7 +252,6 @@ B502DA280F098056005BE90C /* visit_database_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFA180E9D48F7009A6919 /* visit_database_unittest.cc */; }; B502DA520F098888005BE90C /* l10n_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBC90E9D4C9F009A6919 /* l10n_util.cc */; }; B503E0F00F0175FD00547DC6 /* user_script_slave.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D640CC90EAE868600EBCFC0 /* user_script_slave.cc */; }; - B503E0FC0F01764800547DC6 /* user_script_slave_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B503E0FB0F01764800547DC6 /* user_script_slave_unittest.cc */; }; B503E1030F017C1000547DC6 /* librenderer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D640CEB0EAE86BD00EBCFC0 /* librenderer.a */; }; B507AC1F0F0048E10060FEE8 /* ipc_sync_message.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBBA0E9D4C9F009A6919 /* ipc_sync_message.cc */; }; B507AC440F004B610060FEE8 /* ipc_sync_message_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBBC0E9D4C9F009A6919 /* ipc_sync_message_unittest.cc */; }; @@ -1314,6 +1315,7 @@ 3380A6B50F2E9252004EF74F /* render_thread_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = render_thread_unittest.cc; sourceTree = "<group>"; }; 3380A6B90F2E9275004EF74F /* render_view_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = render_view_unittest.cc; sourceTree = "<group>"; }; 3380A9BF0F2FC61E004EF74F /* render_process_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = render_process_unittest.cc; sourceTree = "<group>"; }; + 37521A11B07C479E93A39D52 /* user_script_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = user_script_unittest.cc; path = common/extensions/user_script_unittest.cc; sourceTree = SOURCE_ROOT; }; 3CCF8AA8A56FF8FE59F0C299 /* template_url.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = template_url.cc; sourceTree = "<group>"; }; 433B6EFB7A1D931A13C9556F /* url_fetcher_protect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = url_fetcher_protect.h; sourceTree = "<group>"; }; 4D1F59EA0F2A6B590040C1E3 /* image_diff */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = image_diff; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1877,6 +1879,7 @@ 56E1D7DF17D327BFCB0B895D /* test_web_contents.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = test_web_contents.cc; path = browser/tab_contents/test_web_contents.cc; sourceTree = SOURCE_ROOT; }; 629BF493DEA096E2DD844F2B /* autofill_manager.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = autofill_manager.cc; sourceTree = "<group>"; }; 6447F24FADC63E58A44DB762 /* url_pattern.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = url_pattern.cc; path = common/extensions/url_pattern.cc; sourceTree = SOURCE_ROOT; }; + 699499C4FBA07FB2D7B298A2 /* user_script.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = user_script.cc; path = common/extensions/user_script.cc; sourceTree = SOURCE_ROOT; }; 778D7927798B7E3FAA498D3D /* url_fetcher.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = url_fetcher.cc; sourceTree = "<group>"; }; 8104B4AFD95DCA06B2F37551 /* chrome_paths_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chrome_paths_internal.h; sourceTree = "<group>"; }; 82684C5F0F2FAE68009F6555 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; @@ -1928,7 +1931,6 @@ A7C6146E0F30DA1D008CEE5D /* ipc_test_sink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ipc_test_sink.h; sourceTree = "<group>"; }; A7CBAD370F322A7E00360BF5 /* shell_dialogs_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = shell_dialogs_mac.mm; path = cocoa/shell_dialogs_mac.mm; sourceTree = "<group>"; }; A9C335E39D39A7DE087850FC /* url_pattern_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = url_pattern_unittest.cc; path = common/extensions/url_pattern_unittest.cc; sourceTree = SOURCE_ROOT; }; - B503E0FB0F01764800547DC6 /* user_script_slave_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = user_script_slave_unittest.cc; sourceTree = "<group>"; }; B51F6D110F37C4DC00152D66 /* renderer_main_platform_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = renderer_main_platform_delegate.h; sourceTree = "<group>"; }; B51F6D120F37C4DC00152D66 /* renderer_main_platform_delegate_win.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_main_platform_delegate_win.cc; sourceTree = "<group>"; }; B51F6D130F37C4DC00152D66 /* renderer_main_platform_delegate_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_main_platform_delegate_mac.cc; sourceTree = "<group>"; }; @@ -2419,7 +2421,6 @@ 4D640CDA0EAE868600EBCFC0 /* renderer_resources.h */, 4D640CC90EAE868600EBCFC0 /* user_script_slave.cc */, 4D640CCA0EAE868600EBCFC0 /* user_script_slave.h */, - B503E0FB0F01764800547DC6 /* user_script_slave_unittest.cc */, 4D640CDC0EAE868600EBCFC0 /* visitedlink_slave.cc */, 4D640CDD0EAE868600EBCFC0 /* visitedlink_slave.h */, 4D640CDE0EAE868600EBCFC0 /* webplugin_delegate_proxy.cc */, @@ -2486,6 +2487,8 @@ B94B5B0CBF4D7FAC48BB1AE2 /* backing_store_posix.cc */, 6447F24FADC63E58A44DB762 /* url_pattern.cc */, 56E1D7DF17D327BFCB0B895D /* test_web_contents.cc */, + 699499C4FBA07FB2D7B298A2 /* user_script.cc */, + 37521A11B07C479E93A39D52 /* user_script_unittest.cc */, ); sourceTree = "<group>"; }; @@ -4744,7 +4747,7 @@ 4D7BFB610E9D4C4B009A6919 /* units_unittest.cc in Sources */, A572828F0F31156100384E1B /* unzip_unittest.cc in Sources */, 8570EB3F140C07ABF1957F12 /* url_pattern_unittest.cc in Sources */, - B503E0FC0F01764800547DC6 /* user_script_slave_unittest.cc in Sources */, + A0EB956531B9DB1E40DAE980 /* user_script_unittest.cc in Sources */, B502DA280F098056005BE90C /* visit_database_unittest.cc in Sources */, 4D7BFB420E9D4C35009A6919 /* visit_tracker_unittest.cc in Sources */, E46C4B4C0F21098F00B393B8 /* worker_thread_ticker_unittest.cc in Sources */, @@ -4799,6 +4802,7 @@ E45076E50F153AB6003BE099 /* unzip.cc in Sources */, 406DFE278638D6132B21B2C9 /* url_pattern.cc in Sources */, E46C4B3F0F21095400B393B8 /* url_request_intercept_job.cc in Sources */, + 49C8AD19AA0094034F59B6F0 /* user_script.cc in Sources */, 4D7BFCA30E9D4D48009A6919 /* visitedlink_common.cc in Sources */, E46C4B490F21096300B393B8 /* worker_thread_ticker.cc in Sources */, ); diff --git a/chrome/common/common.scons b/chrome/common/common.scons index 23fa414..71f1761 100644 --- a/chrome/common/common.scons +++ b/chrome/common/common.scons @@ -46,6 +46,8 @@ input_files = ChromeFileList([ MSVSFilter('extensions', [ 'extensions/url_pattern.cc', 'extensions/url_pattern.h', + 'extensions/user_script.cc', + 'extensions/user_script.h', ]), MSVSFilter('net', [ 'net/cookie_monster_sqlite.cc', diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index 9557647..8e88bb7 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -312,6 +312,14 @@ RelativePath=".\extensions\url_pattern.h" > </File> + <File + RelativePath=".\extensions\user_script.cc" + > + </File> + <File + RelativePath=".\extensions\user_script.h" + > + </File> </Filter> <File RelativePath=".\accessibility.h" diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc index bb32cb5..ce345ca 100644 --- a/chrome/common/extensions/url_pattern.cc +++ b/chrome/common/extensions/url_pattern.cc @@ -126,3 +126,21 @@ bool URLPattern::MatchesPath(const GURL& test) { return true; } + +std::string URLPattern::GetAsString() const { + std::string spec = scheme_ + kSchemeSeparator; + + if (match_subdomains_) { + spec += "*"; + if (!host_.empty()) + spec += "."; + } + + if (!host_.empty()) + spec += host_; + + if (!path_.empty()) + spec += path_; + + return spec; +} diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h index 0be9660..4778016 100644 --- a/chrome/common/extensions/url_pattern.h +++ b/chrome/common/extensions/url_pattern.h @@ -46,7 +46,7 @@ // // From a 2008-ish crawl of userscripts.org, the following patterns were found // in @include lines: -// - total lines : 24271 +// - total lines : 24471 // - @include * : 919 // - @include http://[^\*]+?/ : 11128 (no star in host) // - @include http://\*\.[^\*]+?/ : 2325 (host prefixed by *.) @@ -77,6 +77,8 @@ class URLPattern { // Returns true if this instance matches the specified URL. bool MatchesUrl(const GURL& url); + std::string GetAsString() const; + // Get the scheme the pattern matches. This will always return a valid scheme // if is_valid() returns true. std::string scheme() const { return scheme_; } diff --git a/chrome/common/extensions/user_script.cc b/chrome/common/extensions/user_script.cc new file mode 100644 index 0000000..c726ad3 --- /dev/null +++ b/chrome/common/extensions/user_script.cc @@ -0,0 +1,69 @@ +// Copyright 2009 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/common/extensions/user_script.h" + +#include "base/string_util.h" + +bool UserScript::MatchesUrl(const GURL& url) { + for (std::vector<std::string>::iterator glob = globs_.begin(); + glob != globs_.end(); ++glob) { + if (MatchPattern(url.spec(), *glob)) + return true; + } + + for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin(); + pattern != url_patterns_.end(); ++pattern) { + if (pattern->MatchesUrl(url)) + return true; + } + + return false; +} + +void UserScript::Pickle(::Pickle* pickle) { + pickle->WriteString(url_.spec()); + + // Don't write path as we don't need that in the renderer. + + pickle->WriteSize(globs_.size()); + for (std::vector<std::string>::iterator glob = globs_.begin(); + glob != globs_.end(); ++glob) { + pickle->WriteString(*glob); + } + + pickle->WriteSize(url_patterns_.size()); + for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin(); + pattern != url_patterns_.end(); ++pattern) { + pickle->WriteString(pattern->GetAsString()); + } +} + +void UserScript::Unpickle(const ::Pickle& pickle, void** iter) { + std::string url_spec; + CHECK(pickle.ReadString(iter, &url_spec)); + url_ = GURL(url_spec); + + size_t num_globs = 0; + CHECK(pickle.ReadSize(iter, &num_globs)); + + globs_.clear(); + for (size_t i = 0; i < num_globs; ++i) { + std::string glob; + CHECK(pickle.ReadString(iter, &glob)); + globs_.push_back(glob); + } + + size_t num_patterns = 0; + CHECK(pickle.ReadSize(iter, &num_patterns)); + + url_patterns_.clear(); + for (size_t i = 0; i < num_patterns; ++i) { + std::string pattern_str; + URLPattern pattern; + CHECK(pickle.ReadString(iter, &pattern_str)); + CHECK(pattern.Parse(pattern_str)); + url_patterns_.push_back(pattern); + } +} diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h new file mode 100644 index 0000000..6453c8e --- /dev/null +++ b/chrome/common/extensions/user_script.h @@ -0,0 +1,74 @@ +// Copyright 2009 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_COMMON_EXTENSIONS_USER_SCRIPT_H_ +#define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ + +#include <vector> +#include <string> + +#include "base/file_path.h" +#include "base/pickle.h" +#include "chrome/common/extensions/url_pattern.h" +#include "googleurl/src/gurl.h" + +// Represents a user script, either a standalone one, or one that is part of an +// extension. +class UserScript { + public: + UserScript(){} + + // The URL to retrieve the content of this script at. + const GURL& url() const { return url_; } + void set_url(const GURL& url) { url_ = url; } + + // The path to find the script at. + const FilePath& path() const { return path_; } + void set_path(const FilePath& path) { path_ = path; } + + // The globs, if any, that determine which pages this script runs against. + // These are only used with "standalone" Greasemonkey-like user scripts. + const std::vector<std::string>& globs() const { return globs_; } + void add_glob(const std::string& glob) { globs_.push_back(glob); } + void clear_globs() { globs_.clear(); } + + // The URLPatterns, if any, that determine which pages this script runs + // against. + const std::vector<URLPattern>& url_patterns() const { return url_patterns_; } + void add_url_pattern(const URLPattern& pattern) { + url_patterns_.push_back(pattern); + } + void clear_url_patterns() { url_patterns_.clear(); } + + // Returns true if the script should be applied to the specified URL, false + // otherwise. + bool MatchesUrl(const GURL& url); + + // Serialize the script into a pickle. + void Pickle(::Pickle* pickle); + + // Deserialize the script from a pickle. Note that this always succeeds + // because presumably we were the one that pickled it, and we did it + // correctly. + void Unpickle(const ::Pickle& pickle, void** iter); + + private: + // The URL to the content of the script. + GURL url_; + + // The path to the content of the script. + FilePath path_; + + // Greasemonkey-style globs that determine pages to inject the script into. + // These are only used with standalone scripts. + std::vector<std::string> globs_; + + // URLPatterns that determine pages to inject the script into. These are + // only used with scripts that are part of extensions. + std::vector<URLPattern> url_patterns_; +}; + +typedef std::vector<UserScript> UserScriptList; + +#endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ diff --git a/chrome/common/extensions/user_script_unittest.cc b/chrome/common/extensions/user_script_unittest.cc new file mode 100644 index 0000000..0266260 --- /dev/null +++ b/chrome/common/extensions/user_script_unittest.cc @@ -0,0 +1,101 @@ +// Copyright (c) 2009 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 "base/file_path.h"
+#include "base/logging.h"
+#include "chrome/common/extensions/user_script.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(UserScriptTest, Match1) {
+ UserScript script;
+ script.add_glob("*mail.google.com*");
+ script.add_glob("*mail.yahoo.com*");
+ script.add_glob("*mail.msn.com*");
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("https://mail.google.com/foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("ftp://mail.google.com/foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://woo.mail.google.com/foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com")));
+}
+
+TEST(UserScriptTest, Match2) {
+ UserScript script;
+ script.add_glob("*mail.google.com/");
+ // GURL normalizes the URL to have a trailing "/"
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
+}
+
+TEST(UserScriptTest, Match3) {
+ UserScript script;
+ script.add_glob("http://mail.google.com/*");
+ // GURL normalizes the URL to have a trailing "/"
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("https://mail.google.com/foo")));
+}
+
+TEST(UserScriptTest, Match4) {
+ UserScript script;
+ script.add_glob("*");
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("https://hot.com/dog")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("file:///foo/bar")));
+}
+
+TEST(UserScriptTest, Match5) {
+ UserScript script;
+ script.add_glob("*foo*");
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://baz.org/foo/bar")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org")));
+}
+
+TEST(UserScriptTest, Match6) {
+ URLPattern pattern;
+ ASSERT_TRUE(pattern.Parse("http://*/foo*"));
+
+ UserScript script;
+ script.add_url_pattern(pattern);
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://monkey.com/foobar")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://monkey.com/hotdog")));
+
+ // NOTE: URLPattern is tested more extensively in url_pattern_unittest.cc.
+}
+
+TEST(UserScriptTest, Pickle) {
+ URLPattern pattern1;
+ URLPattern pattern2;
+ ASSERT_TRUE(pattern1.Parse("http://*/foo*"));
+ ASSERT_TRUE(pattern2.Parse("http://bar/baz*"));
+
+ UserScript script1;
+ script1.set_url(GURL("chrome-user-script:/foo.user.js"));
+ script1.add_url_pattern(pattern1);
+ script1.add_url_pattern(pattern2);
+
+ Pickle pickle;
+ script1.Pickle(&pickle);
+
+ void* iter = NULL;
+ UserScript script2;
+ script2.Unpickle(pickle, &iter);
+
+ EXPECT_EQ(script1.url(), script2.url());
+ ASSERT_EQ(script1.globs().size(), script2.globs().size());
+ for (size_t i = 0; i < script1.globs().size(); ++i) {
+ EXPECT_EQ(script1.globs()[i], script2.globs()[i]);
+ }
+ ASSERT_EQ(script1.url_patterns().size(), script2.url_patterns().size());
+ for (size_t i = 0; i < script1.url_patterns().size(); ++i) {
+ EXPECT_EQ(script1.url_patterns()[i].GetAsString(),
+ script2.url_patterns()[i].GetAsString());
+ }
+}
diff --git a/chrome/renderer/user_script_slave.cc b/chrome/renderer/user_script_slave.cc index a0877d9..9db7e68 100644 --- a/chrome/renderer/user_script_slave.cc +++ b/chrome/renderer/user_script_slave.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -16,47 +16,9 @@ static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; static const char kUserScriptTail[] = "\n})(window);"; -// UserScript - -bool UserScript::MatchesUrl(const GURL& url) { - for (std::vector<std::string>::iterator pattern = include_patterns_.begin(); - pattern != include_patterns_.end(); ++pattern) { - if (MatchPattern(url.spec(), *pattern)) { - return true; - } - } - - return false; -} - -void UserScript::AddInclude(const std::string &glob_pattern) { - include_patterns_.push_back(EscapeGlob(glob_pattern)); -} - -std::string UserScript::EscapeGlob(const std::string& input_pattern) { - std::string output_pattern; - - for (size_t i = 0; i < input_pattern.length(); ++i) { - switch (input_pattern[i]) { - // These characters have special meaning to the MatchPattern() function, - // so we escape them. - case '\\': - case '?': - output_pattern += '\\'; - // fall through - - default: - output_pattern += input_pattern[i]; - } - } - - return output_pattern; -} - - -// UserScriptSlave UserScriptSlave::UserScriptSlave() : shared_memory_(NULL), + script_deleter_(&scripts_), user_script_start_line_(0) { // TODO: Only windows supports resources and only windows supports user // scrips, so only load the Greasemonkey API on windows. Fix this when @@ -81,6 +43,7 @@ UserScriptSlave::UserScriptSlave() bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { scripts_.clear(); + script_contents_.clear(); // Create the shared memory object (read only). shared_memory_.reset(new base::SharedMemory(shared_memory, true)); @@ -107,40 +70,33 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { pickle.ReadSize(&iter, &num_scripts); for (size_t i = 0; i < num_scripts; ++i) { - const char* url = NULL; - int url_length = 0; + UserScript* script = new UserScript(); + script->Unpickle(pickle, &iter); + + // Note that this is a pointer into shared memory. We don't own it. It gets + // cleared up when the last renderer or browser process drops their + // reference to the shared memory. const char* body = NULL; int body_length = 0; + CHECK(pickle.ReadData(&iter, &body, &body_length)); - pickle.ReadData(&iter, &url, &url_length); - pickle.ReadData(&iter, &body, &body_length); - - scripts_.push_back(UserScript(StringPiece(url, url_length), - StringPiece(body, body_length))); - UserScript& script = scripts_.back(); - - size_t num_includes; - pickle.ReadSize(&iter, &num_includes); - for (size_t j = 0; j < num_includes; ++j) { - std::string include; - pickle.ReadString(&iter, &include); - script.AddInclude(include); - } + scripts_.push_back(script); + script_contents_[script] = StringPiece(body, body_length); } return true; } bool UserScriptSlave::InjectScripts(WebFrame* frame) { - for (std::vector<UserScript>::iterator script = scripts_.begin(); + for (std::vector<UserScript*>::iterator script = scripts_.begin(); script != scripts_.end(); ++script) { - if (script->MatchesUrl(frame->GetURL())) { + if ((*script)->MatchesUrl(frame->GetURL())) { std::string inject(kUserScriptHead); inject.append(api_js_.as_string()); - inject.append(script->GetBody().as_string()); + inject.append(script_contents_[*script].as_string()); inject.append(kUserScriptTail); frame->ExecuteJavaScript(inject, - GURL(script->GetURL().as_string()), + GURL((*script)->url().spec()), -user_script_start_line_); } } diff --git a/chrome/renderer/user_script_slave.h b/chrome/renderer/user_script_slave.h index b4558a6..3958b19 100644 --- a/chrome/renderer/user_script_slave.h +++ b/chrome/renderer/user_script_slave.h @@ -1,66 +1,23 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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_EXTENSIONS_USER_SCRIPT_SLAVE_H_ #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ +#include <map> +#include <vector> + #include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/string_piece.h" #include "base/string_util.h" +#include "chrome/common/extensions/user_script.h" +#include "chrome/common/stl_util-inl.h" #include "testing/gtest/include/gtest/gtest_prod.h" #include "webkit/glue/webframe.h" -// Parsed representation of a user script. -class UserScript { - public: - UserScript(const StringPiece& script_url, - const StringPiece& body) - : url_(script_url), body_(body) {} - - // Gets a URL where this script can be found. - const StringPiece& GetURL() const { - return url_; - } - - // Gets the script body that should be injected into matching content. - const StringPiece& GetBody() const { - return body_; - } - - // Adds an include pattern that will be checked to determine whether to - // include a script on a given page. - void AddInclude(const std::string &glob_pattern); - - // Returns true if the script should be applied to the specified URL, false - // otherwise. - bool MatchesUrl(const GURL& url); - - private: - FRIEND_TEST(UserScriptSlaveTest, EscapeGlob); - - // Helper function to convert the user script glob format to the patterns - // used internally to test URLs. - static std::string EscapeGlob(const std::string& glob); - - // The url of the file the script came from. This references shared_memory_, - // and is valid until that memory is either deleted or Unmap()'d. - StringPiece url_; - - // The body of the script, which will be injected into content pages. This - // references shared_memory_, and is valid until that memory is either - // deleted or Unmap()'d. - StringPiece body_; - - // List of patterns to test URLs against for this script. These patterns have - // been escaped for use with MatchPattern() in string_utils ('?' and '\' are - // escaped). - std::vector<std::string> include_patterns_; -}; - - // Manages installed UserScripts for a render process. class UserScriptSlave { public: @@ -79,7 +36,11 @@ class UserScriptSlave { scoped_ptr<base::SharedMemory> shared_memory_; // Parsed script data. - std::vector<UserScript> scripts_; + std::vector<UserScript*> scripts_; + STLElementDeleter<std::vector<UserScript*> > script_deleter_; + + // Script contents. + std::map<UserScript*, StringPiece> script_contents_; // Greasemonkey API source that is injected with the scripts. StringPiece api_js_; diff --git a/chrome/renderer/user_script_slave_unittest.cc b/chrome/renderer/user_script_slave_unittest.cc deleted file mode 100644 index eeea749..0000000 --- a/chrome/renderer/user_script_slave_unittest.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2008 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 "base/logging.h"
-#include "chrome/renderer/user_script_slave.h"
-#include "googleurl/src/gurl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(UserScriptSlaveTest, EscapeGlob) {
- EXPECT_EQ("", UserScript::EscapeGlob(""));
- EXPECT_EQ("*", UserScript::EscapeGlob("*"));
- EXPECT_EQ("www.google.com", UserScript::EscapeGlob("www.google.com"));
- EXPECT_EQ("*google.com*", UserScript::EscapeGlob("*google.com*"));
- EXPECT_EQ("foo\\\\bar\\?hot=dog",
- UserScript::EscapeGlob("foo\\bar?hot=dog"));
-}
-
-TEST(UserScriptSlaveTest, Match1) {
- UserScript script("foo", "bar");
- script.AddInclude("*mail.google.com*");
- script.AddInclude("*mail.yahoo.com*");
- script.AddInclude("*mail.msn.com*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com")));
-}
-
-TEST(UserScriptSlaveTest, Match2) {
- UserScript script("foo", "bar");
- script.AddInclude("*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog")));
-}
-
-TEST(UserScriptSlaveTest, Match3) {
- UserScript script("foo", "bar");
- script.AddInclude("*foo*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org")));
-}
diff --git a/chrome/test/unit/unit_tests.scons b/chrome/test/unit/unit_tests.scons index 4a2c333..f980ec1 100644 --- a/chrome/test/unit/unit_tests.scons +++ b/chrome/test/unit/unit_tests.scons @@ -205,6 +205,7 @@ input_files = ChromeFileList([ '$CHROME_DIR/common/bzip2_unittest.cc', '$CHROME_DIR/common/chrome_plugin_unittest.cc', '$CHROME_DIR/common/extensions/url_pattern_unittest.cc', + '$CHROME_DIR/common/extensions/user_script_unittest.cc', '$CHROME_DIR/common/gfx/emf_unittest.cc', '$CHROME_DIR/common/gfx/icon_util_unittest.cc', '$CHROME_DIR/common/ipc_message_unittest.cc', @@ -252,7 +253,6 @@ input_files = ChromeFileList([ '$CHROME_DIR/renderer/net/render_dns_queue_unittest.cc', '$CHROME_DIR/renderer/render_view_unittest.cc', '$CHROME_DIR/renderer/render_widget_unittest.cc', - '$CHROME_DIR/renderer/user_script_slave_unittest.cc', '$CHROME_DIR/renderer/render_process_unittest.cc', '$CHROME_DIR/renderer/render_thread_unittest.cc', diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 70c9d65..89f6c66 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -603,6 +603,14 @@ > </File> <File + RelativePath="..\..\browser\net\resolve_proxy_msg_helper_unittest.cc" + > + </File> + <File + RelativePath="..\..\browser\net\resolve_proxy_msg_helper_unittest.h" + > + </File> + <File RelativePath="..\..\browser\renderer_host\resource_dispatcher_host_unittest.cc" > </File> @@ -711,14 +719,6 @@ > </File> <File - RelativePath="..\..\browser\net\resolve_proxy_msg_helper_unittest.cc" - > - </File> - <File - RelativePath="..\..\browser\net\resolve_proxy_msg_helper_unittest.h" - > - </File> - <File RelativePath="..\..\browser\extensions\user_script_master_unittest.cc" > </File> @@ -830,10 +830,6 @@ RelativePath="..\..\renderer\render_widget_unittest.cc" > </File> - <File - RelativePath="..\..\renderer\user_script_slave_unittest.cc" - > - </File> <Filter Name="test_infrastructure" > @@ -943,6 +939,10 @@ > </File> <File + RelativePath="..\..\common\extensions\user_script_unittest.cc" + > + </File> + <File RelativePath="..\..\common\win_util_unittest.cc" > </File> |