OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/unpacked_installer.h" | 5 #include "chrome/browser/extensions/unpacked_installer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( | 88 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( |
89 ExtensionService* extension_service) { | 89 ExtensionService* extension_service) { |
90 return scoped_refptr<UnpackedInstaller>( | 90 return scoped_refptr<UnpackedInstaller>( |
91 new UnpackedInstaller(extension_service)); | 91 new UnpackedInstaller(extension_service)); |
92 } | 92 } |
93 | 93 |
94 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) | 94 UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service) |
95 : service_weak_(extension_service->AsWeakPtr()), | 95 : service_weak_(extension_service->AsWeakPtr()), |
96 prompt_for_plugins_(true), | 96 prompt_for_plugins_(true), |
97 require_modern_manifest_version_(true), | 97 require_modern_manifest_version_(true), |
98 launch_on_load_(false), | |
99 installer_(extension_service->profile()) { | 98 installer_(extension_service->profile()) { |
100 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
101 } | 100 } |
102 | 101 |
103 UnpackedInstaller::~UnpackedInstaller() { | 102 UnpackedInstaller::~UnpackedInstaller() { |
104 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 103 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
105 BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 104 BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
106 } | 105 } |
107 | 106 |
108 void UnpackedInstaller::Load(const base::FilePath& path_in) { | 107 void UnpackedInstaller::Load(const base::FilePath& path_in) { |
109 DCHECK(extension_path_.empty()); | 108 DCHECK(extension_path_.empty()); |
110 extension_path_ = path_in; | 109 extension_path_ = path_in; |
111 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
112 BrowserThread::FILE, | 111 BrowserThread::FILE, |
113 FROM_HERE, | 112 FROM_HERE, |
114 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); | 113 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); |
115 } | 114 } |
116 | 115 |
117 void UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, | 116 bool UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, |
118 bool launch_on_load) { | 117 std::string* extension_id) { |
119 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 DCHECK(extension_path_.empty()); | 119 DCHECK(extension_path_.empty()); |
121 | 120 |
122 if (!service_weak_) | 121 if (!service_weak_) |
123 return; | 122 return false; |
124 // Load extensions from the command line synchronously to avoid a race | 123 // Load extensions from the command line synchronously to avoid a race |
125 // between extension loading and loading an URL from the command line. | 124 // between extension loading and loading an URL from the command line. |
126 base::ThreadRestrictions::ScopedAllowIO allow_io; | 125 base::ThreadRestrictions::ScopedAllowIO allow_io; |
127 | 126 |
128 extension_path_ = base::MakeAbsoluteFilePath(path_in); | 127 extension_path_ = base::MakeAbsoluteFilePath(path_in); |
129 | 128 |
130 if (!IsLoadingUnpackedAllowed()) { | 129 if (!IsLoadingUnpackedAllowed()) { |
131 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 130 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
132 return; | 131 return false; |
133 } | 132 } |
134 | 133 |
135 std::string error; | 134 std::string error; |
136 installer_.set_extension(extension_file_util::LoadExtension( | 135 installer_.set_extension(extension_file_util::LoadExtension( |
137 extension_path_, | 136 extension_path_, |
138 Manifest::COMMAND_LINE, | 137 Manifest::COMMAND_LINE, |
139 GetFlags(), | 138 GetFlags(), |
140 &error)); | 139 &error)); |
141 | 140 |
142 if (!installer_.extension()) { | 141 if (!installer_.extension()) { |
143 ReportExtensionLoadError(error); | 142 ReportExtensionLoadError(error); |
144 return; | 143 return false; |
145 } | 144 } |
146 | 145 |
147 launch_on_load_ = launch_on_load; | 146 ShowInstallPrompt(); |
148 | 147 |
149 ShowInstallPrompt(); | 148 *extension_id = installer_.extension()->id(); |
| 149 return true; |
150 } | 150 } |
151 | 151 |
152 void UnpackedInstaller::ShowInstallPrompt() { | 152 void UnpackedInstaller::ShowInstallPrompt() { |
153 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
154 if (!service_weak_) | 154 if (!service_weak_) |
155 return; | 155 return; |
156 | 156 |
157 const ExtensionSet* disabled_extensions = | 157 const ExtensionSet* disabled_extensions = |
158 service_weak_->disabled_extensions(); | 158 service_weak_->disabled_extensions(); |
159 if (service_weak_->show_extensions_prompts() && | 159 if (service_weak_->show_extensions_prompts() && |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
275 string16 error = installer_.CheckManagementPolicy(); | 275 string16 error = installer_.CheckManagementPolicy(); |
276 if (!error.empty()) { | 276 if (!error.empty()) { |
277 ReportExtensionLoadError(UTF16ToUTF8(error)); | 277 ReportExtensionLoadError(UTF16ToUTF8(error)); |
278 return; | 278 return; |
279 } | 279 } |
280 | 280 |
281 PermissionsUpdater perms_updater(service_weak_->profile()); | 281 PermissionsUpdater perms_updater(service_weak_->profile()); |
282 perms_updater.GrantActivePermissions(installer_.extension()); | 282 perms_updater.GrantActivePermissions(installer_.extension()); |
283 | 283 |
284 if (launch_on_load_) | |
285 service_weak_->ScheduleLaunchOnLoad(installer_.extension()->id()); | |
286 | |
287 service_weak_->OnExtensionInstalled( | 284 service_weak_->OnExtensionInstalled( |
288 installer_.extension(), | 285 installer_.extension(), |
289 syncer::StringOrdinal(), | 286 syncer::StringOrdinal(), |
290 false /* no requirement errors */, | 287 false /* no requirement errors */, |
291 false /* don't wait for idle */); | 288 false /* don't wait for idle */); |
292 } | 289 } |
293 | 290 |
294 } // namespace extensions | 291 } // namespace extensions |
OLD | NEW |