Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/extensions/extensions_service.cc

Issue 18198: Add user script support to extensions. (Closed)
Patch Set: Compile fixes for linux and mac Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extensions_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/user_script_master.h"
12 #include "chrome/common/json_value_serializer.h" 13 #include "chrome/common/json_value_serializer.h"
13 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
14 15
15 // ExtensionsService 16 // ExtensionsService
16 17
17 const FilePath::CharType* ExtensionsService::kInstallDirectoryName = 18 const FilePath::CharType* ExtensionsService::kInstallDirectoryName =
18 FILE_PATH_LITERAL("Extensions"); 19 FILE_PATH_LITERAL("Extensions");
19 20
20 ExtensionsService::ExtensionsService(const FilePath& profile_directory) 21 ExtensionsService::ExtensionsService(const FilePath& profile_directory,
22 UserScriptMaster* user_script_master)
21 : message_loop_(MessageLoop::current()), 23 : message_loop_(MessageLoop::current()),
22 backend_(new ExtensionsServiceBackend), 24 backend_(new ExtensionsServiceBackend),
23 install_directory_(profile_directory.Append(kInstallDirectoryName)) { 25 install_directory_(profile_directory.Append(kInstallDirectoryName)),
26 user_script_master_(user_script_master) {
24 } 27 }
25 28
26 ExtensionsService::~ExtensionsService() { 29 ExtensionsService::~ExtensionsService() {
27 for (ExtensionList::iterator iter = extensions_.begin(); 30 for (ExtensionList::iterator iter = extensions_.begin();
28 iter != extensions_.end(); ++iter) { 31 iter != extensions_.end(); ++iter) {
29 delete *iter; 32 delete *iter;
30 } 33 }
31 } 34 }
32 35
33 bool ExtensionsService::Init() { 36 bool ExtensionsService::Init() {
(...skipping 12 matching lines...) Expand all
46 49
47 MessageLoop* ExtensionsService::GetMessageLoop() { 50 MessageLoop* ExtensionsService::GetMessageLoop() {
48 return message_loop_; 51 return message_loop_;
49 } 52 }
50 53
51 void ExtensionsService::OnExtensionsLoadedFromDirectory( 54 void ExtensionsService::OnExtensionsLoadedFromDirectory(
52 ExtensionList* new_extensions) { 55 ExtensionList* new_extensions) {
53 extensions_.insert(extensions_.end(), new_extensions->begin(), 56 extensions_.insert(extensions_.end(), new_extensions->begin(),
54 new_extensions->end()); 57 new_extensions->end());
55 58
59 // Tell UserScriptMaster about any scripts in the loaded extensions.
60 for (ExtensionList::iterator extension = extensions_.begin();
61 extension != extensions_.end(); ++extension) {
62 const UserScriptList& scripts = (*extension)->user_scripts();
63 for (UserScriptList::const_iterator script = scripts.begin();
64 script != scripts.end(); ++script) {
65 user_script_master_->AddLoneScript(*script);
66 }
67 }
68
69 // Tell UserScriptMaster to also watch the extensions directory for changes
70 // and then kick off the first scan.
71 // TODO(aa): This should go away when we implement the --extension flag, since
72 // developing scripts in the Extensions directory will no longer be a common
73 // use-case.
74 user_script_master_->AddWatchedPath(install_directory_);
75 user_script_master_->StartScan();
76
56 NotificationService::current()->Notify(NOTIFY_EXTENSIONS_LOADED, 77 NotificationService::current()->Notify(NOTIFY_EXTENSIONS_LOADED,
57 NotificationService::AllSources(), 78 NotificationService::AllSources(),
58 Details<ExtensionList>(new_extensions)); 79 Details<ExtensionList>(new_extensions));
59 80
60 delete new_extensions; 81 delete new_extensions;
61 } 82 }
62 83
63 void ExtensionsService::OnExtensionLoadError(const std::string& error) { 84 void ExtensionsService::OnExtensionLoadError(const std::string& error) {
64 // TODO(aa): Print the error message out somewhere better. I think we are 85 // TODO(aa): Print the error message out somewhere better. I think we are
65 // going to need some sort of 'extension inspector'. 86 // going to need some sort of 'extension inspector'.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 message)); 153 message));
133 } 154 }
134 155
135 void ExtensionsServiceBackend::ReportExtensionsLoaded( 156 void ExtensionsServiceBackend::ReportExtensionsLoaded(
136 ExtensionsServiceFrontendInterface *frontend, ExtensionList* extensions) { 157 ExtensionsServiceFrontendInterface *frontend, ExtensionList* extensions) {
137 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod( 158 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod(
138 frontend, 159 frontend,
139 &ExtensionsServiceFrontendInterface::OnExtensionsLoadedFromDirectory, 160 &ExtensionsServiceFrontendInterface::OnExtensionsLoadedFromDirectory,
140 extensions)); 161 extensions));
141 } 162 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.h ('k') | chrome/browser/extensions/user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698