Chromium Code Reviews| 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/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
| 6 | 6 |
| 7 #include "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/saved_files_service.h" | 8 #include "apps/saved_files_service.h" |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 int render_view_id, | 132 int render_view_id, |
| 133 bool incognito, | 133 bool incognito, |
| 134 bool generated_background_page) | 134 bool generated_background_page) |
| 135 : url(url), | 135 : url(url), |
| 136 render_process_id(render_process_id), | 136 render_process_id(render_process_id), |
| 137 render_view_id(render_view_id), | 137 render_view_id(render_view_id), |
| 138 incognito(incognito), | 138 incognito(incognito), |
| 139 generated_background_page(generated_background_page) { | 139 generated_background_page(generated_background_page) { |
| 140 } | 140 } |
| 141 | 141 |
| 142 // On Mac, the install prompt is not modal. This means that the user can | 142 // On Mac (and Linux with Unity), the install prompt is not modal. This means |
|
not at google - send to devlin
2014/11/03 17:37:49
How about just "The install prompt is not necessar
sashab
2014/11/04 01:32:20
Nice suggestion; done.
| |
| 143 // navigate while the dialog is up, causing the dialog handler to outlive the | 143 // that the user can navigate while the dialog is up, causing the dialog handler |
| 144 // ExtensionSettingsHandler. That's a problem because the dialog framework will | 144 // to outlive the ExtensionSettingsHandler. That's a problem because the dialog |
| 145 // try to contact us back once the dialog is closed, which causes a crash. | 145 // framework will try to contact us back once the dialog is closed, which causes |
| 146 // This class is designed to broker the message between the two objects, while | 146 // a crash. This class is designed to broker the message between the two |
| 147 // managing its own lifetime so that it can outlive the ExtensionSettingsHandler | 147 // objects, while managing its own lifetime so that it can outlive the |
| 148 // and (when doing so) gracefully ignore the message from the dialog. | 148 // ExtensionSettingsHandler and (when doing so) gracefully ignore the message |
| 149 // from the dialog. | |
| 149 class BrokerDelegate : public ExtensionInstallPrompt::Delegate { | 150 class BrokerDelegate : public ExtensionInstallPrompt::Delegate { |
| 150 public: | 151 public: |
| 151 explicit BrokerDelegate( | 152 explicit BrokerDelegate( |
| 152 const base::WeakPtr<ExtensionSettingsHandler>& delegate) | 153 const base::WeakPtr<ExtensionSettingsHandler>& delegate) |
| 153 : delegate_(delegate) {} | 154 : delegate_(delegate) {} |
| 154 | 155 |
| 155 // ExtensionInstallPrompt::Delegate implementation. | 156 // ExtensionInstallPrompt::Delegate implementation. |
| 156 void InstallUIProceed() override { | 157 void InstallUIProceed() override { |
| 157 if (delegate_) | 158 if (delegate_) |
| 158 delegate_->InstallUIProceed(); | 159 delegate_->InstallUIProceed(); |
| 159 delete this; | 160 delete this; |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 void InstallUIAbort(bool user_initiated) override { | 163 void InstallUIAbort(bool user_initiated) override { |
| 163 if (delegate_) | 164 if (delegate_) |
| 164 delegate_->InstallUIAbort(user_initiated); | 165 delegate_->InstallUIAbort(user_initiated); |
| 165 delete this; | 166 delete this; |
| 166 }; | 167 }; |
| 167 | 168 |
| 169 void AppInfoDialogClosed() { | |
| 170 if (delegate_) | |
| 171 delegate_->AppInfoDialogClosed(); | |
| 172 delete this; | |
| 173 } | |
| 174 | |
| 168 private: | 175 private: |
| 169 base::WeakPtr<ExtensionSettingsHandler> delegate_; | 176 base::WeakPtr<ExtensionSettingsHandler> delegate_; |
| 170 | 177 |
| 171 DISALLOW_COPY_AND_ASSIGN(BrokerDelegate); | 178 DISALLOW_COPY_AND_ASSIGN(BrokerDelegate); |
| 172 }; | 179 }; |
| 173 | 180 |
| 174 /////////////////////////////////////////////////////////////////////////////// | 181 /////////////////////////////////////////////////////////////////////////////// |
| 175 // | 182 // |
| 176 // ExtensionSettingsHandler | 183 // ExtensionSettingsHandler |
| 177 // | 184 // |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 std::string extension_id(base::UTF16ToUTF8(ExtractStringValue(args))); | 1208 std::string extension_id(base::UTF16ToUTF8(ExtractStringValue(args))); |
| 1202 CHECK(!extension_id.empty()); | 1209 CHECK(!extension_id.empty()); |
| 1203 const Extension* extension = | 1210 const Extension* extension = |
| 1204 ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) | 1211 ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) |
| 1205 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 1212 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
| 1206 if (!extension) | 1213 if (!extension) |
| 1207 return; | 1214 return; |
| 1208 | 1215 |
| 1209 if (!extension_id_prompting_.empty()) | 1216 if (!extension_id_prompting_.empty()) |
| 1210 return; // Only one prompt at a time. | 1217 return; // Only one prompt at a time. |
| 1218 extension_id_prompting_ = extension->id(); | |
| 1211 | 1219 |
| 1212 extension_id_prompting_ = extension->id(); | 1220 // The BrokerDelegate manages its own lifetime. |
| 1221 BrokerDelegate* broker_delegate = new BrokerDelegate(AsWeakPtr()); | |
| 1213 | 1222 |
| 1214 // Show the new-style extensions dialog when the flag is set. The flag cannot | 1223 // Show the new-style extensions dialog when the flag is set. The flag cannot |
| 1215 // be set on Mac platforms. | 1224 // be set on Mac platforms. |
| 1216 if (ShouldDisplayExtensionInfoDialog()) { | 1225 if (ShouldDisplayExtensionInfoDialog()) { |
| 1217 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches", | 1226 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches", |
| 1218 AppInfoLaunchSource::FROM_EXTENSIONS_PAGE, | 1227 AppInfoLaunchSource::FROM_EXTENSIONS_PAGE, |
| 1219 AppInfoLaunchSource::NUM_LAUNCH_SOURCES); | 1228 AppInfoLaunchSource::NUM_LAUNCH_SOURCES); |
| 1220 | 1229 |
| 1221 // Display the dialog at a size similar to the app list. | 1230 // Display the dialog at a size similar to the app list. |
| 1222 const int kAppInfoDialogWidth = 380; | 1231 const int kAppInfoDialogWidth = 380; |
| 1223 const int kAppInfoDialogHeight = 490; | 1232 const int kAppInfoDialogHeight = 490; |
| 1233 | |
| 1224 ShowAppInfoInNativeDialog( | 1234 ShowAppInfoInNativeDialog( |
| 1225 web_contents()->GetTopLevelNativeWindow(), | 1235 web_contents()->GetTopLevelNativeWindow(), |
| 1226 gfx::Size(kAppInfoDialogWidth, kAppInfoDialogHeight), | 1236 gfx::Size(kAppInfoDialogWidth, kAppInfoDialogHeight), |
| 1227 Profile::FromWebUI(web_ui()), | 1237 Profile::FromWebUI(web_ui()), extension, |
| 1228 extension, | 1238 base::Bind(&BrokerDelegate::AppInfoDialogClosed, |
| 1229 base::Bind(&ExtensionSettingsHandler::AppInfoDialogClosed, | 1239 base::Unretained(broker_delegate))); |
| 1230 base::Unretained(this))); | |
| 1231 } else { | 1240 } else { |
| 1232 prompt_.reset(new ExtensionInstallPrompt(web_contents())); | 1241 prompt_.reset(new ExtensionInstallPrompt(web_contents())); |
| 1233 std::vector<base::FilePath> retained_file_paths; | 1242 std::vector<base::FilePath> retained_file_paths; |
| 1234 if (extension->permissions_data()->HasAPIPermission( | 1243 if (extension->permissions_data()->HasAPIPermission( |
| 1235 APIPermission::kFileSystem)) { | 1244 APIPermission::kFileSystem)) { |
| 1236 std::vector<apps::SavedFileEntry> retained_file_entries = | 1245 std::vector<apps::SavedFileEntry> retained_file_entries = |
| 1237 apps::SavedFilesService::Get(Profile::FromWebUI(web_ui())) | 1246 apps::SavedFilesService::Get(Profile::FromWebUI(web_ui())) |
| 1238 ->GetAllFileEntries(extension_id_prompting_); | 1247 ->GetAllFileEntries(extension_id_prompting_); |
| 1239 for (size_t i = 0; i < retained_file_entries.size(); ++i) { | 1248 for (size_t i = 0; i < retained_file_entries.size(); ++i) { |
| 1240 retained_file_paths.push_back(retained_file_entries[i].path); | 1249 retained_file_paths.push_back(retained_file_entries[i].path); |
| 1241 } | 1250 } |
| 1242 } | 1251 } |
| 1243 std::vector<base::string16> retained_device_messages; | 1252 std::vector<base::string16> retained_device_messages; |
| 1244 if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { | 1253 if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { |
| 1245 retained_device_messages = | 1254 retained_device_messages = |
| 1246 extensions::DevicePermissionsManager::Get( | 1255 extensions::DevicePermissionsManager::Get( |
| 1247 Profile::FromWebUI(web_ui())) | 1256 Profile::FromWebUI(web_ui())) |
| 1248 ->GetPermissionMessageStrings(extension_id_prompting_); | 1257 ->GetPermissionMessageStrings(extension_id_prompting_); |
| 1249 } | 1258 } |
| 1250 | 1259 |
| 1251 // The BrokerDelegate manages its own lifetime. | 1260 prompt_->ReviewPermissions(broker_delegate, extension, retained_file_paths, |
| 1252 prompt_->ReviewPermissions(new BrokerDelegate(AsWeakPtr()), | |
| 1253 extension, | |
| 1254 retained_file_paths, | |
| 1255 retained_device_messages); | 1261 retained_device_messages); |
| 1256 } | 1262 } |
| 1257 } | 1263 } |
| 1258 | 1264 |
| 1259 void ExtensionSettingsHandler::HandleShowButtonMessage( | 1265 void ExtensionSettingsHandler::HandleShowButtonMessage( |
| 1260 const base::ListValue* args) { | 1266 const base::ListValue* args) { |
| 1261 const Extension* extension = GetActiveExtension(args); | 1267 const Extension* extension = GetActiveExtension(args); |
| 1262 if (!extension) | 1268 if (!extension) |
| 1263 return; | 1269 return; |
| 1264 ExtensionActionAPI::SetBrowserActionVisibility( | 1270 ExtensionActionAPI::SetBrowserActionVisibility( |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1507 extension_service_->EnableExtension(extension_id); | 1513 extension_service_->EnableExtension(extension_id); |
| 1508 } else { | 1514 } else { |
| 1509 ExtensionErrorReporter::GetInstance()->ReportError( | 1515 ExtensionErrorReporter::GetInstance()->ReportError( |
| 1510 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1516 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
| 1511 true); // Be noisy. | 1517 true); // Be noisy. |
| 1512 } | 1518 } |
| 1513 requirements_checker_.reset(); | 1519 requirements_checker_.reset(); |
| 1514 } | 1520 } |
| 1515 | 1521 |
| 1516 } // namespace extensions | 1522 } // namespace extensions |
| OLD | NEW |