diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 23:12:37 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 23:12:37 +0000 |
commit | 20f97c98c89c8a22b94564baa485a646838555cc (patch) | |
tree | 3a62215292dde87795a377c427be3671f1f460f8 | |
parent | d04f59dbcff106a786c1fc3b34d96782a5760803 (diff) | |
download | chromium_src-20f97c98c89c8a22b94564baa485a646838555cc.zip chromium_src-20f97c98c89c8a22b94564baa485a646838555cc.tar.gz chromium_src-20f97c98c89c8a22b94564baa485a646838555cc.tar.bz2 |
Move UserScript and related into extensions namespace
Moved UserScript, UserScriptMaster, UserScriptSlave, UserScriptListener,
and UserScriptScheduler into extensions namespace.
BUG=136876, 117261
Review URL: https://chromiumcodereview.appspot.com/10696176
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146682 0039d316-1c4b-4281-b951-d872f2087c98
42 files changed, 148 insertions, 88 deletions
diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.cc b/chrome/browser/chromeos/accessibility/accessibility_util.cc index 30ac4f3..2290a88 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_util.cc +++ b/chrome/browser/chromeos/accessibility/accessibility_util.cc @@ -79,7 +79,7 @@ class ContentScriptLoader { params.extension_id = extension_id_; params.is_javascript = true; params.code = data; - params.run_at = UserScript::DOCUMENT_IDLE; + params.run_at = extensions::UserScript::DOCUMENT_IDLE; params.all_frames = true; params.in_main_world = false; render_view_host_->Send(new ExtensionMsg_ExecuteCode( @@ -134,7 +134,7 @@ void EnableSpokenFeedback(bool enabled, content::WebUI* login_web_ui) { params.extension_id = extension->id(); params.is_javascript = true; params.code = "window.INJECTED_AFTER_LOAD = true;"; - params.run_at = UserScript::DOCUMENT_IDLE; + params.run_at = extensions::UserScript::DOCUMENT_IDLE; params.all_frames = true; params.in_main_world = false; render_view_host->Send(new ExtensionMsg_ExecuteCode( @@ -145,9 +145,9 @@ void EnableSpokenFeedback(bool enabled, content::WebUI* login_web_ui) { extension->id(), render_view_host); for (size_t i = 0; i < extension->content_scripts().size(); i++) { - const UserScript& script = extension->content_scripts()[i]; + const extensions::UserScript& script = extension->content_scripts()[i]; for (size_t j = 0; j < script.js_scripts().size(); ++j) { - const UserScript::File &file = script.js_scripts()[j]; + const extensions::UserScript::File &file = script.js_scripts()[j]; ExtensionResource resource = extension->GetResource( file.relative_path()); loader->AppendScript(resource); diff --git a/chrome/browser/download/download_crx_util.cc b/chrome/browser/download/download_crx_util.cc index 95d3843..1fde045 100644 --- a/chrome/browser/download/download_crx_util.cc +++ b/chrome/browser/download/download_crx_util.cc @@ -91,8 +91,8 @@ scoped_refptr<CrxInstaller> OpenChromeExtension( CrxInstaller::OffStoreInstallAllowedBecausePref); } - if (UserScript::IsURLUserScript(download_item.GetURL(), - download_item.GetMimeType())) { + if (extensions::UserScript::IsURLUserScript(download_item.GetURL(), + download_item.GetMimeType())) { installer->InstallUserScript(download_item.GetFullPath(), download_item.GetURL()); } else { @@ -117,8 +117,8 @@ bool IsExtensionDownload(const DownloadItem& download_item) { return false; if (download_item.GetMimeType() == extensions::Extension::kMimeType || - UserScript::IsURLUserScript(download_item.GetURL(), - download_item.GetMimeType())) { + extensions::UserScript::IsURLUserScript(download_item.GetURL(), + download_item.GetMimeType())) { return true; } else { return false; diff --git a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc index cdcbd0d..b032775 100644 --- a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc +++ b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc @@ -36,7 +36,7 @@ namespace keys = extensions::tabs_constants; ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() : execute_tab_id_(-1), all_frames_(false), - run_at_(UserScript::DOCUMENT_IDLE) { + run_at_(extensions::UserScript::DOCUMENT_IDLE) { } ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} @@ -105,11 +105,11 @@ bool ExecuteCodeInTabFunction::RunImpl() { keys::kRunAtKey, &run_string)); if (run_string == extension_manifest_values::kRunAtDocumentStart) - run_at_ = UserScript::DOCUMENT_START; + run_at_ = extensions::UserScript::DOCUMENT_START; else if (run_string == extension_manifest_values::kRunAtDocumentEnd) - run_at_ = UserScript::DOCUMENT_END; + run_at_ = extensions::UserScript::DOCUMENT_END; else if (run_string == extension_manifest_values::kRunAtDocumentIdle) - run_at_ = UserScript::DOCUMENT_IDLE; + run_at_ = extensions::UserScript::DOCUMENT_IDLE; else EXTENSION_FUNCTION_VALIDATE(false); } diff --git a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h index 98573a9..baa939a 100644 --- a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h +++ b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h @@ -59,7 +59,7 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction { bool all_frames_; // The intended time to run the script. - UserScript::RunLocation run_at_; + extensions::UserScript::RunLocation run_at_; }; class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { diff --git a/chrome/browser/extensions/api/tabs/tabs.cc b/chrome/browser/extensions/api/tabs/tabs.cc index c5b7bc1..9893434 100644 --- a/chrome/browser/extensions/api/tabs/tabs.cc +++ b/chrome/browser/extensions/api/tabs/tabs.cc @@ -1315,7 +1315,7 @@ bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props, ScriptExecutor::JAVASCRIPT, url.path(), ScriptExecutor::TOP_FRAME, - UserScript::DOCUMENT_IDLE, + extensions::UserScript::DOCUMENT_IDLE, ScriptExecutor::MAIN_WORLD, base::Bind(&UpdateTabFunction::OnExecuteCodeFinished, this)); diff --git a/chrome/browser/extensions/convert_user_script.cc b/chrome/browser/extensions/convert_user_script.cc index 92fadbd..4531ef0 100644 --- a/chrome/browser/extensions/convert_user_script.cc +++ b/chrome/browser/extensions/convert_user_script.cc @@ -24,11 +24,11 @@ #include "crypto/sha2.h" #include "googleurl/src/gurl.h" -using extensions::Extension; - namespace keys = extension_manifest_keys; namespace values = extension_manifest_values; +namespace extensions { + scoped_refptr<Extension> ConvertUserScriptToExtension( const FilePath& user_script_path, const GURL& original_url, string16* error) { @@ -187,3 +187,5 @@ scoped_refptr<Extension> ConvertUserScriptToExtension( temp_dir.Take(); // The caller takes ownership of the directory. return extension; } + +} // namespace extensions diff --git a/chrome/browser/extensions/convert_user_script.h b/chrome/browser/extensions/convert_user_script.h index 480b6ae..03e311e 100644 --- a/chrome/browser/extensions/convert_user_script.h +++ b/chrome/browser/extensions/convert_user_script.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -15,7 +15,6 @@ class GURL; namespace extensions { class Extension; -} // Wraps the specified user script in an extension. The extension is created // unpacked in the system temp dir. Returns a valid extension that the caller @@ -27,4 +26,6 @@ class Extension; scoped_refptr<extensions::Extension> ConvertUserScriptToExtension( const FilePath& user_script, const GURL& original_url, string16* error); +} // namespace extensions + #endif // CHROME_BROWSER_EXTENSIONS_CONVERT_USER_SCRIPT_H_ diff --git a/chrome/browser/extensions/convert_user_script_unittest.cc b/chrome/browser/extensions/convert_user_script_unittest.cc index cafdbe8..dee24c8 100644 --- a/chrome/browser/extensions/convert_user_script_unittest.cc +++ b/chrome/browser/extensions/convert_user_script_unittest.cc @@ -16,8 +16,6 @@ #include "chrome/common/extensions/extension.h" #include "testing/gtest/include/gtest/gtest.h" -using extensions::Extension; - namespace { static void AddPattern(URLPatternSet* extent, const std::string& pattern) { @@ -27,6 +25,8 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) { } +namespace extensions { + TEST(ExtensionFromUserScript, Basic) { FilePath test_file; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_file)); @@ -217,3 +217,5 @@ TEST(ExtensionFromUserScript, RunAtDocumentIdle) { const UserScript& script = extension->content_scripts()[0]; EXPECT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); } + +} // namespace extensions diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 61ce008..93e8978 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -172,8 +172,8 @@ void CrxInstaller::InstallUserScript(const FilePath& source_file, void CrxInstaller::ConvertUserScriptOnFileThread() { string16 error; - scoped_refptr<Extension> extension = - ConvertUserScriptToExtension(source_file_, download_url_, &error); + scoped_refptr<Extension> extension = extensions::ConvertUserScriptToExtension( + source_file_, download_url_, &error); if (!extension) { ReportFailureFromFileThread(CrxInstallerError(error)); return; @@ -315,7 +315,7 @@ CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { // For self-hosted apps, verify that the entire extent is on the same // host (or a subdomain of the host) the download happened from. There's // no way for us to verify that the app controls any other hosts. - URLPattern pattern(UserScript::kValidUserScriptSchemes); + URLPattern pattern(extensions::UserScript::kValidUserScriptSchemes); pattern.SetHost(download_url_.host()); pattern.SetMatchSubdomains(true); diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 2313467..4bbddf8 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -1057,7 +1057,7 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { AddPattern(&expected_patterns, "http://*.google.com/*"); AddPattern(&expected_patterns, "https://*.google.com/*"); const Extension* extension = loaded_[0]; - const UserScriptList& scripts = extension->content_scripts(); + const extensions::UserScriptList& scripts = extension->content_scripts(); ASSERT_EQ(2u, scripts.size()); EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); EXPECT_EQ(2u, scripts[0].js_scripts().size()); diff --git a/chrome/browser/extensions/extension_startup_browsertest.cc b/chrome/browser/extensions/extension_startup_browsertest.cc index 09e1a69..5c14c65 100644 --- a/chrome/browser/extensions/extension_startup_browsertest.cc +++ b/chrome/browser/extensions/extension_startup_browsertest.cc @@ -101,7 +101,8 @@ class ExtensionStartupTestBase : public InProcessBrowserTest { ui_test_utils::WindowedNotificationObserver user_scripts_observer( chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, content::NotificationService::AllSources()); - UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); + extensions::UserScriptMaster* master = + browser()->profile()->GetUserScriptMaster(); if (!master->ScriptsReady()) user_scripts_observer.Wait(); ASSERT_TRUE(master->ScriptsReady()); diff --git a/chrome/browser/extensions/extension_system.h b/chrome/browser/extensions/extension_system.h index c84f0ab..acb5ed3 100644 --- a/chrome/browser/extensions/extension_system.h +++ b/chrome/browser/extensions/extension_system.h @@ -20,7 +20,6 @@ class ExtensionNavigationObserver; class ExtensionProcessManager; class ExtensionService; class Profile; -class UserScriptMaster; namespace extensions { class AlarmManager; @@ -31,6 +30,7 @@ class LazyBackgroundTaskQueue; class ManagementPolicy; class RulesRegistryService; class StateStore; +class UserScriptMaster; // The ExtensionSystem manages the creation and destruction of services // related to extensions. Most objects are shared between normal diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc index 47fed2b..efa0e9c 100644 --- a/chrome/browser/extensions/user_script_listener.cc +++ b/chrome/browser/extensions/user_script_listener.cc @@ -19,6 +19,8 @@ using content::BrowserThread; using content::ResourceThrottle; +namespace extensions { + class UserScriptListener::Throttle : public ResourceThrottle, public base::SupportsWeakPtr<UserScriptListener::Throttle> { @@ -164,9 +166,8 @@ void UserScriptListener::ReplaceURLPatterns(void* profile_id, data.url_patterns = patterns; } -void UserScriptListener::CollectURLPatterns( - const extensions::Extension* extension, - URLPatterns* patterns) { +void UserScriptListener::CollectURLPatterns(const Extension* extension, + URLPatterns* patterns) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const UserScriptList& scripts = extension->content_scripts(); @@ -186,8 +187,8 @@ void UserScriptListener::Observe(int type, switch (type) { case chrome::NOTIFICATION_EXTENSION_LOADED: { Profile* profile = content::Source<Profile>(source).ptr(); - const extensions::Extension* extension = - content::Details<const extensions::Extension>(details).ptr(); + const Extension* extension = + content::Details<const Extension>(details).ptr(); if (extension->content_scripts().empty()) return; // no new patterns from this extension. @@ -203,9 +204,8 @@ void UserScriptListener::Observe(int type, case chrome::NOTIFICATION_EXTENSION_UNLOADED: { Profile* profile = content::Source<Profile>(source).ptr(); - const extensions::Extension* unloaded_extension = - content::Details<extensions::UnloadedExtensionInfo>( - details)->extension; + const Extension* unloaded_extension = + content::Details<UnloadedExtensionInfo>(details)->extension; if (unloaded_extension->content_scripts().empty()) return; // no patterns to delete for this extension. @@ -241,3 +241,5 @@ void UserScriptListener::Observe(int type, NOTREACHED(); } } + +} // namespace extensions diff --git a/chrome/browser/extensions/user_script_listener.h b/chrome/browser/extensions/user_script_listener.h index 0ec4585..d4f6c4a 100644 --- a/chrome/browser/extensions/user_script_listener.h +++ b/chrome/browser/extensions/user_script_listener.h @@ -26,7 +26,6 @@ class ResourceThrottle; namespace extensions { class Extension; -} // This class handles delaying of resource loads that depend on unloaded user // scripts. For each request that comes in, we check if it depends on a user @@ -97,7 +96,7 @@ class UserScriptListener // Helper to collect the extension's user script URL patterns in a list and // return it. - void CollectURLPatterns(const extensions::Extension* extension, + void CollectURLPatterns(const Extension* extension, URLPatterns* patterns); // content::NotificationObserver @@ -110,4 +109,6 @@ class UserScriptListener DISALLOW_COPY_AND_ASSIGN(UserScriptListener); }; +} // namespace extensions + #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LISTENER_H_ diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc index 9eb691a..93d7c0b 100644 --- a/chrome/browser/extensions/user_script_listener_unittest.cc +++ b/chrome/browser/extensions/user_script_listener_unittest.cc @@ -23,7 +23,8 @@ using content::ResourceController; using content::ResourceThrottle; -using extensions::Extension; + +namespace extensions { namespace { @@ -151,7 +152,7 @@ class UserScriptListenerTest .AppendASCII("Extensions") .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") .AppendASCII("1.0.0.0"); - extensions::UnpackedInstaller::Create(service_)->Load(extension_path); + UnpackedInstaller::Create(service_)->Load(extension_path); } void UnloadTestExtension() { @@ -281,3 +282,5 @@ TEST_F(UserScriptListenerTest, MultiProfile) { } } // namespace + +} // namespace extensions diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index f55295d7..b8b662a 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -29,6 +29,8 @@ using content::BrowserThread; +namespace extensions { + // Helper function to parse greasesmonkey headers static bool GetDeclarationValue(const base::StringPiece& line, const base::StringPiece& prefix, @@ -350,8 +352,8 @@ void UserScriptMaster::Observe(int type, break; case chrome::NOTIFICATION_EXTENSION_LOADED: { // Add any content scripts inside the extension. - const extensions::Extension* extension = - content::Details<const extensions::Extension>(details).ptr(); + const Extension* extension = + content::Details<const Extension>(details).ptr(); extensions_info_[extension->id()] = ExtensionSet::ExtensionPathAndDefaultLocale( extension->path(), extension->default_locale()); @@ -369,9 +371,8 @@ void UserScriptMaster::Observe(int type, } case chrome::NOTIFICATION_EXTENSION_UNLOADED: { // Remove any content scripts. - const extensions::Extension* extension = - content::Details<extensions::UnloadedExtensionInfo>( - details)->extension; + const Extension* extension = + content::Details<UnloadedExtensionInfo>(details)->extension; extensions_info_.erase(extension->id()); UserScriptList new_user_scripts; for (UserScriptList::iterator iter = user_scripts_.begin(); @@ -438,3 +439,5 @@ void UserScriptMaster::SendUpdate(content::RenderProcessHost* process, if (base::SharedMemory::IsHandleValid(handle_for_process)) process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); } + +} // namespace extensions diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h index f41d8fd9..1f9e874 100644 --- a/chrome/browser/extensions/user_script_master.h +++ b/chrome/browser/extensions/user_script_master.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -31,6 +31,8 @@ class Profile; typedef std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale> ExtensionsInfo; +namespace extensions { + // Manages a segment of shared memory that contains the user scripts the user // has installed. Lives on the UI thread. class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, @@ -167,4 +169,6 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); }; +} // namespace extensions + #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc index 8ec0ba7..0aabb5a 100644 --- a/chrome/browser/extensions/user_script_master_unittest.cc +++ b/chrome/browser/extensions/user_script_master_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -30,6 +30,8 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) { } +namespace extensions { + // Test bringing up a master on a specific directory, putting a script // in there, etc. @@ -272,3 +274,5 @@ TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) { EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); } + +} // namespace extensions diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index b919e93..957faa6 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -196,7 +196,7 @@ ExtensionService* OffTheRecordProfileImpl::GetExtensionService() { return extensions::ExtensionSystem::Get(this)->extension_service(); } -UserScriptMaster* OffTheRecordProfileImpl::GetUserScriptMaster() { +extensions::UserScriptMaster* OffTheRecordProfileImpl::GetUserScriptMaster() { return extensions::ExtensionSystem::Get(this)->user_script_master(); } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index d0aac2b..3c05723 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -40,7 +40,7 @@ class OffTheRecordProfileImpl : public Profile, virtual Profile* GetOriginalProfile() OVERRIDE; virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; virtual ExtensionService* GetExtensionService() OVERRIDE; - virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; + virtual extensions::UserScriptMaster* GetUserScriptMaster() OVERRIDE; virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE; virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE; virtual ExtensionSpecialStoragePolicy* diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 496737f..7c73363 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -32,7 +32,6 @@ class PrefService; class PromoCounter; class ProtocolHandlerRegistry; class TestingProfile; -class UserScriptMaster; class VisitedLinkMaster; class WebDataService; @@ -53,11 +52,14 @@ class LibCrosServiceLibraryImpl; class ResetDefaultProxyConfigServiceTask; } - namespace content { class WebUI; } +namespace extensions { +class UserScriptMaster; +} + namespace fileapi { class FileSystemContext; } @@ -193,11 +195,11 @@ class Profile : public content::BrowserContext { virtual ExtensionService* GetExtensionService() = 0; // DEPRECATED. Instead, use ExtensionSystem::user_script_master(). - // Retrieves a pointer to the UserScriptMaster associated with this - // profile. The UserScriptMaster is lazily created the first time - // that this method is called. + // Retrieves a pointer to the extensions::UserScriptMaster associated with + // this profile. The extensions::UserScriptMaster is lazily created the first + // time that this method is called. // TODO(yoz): remove this accessor (bug 104095). - virtual UserScriptMaster* GetUserScriptMaster() = 0; + virtual extensions::UserScriptMaster* GetUserScriptMaster() = 0; // DEPRECATED. Instead, use ExtensionSystem::process_manager(). // Retrieves a pointer to the ExtensionProcessManager associated with this diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index c9fbcce..966d5b3 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -606,7 +606,7 @@ ExtensionService* ProfileImpl::GetExtensionService() { return extensions::ExtensionSystem::Get(this)->extension_service(); } -UserScriptMaster* ProfileImpl::GetUserScriptMaster() { +extensions::UserScriptMaster* ProfileImpl::GetUserScriptMaster() { return extensions::ExtensionSystem::Get(this)->user_script_master(); } diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index f7fb934..31e49eb 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -81,7 +81,7 @@ class ProfileImpl : public Profile, virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; virtual ExtensionService* GetExtensionService() OVERRIDE; - virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; + virtual extensions::UserScriptMaster* GetUserScriptMaster() OVERRIDE; virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE; virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE; virtual ExtensionSpecialStoragePolicy* diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc index 8be42ed..2137533 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -74,7 +74,7 @@ ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( prerender::PrerenderTracker* prerender_tracker) : download_request_limiter_(g_browser_process->download_request_limiter()), safe_browsing_(g_browser_process->safe_browsing_service()), - user_script_listener_(new UserScriptListener()), + user_script_listener_(new extensions::UserScriptListener()), prerender_tracker_(prerender_tracker), variation_ids_cache_initialized_(false) { } @@ -321,7 +321,7 @@ void ChromeResourceDispatcherHostDelegate::AppendChromeMetricsHeaders( bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( const GURL& url, const std::string& mime_type) { // Special-case user scripts to get downloaded instead of viewed. - return UserScript::IsURLUserScript(url, mime_type); + return extensions::UserScript::IsURLUserScript(url, mime_type); } void ChromeResourceDispatcherHostDelegate::OnResponseStarted( diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h index cf38548..1a914bc 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h @@ -16,7 +16,10 @@ class DelayedResourceQueue; class DownloadRequestLimiter; class SafeBrowsingService; + +namespace extensions { class UserScriptListener; +} namespace prerender { class PrerenderTracker; @@ -117,7 +120,7 @@ class ChromeResourceDispatcherHostDelegate scoped_refptr<DownloadRequestLimiter> download_request_limiter_; scoped_refptr<SafeBrowsingService> safe_browsing_; - scoped_refptr<UserScriptListener> user_script_listener_; + scoped_refptr<extensions::UserScriptListener> user_script_listener_; prerender::PrerenderTracker* prerender_tracker_; // Whether or not we've initialized the Cache. diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc index 4a6f150..a3812f5 100644 --- a/chrome/common/extensions/extension_file_util.cc +++ b/chrome/common/extensions/extension_file_util.cc @@ -272,10 +272,10 @@ bool ValidateExtension(const Extension* extension, } for (size_t i = 0; i < extension->content_scripts().size(); ++i) { - const UserScript& script = extension->content_scripts()[i]; + const extensions::UserScript& script = extension->content_scripts()[i]; for (size_t j = 0; j < script.js_scripts().size(); j++) { - const UserScript::File& js_script = script.js_scripts()[j]; + const extensions::UserScript::File& js_script = script.js_scripts()[j]; const FilePath& path = ExtensionResource::GetFilePath( js_script.extension_root(), js_script.relative_path(), symlink_policy); @@ -285,7 +285,7 @@ bool ValidateExtension(const Extension* extension, } for (size_t j = 0; j < script.css_scripts().size(); j++) { - const UserScript::File& css_script = script.css_scripts()[j]; + const extensions::UserScript::File& css_script = script.css_scripts()[j]; const FilePath& path = ExtensionResource::GetFilePath( css_script.extension_root(), css_script.relative_path(), symlink_policy); diff --git a/chrome/common/extensions/permissions/permission_set.cc b/chrome/common/extensions/permissions/permission_set.cc index 019504d..890103b 100644 --- a/chrome/common/extensions/permissions/permission_set.cc +++ b/chrome/common/extensions/permissions/permission_set.cc @@ -506,7 +506,7 @@ void PermissionSet::InitImplicitExtensionPermissions( apis_.insert(APIPermission::kFileBrowserHandlerInternal); // Add the scriptable hosts. - for (UserScriptList::const_iterator content_script = + for (extensions::UserScriptList::const_iterator content_script = extension->content_scripts().begin(); content_script != extension->content_scripts().end(); ++content_script) { URLPatternSet::const_iterator pattern = diff --git a/chrome/common/extensions/user_script.cc b/chrome/common/extensions/user_script.cc index 6ccfea4..0334e58 100644 --- a/chrome/common/extensions/user_script.cc +++ b/chrome/common/extensions/user_script.cc @@ -22,6 +22,8 @@ bool UrlMatchesGlobs(const std::vector<std::string>* globs, } // namespace +namespace extensions { + // static const char UserScript::kFileExtension[] = ".user.js"; @@ -211,3 +213,5 @@ void UserScript::UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, scripts->push_back(file); } } + +} // namespace extensions diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h index 73dd020..e7caad6 100644 --- a/chrome/common/extensions/user_script.h +++ b/chrome/common/extensions/user_script.h @@ -17,6 +17,8 @@ class Pickle; class PickleIterator; +namespace extensions { + // Represents a user script, either a standalone one, or one that is part of an // extension. class UserScript { @@ -256,4 +258,6 @@ class UserScript { typedef std::vector<UserScript> UserScriptList; +} // namespace extensions + #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 index 51e9b31..323f573 100644 --- a/chrome/common/extensions/user_script_unittest.cc +++ b/chrome/common/extensions/user_script_unittest.cc @@ -8,6 +8,8 @@ #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" +namespace extensions { + static const int kAllSchemes = URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | @@ -214,3 +216,5 @@ TEST(ExtensionUserScriptTest, Defaults) { UserScript script; ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); } + +} // namespace extensions diff --git a/chrome/renderer/extensions/chrome_v8_context.cc b/chrome/renderer/extensions/chrome_v8_context.cc index 6772a6f..b4f2bae 100644 --- a/chrome/renderer/extensions/chrome_v8_context.cc +++ b/chrome/renderer/extensions/chrome_v8_context.cc @@ -159,7 +159,8 @@ const std::set<std::string>& ChromeV8Context::GetAvailableExtensionAPIs() { extensions::ExtensionAPI::GetSharedInstance()->GetAPIsForContext( context_type_, extension_, - UserScriptSlave::GetDataSourceURLForFrame(web_frame_)).Pass(); + extensions::UserScriptSlave::GetDataSourceURLForFrame( + web_frame_)).Pass(); } return *(available_extension_apis_.get()); } diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index e1e84d9..f6618d0 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -277,7 +277,7 @@ ExtensionDispatcher::ExtensionDispatcher() kInitialExtensionIdleHandlerDelayMs); } - user_script_slave_.reset(new UserScriptSlave(&extensions_)); + user_script_slave_.reset(new extensions::UserScriptSlave(&extensions_)); request_sender_.reset(new ExtensionRequestSender(this, &v8_context_set_)); PopulateSourceMap(); PopulateLazyBindingsMap(); @@ -693,7 +693,7 @@ void ExtensionDispatcher::DidCreateScriptContext( } ExtensionURLInfo url_info(frame->document().securityOrigin(), - UserScriptSlave::GetDataSourceURLForFrame(frame)); + extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); Feature::Context context_type = ClassifyJavaScriptContext(extension_id, extension_group, url_info); @@ -792,7 +792,7 @@ std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame, } // Extension pages (chrome-extension:// URLs). - GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); + GURL frame_url = extensions::UserScriptSlave::GetDataSourceURLForFrame(frame); return extensions_.GetExtensionOrAppIDByURL( ExtensionURLInfo(frame->document().securityOrigin(), frame_url)); } @@ -1064,7 +1064,7 @@ bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( // we should abort. WebKit::WebFrame* frame = context->web_frame(); ExtensionURLInfo url_info(frame->document().securityOrigin(), - UserScriptSlave::GetDataSourceURLForFrame(frame)); + extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); CHECK(!extensions_.IsSandboxedPage(url_info)); return true; diff --git a/chrome/renderer/extensions/extension_dispatcher.h b/chrome/renderer/extensions/extension_dispatcher.h index 49f02b6..e1c8ec7 100644 --- a/chrome/renderer/extensions/extension_dispatcher.h +++ b/chrome/renderer/extensions/extension_dispatcher.h @@ -25,11 +25,11 @@ class ExtensionRequestSender; class GURL; class ModuleSystem; class URLPattern; -class UserScriptSlave; struct ExtensionMsg_Loaded_Params; namespace extensions { class FilteredEventRouter; +class UserScriptSlave; } namespace WebKit { @@ -64,7 +64,9 @@ class ExtensionDispatcher : public content::RenderProcessObserver { const ChromeV8ContextSet& v8_context_set() const { return v8_context_set_; } - UserScriptSlave* user_script_slave() { return user_script_slave_.get(); } + extensions::UserScriptSlave* user_script_slave() { + return user_script_slave_.get(); + } extensions::V8SchemaRegistry* v8_schema_registry() { return &v8_schema_registry_; } @@ -222,7 +224,7 @@ class ExtensionDispatcher : public content::RenderProcessObserver { // There is zero or one for each v8 context. ChromeV8ContextSet v8_context_set_; - scoped_ptr<UserScriptSlave> user_script_slave_; + scoped_ptr<extensions::UserScriptSlave> user_script_slave_; // Same as above, but on a longer timer and will run even if the process is // not idle, to ensure that IdleHandle gets called eventually. diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc index 24d3dc2..47a48be 100644 --- a/chrome/renderer/extensions/extension_helper.cc +++ b/chrome/renderer/extensions/extension_helper.cc @@ -48,7 +48,7 @@ namespace { // We store this mapping per process, because a frame can jump from one // document to another with adoptNode, and so having the object be a // RenderViewObserver means it might miss some notifications after it moves. -typedef std::map<WebFrame*, UserScriptScheduler*> SchedulerMap; +typedef std::map<WebFrame*, extensions::UserScriptScheduler*> SchedulerMap; static base::LazyInstance<SchedulerMap> g_schedulers = LAZY_INSTANCE_INITIALIZER; @@ -225,7 +225,7 @@ bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { extension_dispatcher_->user_script_slave()->InjectScripts( - frame, UserScript::DOCUMENT_END); + frame, extensions::UserScript::DOCUMENT_END); SchedulerMap::iterator i = g_schedulers.Get().find(frame); if (i != g_schedulers.Get().end()) @@ -240,7 +240,7 @@ void ExtensionHelper::DidFinishLoad(WebKit::WebFrame* frame) { void ExtensionHelper::DidCreateDocumentElement(WebFrame* frame) { extension_dispatcher_->user_script_slave()->InjectScripts( - frame, UserScript::DOCUMENT_START); + frame, extensions::UserScript::DOCUMENT_START); SchedulerMap::iterator i = g_schedulers.Get().find(frame); if (i != g_schedulers.Get().end()) i->second->DidCreateDocumentElement(); @@ -276,7 +276,7 @@ void ExtensionHelper::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) { if (g_schedulers.Get().count(frame)) return; - g_schedulers.Get()[frame] = new UserScriptScheduler( + g_schedulers.Get()[frame] = new extensions::UserScriptScheduler( frame, extension_dispatcher_); } diff --git a/chrome/renderer/extensions/file_system_natives.cc b/chrome/renderer/extensions/file_system_natives.cc index 7ed653f..88faeba 100644 --- a/chrome/renderer/extensions/file_system_natives.cc +++ b/chrome/renderer/extensions/file_system_natives.cc @@ -27,7 +27,8 @@ static v8::Handle<v8::Value> GetIsolatedFileSystem( WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); DCHECK(webframe); - GURL context_url = UserScriptSlave::GetDataSourceURLForFrame(webframe); + GURL context_url = + extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe); CHECK(context_url.SchemeIs(chrome::kExtensionScheme)); std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), diff --git a/chrome/renderer/extensions/user_script_scheduler.cc b/chrome/renderer/extensions/user_script_scheduler.cc index dc4ebee..8e5ee157 100644 --- a/chrome/renderer/extensions/user_script_scheduler.cc +++ b/chrome/renderer/extensions/user_script_scheduler.cc @@ -29,7 +29,8 @@ using WebKit::WebDocument; using WebKit::WebFrame; using WebKit::WebString; using WebKit::WebView; -using extensions::Extension; + +namespace extensions { UserScriptScheduler::UserScriptScheduler( WebFrame* frame, ExtensionDispatcher* extension_dispatcher) @@ -221,3 +222,5 @@ bool UserScriptScheduler::GetAllChildFrames( } return true; } + +} // namespace extensions diff --git a/chrome/renderer/extensions/user_script_scheduler.h b/chrome/renderer/extensions/user_script_scheduler.h index 125ec99..20de234 100644 --- a/chrome/renderer/extensions/user_script_scheduler.h +++ b/chrome/renderer/extensions/user_script_scheduler.h @@ -20,6 +20,8 @@ namespace WebKit { class WebFrame; } +namespace extensions { + // Implements support for injecting scripts at different times in the document // loading process. The different possible time are described in // UserScript::RunLocation. @@ -42,7 +44,7 @@ class WebFrame; class UserScriptScheduler { public: UserScriptScheduler(WebKit::WebFrame* frame, - ExtensionDispatcher* extension_dispatcher); + ExtensionDispatcher* extension_dispatcher); ~UserScriptScheduler(); void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); @@ -89,4 +91,6 @@ class UserScriptScheduler { ExtensionDispatcher* extension_dispatcher_; }; +} // namespace extensions + #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ diff --git a/chrome/renderer/extensions/user_script_slave.cc b/chrome/renderer/extensions/user_script_slave.cc index 9225014..c453078 100644 --- a/chrome/renderer/extensions/user_script_slave.cc +++ b/chrome/renderer/extensions/user_script_slave.cc @@ -42,7 +42,8 @@ using WebKit::WebString; using WebKit::WebVector; using WebKit::WebView; using content::RenderThread; -using extensions::Extension; + +namespace extensions { // These two strings are injected before and after the Greasemonkey API and // user script to wrap it in an anonymous scope. @@ -368,3 +369,5 @@ void UserScriptSlave::InjectScripts(WebFrame* frame, NOTREACHED(); } } + +} // namespace extensions diff --git a/chrome/renderer/extensions/user_script_slave.h b/chrome/renderer/extensions/user_script_slave.h index 8f4aa87..02b61cf 100644 --- a/chrome/renderer/extensions/user_script_slave.h +++ b/chrome/renderer/extensions/user_script_slave.h @@ -20,16 +20,15 @@ class ExtensionSet; class GURL; -namespace extensions { -class Extension; -} - namespace WebKit { class WebFrame; } using WebKit::WebScriptSource; +namespace extensions { +class Extension; + // Manages installed UserScripts for a render process. class UserScriptSlave { public: @@ -54,7 +53,7 @@ class UserScriptSlave { // Gets the isolated world ID to use for the given |extension| in the given // |frame|. If no isolated world has been created for that extension, // one will be created and initialized. - int GetIsolatedWorldIdForExtension(const extensions::Extension* extension, + int GetIsolatedWorldIdForExtension(const Extension* extension, WebKit::WebFrame* frame); // Gets the id of the extension running in a given isolated world. If no such @@ -66,7 +65,7 @@ class UserScriptSlave { private: static void InitializeIsolatedWorld(int isolated_world_id, - const extensions::Extension* extension); + const Extension* extension); // Shared memory containing raw script data. scoped_ptr<base::SharedMemory> shared_memory_; @@ -87,4 +86,6 @@ class UserScriptSlave { DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); }; +} // namespace extensions + #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 30fd382..f55347f 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -452,7 +452,7 @@ ExtensionService* TestingProfile::GetExtensionService() { return extensions::ExtensionSystem::Get(this)->extension_service(); } -UserScriptMaster* TestingProfile::GetUserScriptMaster() { +extensions::UserScriptMaster* TestingProfile::GetUserScriptMaster() { return extensions::ExtensionSystem::Get(this)->user_script_master(); } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 8d9f127..706072b 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -148,7 +148,7 @@ class TestingProfile : public Profile { virtual Profile* GetOriginalProfile() OVERRIDE; virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; virtual ExtensionService* GetExtensionService() OVERRIDE; - virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; + virtual extensions::UserScriptMaster* GetUserScriptMaster() OVERRIDE; virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE; virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE; void SetExtensionSpecialStoragePolicy( diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 4b27a83..f405de2 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -35,7 +35,6 @@ class ChildProcessSecurityPolicyTest; class ComponentUpdateInterceptor; class TestAutomationProvider; class URLRequestAutomationJob; -class UserScriptListenerTest; namespace base { namespace debug { @@ -59,6 +58,12 @@ class ResourceDispatcherHostTest; // Temporary layering violation to allow existing users of a deprecated // interface. +namespace extensions { +class UserScriptListenerTest; +} + +// Temporary layering violation to allow existing users of a deprecated +// interface. namespace fileapi { class FileSystemDirURLRequestJobTest; class FileSystemURLRequestJobTest; @@ -180,7 +185,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), friend class ::ChildProcessSecurityPolicyTest; friend class ::ComponentUpdateInterceptor; friend class ::TestAutomationProvider; - friend class ::UserScriptListenerTest; friend class ::URLRequestAutomationJob; friend class TestInterceptor; friend class URLRequestFilter; @@ -188,6 +192,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), friend class appcache::AppCacheRequestHandlerTest; friend class appcache::AppCacheURLRequestJobTest; friend class content::ResourceDispatcherHostTest; + friend class extensions::UserScriptListenerTest; friend class fileapi::FileSystemDirURLRequestJobTest; friend class fileapi::FileSystemURLRequestJobTest; friend class fileapi::FileWriterDelegateTest; |