Chromium Code Reviews| 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/file_util.h" | 8 #include "base/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 13 matching lines...) Expand all Loading... | |
| 24 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/browser/file_highlighter.h" | 25 #include "extensions/browser/file_highlighter.h" |
| 26 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
| 27 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/manifest_constants.h" | 28 #include "extensions/common/manifest_constants.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "third_party/re2/re2/re2.h" | 30 #include "third_party/re2/re2/re2.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/shell_dialogs/select_file_dialog.h" | 32 #include "ui/shell_dialogs/select_file_dialog.h" |
| 33 | 33 |
| 34 class ExtensionErrorReporter; | |
|
Devlin
2014/06/24 22:21:12
Don't need to forward declare classes either forwa
| |
| 35 class ExtensionErrorReporterObserver; | |
| 36 | |
| 34 namespace extensions { | 37 namespace extensions { |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 // Read a file to a string and return. | 41 // Read a file to a string and return. |
| 39 std::string ReadFileToString(const base::FilePath& path) { | 42 std::string ReadFileToString(const base::FilePath& path) { |
| 40 std::string data; | 43 std::string data; |
| 41 // This call can fail, but it doesn't matter for our purposes. If it fails, | 44 // This call can fail, but it doesn't matter for our purposes. If it fails, |
| 42 // we simply return an empty string for the manifest, and ignore it. | 45 // we simply return an empty string for the manifest, and ignore it. |
| 43 base::ReadFileToString(path, &data); | 46 base::ReadFileToString(path, &data); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 } | 127 } |
| 125 | 128 |
| 126 void ExtensionLoaderHandler::FileHelper::MultiFilesSelected( | 129 void ExtensionLoaderHandler::FileHelper::MultiFilesSelected( |
| 127 const std::vector<base::FilePath>& files, void* params) { | 130 const std::vector<base::FilePath>& files, void* params) { |
| 128 NOTREACHED(); | 131 NOTREACHED(); |
| 129 } | 132 } |
| 130 | 133 |
| 131 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile) | 134 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile) |
| 132 : profile_(profile), | 135 : profile_(profile), |
| 133 file_helper_(new FileHelper(this)), | 136 file_helper_(new FileHelper(this)), |
| 134 weak_ptr_factory_(this) { | 137 weak_ptr_factory_(this), |
| 138 extension_error_reporter_observer_(this) { | |
| 135 DCHECK(profile_); | 139 DCHECK(profile_); |
| 140 extension_error_reporter_observer_.Add(ExtensionErrorReporter::GetInstance()); | |
| 136 } | 141 } |
| 137 | 142 |
| 138 ExtensionLoaderHandler::~ExtensionLoaderHandler() { | 143 ExtensionLoaderHandler::~ExtensionLoaderHandler() { |
| 139 } | 144 } |
| 140 | 145 |
| 141 void ExtensionLoaderHandler::GetLocalizedValues( | 146 void ExtensionLoaderHandler::GetLocalizedValues( |
| 142 content::WebUIDataSource* source) { | 147 content::WebUIDataSource* source) { |
| 143 source->AddString( | 148 source->AddString( |
| 144 "extensionLoadErrorHeading", | 149 "extensionLoadErrorHeading", |
| 145 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING)); | 150 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING)); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 175 | 180 |
| 176 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { | 181 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { |
| 177 DCHECK(args->empty()); | 182 DCHECK(args->empty()); |
| 178 LoadUnpackedExtensionImpl(failed_path_); | 183 LoadUnpackedExtensionImpl(failed_path_); |
| 179 } | 184 } |
| 180 | 185 |
| 181 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( | 186 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( |
| 182 const base::FilePath& file_path) { | 187 const base::FilePath& file_path) { |
| 183 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( | 188 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( |
| 184 ExtensionSystem::Get(profile_)->extension_service()); | 189 ExtensionSystem::Get(profile_)->extension_service()); |
| 185 installer->set_on_failure_callback( | |
| 186 base::Bind(&ExtensionLoaderHandler::OnLoadFailure, | |
| 187 weak_ptr_factory_.GetWeakPtr())); | |
| 188 | 190 |
| 189 // We do our own error handling, so we don't want a load failure to trigger | 191 // We do our own error handling, so we don't want a load failure to trigger |
| 190 // a dialog. | 192 // a dialog. |
| 191 installer->set_be_noisy_on_failure(false); | 193 installer->set_be_noisy_on_failure(false); |
| 192 | 194 |
| 193 installer->Load(file_path); | 195 installer->Load(file_path); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path, | 198 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path, |
| 197 const std::string& error) { | 199 const std::string& error) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 const std::string& manifest) { | 231 const std::string& manifest) { |
| 230 base::StringValue file_value(file_path.LossyDisplayName()); | 232 base::StringValue file_value(file_path.LossyDisplayName()); |
| 231 base::StringValue error_value(base::UTF8ToUTF16(error)); | 233 base::StringValue error_value(base::UTF8ToUTF16(error)); |
| 232 | 234 |
| 233 base::DictionaryValue manifest_value; | 235 base::DictionaryValue manifest_value; |
| 234 SourceHighlighter highlighter(manifest, line_number); | 236 SourceHighlighter highlighter(manifest, line_number); |
| 235 // If the line number is 0, this highlights no regions, but still adds the | 237 // If the line number is 0, this highlights no regions, but still adds the |
| 236 // full manifest. | 238 // full manifest. |
| 237 highlighter.SetHighlightedRegions(&manifest_value); | 239 highlighter.SetHighlightedRegions(&manifest_value); |
| 238 | 240 |
| 239 web_ui()->CallJavascriptFunction( | 241 web_ui()->CallJavascriptFunction( |
|
gpdavis
2014/06/21 01:22:07
There is an issue with synchronicity here. On a p
Devlin
2014/06/24 22:21:12
What I would envision would be keeping track of al
gpdavis
2014/06/25 00:21:01
The current behavior is that only the last one is
Devlin
2014/06/25 19:49:36
Sorry, I was unclear. By "current behavior", I me
Devlin
2014/06/27 22:31:08
Still waiting on an answer for current behavior?
| |
| 240 "extensions.ExtensionLoader.notifyLoadFailed", | 242 "extensions.ExtensionLoader.notifyLoadFailed", |
| 241 file_value, | 243 file_value, |
| 242 error_value, | 244 error_value, |
| 243 manifest_value); | 245 manifest_value); |
| 244 } | 246 } |
| 245 | 247 |
| 246 } // namespace extensions | 248 } // namespace extensions |
| OLD | NEW |