| Index: chrome/browser/extensions/user_script_master.cc
|
| diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
|
| index 1f72436b6c30084a31ea90f29a7f8d47dea98099..57e7a1af70e3368072fb2d86e2dafc4a98c18ff4 100644
|
| --- a/chrome/browser/extensions/user_script_master.cc
|
| +++ b/chrome/browser/extensions/user_script_master.cc
|
| @@ -15,7 +15,6 @@
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/extensions/extension_util.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
|
| #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/render_process_host.h"
|
| @@ -35,10 +34,6 @@ namespace extensions {
|
|
|
| namespace {
|
|
|
| -typedef base::Callback<void(scoped_ptr<UserScriptList>,
|
| - scoped_ptr<base::SharedMemory>)>
|
| - LoadScriptsCallback;
|
| -
|
| void VerifyContent(scoped_refptr<ContentVerifier> verifier,
|
| const std::string& extension_id,
|
| const base::FilePath& extension_root,
|
| @@ -197,23 +192,6 @@ scoped_ptr<base::SharedMemory> Serialize(const UserScriptList& scripts) {
|
| /*read_only=*/true));
|
| }
|
|
|
| -void LoadScriptsOnFileThread(scoped_ptr<UserScriptList> user_scripts,
|
| - const ExtensionsInfo& extensions_info,
|
| - const std::set<std::string>& new_extensions,
|
| - scoped_refptr<ContentVerifier> verifier,
|
| - LoadScriptsCallback callback) {
|
| - DCHECK(user_scripts.get());
|
| - LoadUserScripts(
|
| - user_scripts.get(), extensions_info, new_extensions, verifier);
|
| - scoped_ptr<base::SharedMemory> memory = Serialize(*user_scripts);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(callback,
|
| - base::Passed(&user_scripts),
|
| - base::Passed(&memory)));
|
| -}
|
| -
|
| // Helper function to parse greasesmonkey headers
|
| bool GetDeclarationValue(const base::StringPiece& line,
|
| const base::StringPiece& prefix,
|
| @@ -342,18 +320,29 @@ void UserScriptMaster::LoadScriptsForTest(UserScriptList* user_scripts) {
|
| user_scripts, info, new_extensions, NULL /* no verifier for testing */);
|
| }
|
|
|
| +// static
|
| +void UserScriptMaster::LoadScriptsOnFileThread(
|
| + scoped_ptr<UserScriptList> user_scripts,
|
| + const ExtensionsInfo& extensions_info,
|
| + const std::set<std::string>& new_extensions,
|
| + scoped_refptr<ContentVerifier> verifier,
|
| + LoadScriptsCallback callback) {
|
| + DCHECK(user_scripts.get());
|
| + LoadUserScripts(
|
| + user_scripts.get(), extensions_info, new_extensions, verifier);
|
| + scoped_ptr<base::SharedMemory> memory = Serialize(*user_scripts);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory)));
|
| +}
|
| +
|
| UserScriptMaster::UserScriptMaster(Profile* profile)
|
| : user_scripts_(new UserScriptList()),
|
| extensions_service_ready_(false),
|
| pending_load_(false),
|
| profile_(profile),
|
| - extension_registry_observer_(this),
|
| weak_factory_(this) {
|
| - extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
|
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
|
| - content::Source<Profile>(profile_));
|
| - registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
|
| - content::NotificationService::AllBrowserContextsAndSources());
|
| }
|
|
|
| UserScriptMaster::~UserScriptMaster() {
|
| @@ -401,125 +390,6 @@ void UserScriptMaster::OnScriptsLoaded(
|
| content::Details<base::SharedMemory>(shared_memory_.get()));
|
| }
|
|
|
| -void UserScriptMaster::OnExtensionLoaded(
|
| - content::BrowserContext* browser_context,
|
| - const Extension* extension) {
|
| - added_extensions_.insert(extension->id());
|
| - removed_extensions_.erase(extension->id());
|
| - extensions_info_[extension->id()] =
|
| - ExtensionSet::ExtensionPathAndDefaultLocale(
|
| - extension->path(), LocaleInfo::GetDefaultLocale(extension));
|
| - if (extensions_service_ready_) {
|
| - changed_extensions_.insert(extension->id());
|
| - if (is_loading())
|
| - pending_load_ = true;
|
| - else
|
| - StartLoad();
|
| - }
|
| -}
|
| -
|
| -void UserScriptMaster::OnExtensionUnloaded(
|
| - content::BrowserContext* browser_context,
|
| - const Extension* extension,
|
| - UnloadedExtensionInfo::Reason reason) {
|
| - removed_extensions_.insert(extension->id());
|
| - added_extensions_.erase(extension->id());
|
| - // Remove any content scripts.
|
| - extensions_info_.erase(extension->id());
|
| - changed_extensions_.insert(extension->id());
|
| - if (is_loading())
|
| - pending_load_ = true;
|
| - else
|
| - StartLoad();
|
| -}
|
| -
|
| -void UserScriptMaster::Observe(int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) {
|
| - bool should_start_load = false;
|
| - switch (type) {
|
| - case chrome::NOTIFICATION_EXTENSIONS_READY:
|
| - extensions_service_ready_ = true;
|
| - should_start_load = true;
|
| - break;
|
| - case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
|
| - content::RenderProcessHost* process =
|
| - content::Source<content::RenderProcessHost>(source).ptr();
|
| - Profile* profile = Profile::FromBrowserContext(
|
| - process->GetBrowserContext());
|
| - if (!profile_->IsSameProfile(profile))
|
| - return;
|
| - if (ScriptsReady()) {
|
| - SendUpdate(process,
|
| - GetSharedMemory(),
|
| - std::set<std::string>()); // Include all extensions.
|
| - }
|
| - break;
|
| - }
|
| - default:
|
| - DCHECK(false);
|
| - }
|
| -
|
| - if (should_start_load) {
|
| - if (is_loading())
|
| - pending_load_ = true;
|
| - else
|
| - StartLoad();
|
| - }
|
| -}
|
| -
|
| -void UserScriptMaster::StartLoad() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK(!is_loading());
|
| -
|
| - // Remove any user scripts belonging to any extension that was updated or
|
| - // removed.
|
| - for (UserScriptList::iterator iter = user_scripts_->begin();
|
| - iter != user_scripts_->end();) {
|
| - if (removed_extensions_.count(iter->extension_id()) > 0 ||
|
| - added_extensions_.count(iter->extension_id()) > 0) {
|
| - iter = user_scripts_->erase(iter);
|
| - } else {
|
| - ++iter;
|
| - }
|
| - }
|
| -
|
| - // Add any content scripts for extensions that were recently loaded.
|
| - const ExtensionSet& enabled_extensions =
|
| - ExtensionRegistry::Get(profile_)->enabled_extensions();
|
| - for (std::set<std::string>::const_iterator iter = added_extensions_.begin();
|
| - iter != added_extensions_.end(); ++iter) {
|
| - const Extension* extension = enabled_extensions.GetByID(*iter);
|
| - if (!extension)
|
| - continue;
|
| - bool incognito_enabled =
|
| - util::IsIncognitoEnabled(extension->id(), profile_);
|
| - const UserScriptList& scripts =
|
| - ContentScriptsInfo::GetContentScripts(extension);
|
| - for (UserScriptList::const_iterator script = scripts.begin();
|
| - script != scripts.end();
|
| - ++script) {
|
| - user_scripts_->push_back(*script);
|
| - user_scripts_->back().set_incognito_enabled(incognito_enabled);
|
| - }
|
| - }
|
| -
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE,
|
| - FROM_HERE,
|
| - base::Bind(&LoadScriptsOnFileThread,
|
| - base::Passed(&user_scripts_),
|
| - extensions_info_,
|
| - added_extensions_,
|
| - make_scoped_refptr(
|
| - ExtensionSystem::Get(profile_)->content_verifier()),
|
| - base::Bind(&UserScriptMaster::OnScriptsLoaded,
|
| - weak_factory_.GetWeakPtr())));
|
| - added_extensions_.clear();
|
| - removed_extensions_.clear();
|
| - user_scripts_.reset(NULL);
|
| -}
|
| -
|
| void UserScriptMaster::SendUpdate(
|
| content::RenderProcessHost* process,
|
| base::SharedMemory* shared_memory,
|
| @@ -545,7 +415,7 @@ void UserScriptMaster::SendUpdate(
|
|
|
| if (base::SharedMemory::IsHandleValid(handle_for_process)) {
|
| process->Send(new ExtensionMsg_UpdateUserScripts(
|
| - handle_for_process, "" /* owner */, changed_extensions));
|
| + handle_for_process, owner_extension_id_, changed_extensions));
|
| }
|
| }
|
|
|
|
|