| 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* profile = Profile::FromWebUI(web_ui_); |
| 581 Profile* source_profile = NULL; |
| 576 switch (type) { | 582 switch (type) { |
| 577 // We listen for notifications that will result in the page being | 583 // We listen for notifications that will result in the page being |
| 578 // repopulated with data twice for the same event in certain cases. | 584 // repopulated with data twice for the same event in certain cases. |
| 579 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because | 585 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because |
| 580 // we don't know about the views for an extension at EXTENSION_LOADED, but | 586 // 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 | 587 // 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 & | 588 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & |
| 583 // RENDER_VIEW_HOST_CREATED because we want to handle both | 589 // 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 | 590 // 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 | 591 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as |
| 586 // extension content being shown in popups and balloons (which will generate | 592 // extension content being shown in popups and balloons (which will generate |
| 587 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). | 593 // RENDER_VIEW_HOST_CREATED but no NAV_ENTRY_COMMITTED). |
| 588 // | 594 // |
| 589 // Doing it this way gets everything but causes the page to be rendered | 595 // 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. | 596 // more than we need. It doesn't seem to result in any noticeable flicker. |
| 591 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: | 597 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
| 592 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); | 598 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); |
| 599 // Fall through. |
| 600 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| 601 source_profile = Profile::FromBrowserContext( |
| 602 Source<RenderViewHost>(source)->site_instance()-> |
| 603 browsing_instance()->browser_context()); |
| 604 if (!profile->IsSameProfile(source_profile)) |
| 605 return; |
| 593 MaybeUpdateAfterNotification(); | 606 MaybeUpdateAfterNotification(); |
| 594 break; | 607 break; |
| 595 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: | 608 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| 596 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); | 609 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); |
| 610 // Fall through. |
| 611 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| 612 source_profile = Source<Profile>(source).ptr(); |
| 613 if (!profile->IsSameProfile(source_profile)) |
| 614 return; |
| 615 MaybeUpdateAfterNotification(); |
| 616 break; |
| 617 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
| 618 source_profile = Profile::FromBrowserContext( |
| 619 Source<NavigationController>(source).ptr()->browser_context()); |
| 620 if (!profile->IsSameProfile(source_profile)) |
| 621 return; |
| 597 MaybeUpdateAfterNotification(); | 622 MaybeUpdateAfterNotification(); |
| 598 break; | 623 break; |
| 599 case chrome::NOTIFICATION_EXTENSION_LOADED: | 624 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 600 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: | 625 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: |
| 601 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 626 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 602 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 627 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: | 628 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 607 MaybeUpdateAfterNotification(); | 629 MaybeUpdateAfterNotification(); |
| 608 break; | 630 break; |
| 609 default: | 631 default: |
| 610 NOTREACHED(); | 632 NOTREACHED(); |
| 611 } | 633 } |
| 612 } | 634 } |
| 613 | 635 |
| 614 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { | 636 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
| 615 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 637 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 continue; | 768 continue; |
| 747 } else if (!extension->web_extent().MatchesURL(url)) { | 769 } else if (!extension->web_extent().MatchesURL(url)) { |
| 748 continue; | 770 continue; |
| 749 } | 771 } |
| 750 | 772 |
| 751 result->push_back( | 773 result->push_back( |
| 752 ExtensionPage(url, process->id(), host->routing_id(), | 774 ExtensionPage(url, process->id(), host->routing_id(), |
| 753 process->browser_context()->IsOffTheRecord())); | 775 process->browser_context()->IsOffTheRecord())); |
| 754 } | 776 } |
| 755 } | 777 } |
| OLD | NEW |