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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_loader_handler.cc

Issue 406713002: Allow drag-and-drop of zipped extensions on chrome://extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add zipfile installer Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/extensions/path_util.h" 15 #include "chrome/browser/extensions/path_util.h"
16 #include "chrome/browser/extensions/unpacked_installer.h" 16 #include "chrome/browser/extensions/unpacked_installer.h"
17 #include "chrome/browser/extensions/zipfile_installer.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/chrome_select_file_policy.h" 19 #include "chrome/browser/ui/chrome_select_file_policy.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/user_metrics.h" 21 #include "content/public/browser/user_metrics.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
23 #include "content/public/browser/web_ui_data_source.h" 24 #include "content/public/browser/web_ui_data_source.h"
24 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
25 #include "extensions/browser/file_highlighter.h" 26 #include "extensions/browser/file_highlighter.h"
26 #include "extensions/common/constants.h" 27 #include "extensions/common/constants.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ui_ready_ = true; 212 ui_ready_ = true;
212 213
213 // 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
214 // chrome://extensions page was loading. 215 // chrome://extensions page was loading.
215 if (!failures_.empty()) 216 if (!failures_.empty())
216 NotifyFrontendOfFailure(); 217 NotifyFrontendOfFailure();
217 } 218 }
218 219
219 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( 220 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl(
220 const base::FilePath& file_path) { 221 const base::FilePath& file_path) {
221 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( 222 if (EndsWith(file_path.AsUTF16Unsafe(),
222 ExtensionSystem::Get(profile_)->extension_service()); 223 base::ASCIIToUTF16(".zip"),
224 false /* case insensitive */)) {
225 scoped_refptr<ZipFileInstaller> installer = ZipFileInstaller::Create(
226 ExtensionSystem::Get(profile_)->extension_service());
223 227
224 // We do our own error handling, so we don't want a load failure to trigger 228 // We do our own error handling, so we don't want a load failure to trigger
225 // a dialog. 229 // a dialog.
226 installer->set_be_noisy_on_failure(false); 230 installer->set_be_noisy_on_failure(false);
227 231
228 installer->Load(file_path); 232 installer->LoadFromZipFile(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 }
229 } 243 }
230 244
231 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path, 245 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path,
232 const std::string& error) { 246 const std::string& error) {
233 size_t line = 0u; 247 size_t line = 0u;
234 size_t column = 0u; 248 size_t column = 0u;
235 std::string regex = 249 std::string regex =
236 base::StringPrintf("%s Line: (\\d+), column: (\\d+), Syntax error.", 250 base::StringPrintf("%s Line: (\\d+), column: (\\d+), Syntax error.",
237 manifest_errors::kManifestParseError); 251 manifest_errors::kManifestParseError);
238 // If this was a JSON parse error, we can highlight the exact line with the 252 // If this was a JSON parse error, we can highlight the exact line with the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 291
278 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue()); 292 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue());
279 SourceHighlighter highlighter(manifest, line_number); 293 SourceHighlighter highlighter(manifest, line_number);
280 // If the line number is 0, this highlights no regions, but still adds the 294 // If the line number is 0, this highlights no regions, but still adds the
281 // full manifest. 295 // full manifest.
282 highlighter.SetHighlightedRegions(manifest_value.get()); 296 highlighter.SetHighlightedRegions(manifest_value.get());
283 297
284 scoped_ptr<base::DictionaryValue> failure(new base::DictionaryValue()); 298 scoped_ptr<base::DictionaryValue> failure(new base::DictionaryValue());
285 failure->Set("path", 299 failure->Set("path",
286 new base::StringValue(prettified_path.LossyDisplayName())); 300 new base::StringValue(prettified_path.LossyDisplayName()));
287 failure->Set("error", new base::StringValue(base::UTF8ToUTF16(error))); 301 failure->Set("reason", new base::StringValue(base::UTF8ToUTF16(error)));
elijahtaylor1 2014/07/31 17:26:28 this is a bug fix for the unpacked extension loade
288 failure->Set("manifest", manifest_value.release()); 302 failure->Set("manifest", manifest_value.release());
289 failures_.Append(failure.release()); 303 failures_.Append(failure.release());
290 304
291 // Only notify the frontend if the frontend UI is ready. 305 // Only notify the frontend if the frontend UI is ready.
292 if (ui_ready_) 306 if (ui_ready_)
293 NotifyFrontendOfFailure(); 307 NotifyFrontendOfFailure();
294 } 308 }
295 309
296 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { 310 void ExtensionLoaderHandler::NotifyFrontendOfFailure() {
297 web_ui()->CallJavascriptFunction( 311 web_ui()->CallJavascriptFunction(
298 "extensions.ExtensionLoader.notifyLoadFailed", 312 "extensions.ExtensionLoader.notifyLoadFailed",
299 failures_); 313 failures_);
300 failures_.Clear(); 314 failures_.Clear();
301 } 315 }
302 316
303 } // namespace extensions 317 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698