Commit 7dd05290 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Move remaining notifications out of ExtensionSettingsHandler

Move the remaining notifications from ExtensionSettingsHandler to the
DeveloperPrivate API.
Also adjust the WarningService observer method to include a set of modified
extensions.

BUG=461039

Review URL: https://codereview.chromium.org/1146693004

Cr-Commit-Position: refs/heads/master@{#330633}
parent 14769fd8
...@@ -155,6 +155,23 @@ void PerformVerificationCheck(content::BrowserContext* context) { ...@@ -155,6 +155,23 @@ void PerformVerificationCheck(content::BrowserContext* context) {
InstallVerifier::Get(context)->VerifyAllExtensions(); InstallVerifier::Get(context)->VerifyAllExtensions();
} }
scoped_ptr<developer::ProfileInfo> CreateProfileInfo(Profile* profile) {
scoped_ptr<developer::ProfileInfo> info(new developer::ProfileInfo());
info->is_supervised = profile->IsSupervised();
PrefService* prefs = profile->GetPrefs();
info->is_incognito_available =
IncognitoModePrefs::GetAvailability(prefs) !=
IncognitoModePrefs::DISABLED;
info->in_developer_mode =
!info->is_supervised &&
prefs->GetBoolean(prefs::kExtensionsUIDeveloperMode);
info->app_info_dialog_enabled = CanShowAppInfoDialog();
info->can_load_unpacked =
!ExtensionManagementFactory::GetForBrowserContext(profile)
->BlacklistedByDefault();
return info.Pass();
}
} // namespace } // namespace
namespace ChoosePath = api::developer_private::ChoosePath; namespace ChoosePath = api::developer_private::ChoosePath;
...@@ -188,6 +205,9 @@ DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) ...@@ -188,6 +205,9 @@ DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile)
process_manager_observer_(this), process_manager_observer_(this),
app_window_registry_observer_(this), app_window_registry_observer_(this),
extension_action_api_observer_(this), extension_action_api_observer_(this),
warning_service_observer_(this),
extension_prefs_observer_(this),
extension_management_observer_(this),
profile_(profile), profile_(profile),
event_router_(EventRouter::Get(profile_)), event_router_(EventRouter::Get(profile_)),
weak_factory_(this) { weak_factory_(this) {
...@@ -196,6 +216,10 @@ DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile) ...@@ -196,6 +216,10 @@ DeveloperPrivateEventRouter::DeveloperPrivateEventRouter(Profile* profile)
process_manager_observer_.Add(ProcessManager::Get(profile)); process_manager_observer_.Add(ProcessManager::Get(profile));
app_window_registry_observer_.Add(AppWindowRegistry::Get(profile)); app_window_registry_observer_.Add(AppWindowRegistry::Get(profile));
extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile)); extension_action_api_observer_.Add(ExtensionActionAPI::Get(profile));
warning_service_observer_.Add(WarningService::Get(profile));
extension_prefs_observer_.Add(ExtensionPrefs::Get(profile));
extension_management_observer_.Add(
ExtensionManagementFactory::GetForBrowserContext(profile));
} }
DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() { DeveloperPrivateEventRouter::~DeveloperPrivateEventRouter() {
...@@ -291,6 +315,25 @@ void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged( ...@@ -291,6 +315,25 @@ void DeveloperPrivateEventRouter::OnExtensionActionVisibilityChanged(
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id); BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id);
} }
void DeveloperPrivateEventRouter::OnExtensionDisableReasonsChanged(
const std::string& extension_id, int disable_reasons) {
BroadcastItemStateChanged(developer::EVENT_TYPE_PREFS_CHANGED, extension_id);
}
void DeveloperPrivateEventRouter::OnExtensionManagementSettingsChanged() {
scoped_ptr<base::ListValue> args(new base::ListValue());
args->Append(CreateProfileInfo(profile_)->ToValue());
scoped_ptr<Event> event(new Event(
developer::OnProfileStateChanged::kEventName, args.Pass()));
event_router_->BroadcastEvent(event.Pass());
}
void DeveloperPrivateEventRouter::ExtensionWarningsChanged(
const ExtensionIdSet& affected_extensions) {
for (const ExtensionId& id : affected_extensions)
BroadcastItemStateChanged(developer::EVENT_TYPE_WARNINGS_CHANGED, id);
}
void DeveloperPrivateEventRouter::BroadcastItemStateChanged( void DeveloperPrivateEventRouter::BroadcastItemStateChanged(
developer::EventType event_type, developer::EventType event_type,
const std::string& extension_id) { const std::string& extension_id) {
...@@ -499,18 +542,7 @@ DeveloperPrivateGetProfileConfigurationFunction:: ...@@ -499,18 +542,7 @@ DeveloperPrivateGetProfileConfigurationFunction::
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
DeveloperPrivateGetProfileConfigurationFunction::Run() { DeveloperPrivateGetProfileConfigurationFunction::Run() {
developer::ProfileInfo info; scoped_ptr<developer::ProfileInfo> info = CreateProfileInfo(GetProfile());
info.is_supervised = GetProfile()->IsSupervised();
info.is_incognito_available =
IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs()) !=
IncognitoModePrefs::DISABLED;
info.in_developer_mode =
!info.is_supervised &&
GetProfile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
info.app_info_dialog_enabled = CanShowAppInfoDialog();
info.can_load_unpacked =
!ExtensionManagementFactory::GetForBrowserContext(browser_context())
->BlacklistedByDefault();
// If this is called from the chrome://extensions page, we use this as a // If this is called from the chrome://extensions page, we use this as a
// heuristic that it's a good time to verify installs. We do this on startup, // heuristic that it's a good time to verify installs. We do this on startup,
...@@ -519,7 +551,7 @@ DeveloperPrivateGetProfileConfigurationFunction::Run() { ...@@ -519,7 +551,7 @@ DeveloperPrivateGetProfileConfigurationFunction::Run() {
if (source_context_type() == Feature::WEBUI_CONTEXT) if (source_context_type() == Feature::WEBUI_CONTEXT)
PerformVerificationCheck(browser_context()); PerformVerificationCheck(browser_context());
return RespondNow(OneArgument(info.ToValue())); return RespondNow(OneArgument(info->ToValue()));
} }
DeveloperPrivateUpdateProfileConfigurationFunction:: DeveloperPrivateUpdateProfileConfigurationFunction::
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/api/file_system/file_system_api.h" #include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/extensions/chrome_extension_function.h" #include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/extensions/error_console/error_console.h" #include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h" #include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/extensions/pack_extension_job.h" #include "chrome/browser/extensions/pack_extension_job.h"
#include "chrome/common/extensions/api/developer_private.h" #include "chrome/common/extensions/api/developer_private.h"
...@@ -22,8 +23,10 @@ ...@@ -22,8 +23,10 @@
#include "extensions/browser/app_window/app_window_registry.h" #include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs_observer.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/process_manager_observer.h" #include "extensions/browser/process_manager_observer.h"
#include "extensions/browser/warning_service.h"
#include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation.h"
#include "ui/shell_dialogs/select_file_dialog.h" #include "ui/shell_dialogs/select_file_dialog.h"
...@@ -52,7 +55,10 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver, ...@@ -52,7 +55,10 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver,
public ErrorConsole::Observer, public ErrorConsole::Observer,
public ProcessManagerObserver, public ProcessManagerObserver,
public AppWindowRegistry::Observer, public AppWindowRegistry::Observer,
public ExtensionActionAPI::Observer { public ExtensionActionAPI::Observer,
public ExtensionPrefsObserver,
public ExtensionManagement::Observer,
public WarningService::Observer {
public: public:
explicit DeveloperPrivateEventRouter(Profile* profile); explicit DeveloperPrivateEventRouter(Profile* profile);
~DeveloperPrivateEventRouter() override; ~DeveloperPrivateEventRouter() override;
...@@ -95,6 +101,17 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver, ...@@ -95,6 +101,17 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver,
void OnExtensionActionVisibilityChanged(const std::string& extension_id, void OnExtensionActionVisibilityChanged(const std::string& extension_id,
bool is_now_visible) override; bool is_now_visible) override;
// ExtensionPrefsObserver:
void OnExtensionDisableReasonsChanged(const std::string& extension_id,
int disable_reasons) override;
// ExtensionManagement::Observer:
void OnExtensionManagementSettingsChanged() override;
// WarningService::Observer:
void ExtensionWarningsChanged(
const ExtensionIdSet& affected_extensions) override;
// Broadcasts an event to all listeners. // Broadcasts an event to all listeners.
void BroadcastItemStateChanged(api::developer_private::EventType event_type, void BroadcastItemStateChanged(api::developer_private::EventType event_type,
const std::string& id); const std::string& id);
...@@ -114,6 +131,12 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver, ...@@ -114,6 +131,12 @@ class DeveloperPrivateEventRouter : public ExtensionRegistryObserver,
app_window_registry_observer_; app_window_registry_observer_;
ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer>
extension_action_api_observer_; extension_action_api_observer_;
ScopedObserver<WarningService, WarningService::Observer>
warning_service_observer_;
ScopedObserver<ExtensionPrefs, ExtensionPrefsObserver>
extension_prefs_observer_;
ScopedObserver<ExtensionManagement, ExtensionManagement::Observer>
extension_management_observer_;
Profile* profile_; Profile* profile_;
......
...@@ -125,7 +125,8 @@ const WarningSet& WarningBadgeService::GetCurrentWarnings() const { ...@@ -125,7 +125,8 @@ const WarningSet& WarningBadgeService::GetCurrentWarnings() const {
return WarningService::Get(profile_)->warnings(); return WarningService::Get(profile_)->warnings();
} }
void WarningBadgeService::ExtensionWarningsChanged() { void WarningBadgeService::ExtensionWarningsChanged(
const ExtensionIdSet& affected_extensions) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
UpdateBadgeStatus(); UpdateBadgeStatus();
} }
......
...@@ -36,7 +36,8 @@ class WarningBadgeService : public KeyedService, ...@@ -36,7 +36,8 @@ class WarningBadgeService : public KeyedService,
private: private:
// Implementation of WarningService::Observer. // Implementation of WarningService::Observer.
void ExtensionWarningsChanged() override; void ExtensionWarningsChanged(
const ExtensionIdSet& affected_extensions) override;
void UpdateBadgeStatus(); void UpdateBadgeStatus();
virtual void ShowBadge(bool show); virtual void ShowBadge(bool show);
......
...@@ -148,10 +148,12 @@ cr.define('extensions', function() { ...@@ -148,10 +148,12 @@ cr.define('extensions', function() {
var wrapper = $('extension-list-wrapper'); var wrapper = $('extension-list-wrapper');
wrapper.insertBefore(extensionList, wrapper.firstChild); wrapper.insertBefore(extensionList, wrapper.firstChild);
this.update_(); // Get the initial profile state, and register to be notified of any
// TODO(devlin): Remove this once all notifications are moved to events on // future changes.
// the developerPrivate api. chrome.developerPrivate.getProfileConfiguration(
chrome.send('extensionSettingsRegister'); this.update_.bind(this));
chrome.developerPrivate.onProfileStateChanged.addListener(
this.update_.bind(this));
var extensionLoader = extensions.ExtensionLoader.getInstance(); var extensionLoader = extensions.ExtensionLoader.getInstance();
...@@ -239,24 +241,15 @@ cr.define('extensions', function() { ...@@ -239,24 +241,15 @@ cr.define('extensions', function() {
} }
}, },
/**
* Updates the extensions page to the latest profile and extensions
* configuration.
* @private
*/
update_: function() {
chrome.developerPrivate.getProfileConfiguration(
this.returnProfileConfiguration_.bind(this));
},
/** /**
* [Re]-Populates the page with data representing the current state of * [Re]-Populates the page with data representing the current state of
* installed extensions. * installed extensions.
* @param {ProfileInfo} profileInfo * @param {ProfileInfo} profileInfo
* @private * @private
*/ */
returnProfileConfiguration_: function(profileInfo) { update_: function(profileInfo) {
webuiResponded = true; webuiResponded = true;
/** @const */ /** @const */
var supervised = profileInfo.isSupervised; var supervised = profileInfo.isSupervised;
...@@ -366,14 +359,6 @@ cr.define('extensions', function() { ...@@ -366,14 +359,6 @@ cr.define('extensions', function() {
}, },
}; };
/**
* Called by the WebUI when something has changed and the extensions UI needs
* to be updated.
*/
ExtensionSettings.onExtensionsChanged = function() {
ExtensionSettings.getInstance().update_();
};
/** /**
* Returns the current overlay or null if one does not exist. * Returns the current overlay or null if one does not exist.
* @return {Element} The overlay element. * @return {Element} The overlay element.
......
...@@ -6,57 +6,29 @@ ...@@ -6,57 +6,29 @@
#include <vector> #include <vector>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/background/background_contents.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/apps/app_info_dialog.h" #include "chrome/browser/ui/apps/app_info_dialog.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/google/core/browser/google_util.h" #include "components/google/core/browser/google_util.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "extensions/browser/api/device_permissions_manager.h"
#include "extensions/browser/blacklist_state.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/warning_set.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
#include "extensions/common/extension_urls.h" #include "extensions/common/extension_urls.h"
#include "extensions/common/manifest.h" #include "extensions/common/manifest.h"
#include "extensions/common/permissions/permissions_data.h"
#include "grit/browser_resources.h" #include "grit/browser_resources.h"
#include "grit/components_strings.h" #include "grit/components_strings.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
...@@ -65,17 +37,8 @@ ...@@ -65,17 +37,8 @@
namespace extensions { namespace extensions {
///////////////////////////////////////////////////////////////////////////////
//
// ExtensionSettingsHandler
//
///////////////////////////////////////////////////////////////////////////////
ExtensionSettingsHandler::ExtensionSettingsHandler() ExtensionSettingsHandler::ExtensionSettingsHandler()
: extension_service_(NULL), : extension_service_(nullptr) {
warning_service_observer_(this),
extension_prefs_observer_(this),
extension_management_observer_(this) {
} }
ExtensionSettingsHandler::~ExtensionSettingsHandler() { ExtensionSettingsHandler::~ExtensionSettingsHandler() {
...@@ -277,15 +240,6 @@ void ExtensionSettingsHandler::GetLocalizedValues( ...@@ -277,15 +240,6 @@ void ExtensionSettingsHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY)); l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY));
} }
void ExtensionSettingsHandler::RenderViewDeleted(
content::RenderViewHost* render_view_host) {
Profile* source_profile = Profile::FromBrowserContext(
render_view_host->GetSiteInstance()->GetBrowserContext());
if (!Profile::FromWebUI(web_ui())->IsSameProfile(source_profile))
return;
MaybeUpdateAfterNotification();
}
void ExtensionSettingsHandler::DidStartNavigationToPendingEntry( void ExtensionSettingsHandler::DidStartNavigationToPendingEntry(
const GURL& url, const GURL& url,
content::NavigationController::ReloadType reload_type) { content::NavigationController::ReloadType reload_type) {
...@@ -297,23 +251,10 @@ void ExtensionSettingsHandler::RegisterMessages() { ...@@ -297,23 +251,10 @@ void ExtensionSettingsHandler::RegisterMessages() {
Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile();
extension_service_ = extension_service_ =
extensions::ExtensionSystem::Get(profile)->extension_service(); extensions::ExtensionSystem::Get(profile)->extension_service();
// Clear the preference for the ADT Promo before fully removing it.
web_ui()->RegisterMessageCallback("extensionSettingsRegister", // TODO(devlin): Take this out when everyone's been updated.
base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage, Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref(
AsWeakPtr())); prefs::kExtensionsUIDismissedADTPromo);
}
void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged(
const std::string& extension_id, int disable_reasons) {
MaybeUpdateAfterNotification();
}
void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() {
MaybeUpdateAfterNotification();
}
void ExtensionSettingsHandler::ExtensionWarningsChanged() {
MaybeUpdateAfterNotification();
} }
void ExtensionSettingsHandler::ReloadUnpackedExtensions() { void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
...@@ -332,29 +273,4 @@ void ExtensionSettingsHandler::ReloadUnpackedExtensions() { ...@@ -332,29 +273,4 @@ void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
} }
} }
void ExtensionSettingsHandler::HandleRegisterMessage(
const base::ListValue* args) {
if (content::WebContentsObserver::web_contents())
return; // Only register once.
content::WebContentsObserver::Observe(web_ui()->GetWebContents());
Profile* profile = Profile::FromWebUI(web_ui());
warning_service_observer_.Add(WarningService::Get(profile));
extension_management_observer_.Add(
ExtensionManagementFactory::GetForBrowserContext(profile));
// Clear the preference for the ADT Promo before fully removing it.
// TODO(devlin): Take this out when everyone's been updated.
profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo);
}
void ExtensionSettingsHandler::MaybeUpdateAfterNotification() {
content::WebContents* contents = web_ui()->GetWebContents();
if (contents && contents->GetRenderViewHost()) {
web_ui()->CallJavascriptFunction(
"extensions.ExtensionSettings.onExtensionsChanged");
}
}
} // namespace extensions } // namespace extensions
...@@ -5,25 +5,13 @@ ...@@ -5,25 +5,13 @@
#ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_ #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_HANDLER_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/extension_management.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
#include "extensions/browser/extension_prefs_observer.h"
#include "extensions/browser/warning_service.h"
class ExtensionService; class ExtensionService;
class GURL; class GURL;
namespace base {
class FilePath;
class ListValue;
}
namespace content { namespace content {
class WebUIDataSource; class WebUIDataSource;
} }
...@@ -33,17 +21,10 @@ class PrefRegistrySyncable; ...@@ -33,17 +21,10 @@ class PrefRegistrySyncable;
} }
namespace extensions { namespace extensions {
class Extension;
class ExtensionPrefs;
// Extension Settings UI handler. // Extension Settings UI handler.
class ExtensionSettingsHandler class ExtensionSettingsHandler : public content::WebUIMessageHandler,
: public content::WebUIMessageHandler, public content::WebContentsObserver {
public content::WebContentsObserver,
public ExtensionManagement::Observer,
public ExtensionPrefsObserver,
public WarningService::Observer,
public base::SupportsWeakPtr<ExtensionSettingsHandler> {
public: public:
ExtensionSettingsHandler(); ExtensionSettingsHandler();
~ExtensionSettingsHandler() override; ~ExtensionSettingsHandler() override;
...@@ -53,8 +34,7 @@ class ExtensionSettingsHandler ...@@ -53,8 +34,7 @@ class ExtensionSettingsHandler
void GetLocalizedValues(content::WebUIDataSource* source); void GetLocalizedValues(content::WebUIDataSource* source);
private: private:
// content::WebContentsObserver implementation. // WebContentsObserver implementation.
void RenderViewDeleted(content::RenderViewHost* render_view_host) override;
void DidStartNavigationToPendingEntry( void DidStartNavigationToPendingEntry(
const GURL& url, const GURL& url,
content::NavigationController::ReloadType reload_type) override; content::NavigationController::ReloadType reload_type) override;
...@@ -62,39 +42,12 @@ class ExtensionSettingsHandler ...@@ -62,39 +42,12 @@ class ExtensionSettingsHandler
// WebUIMessageHandler implementation. // WebUIMessageHandler implementation.
void RegisterMessages() override; void RegisterMessages() override;
// ExtensionPrefsObserver implementation.
void OnExtensionDisableReasonsChanged(const std::string& extension_id,
int disable_reasons) override;
// ExtensionManagement::Observer implementation.
void OnExtensionManagementSettingsChanged() override;
// WarningService::Observer implementation.
void ExtensionWarningsChanged() override;
// Helper method that reloads all unpacked extensions. // Helper method that reloads all unpacked extensions.
void ReloadUnpackedExtensions(); void ReloadUnpackedExtensions();
// Callback for the "extensionSettingsRegister" message.
void HandleRegisterMessage(const base::ListValue* args);
// Forces a UI update if appropriate after a notification is received.
void MaybeUpdateAfterNotification();
// Our model. Outlives us since it's owned by our containing profile. // Our model. Outlives us since it's owned by our containing profile.
ExtensionService* extension_service_; ExtensionService* extension_service_;
ScopedObserver<WarningService, WarningService::Observer>
warning_service_observer_;
// An observer to listen for notable changes in the ExtensionPrefs, like
// a change in Disable Reasons.
ScopedObserver<ExtensionPrefs, ExtensionPrefsObserver>
extension_prefs_observer_;
ScopedObserver<ExtensionManagement, ExtensionManagement::Observer>
extension_management_observer_;
DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler); DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler);
}; };
......
...@@ -288,7 +288,8 @@ namespace developerPrivate { ...@@ -288,7 +288,8 @@ namespace developerPrivate {
VIEW_UNREGISTERED, VIEW_UNREGISTERED,
ERROR_ADDED, ERROR_ADDED,
ERRORS_REMOVED, ERRORS_REMOVED,
PREFS_CHANGED PREFS_CHANGED,
WARNINGS_CHANGED
}; };
dictionary PackDirectoryResponse { dictionary PackDirectoryResponse {
...@@ -536,6 +537,9 @@ namespace developerPrivate { ...@@ -536,6 +537,9 @@ namespace developerPrivate {
interface Events { interface Events {
// Fired when a item state is changed. // Fired when a item state is changed.
static void onItemStateChanged(EventData response); static void onItemStateChanged(EventData response);
// Fired when the profile's state has changed.
static void onProfileStateChanged(ProfileInfo info);
}; };
}; };
...@@ -33,19 +33,19 @@ WarningService* WarningService::Get(content::BrowserContext* browser_context) { ...@@ -33,19 +33,19 @@ WarningService* WarningService::Get(content::BrowserContext* browser_context) {
void WarningService::ClearWarnings( void WarningService::ClearWarnings(
const std::set<Warning::WarningType>& types) { const std::set<Warning::WarningType>& types) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
bool deleted_anything = false; ExtensionIdSet affected_extensions;
for (WarningSet::iterator i = warnings_.begin(); for (WarningSet::iterator i = warnings_.begin();
i != warnings_.end();) { i != warnings_.end();) {
if (types.find(i->warning_type()) != types.end()) { if (types.find(i->warning_type()) != types.end()) {
deleted_anything = true; affected_extensions.insert(i->extension_id());
warnings_.erase(i++); warnings_.erase(i++);
} else { } else {
++i; ++i;
} }
} }
if (deleted_anything) if (!affected_extensions.empty())
NotifyWarningsChanged(); NotifyWarningsChanged(affected_extensions);
} }
std::set<Warning::WarningType> WarningService:: std::set<Warning::WarningType> WarningService::
...@@ -78,12 +78,14 @@ std::vector<std::string> WarningService::GetWarningMessagesForExtension( ...@@ -78,12 +78,14 @@ std::vector<std::string> WarningService::GetWarningMessagesForExtension(
void WarningService::AddWarnings(const WarningSet& warnings) { void WarningService::AddWarnings(const WarningSet& warnings) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
size_t old_size = warnings_.size();
warnings_.insert(warnings.begin(), warnings.end()); ExtensionIdSet affected_extensions;
for (const Warning& warning : warnings) {
if (old_size != warnings_.size()) if (warnings_.insert(warning).second)
NotifyWarningsChanged(); affected_extensions.insert(warning.extension_id());
}
if (!affected_extensions.empty())
NotifyWarningsChanged(affected_extensions);
} }
// static // static
...@@ -113,8 +115,10 @@ void WarningService::RemoveObserver(Observer* observer) { ...@@ -113,8 +115,10 @@ void WarningService::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer); observer_list_.RemoveObserver(observer);
} }
void WarningService::NotifyWarningsChanged() { void WarningService::NotifyWarningsChanged(
FOR_EACH_OBSERVER(Observer, observer_list_, ExtensionWarningsChanged()); const ExtensionIdSet& affected_extensions) {
FOR_EACH_OBSERVER(Observer, observer_list_,
ExtensionWarningsChanged(affected_extensions));
} }
void WarningService::OnExtensionUnloaded( void WarningService::OnExtensionUnloaded(
......
...@@ -38,7 +38,8 @@ class WarningService : public KeyedService, ...@@ -38,7 +38,8 @@ class WarningService : public KeyedService,
public: public:
class Observer { class Observer {
public: public:
virtual void ExtensionWarningsChanged() = 0; virtual void ExtensionWarningsChanged(
const ExtensionIdSet& affected_extensions) = 0;
}; };
// |browser_context| may be NULL for testing. In this case, be sure to not // |browser_context| may be NULL for testing. In this case, be sure to not
...@@ -75,7 +76,7 @@ class WarningService : public KeyedService, ...@@ -75,7 +76,7 @@ class WarningService : public KeyedService,
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
private: private:
void NotifyWarningsChanged(); void NotifyWarningsChanged(const ExtensionIdSet& affected_extensions);
// ExtensionRegistryObserver implementation. // ExtensionRegistryObserver implementation.
void OnExtensionUnloaded(content::BrowserContext* browser_context, void OnExtensionUnloaded(content::BrowserContext* browser_context,
......
...@@ -30,17 +30,15 @@ class TestWarningService : public WarningService { ...@@ -30,17 +30,15 @@ class TestWarningService : public WarningService {
class MockObserver : public WarningService::Observer { class MockObserver : public WarningService::Observer {
public: public:
virtual ~MockObserver() {} virtual ~MockObserver() {}
MOCK_METHOD0(ExtensionWarningsChanged, void()); MOCK_METHOD1(ExtensionWarningsChanged, void(const ExtensionIdSet&));
}; };
typedef ExtensionsTest WarningServiceTest; typedef ExtensionsTest WarningServiceTest;
const char* ext1_id = "extension1"; const char* ext1_id = "extension1";
const char* ext2_id = "extension2"; const char* ext2_id = "extension2";
const Warning::WarningType warning_1 = const Warning::WarningType warning_1 = Warning::kNetworkDelay;
Warning::kNetworkDelay; const Warning::WarningType warning_2 = Warning::kNetworkConflict;
const Warning::WarningType warning_2 =
Warning::kNetworkConflict;
} // namespace } // namespace
...@@ -52,15 +50,16 @@ TEST_F(WarningServiceTest, SetWarning) { ...@@ -52,15 +50,16 @@ TEST_F(WarningServiceTest, SetWarning) {
MockObserver observer; MockObserver observer;
warning_service.AddObserver(&observer); warning_service.AddObserver(&observer);
ExtensionIdSet affected_extensions;
affected_extensions.insert(ext1_id);
// Insert warning for the first time. // Insert warning for the first time.
EXPECT_CALL(observer, ExtensionWarningsChanged()); EXPECT_CALL(observer, ExtensionWarningsChanged(affected_extensions));
warning_service.AddWarning( warning_service.AddWarning(
Warning::CreateNetworkDelayWarning(ext1_id)); Warning::CreateNetworkDelayWarning(ext1_id));
testing::Mock::VerifyAndClearExpectations(&warning_service); testing::Mock::VerifyAndClearExpectations(&warning_service);
// Second insertion of same warning does not trigger anything. // Second insertion of same warning does not trigger anything.
warning_service.AddWarning( warning_service.AddWarning(Warning::CreateNetworkDelayWarning(ext1_id));
Warning::CreateNetworkDelayWarning(ext1_id));
testing::Mock::VerifyAndClearExpectations(&warning_service); testing::Mock::VerifyAndClearExpectations(&warning_service);
warning_service.RemoveObserver(&observer); warning_service.RemoveObserver(&observer);
...@@ -75,7 +74,10 @@ TEST_F(WarningServiceTest, ClearWarnings) { ...@@ -75,7 +74,10 @@ TEST_F(WarningServiceTest, ClearWarnings) {
warning_service.AddObserver(&observer); warning_service.AddObserver(&observer);
// Insert two unique warnings in one batch. // Insert two unique warnings in one batch.
EXPECT_CALL(observer, ExtensionWarningsChanged()); std::set<std::string> affected_extensions;
affected_extensions.insert(ext1_id);
affected_extensions.insert(ext2_id);
EXPECT_CALL(observer, ExtensionWarningsChanged(affected_extensions));
WarningSet warning_set; WarningSet warning_set;
warning_set.insert(Warning::CreateNetworkDelayWarning(ext1_id)); warning_set.insert(Warning::CreateNetworkDelayWarning(ext1_id));
warning_set.insert(Warning::CreateNetworkConflictWarning(ext2_id)); warning_set.insert(Warning::CreateNetworkConflictWarning(ext2_id));
...@@ -83,7 +85,9 @@ TEST_F(WarningServiceTest, ClearWarnings) { ...@@ -83,7 +85,9 @@ TEST_F(WarningServiceTest, ClearWarnings) {
testing::Mock::VerifyAndClearExpectations(&warning_service); testing::Mock::VerifyAndClearExpectations(&warning_service);
// Remove one warning and check that the badge remains. // Remove one warning and check that the badge remains.
EXPECT_CALL(observer, ExtensionWarningsChanged()); affected_extensions.clear();
affected_extensions.insert(ext2_id);
EXPECT_CALL(observer, ExtensionWarningsChanged(affected_extensions));
std::set<Warning::WarningType> to_clear; std::set<Warning::WarningType> to_clear;
to_clear.insert(warning_2); to_clear.insert(warning_2);
warning_service.ClearWarnings(to_clear); warning_service.ClearWarnings(to_clear);
...@@ -98,12 +102,14 @@ TEST_F(WarningServiceTest, ClearWarnings) { ...@@ -98,12 +102,14 @@ TEST_F(WarningServiceTest, ClearWarnings) {
EXPECT_EQ(0u, existing_warnings.size()); EXPECT_EQ(0u, existing_warnings.size());
// Remove the other one warning. // Remove the other one warning.
EXPECT_CALL(observer, ExtensionWarningsChanged()); affected_extensions.clear();
affected_extensions.insert(ext1_id);
EXPECT_CALL(observer, ExtensionWarningsChanged(affected_extensions));
to_clear.insert(warning_1); to_clear.insert(warning_1);
warning_service.ClearWarnings(to_clear); warning_service.ClearWarnings(to_clear);
testing::Mock::VerifyAndClearExpectations(&warning_service); testing::Mock::VerifyAndClearExpectations(&warning_service);
// Check that not warnings remain. // Check that no warnings remain.
existing_warnings = existing_warnings =
warning_service.GetWarningTypesAffectingExtension(ext1_id); warning_service.GetWarningTypesAffectingExtension(ext1_id);
EXPECT_EQ(0u, existing_warnings.size()); EXPECT_EQ(0u, existing_warnings.size());
......
...@@ -14,11 +14,11 @@ chrome.developerPrivate = {}; ...@@ -14,11 +14,11 @@ chrome.developerPrivate = {};
* @see https://developer.chrome.com/extensions/developerPrivate#type-ItemType * @see https://developer.chrome.com/extensions/developerPrivate#type-ItemType
*/ */
chrome.developerPrivate.ItemType = { chrome.developerPrivate.ItemType = {
hosted_app: 'hosted_app', HOSTED_APP: 'hosted_app',
packaged_app: 'packaged_app', PACKAGED_APP: 'packaged_app',
legacy_packaged_app: 'legacy_packaged_app', LEGACY_PACKAGED_APP: 'legacy_packaged_app',
extension: 'extension', EXTENSION: 'extension',
theme: 'theme', THEME: 'theme',
}; };
/** /**
...@@ -390,6 +390,7 @@ chrome.developerPrivate.EventType = { ...@@ -390,6 +390,7 @@ chrome.developerPrivate.EventType = {
ERROR_ADDED: 'ERROR_ADDED', ERROR_ADDED: 'ERROR_ADDED',
ERRORS_REMOVED: 'ERRORS_REMOVED', ERRORS_REMOVED: 'ERRORS_REMOVED',
PREFS_CHANGED: 'PREFS_CHANGED', PREFS_CHANGED: 'PREFS_CHANGED',
WARNINGS_CHANGED: 'WARNINGS_CHANGED',
}; };
/** /**
...@@ -616,7 +617,8 @@ chrome.developerPrivate.openDevTools = function(properties, callback) {}; ...@@ -616,7 +617,8 @@ chrome.developerPrivate.openDevTools = function(properties, callback) {};
/** /**
* Delete reported extension erors. * Delete reported extension erors.
* @param {DeleteExtensionErrorsProperties} properties * @param {DeleteExtensionErrorsProperties} properties The properties specifying
* the errors to remove.
* @param {function():void=} callback * @param {function():void=} callback
* @see https://developer.chrome.com/extensions/developerPrivate#method-deleteExtensionErrors * @see https://developer.chrome.com/extensions/developerPrivate#method-deleteExtensionErrors
*/ */
...@@ -624,7 +626,7 @@ chrome.developerPrivate.deleteExtensionErrors = function(properties, callback) { ...@@ -624,7 +626,7 @@ chrome.developerPrivate.deleteExtensionErrors = function(properties, callback) {
/** /**
* Repairs the extension specified. * Repairs the extension specified.
* @param {string} extensionId * @param {string} extensionId The id of the extension to repair.
* @param {function():void=} callback * @param {function():void=} callback
* @see https://developer.chrome.com/extensions/developerPrivate#method-repairExtension * @see https://developer.chrome.com/extensions/developerPrivate#method-repairExtension
*/ */
...@@ -632,7 +634,8 @@ chrome.developerPrivate.repairExtension = function(extensionId, callback) {}; ...@@ -632,7 +634,8 @@ chrome.developerPrivate.repairExtension = function(extensionId, callback) {};
/** /**
* Shows the options page for the extension specified. * Shows the options page for the extension specified.
* @param {string} extensionId * @param {string} extensionId The id of the extension to show the options page
* for.
* @param {function():void=} callback * @param {function():void=} callback
* @see https://developer.chrome.com/extensions/developerPrivate#method-showOptions * @see https://developer.chrome.com/extensions/developerPrivate#method-showOptions
*/ */
...@@ -640,7 +643,7 @@ chrome.developerPrivate.showOptions = function(extensionId, callback) {}; ...@@ -640,7 +643,7 @@ chrome.developerPrivate.showOptions = function(extensionId, callback) {};
/** /**
* Shows the path of the extension specified. * Shows the path of the extension specified.
* @param {string} extensionId * @param {string} extensionId The id of the extension to show the path for.
* @param {function():void=} callback * @param {function():void=} callback
* @see https://developer.chrome.com/extensions/developerPrivate#method-showPath * @see https://developer.chrome.com/extensions/developerPrivate#method-showPath
*/ */
...@@ -687,3 +690,10 @@ chrome.developerPrivate.inspect = function(options, callback) {}; ...@@ -687,3 +690,10 @@ chrome.developerPrivate.inspect = function(options, callback) {};
* @see https://developer.chrome.com/extensions/developerPrivate#event-onItemStateChanged * @see https://developer.chrome.com/extensions/developerPrivate#event-onItemStateChanged
*/ */
chrome.developerPrivate.onItemStateChanged; chrome.developerPrivate.onItemStateChanged;
/**
* Fired when the profile's state has changed.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/developerPrivate#event-onProfileStateChanged
*/
chrome.developerPrivate.onProfileStateChanged;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment