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