| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "content/public/browser/web_contents_view.h" | 42 #include "content/public/browser/web_contents_view.h" |
| 43 #include "grit/browser_resources.h" | 43 #include "grit/browser_resources.h" |
| 44 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
| 45 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 46 #include "grit/theme_resources.h" | 46 #include "grit/theme_resources.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/base/resource/resource_bundle.h" | 48 #include "ui/base/resource/resource_bundle.h" |
| 49 | 49 |
| 50 using content::RenderViewHost; | 50 using content::RenderViewHost; |
| 51 using content::WebContents; | 51 using content::WebContents; |
| 52 using extensions::ExtensionUpdater; |
| 52 | 53 |
| 53 namespace { | 54 namespace { |
| 54 | 55 |
| 55 bool ShouldShowExtension(const Extension* extension) { | 56 bool ShouldShowExtension(const Extension* extension) { |
| 56 // Don't show themes since this page's UI isn't really useful for themes. | 57 // Don't show themes since this page's UI isn't really useful for themes. |
| 57 if (extension->is_theme()) | 58 if (extension->is_theme()) |
| 58 return false; | 59 return false; |
| 59 | 60 |
| 60 // Don't show component extensions because they are only extensions as an | 61 // Don't show component extensions because they are only extensions as an |
| 61 // implementation detail of Chrome. | 62 // implementation detail of Chrome. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 90 ExtensionSettingsHandler::ExtensionSettingsHandler() | 91 ExtensionSettingsHandler::ExtensionSettingsHandler() |
| 91 : extension_service_(NULL), | 92 : extension_service_(NULL), |
| 92 ignore_notifications_(false), | 93 ignore_notifications_(false), |
| 93 deleting_rvh_(NULL), | 94 deleting_rvh_(NULL), |
| 94 registered_for_notifications_(false) { | 95 registered_for_notifications_(false) { |
| 95 } | 96 } |
| 96 | 97 |
| 97 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 98 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
| 98 // There may be pending file dialogs, we need to tell them that we've gone | 99 // There may be pending file dialogs, we need to tell them that we've gone |
| 99 // away so they don't try and call back to us. | 100 // away so they don't try and call back to us. |
| 100 if (load_extension_dialog_.get()) | 101 if (load_extension_dialog_) |
| 101 load_extension_dialog_->ListenerDestroyed(); | 102 load_extension_dialog_->ListenerDestroyed(); |
| 102 | 103 |
| 103 registrar_.RemoveAll(); | 104 registrar_.RemoveAll(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 // static | 107 // static |
| 107 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { | 108 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { |
| 108 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | 109 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, |
| 109 false, | 110 false, |
| 110 PrefService::SYNCABLE_PREF); | 111 PrefService::SYNCABLE_PREF); |
| 111 } | 112 } |
| 112 | 113 |
| 114 // Static |
| 115 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 116 ExtensionService* service, const Extension* extension, |
| 117 const std::vector<ExtensionPage>& pages, |
| 118 const ExtensionWarningSet* warnings_set, |
| 119 bool enabled, bool terminated) { |
| 120 DictionaryValue* extension_data = new DictionaryValue(); |
| 121 GURL icon = |
| 122 ExtensionIconSource::GetIconURL(extension, |
| 123 ExtensionIconSet::EXTENSION_ICON_MEDIUM, |
| 124 ExtensionIconSet::MATCH_BIGGER, |
| 125 !enabled, NULL); |
| 126 extension_data->SetString("id", extension->id()); |
| 127 extension_data->SetString("name", extension->name()); |
| 128 extension_data->SetString("description", extension->description()); |
| 129 if (extension->location() == Extension::LOAD) |
| 130 extension_data->SetString("path", extension->path().value()); |
| 131 extension_data->SetString("version", extension->version()->GetString()); |
| 132 extension_data->SetString("icon", icon.spec()); |
| 133 extension_data->SetBoolean("isUnpacked", |
| 134 extension->location() == Extension::LOAD); |
| 135 extension_data->SetBoolean("mayDisable", |
| 136 Extension::UserMayDisable(extension->location())); |
| 137 extension_data->SetBoolean("enabled", enabled); |
| 138 extension_data->SetBoolean("terminated", terminated); |
| 139 extension_data->SetBoolean("enabledIncognito", |
| 140 service ? service->IsIncognitoEnabled(extension->id()) : false); |
| 141 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); |
| 142 extension_data->SetBoolean("allowFileAccess", |
| 143 service ? service->AllowFileAccess(extension) : false); |
| 144 extension_data->SetBoolean("allow_activity", |
| 145 enabled && CommandLine::ForCurrentProcess()->HasSwitch( |
| 146 switches::kEnableExtensionActivityUI)); |
| 147 extension_data->SetBoolean("allow_reload", |
| 148 extension->location() == Extension::LOAD); |
| 149 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); |
| 150 |
| 151 // Determine the sort order: Extensions loaded through --load-extensions show |
| 152 // up at the top. Disabled extensions show up at the bottom. |
| 153 if (extension->location() == Extension::LOAD) |
| 154 extension_data->SetInteger("order", 1); |
| 155 else |
| 156 extension_data->SetInteger("order", 2); |
| 157 |
| 158 if (!extension->options_url().is_empty() && enabled) |
| 159 extension_data->SetString("options_url", extension->options_url().spec()); |
| 160 |
| 161 if (service && !service->GetBrowserActionVisibility(extension)) |
| 162 extension_data->SetBoolean("enable_show_button", true); |
| 163 |
| 164 // Add views |
| 165 ListValue* views = new ListValue; |
| 166 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); |
| 167 iter != pages.end(); ++iter) { |
| 168 DictionaryValue* view_value = new DictionaryValue; |
| 169 if (iter->url.scheme() == chrome::kExtensionScheme) { |
| 170 // No leading slash. |
| 171 view_value->SetString("path", iter->url.path().substr(1)); |
| 172 } else { |
| 173 // For live pages, use the full URL. |
| 174 view_value->SetString("path", iter->url.spec()); |
| 175 } |
| 176 view_value->SetInteger("renderViewId", iter->render_view_id); |
| 177 view_value->SetInteger("renderProcessId", iter->render_process_id); |
| 178 view_value->SetBoolean("incognito", iter->incognito); |
| 179 views->Append(view_value); |
| 180 } |
| 181 extension_data->Set("views", views); |
| 182 extension_data->SetBoolean("hasPopupAction", |
| 183 extension->browser_action() || extension->page_action()); |
| 184 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); |
| 185 |
| 186 // Add warnings. |
| 187 ListValue* warnings_list = new ListValue; |
| 188 if (warnings_set) { |
| 189 std::set<ExtensionWarningSet::WarningType> warnings; |
| 190 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); |
| 191 |
| 192 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = |
| 193 warnings.begin(); |
| 194 iter != warnings.end(); |
| 195 ++iter) { |
| 196 string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); |
| 197 warnings_list->Append(Value::CreateStringValue(warning_string)); |
| 198 } |
| 199 } |
| 200 extension_data->Set("warnings", warnings_list); |
| 201 |
| 202 return extension_data; |
| 203 } |
| 204 |
| 205 void ExtensionSettingsHandler::GetLocalizedValues( |
| 206 DictionaryValue* localized_strings) { |
| 207 localized_strings->SetString("extensionSettings", |
| 208 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE)); |
| 209 |
| 210 localized_strings->SetString("extensionSettingsDeveloperMode", |
| 211 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); |
| 212 localized_strings->SetString("extensionSettingsNoExtensions", |
| 213 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); |
| 214 localized_strings->SetString("extensionSettingsSuggestGallery", |
| 215 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, |
| 216 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| 217 GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| 218 localized_strings->SetString("extensionSettingsGetMoreExtensionsDeprecated", |
| 219 l10n_util::GetStringFUTF16(IDS_GET_MORE_EXTENSIONS_DEPRECATED, |
| 220 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| 221 GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); |
| 222 localized_strings->SetString("extensionSettingsGetMoreExtensions", |
| 223 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS)); |
| 224 localized_strings->SetString("extensionSettingsGetMoreExtensionsUrl", |
| 225 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( |
| 226 GURL(extension_urls::GetWebstoreLaunchURL())).spec())); |
| 227 localized_strings->SetString("extensionSettingsExtensionId", |
| 228 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); |
| 229 localized_strings->SetString("extensionSettingsExtensionPath", |
| 230 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); |
| 231 localized_strings->SetString("extensionSettingsInspectViews", |
| 232 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); |
| 233 localized_strings->SetString("viewIncognito", |
| 234 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); |
| 235 localized_strings->SetString("extensionSettingsEnable", |
| 236 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); |
| 237 localized_strings->SetString("extensionSettingsEnabled", |
| 238 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); |
| 239 localized_strings->SetString("extensionSettingsRemove", |
| 240 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); |
| 241 localized_strings->SetString("extensionSettingsEnableIncognito", |
| 242 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); |
| 243 localized_strings->SetString("extensionSettingsAllowFileAccess", |
| 244 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); |
| 245 localized_strings->SetString("extensionSettingsIncognitoWarning", |
| 246 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING)); |
| 247 localized_strings->SetString("extensionSettingsReload", |
| 248 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); |
| 249 localized_strings->SetString("extensionSettingsOptions", |
| 250 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); |
| 251 localized_strings->SetString("extensionSettingsActivity", |
| 252 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); |
| 253 localized_strings->SetString("extensionSettingsPolicyControlled", |
| 254 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); |
| 255 localized_strings->SetString("extensionSettingsShowButton", |
| 256 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); |
| 257 localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
| 258 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
| 259 localized_strings->SetString("extensionSettingsPackButton", |
| 260 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
| 261 localized_strings->SetString("extensionSettingsUpdateButton", |
| 262 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
| 263 localized_strings->SetString("extensionSettingsCrashMessage", |
| 264 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); |
| 265 localized_strings->SetString("extensionSettingsInDevelopment", |
| 266 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); |
| 267 localized_strings->SetString("extensionSettingsWarningsTitle", |
| 268 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); |
| 269 localized_strings->SetString("extensionSettingsShowDetails", |
| 270 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 271 localized_strings->SetString("extensionSettingsHideDetails", |
| 272 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); |
| 273 |
| 274 // TODO(estade): comb through the above strings to find ones no longer used in |
| 275 // uber extensions. |
| 276 localized_strings->SetString("extensionUninstall", |
| 277 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| 278 } |
| 279 |
| 113 void ExtensionSettingsHandler::RegisterMessages() { | 280 void ExtensionSettingsHandler::RegisterMessages() { |
| 114 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> | 281 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> |
| 115 GetExtensionService(); | 282 GetExtensionService(); |
| 116 | 283 |
| 117 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", | 284 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", |
| 118 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, | 285 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, |
| 119 base::Unretained(this))); | 286 base::Unretained(this))); |
| 120 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", | 287 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", |
| 121 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, | 288 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, |
| 122 base::Unretained(this))); | 289 base::Unretained(this))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 base::Unretained(this))); | 304 base::Unretained(this))); |
| 138 web_ui()->RegisterMessageCallback("extensionSettingsUninstall", | 305 web_ui()->RegisterMessageCallback("extensionSettingsUninstall", |
| 139 base::Bind(&ExtensionSettingsHandler::HandleUninstallMessage, | 306 base::Bind(&ExtensionSettingsHandler::HandleUninstallMessage, |
| 140 base::Unretained(this))); | 307 base::Unretained(this))); |
| 141 web_ui()->RegisterMessageCallback("extensionSettingsOptions", | 308 web_ui()->RegisterMessageCallback("extensionSettingsOptions", |
| 142 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, | 309 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, |
| 143 base::Unretained(this))); | 310 base::Unretained(this))); |
| 144 web_ui()->RegisterMessageCallback("extensionSettingsShowButton", | 311 web_ui()->RegisterMessageCallback("extensionSettingsShowButton", |
| 145 base::Bind(&ExtensionSettingsHandler::HandleShowButtonMessage, | 312 base::Bind(&ExtensionSettingsHandler::HandleShowButtonMessage, |
| 146 base::Unretained(this))); | 313 base::Unretained(this))); |
| 147 web_ui()->RegisterMessageCallback("extensionSettingsLoad", | |
| 148 base::Bind(&ExtensionSettingsHandler::HandleLoadMessage, | |
| 149 base::Unretained(this))); | |
| 150 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", | 314 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", |
| 151 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, | 315 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, |
| 152 base::Unretained(this))); | 316 base::Unretained(this))); |
| 153 web_ui()->RegisterMessageCallback("extensionSettingsSelectFilePath", | 317 web_ui()->RegisterMessageCallback("extensionSettingsLoadUnpackedExtension", |
| 154 base::Bind(&ExtensionSettingsHandler::HandleSelectFilePathMessage, | 318 base::Bind(&ExtensionSettingsHandler::HandleLoadUnpackedExtensionMessage, |
| 155 base::Unretained(this))); | 319 base::Unretained(this))); |
| 156 } | 320 } |
| 157 | 321 |
| 322 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, |
| 323 void* params) { |
| 324 extensions::UnpackedInstaller::Create(extension_service_)->Load(path); |
| 325 } |
| 326 |
| 327 void ExtensionSettingsHandler::MultiFilesSelected( |
| 328 const std::vector<FilePath>& files, void* params) { |
| 329 NOTREACHED(); |
| 330 } |
| 331 |
| 332 void ExtensionSettingsHandler::Observe( |
| 333 int type, |
| 334 const content::NotificationSource& source, |
| 335 const content::NotificationDetails& details) { |
| 336 Profile* profile = Profile::FromWebUI(web_ui()); |
| 337 Profile* source_profile = NULL; |
| 338 switch (type) { |
| 339 // We listen for notifications that will result in the page being |
| 340 // repopulated with data twice for the same event in certain cases. |
| 341 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because |
| 342 // we don't know about the views for an extension at EXTENSION_LOADED, but |
| 343 // if we only listen to EXTENSION_HOST_CREATED, we'll miss extensions |
| 344 // that don't have a process at startup. |
| 345 // |
| 346 // Doing it this way gets everything but causes the page to be rendered |
| 347 // more than we need. It doesn't seem to result in any noticeable flicker. |
| 348 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
| 349 deleting_rvh_ = content::Source<RenderViewHost>(source).ptr(); |
| 350 // Fall through. |
| 351 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| 352 source_profile = Profile::FromBrowserContext( |
| 353 content::Source<RenderViewHost>(source)->GetSiteInstance()-> |
| 354 GetBrowserContext()); |
| 355 if (!profile->IsSameProfile(source_profile)) |
| 356 return; |
| 357 MaybeUpdateAfterNotification(); |
| 358 break; |
| 359 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| 360 deleting_rvh_ = content::Details<BackgroundContents>(details)-> |
| 361 web_contents()->GetRenderViewHost(); |
| 362 // Fall through. |
| 363 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| 364 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| 365 source_profile = content::Source<Profile>(source).ptr(); |
| 366 if (!profile->IsSameProfile(source_profile)) |
| 367 return; |
| 368 MaybeUpdateAfterNotification(); |
| 369 break; |
| 370 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 371 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 372 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 373 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| 374 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 375 MaybeUpdateAfterNotification(); |
| 376 break; |
| 377 default: |
| 378 NOTREACHED(); |
| 379 } |
| 380 } |
| 381 |
| 382 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| 383 DCHECK(!extension_id_prompting_.empty()); |
| 384 |
| 385 bool was_terminated = false; |
| 386 |
| 387 // The extension can be uninstalled in another window while the UI was |
| 388 // showing. Do nothing in that case. |
| 389 const Extension* extension = |
| 390 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 391 if (!extension) { |
| 392 extension = extension_service_->GetTerminatedExtension( |
| 393 extension_id_prompting_); |
| 394 was_terminated = true; |
| 395 } |
| 396 if (!extension) |
| 397 return; |
| 398 |
| 399 extension_service_->UninstallExtension(extension_id_prompting_, |
| 400 false, // External uninstall. |
| 401 NULL); // Error. |
| 402 extension_id_prompting_ = ""; |
| 403 |
| 404 // There will be no EXTENSION_UNLOADED notification for terminated |
| 405 // extensions as they were already unloaded. |
| 406 if (was_terminated) |
| 407 HandleRequestExtensionsData(NULL); |
| 408 } |
| 409 |
| 410 void ExtensionSettingsHandler::ExtensionUninstallCanceled() { |
| 411 extension_id_prompting_ = ""; |
| 412 } |
| 413 |
| 158 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 414 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 159 const ListValue* args) { | 415 const ListValue* args) { |
| 160 DictionaryValue results; | 416 DictionaryValue results; |
| 161 | 417 |
| 162 // Add the extensions to the results structure. | 418 // Add the extensions to the results structure. |
| 163 ListValue *extensions_list = new ListValue(); | 419 ListValue *extensions_list = new ListValue(); |
| 164 | 420 |
| 165 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); | 421 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); |
| 166 | 422 |
| 167 const ExtensionSet* extensions = extension_service_->extensions(); | 423 const ExtensionSet* extensions = extension_service_->extensions(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 bool developer_mode = | 463 bool developer_mode = |
| 208 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 464 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 209 results.SetBoolean("developerMode", developer_mode); | 465 results.SetBoolean("developerMode", developer_mode); |
| 210 | 466 |
| 211 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", | 467 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
| 212 results); | 468 results); |
| 213 | 469 |
| 214 MaybeRegisterForNotifications(); | 470 MaybeRegisterForNotifications(); |
| 215 } | 471 } |
| 216 | 472 |
| 217 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { | |
| 218 if (registered_for_notifications_) | |
| 219 return; | |
| 220 | |
| 221 registered_for_notifications_ = true; | |
| 222 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 223 | |
| 224 // Register for notifications that we need to reload the page. | |
| 225 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 226 content::Source<Profile>(profile)); | |
| 227 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | |
| 228 content::Source<Profile>(profile)); | |
| 229 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | |
| 230 content::Source<Profile>(profile)); | |
| 231 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, | |
| 232 content::Source<Profile>(profile)); | |
| 233 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | |
| 234 content::NotificationService::AllBrowserContextsAndSources()); | |
| 235 registrar_.Add(this, | |
| 236 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | |
| 237 content::NotificationService::AllBrowserContextsAndSources()); | |
| 238 registrar_.Add(this, | |
| 239 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | |
| 240 content::NotificationService::AllBrowserContextsAndSources()); | |
| 241 registrar_.Add(this, | |
| 242 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | |
| 243 content::NotificationService::AllBrowserContextsAndSources()); | |
| 244 registrar_.Add(this, | |
| 245 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | |
| 246 content::NotificationService::AllBrowserContextsAndSources()); | |
| 247 registrar_.Add( | |
| 248 this, | |
| 249 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | |
| 250 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> | |
| 251 extension_prefs())); | |
| 252 } | |
| 253 | |
| 254 ExtensionUninstallDialog* | |
| 255 ExtensionSettingsHandler::GetExtensionUninstallDialog() { | |
| 256 if (!extension_uninstall_dialog_.get()) { | |
| 257 extension_uninstall_dialog_.reset( | |
| 258 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); | |
| 259 } | |
| 260 return extension_uninstall_dialog_.get(); | |
| 261 } | |
| 262 | |
| 263 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | 473 void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
| 264 const ListValue* args) { | 474 const ListValue* args) { |
| 265 Profile* profile = Profile::FromWebUI(web_ui()); | 475 Profile* profile = Profile::FromWebUI(web_ui()); |
| 266 bool developer_mode = | 476 bool developer_mode = |
| 267 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 477 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 268 profile->GetPrefs()->SetBoolean( | 478 profile->GetPrefs()->SetBoolean( |
| 269 prefs::kExtensionsUIDeveloperMode, !developer_mode); | 479 prefs::kExtensionsUIDeveloperMode, !developer_mode); |
| 270 } | 480 } |
| 271 | 481 |
| 272 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { | 482 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 595 } |
| 386 | 596 |
| 387 if (!extension_id_prompting_.empty()) | 597 if (!extension_id_prompting_.empty()) |
| 388 return; // Only one prompt at a time. | 598 return; // Only one prompt at a time. |
| 389 | 599 |
| 390 extension_id_prompting_ = extension_id; | 600 extension_id_prompting_ = extension_id; |
| 391 | 601 |
| 392 GetExtensionUninstallDialog()->ConfirmUninstall(extension); | 602 GetExtensionUninstallDialog()->ConfirmUninstall(extension); |
| 393 } | 603 } |
| 394 | 604 |
| 395 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { | |
| 396 DCHECK(!extension_id_prompting_.empty()); | |
| 397 | |
| 398 bool was_terminated = false; | |
| 399 | |
| 400 // The extension can be uninstalled in another window while the UI was | |
| 401 // showing. Do nothing in that case. | |
| 402 const Extension* extension = | |
| 403 extension_service_->GetExtensionById(extension_id_prompting_, true); | |
| 404 if (!extension) { | |
| 405 extension = extension_service_->GetTerminatedExtension( | |
| 406 extension_id_prompting_); | |
| 407 was_terminated = true; | |
| 408 } | |
| 409 if (!extension) | |
| 410 return; | |
| 411 | |
| 412 extension_service_->UninstallExtension(extension_id_prompting_, | |
| 413 false, // External uninstall. | |
| 414 NULL); // Error. | |
| 415 extension_id_prompting_ = ""; | |
| 416 | |
| 417 // There will be no EXTENSION_UNLOADED notification for terminated | |
| 418 // extensions as they were already unloaded. | |
| 419 if (was_terminated) | |
| 420 HandleRequestExtensionsData(NULL); | |
| 421 } | |
| 422 | |
| 423 void ExtensionSettingsHandler::ExtensionUninstallCanceled() { | |
| 424 extension_id_prompting_ = ""; | |
| 425 } | |
| 426 | |
| 427 void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { | 605 void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { |
| 428 const Extension* extension = GetExtension(args); | 606 const Extension* extension = GetExtension(args); |
| 429 if (!extension || extension->options_url().is_empty()) | 607 if (!extension || extension->options_url().is_empty()) |
| 430 return; | 608 return; |
| 431 Profile::FromWebUI(web_ui())->GetExtensionProcessManager()->OpenOptionsPage( | 609 Profile::FromWebUI(web_ui())->GetExtensionProcessManager()->OpenOptionsPage( |
| 432 extension, NULL); | 610 extension, NULL); |
| 433 } | 611 } |
| 434 | 612 |
| 435 void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { | 613 void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { |
| 436 const Extension* extension = GetExtension(args); | 614 const Extension* extension = GetExtension(args); |
| 437 extension_service_->SetBrowserActionVisibility(extension, true); | 615 extension_service_->SetBrowserActionVisibility(extension, true); |
| 438 } | 616 } |
| 439 | 617 |
| 440 void ExtensionSettingsHandler::HandleLoadMessage(const ListValue* args) { | 618 void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { |
| 441 FilePath::StringType string_path; | 619 ExtensionUpdater* updater = extension_service_->updater(); |
| 442 CHECK_EQ(1U, args->GetSize()) << args->GetSize(); | 620 if (updater) |
| 443 CHECK(args->GetString(0, &string_path)); | 621 updater->CheckNow(); |
| 444 extensions::UnpackedInstaller::Create(extension_service_)-> | 622 } |
| 445 Load(FilePath(string_path)); | 623 |
| 624 void ExtensionSettingsHandler::HandleLoadUnpackedExtensionMessage( |
| 625 const ListValue* args) { |
| 626 DCHECK(args->empty()); |
| 627 |
| 628 string16 select_title = |
| 629 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| 630 |
| 631 const int kFileTypeIndex = 0; // No file type information to index. |
| 632 const SelectFileDialog::Type kSelectType = SelectFileDialog::SELECT_FOLDER; |
| 633 load_extension_dialog_ = SelectFileDialog::Create(this); |
| 634 load_extension_dialog_->SelectFile( |
| 635 kSelectType, select_title, FilePath(), NULL, kFileTypeIndex, |
| 636 FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), |
| 637 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 446 } | 638 } |
| 447 | 639 |
| 448 void ExtensionSettingsHandler::ShowAlert(const std::string& message) { | 640 void ExtensionSettingsHandler::ShowAlert(const std::string& message) { |
| 449 ListValue arguments; | 641 ListValue arguments; |
| 450 arguments.Append(Value::CreateStringValue(message)); | 642 arguments.Append(Value::CreateStringValue(message)); |
| 451 web_ui()->CallJavascriptFunction("alert", arguments); | 643 web_ui()->CallJavascriptFunction("alert", arguments); |
| 452 } | 644 } |
| 453 | 645 |
| 454 void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { | |
| 455 extensions::ExtensionUpdater* updater = extension_service_->updater(); | |
| 456 if (updater) | |
| 457 updater->CheckNow(); | |
| 458 } | |
| 459 | |
| 460 void ExtensionSettingsHandler::HandleSelectFilePathMessage( | |
| 461 const ListValue* args) { | |
| 462 std::string select_type; | |
| 463 std::string operation; | |
| 464 CHECK_EQ(2U, args->GetSize()); | |
| 465 CHECK(args->GetString(0, &select_type)); | |
| 466 CHECK(args->GetString(1, &operation)); | |
| 467 | |
| 468 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; | |
| 469 SelectFileDialog::FileTypeInfo info; | |
| 470 int file_type_index = 0; | |
| 471 if (select_type == "file") | |
| 472 type = SelectFileDialog::SELECT_OPEN_FILE; | |
| 473 | |
| 474 string16 select_title; | |
| 475 if (operation == "load") { | |
| 476 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | |
| 477 } else if (operation == "packRoot") { | |
| 478 select_title = l10n_util::GetStringUTF16( | |
| 479 IDS_EXTENSION_PACK_DIALOG_SELECT_ROOT); | |
| 480 } else if (operation == "pem") { | |
| 481 select_title = l10n_util::GetStringUTF16( | |
| 482 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); | |
| 483 info.extensions.push_back(std::vector<FilePath::StringType>()); | |
| 484 info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); | |
| 485 info.extension_description_overrides.push_back( | |
| 486 l10n_util::GetStringUTF16( | |
| 487 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); | |
| 488 info.include_all_files = true; | |
| 489 file_type_index = 1; | |
| 490 } else { | |
| 491 NOTREACHED(); | |
| 492 return; | |
| 493 } | |
| 494 | |
| 495 load_extension_dialog_ = SelectFileDialog::Create(this); | |
| 496 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, | |
| 497 file_type_index, FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), | |
| 498 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | |
| 499 } | |
| 500 | |
| 501 | |
| 502 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, | |
| 503 void* params) { | |
| 504 // Add the extensions to the results structure. | |
| 505 ListValue results; | |
| 506 results.Append(Value::CreateStringValue(path.value())); | |
| 507 web_ui()->CallJavascriptFunction("window.handleFilePathSelected", results); | |
| 508 } | |
| 509 | |
| 510 void ExtensionSettingsHandler::MultiFilesSelected( | |
| 511 const std::vector<FilePath>& files, void* params) { | |
| 512 NOTREACHED(); | |
| 513 } | |
| 514 | |
| 515 void ExtensionSettingsHandler::GetLocalizedValues( | |
| 516 DictionaryValue* localized_strings) { | |
| 517 localized_strings->SetString("extensionSettings", | |
| 518 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE)); | |
| 519 localized_strings->SetString("extensionSettingsDeveloperMode", | |
| 520 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); | |
| 521 localized_strings->SetString("extensionSettingsNoExtensions", | |
| 522 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); | |
| 523 localized_strings->SetString("extensionSettingsSuggestGallery", | |
| 524 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, | |
| 525 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
| 526 GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); | |
| 527 localized_strings->SetString("extensionSettingsGetMoreExtensionsDeprecated", | |
| 528 l10n_util::GetStringFUTF16(IDS_GET_MORE_EXTENSIONS_DEPRECATED, | |
| 529 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
| 530 GURL(extension_urls::GetWebstoreLaunchURL())).spec()))); | |
| 531 localized_strings->SetString("extensionSettingsGetMoreExtensions", | |
| 532 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS)); | |
| 533 localized_strings->SetString("extensionSettingsGetMoreExtensionsUrl", | |
| 534 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
| 535 GURL(extension_urls::GetWebstoreLaunchURL())).spec())); | |
| 536 localized_strings->SetString("extensionSettingsExtensionId", | |
| 537 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); | |
| 538 localized_strings->SetString("extensionSettingsExtensionPath", | |
| 539 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); | |
| 540 localized_strings->SetString("extensionSettingsInspectViews", | |
| 541 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); | |
| 542 localized_strings->SetString("viewIncognito", | |
| 543 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); | |
| 544 localized_strings->SetString("extensionSettingsEnable", | |
| 545 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); | |
| 546 localized_strings->SetString("extensionSettingsEnabled", | |
| 547 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); | |
| 548 localized_strings->SetString("extensionSettingsRemove", | |
| 549 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); | |
| 550 localized_strings->SetString("extensionSettingsEnableIncognito", | |
| 551 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); | |
| 552 localized_strings->SetString("extensionSettingsAllowFileAccess", | |
| 553 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); | |
| 554 localized_strings->SetString("extensionSettingsIncognitoWarning", | |
| 555 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING)); | |
| 556 localized_strings->SetString("extensionSettingsReload", | |
| 557 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); | |
| 558 localized_strings->SetString("extensionSettingsOptions", | |
| 559 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); | |
| 560 localized_strings->SetString("extensionSettingsActivity", | |
| 561 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); | |
| 562 localized_strings->SetString("extensionSettingsPolicyControlled", | |
| 563 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); | |
| 564 localized_strings->SetString("extensionSettingsShowButton", | |
| 565 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); | |
| 566 localized_strings->SetString("extensionSettingsLoadUnpackedButton", | |
| 567 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); | |
| 568 localized_strings->SetString("extensionSettingsPackButton", | |
| 569 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); | |
| 570 localized_strings->SetString("extensionSettingsUpdateButton", | |
| 571 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); | |
| 572 localized_strings->SetString("extensionSettingsCrashMessage", | |
| 573 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); | |
| 574 localized_strings->SetString("extensionSettingsInDevelopment", | |
| 575 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); | |
| 576 localized_strings->SetString("extensionSettingsWarningsTitle", | |
| 577 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE)); | |
| 578 localized_strings->SetString("extensionSettingsShowDetails", | |
| 579 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | |
| 580 localized_strings->SetString("extensionSettingsHideDetails", | |
| 581 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); | |
| 582 | |
| 583 // TODO(estade): comb through the above strings to find ones no longer used in | |
| 584 // uber extensions. | |
| 585 localized_strings->SetString("extensionUninstall", | |
| 586 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | |
| 587 } | |
| 588 | |
| 589 void ExtensionSettingsHandler::Observe( | |
| 590 int type, | |
| 591 const content::NotificationSource& source, | |
| 592 const content::NotificationDetails& details) { | |
| 593 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 594 Profile* source_profile = NULL; | |
| 595 switch (type) { | |
| 596 // We listen for notifications that will result in the page being | |
| 597 // repopulated with data twice for the same event in certain cases. | |
| 598 // For instance, EXTENSION_LOADED & EXTENSION_HOST_CREATED because | |
| 599 // we don't know about the views for an extension at EXTENSION_LOADED, but | |
| 600 // if we only listen to EXTENSION_HOST_CREATED, we'll miss extensions | |
| 601 // that don't have a process at startup. | |
| 602 // | |
| 603 // Doing it this way gets everything but causes the page to be rendered | |
| 604 // more than we need. It doesn't seem to result in any noticeable flicker. | |
| 605 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: | |
| 606 deleting_rvh_ = content::Source<RenderViewHost>(source).ptr(); | |
| 607 // Fall through. | |
| 608 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: | |
| 609 source_profile = Profile::FromBrowserContext( | |
| 610 content::Source<RenderViewHost>(source)->GetSiteInstance()-> | |
| 611 GetBrowserContext()); | |
| 612 if (!profile->IsSameProfile(source_profile)) | |
| 613 return; | |
| 614 MaybeUpdateAfterNotification(); | |
| 615 break; | |
| 616 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: | |
| 617 deleting_rvh_ = content::Details<BackgroundContents>(details)-> | |
| 618 web_contents()->GetRenderViewHost(); | |
| 619 // Fall through. | |
| 620 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: | |
| 621 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: | |
| 622 source_profile = content::Source<Profile>(source).ptr(); | |
| 623 if (!profile->IsSameProfile(source_profile)) | |
| 624 return; | |
| 625 MaybeUpdateAfterNotification(); | |
| 626 break; | |
| 627 case chrome::NOTIFICATION_EXTENSION_LOADED: | |
| 628 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | |
| 629 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | |
| 630 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: | |
| 631 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | |
| 632 MaybeUpdateAfterNotification(); | |
| 633 break; | |
| 634 default: | |
| 635 NOTREACHED(); | |
| 636 } | |
| 637 } | |
| 638 | |
| 639 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { | 646 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| 640 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 647 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 641 CHECK(!extension_id.empty()); | 648 CHECK(!extension_id.empty()); |
| 642 return extension_service_->GetExtensionById(extension_id, true); | 649 return extension_service_->GetExtensionById(extension_id, true); |
| 643 } | 650 } |
| 644 | 651 |
| 645 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | 652 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 646 WebContents* contents = web_ui()->GetWebContents(); | 653 WebContents* contents = web_ui()->GetWebContents(); |
| 647 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) | 654 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) |
| 648 HandleRequestExtensionsData(NULL); | 655 HandleRequestExtensionsData(NULL); |
| 649 deleting_rvh_ = NULL; | 656 deleting_rvh_ = NULL; |
| 650 } | 657 } |
| 651 | 658 |
| 652 // Static | 659 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| 653 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 660 if (registered_for_notifications_) |
| 654 ExtensionService* service, const Extension* extension, | 661 return; |
| 655 const std::vector<ExtensionPage>& pages, | |
| 656 const ExtensionWarningSet* warnings_set, | |
| 657 bool enabled, bool terminated) { | |
| 658 DictionaryValue* extension_data = new DictionaryValue(); | |
| 659 GURL icon = | |
| 660 ExtensionIconSource::GetIconURL(extension, | |
| 661 ExtensionIconSet::EXTENSION_ICON_MEDIUM, | |
| 662 ExtensionIconSet::MATCH_BIGGER, | |
| 663 !enabled, NULL); | |
| 664 extension_data->SetString("id", extension->id()); | |
| 665 extension_data->SetString("name", extension->name()); | |
| 666 extension_data->SetString("description", extension->description()); | |
| 667 if (extension->location() == Extension::LOAD) | |
| 668 extension_data->SetString("path", extension->path().value()); | |
| 669 extension_data->SetString("version", extension->version()->GetString()); | |
| 670 extension_data->SetString("icon", icon.spec()); | |
| 671 extension_data->SetBoolean("isUnpacked", | |
| 672 extension->location() == Extension::LOAD); | |
| 673 extension_data->SetBoolean("mayDisable", | |
| 674 Extension::UserMayDisable(extension->location())); | |
| 675 extension_data->SetBoolean("enabled", enabled); | |
| 676 extension_data->SetBoolean("terminated", terminated); | |
| 677 extension_data->SetBoolean("enabledIncognito", | |
| 678 service ? service->IsIncognitoEnabled(extension->id()) : false); | |
| 679 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); | |
| 680 extension_data->SetBoolean("allowFileAccess", | |
| 681 service ? service->AllowFileAccess(extension) : false); | |
| 682 extension_data->SetBoolean("allow_activity", | |
| 683 enabled && CommandLine::ForCurrentProcess()->HasSwitch( | |
| 684 switches::kEnableExtensionActivityUI)); | |
| 685 extension_data->SetBoolean("allow_reload", | |
| 686 extension->location() == Extension::LOAD); | |
| 687 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); | |
| 688 | 662 |
| 689 // Determine the sort order: Extensions loaded through --load-extensions show | 663 registered_for_notifications_ = true; |
| 690 // up at the top. Disabled extensions show up at the bottom. | 664 Profile* profile = Profile::FromWebUI(web_ui()); |
| 691 if (extension->location() == Extension::LOAD) | |
| 692 extension_data->SetInteger("order", 1); | |
| 693 else | |
| 694 extension_data->SetInteger("order", 2); | |
| 695 | 665 |
| 696 if (!extension->options_url().is_empty() && enabled) | 666 // Register for notifications that we need to reload the page. |
| 697 extension_data->SetString("options_url", extension->options_url().spec()); | 667 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 698 | 668 content::Source<Profile>(profile)); |
| 699 if (service && !service->GetBrowserActionVisibility(extension)) | 669 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 700 extension_data->SetBoolean("enable_show_button", true); | 670 content::Source<Profile>(profile)); |
| 701 | 671 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 702 // Add views | 672 content::Source<Profile>(profile)); |
| 703 ListValue* views = new ListValue; | 673 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, |
| 704 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); | 674 content::Source<Profile>(profile)); |
| 705 iter != pages.end(); ++iter) { | 675 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 706 DictionaryValue* view_value = new DictionaryValue; | 676 content::NotificationService::AllBrowserContextsAndSources()); |
| 707 if (iter->url.scheme() == chrome::kExtensionScheme) { | 677 registrar_.Add(this, |
| 708 // No leading slash. | 678 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 709 view_value->SetString("path", iter->url.path().substr(1)); | 679 content::NotificationService::AllBrowserContextsAndSources()); |
| 710 } else { | 680 registrar_.Add(this, |
| 711 // For live pages, use the full URL. | 681 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| 712 view_value->SetString("path", iter->url.spec()); | 682 content::NotificationService::AllBrowserContextsAndSources()); |
| 713 } | 683 registrar_.Add(this, |
| 714 view_value->SetInteger("renderViewId", iter->render_view_id); | 684 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 715 view_value->SetInteger("renderProcessId", iter->render_process_id); | 685 content::NotificationService::AllBrowserContextsAndSources()); |
| 716 view_value->SetBoolean("incognito", iter->incognito); | 686 registrar_.Add(this, |
| 717 views->Append(view_value); | 687 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 718 } | 688 content::NotificationService::AllBrowserContextsAndSources()); |
| 719 extension_data->Set("views", views); | 689 registrar_.Add( |
| 720 extension_data->SetBoolean("hasPopupAction", | 690 this, |
| 721 extension->browser_action() || extension->page_action()); | 691 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 722 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); | 692 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> |
| 723 | 693 extension_prefs())); |
| 724 // Add warnings. | |
| 725 ListValue* warnings_list = new ListValue; | |
| 726 if (warnings_set) { | |
| 727 std::set<ExtensionWarningSet::WarningType> warnings; | |
| 728 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); | |
| 729 | |
| 730 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = | |
| 731 warnings.begin(); | |
| 732 iter != warnings.end(); | |
| 733 ++iter) { | |
| 734 string16 warning_string(ExtensionWarningSet::GetLocalizedWarning(*iter)); | |
| 735 warnings_list->Append(Value::CreateStringValue(warning_string)); | |
| 736 } | |
| 737 } | |
| 738 extension_data->Set("warnings", warnings_list); | |
| 739 | |
| 740 return extension_data; | |
| 741 } | 694 } |
| 742 | 695 |
| 743 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( | 696 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( |
| 744 const Extension* extension) { | 697 const Extension* extension) { |
| 745 std::vector<ExtensionPage> result; | 698 std::vector<ExtensionPage> result; |
| 746 | 699 |
| 747 // Get the extension process's active views. | 700 // Get the extension process's active views. |
| 748 ExtensionProcessManager* process_manager = | 701 ExtensionProcessManager* process_manager = |
| 749 extension_service_->profile()->GetExtensionProcessManager(); | 702 extension_service_->profile()->GetExtensionProcessManager(); |
| 750 GetActivePagesForExtensionProcess( | 703 GetActivePagesForExtensionProcess( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 777 chrome::VIEW_TYPE_EXTENSION_DIALOG == host_type) | 730 chrome::VIEW_TYPE_EXTENSION_DIALOG == host_type) |
| 778 continue; | 731 continue; |
| 779 | 732 |
| 780 GURL url = host->GetDelegate()->GetURL(); | 733 GURL url = host->GetDelegate()->GetURL(); |
| 781 content::RenderProcessHost* process = host->GetProcess(); | 734 content::RenderProcessHost* process = host->GetProcess(); |
| 782 result->push_back( | 735 result->push_back( |
| 783 ExtensionPage(url, process->GetID(), host->GetRoutingID(), | 736 ExtensionPage(url, process->GetID(), host->GetRoutingID(), |
| 784 process->GetBrowserContext()->IsOffTheRecord())); | 737 process->GetBrowserContext()->IsOffTheRecord())); |
| 785 } | 738 } |
| 786 } | 739 } |
| 740 |
| 741 ExtensionUninstallDialog* |
| 742 ExtensionSettingsHandler::GetExtensionUninstallDialog() { |
| 743 if (!extension_uninstall_dialog_.get()) { |
| 744 extension_uninstall_dialog_.reset( |
| 745 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); |
| 746 } |
| 747 return extension_uninstall_dialog_.get(); |
| 748 } |
| OLD | NEW |