OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/install_extension_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 if (drop_data->filenames.empty()) { | 72 if (drop_data->filenames.empty()) { |
73 DLOG(ERROR) << "Current drop data contains no files."; | 73 DLOG(ERROR) << "Current drop data contains no files."; |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 const ui::FileInfo& file_info = drop_data->filenames.front(); | 77 const ui::FileInfo& file_info = drop_data->filenames.front(); |
78 | 78 |
79 file_to_install_ = file_info.path; | 79 file_to_install_ = file_info.path; |
80 // Use the display name if provided, for checking file names | 80 // Use the display name if provided, for checking file names |
81 // (.path is likely a random hash value in that case). | 81 // (.path is likely a random hash value in that case). |
82 // TODO(dcheng): It would be nice to make this a FilePath too. | 82 file_display_name_ = |
not at google - send to devlin
2015/05/11 18:06:07
I don't understand this TODO and disagree with thi
| |
83 file_display_name_ = file_info.display_name.empty() | 83 file_info.display_name.empty() ? file_info.path : file_info.display_name; |
84 ? file_info.path.AsUTF16Unsafe() | |
85 : file_info.display_name.AsUTF16Unsafe(); | |
86 } | 84 } |
87 | 85 |
88 void InstallExtensionHandler::HandleStopDragMessage( | 86 void InstallExtensionHandler::HandleStopDragMessage( |
89 const base::ListValue* args) { | 87 const base::ListValue* args) { |
90 file_to_install_.clear(); | 88 file_to_install_.clear(); |
91 file_display_name_.clear(); | 89 file_display_name_.clear(); |
92 } | 90 } |
93 | 91 |
94 void InstallExtensionHandler::HandleInstallMessage( | 92 void InstallExtensionHandler::HandleInstallMessage( |
95 const base::ListValue* args) { | 93 const base::ListValue* args) { |
96 if (file_to_install_.empty()) { | 94 if (file_to_install_.empty()) { |
97 LOG(ERROR) << "No file captured to install."; | 95 LOG(ERROR) << "No file captured to install."; |
98 return; | 96 return; |
99 } | 97 } |
100 | 98 |
101 Profile* profile = Profile::FromBrowserContext( | 99 Profile* profile = Profile::FromBrowserContext( |
102 web_ui()->GetWebContents()->GetBrowserContext()); | 100 web_ui()->GetWebContents()->GetBrowserContext()); |
103 | 101 |
104 const bool kCaseSensitive = false; | 102 const bool kCaseSensitive = false; |
105 | 103 |
106 if (EndsWith( | 104 if (EndsWith(file_display_name_.AsUTF16Unsafe(), base::ASCIIToUTF16(".zip"), |
dcheng
2015/05/11 18:16:15
Why not FilePath::MatchesExtension()?
That being
not at google - send to devlin
2015/05/11 18:28:32
Using MatchesExtension would make this change much
Deepak
2015/05/12 05:41:58
I agree with you, Anyways kCaseSensitive value is
| |
107 file_display_name_, base::ASCIIToUTF16(".zip"), kCaseSensitive)) { | 105 kCaseSensitive)) { |
108 ZipFileInstaller::Create(ExtensionSystem::Get(profile)->extension_service()) | 106 ZipFileInstaller::Create(ExtensionSystem::Get(profile)->extension_service()) |
109 ->LoadFromZipFile(file_to_install_); | 107 ->LoadFromZipFile(file_to_install_); |
110 } else { | 108 } else { |
111 scoped_ptr<ExtensionInstallPrompt> prompt( | 109 scoped_ptr<ExtensionInstallPrompt> prompt( |
112 new ExtensionInstallPrompt(web_ui()->GetWebContents())); | 110 new ExtensionInstallPrompt(web_ui()->GetWebContents())); |
113 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( | 111 scoped_refptr<CrxInstaller> crx_installer(CrxInstaller::Create( |
114 ExtensionSystem::Get(profile)->extension_service(), prompt.Pass())); | 112 ExtensionSystem::Get(profile)->extension_service(), prompt.Pass())); |
115 crx_installer->set_error_on_unsupported_requirements(true); | 113 crx_installer->set_error_on_unsupported_requirements(true); |
116 crx_installer->set_off_store_install_allow_reason( | 114 crx_installer->set_off_store_install_allow_reason( |
117 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); | 115 CrxInstaller::OffStoreInstallAllowedFromSettingsPage); |
118 crx_installer->set_install_immediately(true); | 116 crx_installer->set_install_immediately(true); |
119 | 117 |
120 if (EndsWith(file_display_name_, | 118 if (EndsWith(file_display_name_.AsUTF16Unsafe(), |
121 base::ASCIIToUTF16(".user.js"), | 119 base::ASCIIToUTF16(".user.js"), kCaseSensitive)) { |
122 kCaseSensitive)) { | |
123 crx_installer->InstallUserScript( | 120 crx_installer->InstallUserScript( |
124 file_to_install_, net::FilePathToFileURL(file_to_install_)); | 121 file_to_install_, net::FilePathToFileURL(file_to_install_)); |
125 } else if (EndsWith(file_display_name_, | 122 } else if (EndsWith(file_display_name_.AsUTF16Unsafe(), |
126 base::ASCIIToUTF16(".crx"), | 123 base::ASCIIToUTF16(".crx"), kCaseSensitive)) { |
127 kCaseSensitive)) { | |
128 crx_installer->InstallCrx(file_to_install_); | 124 crx_installer->InstallCrx(file_to_install_); |
129 } else { | 125 } else { |
130 CHECK(false); | 126 CHECK(false); |
131 } | 127 } |
132 } | 128 } |
133 | 129 |
134 file_to_install_.clear(); | 130 file_to_install_.clear(); |
135 file_display_name_.clear(); | 131 file_display_name_.clear(); |
136 } | 132 } |
137 | 133 |
138 void InstallExtensionHandler::HandleInstallDirectoryMessage( | 134 void InstallExtensionHandler::HandleInstallDirectoryMessage( |
139 const base::ListValue* args) { | 135 const base::ListValue* args) { |
140 Profile* profile = Profile::FromBrowserContext( | 136 Profile* profile = Profile::FromBrowserContext( |
141 web_ui()->GetWebContents()->GetBrowserContext()); | 137 web_ui()->GetWebContents()->GetBrowserContext()); |
142 UnpackedInstaller::Create( | 138 UnpackedInstaller::Create( |
143 ExtensionSystem::Get(profile)-> | 139 ExtensionSystem::Get(profile)-> |
144 extension_service())->Load(file_to_install_); | 140 extension_service())->Load(file_to_install_); |
145 } | 141 } |
146 | 142 |
147 } // namespace extensions | 143 } // namespace extensions |
OLD | NEW |