Chromium Code Reviews| 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/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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "chrome/browser/debugger/devtools_window.h" | 16 #include "chrome/browser/debugger/devtools_window.h" |
| 17 #include "chrome/browser/extensions/crx_installer.h" | 17 #include "chrome/browser/extensions/crx_installer.h" |
| 18 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 18 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_updater.h" | 20 #include "chrome/browser/extensions/extension_updater.h" |
| 21 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/tab_contents/background_contents.h" | 23 #include "chrome/browser/tab_contents/background_contents.h" |
| 24 #include "chrome/browser/ui/webui/extension_icon_source.h" | 24 #include "chrome/browser/ui/webui/extension_icon_source.h" |
| 25 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/common/chrome_view_types.h" | 28 #include "chrome/common/chrome_view_types.h" |
| 29 #include "content/browser/browsing_instance.h" | |
| 29 #include "content/browser/renderer_host/render_process_host.h" | 30 #include "content/browser/renderer_host/render_process_host.h" |
| 30 #include "content/browser/renderer_host/render_view_host.h" | 31 #include "content/browser/renderer_host/render_view_host.h" |
| 31 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
| 32 #include "content/browser/tab_contents/tab_contents_view.h" | 33 #include "content/browser/tab_contents/tab_contents_view.h" |
| 33 #include "content/common/content_notification_types.h" | 34 #include "content/common/content_notification_types.h" |
| 34 #include "content/common/notification_service.h" | 35 #include "content/common/notification_service.h" |
| 35 #include "grit/browser_resources.h" | 36 #include "grit/browser_resources.h" |
| 36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 38 #include "grit/theme_resources.h" | 39 #include "grit/theme_resources.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 results); | 188 results); |
| 188 | 189 |
| 189 MaybeRegisterForNotifications(); | 190 MaybeRegisterForNotifications(); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { | 193 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| 193 if (registered_for_notifications_) | 194 if (registered_for_notifications_) |
| 194 return; | 195 return; |
| 195 | 196 |
| 196 registered_for_notifications_ = true; | 197 registered_for_notifications_ = true; |
| 198 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 197 | 199 |
| 198 // Register for notifications that we need to reload the page. | 200 // Register for notifications that we need to reload the page. |
| 199 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 201 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 200 NotificationService::AllSources()); | 202 Source<Profile>(profile)); |
| 201 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, | 203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
| 202 NotificationService::AllSources()); | 204 Source<Profile>(profile)); |
| 203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 204 NotificationService::AllSources()); | 206 Source<Profile>(profile)); |
| 205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 207 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 206 NotificationService::AllSources()); | 208 Source<Profile>(profile)); |
| 207 registrar_.Add(this, | 209 registrar_.Add(this, |
| 208 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 210 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 209 NotificationService::AllSources()); | 211 NotificationService::AllBrowserContextsAndSources()); |
| 210 registrar_.Add(this, | 212 registrar_.Add(this, |
| 211 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 213 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 212 NotificationService::AllSources()); | 214 NotificationService::AllBrowserContextsAndSources()); |
| 213 registrar_.Add(this, | 215 registrar_.Add(this, |
| 214 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 216 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| 215 NotificationService::AllSources()); | 217 NotificationService::AllBrowserContextsAndSources()); |
| 216 registrar_.Add(this, | 218 registrar_.Add(this, |
| 217 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 219 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 218 NotificationService::AllSources()); | 220 NotificationService::AllBrowserContextsAndSources()); |
| 219 registrar_.Add(this, | 221 registrar_.Add(this, |
| 220 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 222 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 221 NotificationService::AllSources()); | 223 NotificationService::AllBrowserContextsAndSources()); |
| 222 registrar_.Add(this, | 224 registrar_.Add( |
| 225 this, | |
| 223 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 226 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 224 NotificationService::AllSources()); | 227 Source<ExtensionPrefs>(profile->GetExtensionService()-> |
| 228 extension_prefs())); | |
| 225 } | 229 } |
| 226 | 230 |
| 227 ExtensionUninstallDialog* | 231 ExtensionUninstallDialog* |
| 228 ExtensionSettingsHandler::GetExtensionUninstallDialog() { | 232 ExtensionSettingsHandler::GetExtensionUninstallDialog() { |
| 229 if (!extension_uninstall_dialog_.get()) { | 233 if (!extension_uninstall_dialog_.get()) { |
| 230 extension_uninstall_dialog_.reset( | 234 extension_uninstall_dialog_.reset( |
| 231 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui_), this)); | 235 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui_), this)); |
| 232 } | 236 } |
| 233 return extension_uninstall_dialog_.get(); | 237 return extension_uninstall_dialog_.get(); |
| 234 } | 238 } |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 extension_service_ = Profile::FromWebUI(web_ui_) | 570 extension_service_ = Profile::FromWebUI(web_ui_) |
| 567 ->GetOriginalProfile()->GetExtensionService(); | 571 ->GetOriginalProfile()->GetExtensionService(); |
| 568 | 572 |
| 569 // Return result from the superclass. | 573 // Return result from the superclass. |
| 570 return handler; | 574 return handler; |
| 571 } | 575 } |
| 572 | 576 |
| 573 void ExtensionSettingsHandler::Observe(int type, | 577 void ExtensionSettingsHandler::Observe(int type, |
| 574 const NotificationSource& source, | 578 const NotificationSource& source, |
| 575 const NotificationDetails& details) { | 579 const NotificationDetails& details) { |
| 580 Profile* this_profile = Profile::FromWebUI(web_ui_); | |
| 576 switch (type) { | 581 switch (type) { |
| 577 // We listen for notifications that will result in the page being | 582 // We listen for notifications that will result in the page being |
| 578 // repopulated with data twice for the same event in certain cases. | 583 // repopulated with data twice for the same event in certain cases. |
| 579 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because | 584 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because |
| 580 // we don't know about the views for an extension at EXTENSION_LOADED, but | 585 // we don't know about the views for an extension at EXTENSION_LOADED, but |
| 581 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions | 586 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions |
| 582 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & | 587 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & |
| 583 // RENDER_VIEW_HOST_CREATED because we want to handle both | 588 // RENDER_VIEW_HOST_CREATED because we want to handle both |
| 584 // the case of navigating from a non-extension page to an extension page in | 589 // the case of navigating from a non-extension page to an extension page in |
| 585 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as | 590 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as |
| 586 // extension content being shown in popups and balloons (which will generate | 591 // extension content being shown in popups and balloons (which will generate |
| 587 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). | 592 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). |
| 588 // | 593 // |
| 589 // Doing it this way gets everything but causes the page to be rendered | 594 // Doing it this way gets everything but causes the page to be rendered |
| 590 // more than we need. It doesn't seem to result in any noticeable flicker. | 595 // more than we need. It doesn't seem to result in any noticeable flicker. |
| 596 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: | |
| 597 { | |
| 598 Profile* profile = Profile::FromBrowserContext( | |
| 599 Source<RenderViewHost>(source)->site_instance()-> | |
| 600 browsing_instance()->browser_context()); | |
| 601 if (!this_profile->IsSameProfile(profile)) | |
| 602 return; | |
| 603 MaybeUpdateAfterNotification(); | |
| 604 break; | |
| 605 } | |
| 591 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: | 606 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
| 592 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); | 607 { |
| 593 MaybeUpdateAfterNotification(); | 608 Profile* profile = Profile::FromBrowserContext( |
| 594 break; | 609 Source<RenderViewHost>(source)->site_instance()-> |
| 610 browsing_instance()->browser_context()); | |
| 611 if (!this_profile->IsSameProfile(profile)) | |
| 612 return; | |
| 613 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); | |
| 614 MaybeUpdateAfterNotification(); | |
| 615 break; | |
| 616 } | |
| 595 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: | 617 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| 596 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); | 618 { |
| 597 MaybeUpdateAfterNotification(); | 619 Profile* profile = Profile::FromBrowserContext( |
| 598 break; | 620 Details<BackgroundContents>(details)->render_view_host()-> |
| 621 site_instance()->browsing_instance()->browser_context()); | |
| 622 if (!this_profile->IsSameProfile(profile)) | |
| 623 return; | |
| 624 deleting_rvh_ = | |
| 625 Details<BackgroundContents>(details)->render_view_host(); | |
| 626 MaybeUpdateAfterNotification(); | |
| 627 break; | |
| 628 } | |
| 629 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: | |
| 630 { | |
| 631 Profile* profile = Profile::FromBrowserContext( | |
| 632 Details<BackgroundContents>(details)->render_view_host()-> | |
| 633 site_instance()->browsing_instance()->browser_context()); | |
| 634 if (!this_profile->IsSameProfile(profile)) | |
| 635 return; | |
| 636 MaybeUpdateAfterNotification(); | |
| 637 break; | |
| 638 } | |
| 639 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
| 640 { | |
| 641 Profile* profile = Profile::FromBrowserContext( | |
| 642 Source<NavigationController>(source).ptr()->browser_context()); | |
| 643 if (!this_profile->IsSameProfile(profile)) | |
| 644 return; | |
| 645 MaybeUpdateAfterNotification(); | |
| 646 break; | |
| 647 } | |
|
Finnur
2011/10/10 10:34:53
There's a lot of duplicate code here... I'm wonder
| |
| 599 case chrome::NOTIFICATION_EXTENSION_LOADED: | 648 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 600 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: | 649 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: |
| 601 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 650 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 602 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 651 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 603 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: | |
| 604 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
| 605 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: | |
| 606 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 652 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 607 MaybeUpdateAfterNotification(); | 653 MaybeUpdateAfterNotification(); |
| 608 break; | 654 break; |
| 609 default: | 655 default: |
| 610 NOTREACHED(); | 656 NOTREACHED(); |
| 611 } | 657 } |
| 612 } | 658 } |
| 613 | 659 |
| 614 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { | 660 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| 615 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 661 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 continue; | 792 continue; |
| 747 } else if (!extension->web_extent().MatchesURL(url)) { | 793 } else if (!extension->web_extent().MatchesURL(url)) { |
| 748 continue; | 794 continue; |
| 749 } | 795 } |
| 750 | 796 |
| 751 result->push_back( | 797 result->push_back( |
| 752 ExtensionPage(url, process->id(), host->routing_id(), | 798 ExtensionPage(url, process->id(), host->routing_id(), |
| 753 process->browser_context()->IsOffTheRecord())); | 799 process->browser_context()->IsOffTheRecord())); |
| 754 } | 800 } |
| 755 } | 801 } |
| OLD | NEW |