OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/extensions/extension_loader_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ui_ready_ = true; | 212 ui_ready_ = true; |
213 | 213 |
214 // Notify the frontend of any load failures that were triggered while the | 214 // Notify the frontend of any load failures that were triggered while the |
215 // chrome://extensions page was loading. | 215 // chrome://extensions page was loading. |
216 if (!failures_.empty()) | 216 if (!failures_.empty()) |
217 NotifyFrontendOfFailure(); | 217 NotifyFrontendOfFailure(); |
218 } | 218 } |
219 | 219 |
220 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( | 220 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( |
221 const base::FilePath& file_path) { | 221 const base::FilePath& file_path) { |
222 if (EndsWith(file_path.AsUTF16Unsafe(), | 222 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( |
223 base::ASCIIToUTF16(".zip"), | 223 ExtensionSystem::Get(profile_)->extension_service()); |
224 false /* case insensitive */)) { | |
225 scoped_refptr<ZipFileInstaller> installer = ZipFileInstaller::Create( | |
226 ExtensionSystem::Get(profile_)->extension_service()); | |
227 | 224 |
228 // We do our own error handling, so we don't want a load failure to trigger | 225 // We do our own error handling, so we don't want a load failure to trigger |
229 // a dialog. | 226 // a dialog. |
230 installer->set_be_noisy_on_failure(false); | 227 installer->set_be_noisy_on_failure(false); |
231 | 228 |
232 installer->LoadFromZipFile(file_path); | 229 installer->Load(file_path); |
233 } else { | |
234 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( | |
235 ExtensionSystem::Get(profile_)->extension_service()); | |
236 | |
237 // We do our own error handling, so we don't want a load failure to trigger | |
238 // a dialog. | |
239 installer->set_be_noisy_on_failure(false); | |
240 | |
241 installer->Load(file_path); | |
242 } | |
243 } | 230 } |
244 | 231 |
245 void ExtensionLoaderHandler::OnLoadFailure( | 232 void ExtensionLoaderHandler::OnLoadFailure( |
246 content::BrowserContext* browser_context, | 233 content::BrowserContext* browser_context, |
247 const base::FilePath& file_path, | 234 const base::FilePath& file_path, |
248 const std::string& error) { | 235 const std::string& error) { |
249 // Only show errors from our browser context. | 236 // Only show errors from our browser context. |
250 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context) | 237 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context) |
251 return; | 238 return; |
252 | 239 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 301 } |
315 | 302 |
316 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { | 303 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { |
317 web_ui()->CallJavascriptFunction( | 304 web_ui()->CallJavascriptFunction( |
318 "extensions.ExtensionLoader.notifyLoadFailed", | 305 "extensions.ExtensionLoader.notifyLoadFailed", |
319 failures_); | 306 failures_); |
320 failures_.Clear(); | 307 failures_.Clear(); |
321 } | 308 } |
322 | 309 |
323 } // namespace extensions | 310 } // namespace extensions |
OLD | NEW |