Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/browser/extensions/extensions_ui.cc

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works now Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = static_cast<Profile*>(web_ui_->tab_contents()->context());
246 bool developer_mode = profile->GetPrefs()
246 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); 247 ->GetBoolean(prefs::kExtensionsUIDeveloperMode);
247 results.SetBoolean("developerMode", developer_mode); 248 results.SetBoolean("developerMode", developer_mode);
248 249
249 web_ui_->CallJavascriptFunction("returnExtensionsData", results); 250 web_ui_->CallJavascriptFunction("returnExtensionsData", results);
250 } 251 }
251 252
252 void ExtensionsDOMHandler::RegisterForNotifications() { 253 void ExtensionsDOMHandler::RegisterForNotifications() {
253 // Register for notifications that we need to reload the page. 254 // Register for notifications that we need to reload the page.
254 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 255 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
255 NotificationService::AllSources()); 256 NotificationService::AllSources());
(...skipping 18 matching lines...) Expand all
274 registrar_.Add(this, 275 registrar_.Add(this,
275 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 276 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
276 NotificationService::AllSources()); 277 NotificationService::AllSources());
277 registrar_.Add(this, 278 registrar_.Add(this,
278 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 279 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
279 NotificationService::AllSources()); 280 NotificationService::AllSources());
280 } 281 }
281 282
282 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { 283 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() {
283 if (!extension_uninstall_dialog_.get()) { 284 if (!extension_uninstall_dialog_.get()) {
285 Profile* profile =
286 static_cast<Profile*>(web_ui_->tab_contents()->context());
284 extension_uninstall_dialog_.reset( 287 extension_uninstall_dialog_.reset(
285 new ExtensionUninstallDialog(web_ui_->GetProfile())); 288 new ExtensionUninstallDialog(profile));
286 } 289 }
287 return extension_uninstall_dialog_.get(); 290 return extension_uninstall_dialog_.get();
288 } 291 }
289 292
290 void ExtensionsDOMHandler::HandleToggleDeveloperMode(const ListValue* args) { 293 void ExtensionsDOMHandler::HandleToggleDeveloperMode(const ListValue* args) {
291 bool developer_mode = web_ui_->GetProfile()->GetPrefs() 294 Profile* profile = static_cast<Profile*>(web_ui_->tab_contents()->context());
295 bool developer_mode = profile->GetPrefs()
292 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); 296 ->GetBoolean(prefs::kExtensionsUIDeveloperMode);
293 web_ui_->GetProfile()->GetPrefs()->SetBoolean( 297 profile->GetPrefs()->SetBoolean(
294 prefs::kExtensionsUIDeveloperMode, !developer_mode); 298 prefs::kExtensionsUIDeveloperMode, !developer_mode);
295 } 299 }
296 300
297 void ExtensionsDOMHandler::HandleInspectMessage(const ListValue* args) { 301 void ExtensionsDOMHandler::HandleInspectMessage(const ListValue* args) {
298 std::string render_process_id_str; 302 std::string render_process_id_str;
299 std::string render_view_id_str; 303 std::string render_view_id_str;
300 int render_process_id; 304 int render_process_id;
301 int render_view_id; 305 int render_view_id;
302 CHECK(args->GetSize() == 2); 306 CHECK(args->GetSize() == 2);
303 CHECK(args->GetString(0, &render_process_id_str)); 307 CHECK(args->GetString(0, &render_process_id_str));
(...skipping 26 matching lines...) Expand all
330 DCHECK(extension); 334 DCHECK(extension);
331 if (!Extension::UserMayDisable(extension->location())) { 335 if (!Extension::UserMayDisable(extension->location())) {
332 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" 336 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was"
333 << "made. Extension id: " << extension->id(); 337 << "made. Extension id: " << extension->id();
334 return; 338 return;
335 } 339 }
336 340
337 if (enable_str == "true") { 341 if (enable_str == "true") {
338 ExtensionPrefs* prefs = extension_service_->extension_prefs(); 342 ExtensionPrefs* prefs = extension_service_->extension_prefs();
339 if (prefs->DidExtensionEscalatePermissions(extension_id)) { 343 if (prefs->DidExtensionEscalatePermissions(extension_id)) {
344 Profile* profile =
345 static_cast<Profile*>(web_ui_->tab_contents()->context());
340 ShowExtensionDisabledDialog(extension_service_, 346 ShowExtensionDisabledDialog(extension_service_,
341 web_ui_->GetProfile(), extension); 347 profile, extension);
342 } else { 348 } else {
343 extension_service_->EnableExtension(extension_id); 349 extension_service_->EnableExtension(extension_id);
344 } 350 }
345 } else { 351 } else {
346 extension_service_->DisableExtension(extension_id); 352 extension_service_->DisableExtension(extension_id);
347 } 353 }
348 } 354 }
349 355
350 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) { 356 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) {
351 CHECK(args->GetSize() == 2); 357 CHECK(args->GetSize() == 2);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 449 }
444 450
445 void ExtensionsDOMHandler::ExtensionDialogCanceled() { 451 void ExtensionsDOMHandler::ExtensionDialogCanceled() {
446 extension_id_prompting_ = ""; 452 extension_id_prompting_ = "";
447 } 453 }
448 454
449 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) { 455 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) {
450 const Extension* extension = GetExtension(args); 456 const Extension* extension = GetExtension(args);
451 if (!extension || extension->options_url().is_empty()) 457 if (!extension || extension->options_url().is_empty())
452 return; 458 return;
453 web_ui_->GetProfile()->GetExtensionProcessManager()->OpenOptionsPage( 459 Profile* profile = static_cast<Profile*>(web_ui_->tab_contents()->context());
454 extension, NULL); 460 profile->GetExtensionProcessManager()->OpenOptionsPage(extension, NULL);
455 } 461 }
456 462
457 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) { 463 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) {
458 const Extension* extension = GetExtension(args); 464 const Extension* extension = GetExtension(args);
459 extension_service_->SetBrowserActionVisibility(extension, true); 465 extension_service_->SetBrowserActionVisibility(extension, true);
460 } 466 }
461 467
462 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) { 468 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) {
463 FilePath::StringType string_path; 469 FilePath::StringType string_path;
464 CHECK(args->GetSize() == 1) << args->GetSize(); 470 CHECK(args->GetSize() == 1) << args->GetSize();
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 757
752 GURL url = host->delegate()->GetURL(); 758 GURL url = host->delegate()->GetURL();
753 if (url.SchemeIs(chrome::kExtensionScheme)) { 759 if (url.SchemeIs(chrome::kExtensionScheme)) {
754 if (url.host() != extension->id()) 760 if (url.host() != extension->id())
755 continue; 761 continue;
756 } else if (!extension->web_extent().MatchesURL(url)) { 762 } else if (!extension->web_extent().MatchesURL(url)) {
757 continue; 763 continue;
758 } 764 }
759 765
760 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), 766 result->push_back(ExtensionPage(url, process->id(), host->routing_id(),
761 process->profile()->IsOffTheRecord())); 767 process->context()->IsOffTheRecord()));
762 } 768 }
763 } 769 }
764 770
765 ExtensionsDOMHandler::~ExtensionsDOMHandler() { 771 ExtensionsDOMHandler::~ExtensionsDOMHandler() {
766 // There may be pending file dialogs, we need to tell them that we've gone 772 // 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. 773 // away so they don't try and call back to us.
768 if (load_extension_dialog_.get()) 774 if (load_extension_dialog_.get())
769 load_extension_dialog_->ListenerDestroyed(); 775 load_extension_dialog_->ListenerDestroyed();
770 776
771 if (pack_job_.get()) 777 if (pack_job_.get())
772 pack_job_->ClearClient(); 778 pack_job_->ClearClient();
773 779
774 registrar_.RemoveAll(); 780 registrar_.RemoveAll();
775 } 781 }
776 782
777 // ExtensionsDOMHandler, public: ----------------------------------------------- 783 // ExtensionsDOMHandler, public: -----------------------------------------------
778 784
779 ExtensionsUI::ExtensionsUI(TabContents* contents) : ChromeWebUI(contents) { 785 ExtensionsUI::ExtensionsUI(TabContents* contents) : ChromeWebUI(contents) {
780 ExtensionService *exstension_service = 786 Profile* profile = static_cast<Profile*>(contents->context());
781 GetProfile()->GetOriginalProfile()->GetExtensionService(); 787 ExtensionService *extension_service =
788 profile->GetOriginalProfile()->GetExtensionService();
782 789
783 ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(exstension_service); 790 ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(extension_service);
784 AddMessageHandler(handler); 791 AddMessageHandler(handler);
785 handler->Attach(this); 792 handler->Attach(this);
786 793
787 // Set up the chrome://extensions/ source. 794 // Set up the chrome://extensions/ source.
788 contents->profile()->GetChromeURLDataManager()->AddDataSource( 795 profile->GetChromeURLDataManager()->AddDataSource(
789 CreateExtensionsUIHTMLSource()); 796 CreateExtensionsUIHTMLSource());
790 } 797 }
791 798
792 // static 799 // static
793 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { 800 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() {
794 return ResourceBundle::GetSharedInstance(). 801 return ResourceBundle::GetSharedInstance().
795 LoadDataResourceBytes(IDR_PLUGIN); 802 LoadDataResourceBytes(IDR_PLUGIN);
796 } 803 }
797 804
798 // static 805 // static
799 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { 806 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) {
800 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, 807 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode,
801 false, 808 false,
802 PrefService::SYNCABLE_PREF); 809 PrefService::SYNCABLE_PREF);
803 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698