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

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: rebase 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( 245 void ExtensionLoaderHandler::OnLoadFailure(
232 content::BrowserContext* browser_context, 246 content::BrowserContext* browser_context,
233 const base::FilePath& file_path, 247 const base::FilePath& file_path,
234 const std::string& error) { 248 const std::string& error) {
235 // Only show errors from our browser context. 249 // Only show errors from our browser context.
236 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context) 250 if (web_ui()->GetWebContents()->GetBrowserContext() != browser_context)
237 return; 251 return;
238 252
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 297
284 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue()); 298 scoped_ptr<base::DictionaryValue> manifest_value(new base::DictionaryValue());
285 SourceHighlighter highlighter(manifest, line_number); 299 SourceHighlighter highlighter(manifest, line_number);
286 // If the line number is 0, this highlights no regions, but still adds the 300 // If the line number is 0, this highlights no regions, but still adds the
287 // full manifest. 301 // full manifest.
288 highlighter.SetHighlightedRegions(manifest_value.get()); 302 highlighter.SetHighlightedRegions(manifest_value.get());
289 303
290 scoped_ptr<base::DictionaryValue> failure(new base::DictionaryValue()); 304 scoped_ptr<base::DictionaryValue> failure(new base::DictionaryValue());
291 failure->Set("path", 305 failure->Set("path",
292 new base::StringValue(prettified_path.LossyDisplayName())); 306 new base::StringValue(prettified_path.LossyDisplayName()));
293 failure->Set("error", new base::StringValue(base::UTF8ToUTF16(error))); 307 failure->Set("reason", new base::StringValue(base::UTF8ToUTF16(error)));
Devlin 2014/08/11 15:58:01 This looks like a merge conflict resolution gone w
294 failure->Set("manifest", manifest_value.release()); 308 failure->Set("manifest", manifest_value.release());
295 failures_.Append(failure.release()); 309 failures_.Append(failure.release());
296 310
297 // Only notify the frontend if the frontend UI is ready. 311 // Only notify the frontend if the frontend UI is ready.
298 if (ui_ready_) 312 if (ui_ready_)
299 NotifyFrontendOfFailure(); 313 NotifyFrontendOfFailure();
300 } 314 }
301 315
302 void ExtensionLoaderHandler::NotifyFrontendOfFailure() { 316 void ExtensionLoaderHandler::NotifyFrontendOfFailure() {
303 web_ui()->CallJavascriptFunction( 317 web_ui()->CallJavascriptFunction(
304 "extensions.ExtensionLoader.notifyLoadFailed", 318 "extensions.ExtensionLoader.notifyLoadFailed",
305 failures_); 319 failures_);
306 failures_.Clear(); 320 failures_.Clear();
307 } 321 }
308 322
309 } // namespace extensions 323 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/resources/extensions/extensions.js ('k') | chrome/browser/ui/webui/extensions/install_extension_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698