| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extensions_ui.h" | 5 #include "chrome/browser/extensions/extensions_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (ShouldShowExtension(*extension)) { | 235 if (ShouldShowExtension(*extension)) { |
| 236 extensions_list->Append(CreateExtensionDetailValue( | 236 extensions_list->Append(CreateExtensionDetailValue( |
| 237 extension_service_, | 237 extension_service_, |
| 238 *extension, | 238 *extension, |
| 239 empty_pages, // Terminated process has no active pages. | 239 empty_pages, // Terminated process has no active pages. |
| 240 false, true)); // enabled, terminated | 240 false, true)); // enabled, terminated |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 results.Set("extensions", extensions_list); | 243 results.Set("extensions", extensions_list); |
| 244 | 244 |
| 245 bool developer_mode = web_ui_->GetProfile()->GetPrefs() | 245 Profile* profile = |
| 246 static_cast<Profile*>(web_ui_->tab_contents()->browser_context()); |
| 247 bool developer_mode = profile->GetPrefs() |
| 246 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 248 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 247 results.SetBoolean("developerMode", developer_mode); | 249 results.SetBoolean("developerMode", developer_mode); |
| 248 | 250 |
| 249 web_ui_->CallJavascriptFunction("returnExtensionsData", results); | 251 web_ui_->CallJavascriptFunction("returnExtensionsData", results); |
| 250 } | 252 } |
| 251 | 253 |
| 252 void ExtensionsDOMHandler::RegisterForNotifications() { | 254 void ExtensionsDOMHandler::RegisterForNotifications() { |
| 253 // Register for notifications that we need to reload the page. | 255 // Register for notifications that we need to reload the page. |
| 254 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 256 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 255 NotificationService::AllSources()); | 257 NotificationService::AllSources()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 274 registrar_.Add(this, | 276 registrar_.Add(this, |
| 275 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 277 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 276 NotificationService::AllSources()); | 278 NotificationService::AllSources()); |
| 277 registrar_.Add(this, | 279 registrar_.Add(this, |
| 278 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 280 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 279 NotificationService::AllSources()); | 281 NotificationService::AllSources()); |
| 280 } | 282 } |
| 281 | 283 |
| 282 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { | 284 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { |
| 283 if (!extension_uninstall_dialog_.get()) { | 285 if (!extension_uninstall_dialog_.get()) { |
| 286 Profile* profile = |
| 287 static_cast<Profile*>(web_ui_->tab_contents()->browser_context()); |
| 284 extension_uninstall_dialog_.reset( | 288 extension_uninstall_dialog_.reset( |
| 285 new ExtensionUninstallDialog(web_ui_->GetProfile())); | 289 new ExtensionUninstallDialog(profile)); |
| 286 } | 290 } |
| 287 return extension_uninstall_dialog_.get(); | 291 return extension_uninstall_dialog_.get(); |
| 288 } | 292 } |
| 289 | 293 |
| 290 void ExtensionsDOMHandler::HandleToggleDeveloperMode(const ListValue* args) { | 294 void ExtensionsDOMHandler::HandleToggleDeveloperMode(const ListValue* args) { |
| 291 bool developer_mode = web_ui_->GetProfile()->GetPrefs() | 295 Profile* profile = |
| 296 static_cast<Profile*>(web_ui_->tab_contents()->browser_context()); |
| 297 bool developer_mode = profile->GetPrefs() |
| 292 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 298 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 293 web_ui_->GetProfile()->GetPrefs()->SetBoolean( | 299 profile->GetPrefs()->SetBoolean( |
| 294 prefs::kExtensionsUIDeveloperMode, !developer_mode); | 300 prefs::kExtensionsUIDeveloperMode, !developer_mode); |
| 295 } | 301 } |
| 296 | 302 |
| 297 void ExtensionsDOMHandler::HandleInspectMessage(const ListValue* args) { | 303 void ExtensionsDOMHandler::HandleInspectMessage(const ListValue* args) { |
| 298 std::string render_process_id_str; | 304 std::string render_process_id_str; |
| 299 std::string render_view_id_str; | 305 std::string render_view_id_str; |
| 300 int render_process_id; | 306 int render_process_id; |
| 301 int render_view_id; | 307 int render_view_id; |
| 302 CHECK(args->GetSize() == 2); | 308 CHECK(args->GetSize() == 2); |
| 303 CHECK(args->GetString(0, &render_process_id_str)); | 309 CHECK(args->GetString(0, &render_process_id_str)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 330 DCHECK(extension); | 336 DCHECK(extension); |
| 331 if (!Extension::UserMayDisable(extension->location())) { | 337 if (!Extension::UserMayDisable(extension->location())) { |
| 332 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 338 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 333 << "made. Extension id: " << extension->id(); | 339 << "made. Extension id: " << extension->id(); |
| 334 return; | 340 return; |
| 335 } | 341 } |
| 336 | 342 |
| 337 if (enable_str == "true") { | 343 if (enable_str == "true") { |
| 338 ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 344 ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 339 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 345 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 346 Profile* profile = |
| 347 static_cast<Profile*>(web_ui_->tab_contents()->browser_context()); |
| 340 ShowExtensionDisabledDialog(extension_service_, | 348 ShowExtensionDisabledDialog(extension_service_, |
| 341 web_ui_->GetProfile(), extension); | 349 profile, extension); |
| 342 } else { | 350 } else { |
| 343 extension_service_->EnableExtension(extension_id); | 351 extension_service_->EnableExtension(extension_id); |
| 344 } | 352 } |
| 345 } else { | 353 } else { |
| 346 extension_service_->DisableExtension(extension_id); | 354 extension_service_->DisableExtension(extension_id); |
| 347 } | 355 } |
| 348 } | 356 } |
| 349 | 357 |
| 350 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) { | 358 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) { |
| 351 CHECK(args->GetSize() == 2); | 359 CHECK(args->GetSize() == 2); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 451 } |
| 444 | 452 |
| 445 void ExtensionsDOMHandler::ExtensionDialogCanceled() { | 453 void ExtensionsDOMHandler::ExtensionDialogCanceled() { |
| 446 extension_id_prompting_ = ""; | 454 extension_id_prompting_ = ""; |
| 447 } | 455 } |
| 448 | 456 |
| 449 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) { | 457 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) { |
| 450 const Extension* extension = GetExtension(args); | 458 const Extension* extension = GetExtension(args); |
| 451 if (!extension || extension->options_url().is_empty()) | 459 if (!extension || extension->options_url().is_empty()) |
| 452 return; | 460 return; |
| 453 web_ui_->GetProfile()->GetExtensionProcessManager()->OpenOptionsPage( | 461 Profile* profile = |
| 454 extension, NULL); | 462 static_cast<Profile*>(web_ui_->tab_contents()->browser_context()); |
| 463 profile->GetExtensionProcessManager()->OpenOptionsPage(extension, NULL); |
| 455 } | 464 } |
| 456 | 465 |
| 457 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) { | 466 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) { |
| 458 const Extension* extension = GetExtension(args); | 467 const Extension* extension = GetExtension(args); |
| 459 extension_service_->SetBrowserActionVisibility(extension, true); | 468 extension_service_->SetBrowserActionVisibility(extension, true); |
| 460 } | 469 } |
| 461 | 470 |
| 462 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) { | 471 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) { |
| 463 FilePath::StringType string_path; | 472 FilePath::StringType string_path; |
| 464 CHECK(args->GetSize() == 1) << args->GetSize(); | 473 CHECK(args->GetSize() == 1) << args->GetSize(); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 760 |
| 752 GURL url = host->delegate()->GetURL(); | 761 GURL url = host->delegate()->GetURL(); |
| 753 if (url.SchemeIs(chrome::kExtensionScheme)) { | 762 if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 754 if (url.host() != extension->id()) | 763 if (url.host() != extension->id()) |
| 755 continue; | 764 continue; |
| 756 } else if (!extension->web_extent().MatchesURL(url)) { | 765 } else if (!extension->web_extent().MatchesURL(url)) { |
| 757 continue; | 766 continue; |
| 758 } | 767 } |
| 759 | 768 |
| 760 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), | 769 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), |
| 761 process->profile()->IsOffTheRecord())); | 770 process->context()->IsOffTheRecord())); |
| 762 } | 771 } |
| 763 } | 772 } |
| 764 | 773 |
| 765 ExtensionsDOMHandler::~ExtensionsDOMHandler() { | 774 ExtensionsDOMHandler::~ExtensionsDOMHandler() { |
| 766 // There may be pending file dialogs, we need to tell them that we've gone | 775 // There may be pending file dialogs, we need to tell them that we've gone |
| 767 // away so they don't try and call back to us. | 776 // away so they don't try and call back to us. |
| 768 if (load_extension_dialog_.get()) | 777 if (load_extension_dialog_.get()) |
| 769 load_extension_dialog_->ListenerDestroyed(); | 778 load_extension_dialog_->ListenerDestroyed(); |
| 770 | 779 |
| 771 if (pack_job_.get()) | 780 if (pack_job_.get()) |
| 772 pack_job_->ClearClient(); | 781 pack_job_->ClearClient(); |
| 773 | 782 |
| 774 registrar_.RemoveAll(); | 783 registrar_.RemoveAll(); |
| 775 } | 784 } |
| 776 | 785 |
| 777 // ExtensionsDOMHandler, public: ----------------------------------------------- | 786 // ExtensionsDOMHandler, public: ----------------------------------------------- |
| 778 | 787 |
| 779 ExtensionsUI::ExtensionsUI(TabContents* contents) : ChromeWebUI(contents) { | 788 ExtensionsUI::ExtensionsUI(TabContents* contents) : ChromeWebUI(contents) { |
| 780 ExtensionService *exstension_service = | 789 Profile* profile = static_cast<Profile*>(contents->browser_context()); |
| 781 GetProfile()->GetOriginalProfile()->GetExtensionService(); | 790 ExtensionService *extension_service = |
| 791 profile->GetOriginalProfile()->GetExtensionService(); |
| 782 | 792 |
| 783 ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(exstension_service); | 793 ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(extension_service); |
| 784 AddMessageHandler(handler); | 794 AddMessageHandler(handler); |
| 785 handler->Attach(this); | 795 handler->Attach(this); |
| 786 | 796 |
| 787 // Set up the chrome://extensions/ source. | 797 // Set up the chrome://extensions/ source. |
| 788 contents->profile()->GetChromeURLDataManager()->AddDataSource( | 798 profile->GetChromeURLDataManager()->AddDataSource( |
| 789 CreateExtensionsUIHTMLSource()); | 799 CreateExtensionsUIHTMLSource()); |
| 790 } | 800 } |
| 791 | 801 |
| 792 // static | 802 // static |
| 793 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { | 803 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { |
| 794 return ResourceBundle::GetSharedInstance(). | 804 return ResourceBundle::GetSharedInstance(). |
| 795 LoadDataResourceBytes(IDR_PLUGIN); | 805 LoadDataResourceBytes(IDR_PLUGIN); |
| 796 } | 806 } |
| 797 | 807 |
| 798 // static | 808 // static |
| 799 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { | 809 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { |
| 800 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | 810 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, |
| 801 false, | 811 false, |
| 802 PrefService::SYNCABLE_PREF); | 812 PrefService::SYNCABLE_PREF); |
| 803 } | 813 } |
| OLD | NEW |