This source file includes following definitions.
- parent_window_
- StartForWebContents
- StartForNativeWindow
- StartForCurrentlyNonexistentWindow
- Run
- CheckPermissionAndMaybePromptUser
- CreatePrompt
- StartObserving
- StopObserving
- Observe
- InstallUIProceed
- InstallUIAbort
- OpenURL
#include "chrome/browser/ui/extensions/extension_enable_flow.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
using extensions::Extension;
ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
const std::string& extension_id,
ExtensionEnableFlowDelegate* delegate)
: profile_(profile),
extension_id_(extension_id),
delegate_(delegate),
parent_contents_(NULL),
parent_window_(NULL) {
}
ExtensionEnableFlow::~ExtensionEnableFlow() {
}
void ExtensionEnableFlow::StartForWebContents(
content::WebContents* parent_contents) {
parent_contents_ = parent_contents;
parent_window_ = NULL;
Run();
}
void ExtensionEnableFlow::StartForNativeWindow(
gfx::NativeWindow parent_window) {
parent_contents_ = NULL;
parent_window_ = parent_window;
Run();
}
void ExtensionEnableFlow::StartForCurrentlyNonexistentWindow(
base::Callback<gfx::NativeWindow(void)> window_getter) {
window_getter_ = window_getter;
Run();
}
void ExtensionEnableFlow::Run() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
const Extension* extension = service->GetExtensionById(extension_id_, true);
if (!extension) {
extension = extensions::ExtensionRegistry::Get(profile_)->GetExtensionById(
extension_id_, extensions::ExtensionRegistry::TERMINATED);
if (!extension)
return;
service->ReloadExtension(extension_id_);
extension = service->GetExtensionById(extension_id_, true);
if (!extension) {
StartObserving();
return;
}
}
CheckPermissionAndMaybePromptUser();
}
void ExtensionEnableFlow::CheckPermissionAndMaybePromptUser() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
const Extension* extension = service->GetExtensionById(extension_id_, true);
if (!extension) {
delegate_->ExtensionEnableFlowAborted(false);
return;
}
extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
if (!prefs->DidExtensionEscalatePermissions(extension_id_)) {
service->EnableExtension(extension_id_);
delegate_->ExtensionEnableFlowFinished();
return;
}
CreatePrompt();
prompt_->ConfirmReEnable(this, extension);
}
void ExtensionEnableFlow::CreatePrompt() {
if (!window_getter_.is_null())
parent_window_ = window_getter_.Run();
prompt_.reset(parent_contents_ ?
new ExtensionInstallPrompt(parent_contents_) :
new ExtensionInstallPrompt(profile_, parent_window_, this));
}
void ExtensionEnableFlow::StartObserving() {
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::Source<Profile>(profile_));
}
void ExtensionEnableFlow::StopObserving() {
registrar_.RemoveAll();
}
void ExtensionEnableFlow::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_LOADED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
if (extension->id() == extension_id_) {
StopObserving();
CheckPermissionAndMaybePromptUser();
}
break;
}
case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: {
StopObserving();
delegate_->ExtensionEnableFlowAborted(false);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
if (extension->id() == extension_id_) {
StopObserving();
delegate_->ExtensionEnableFlowAborted(false);
}
break;
}
default:
NOTREACHED();
}
}
void ExtensionEnableFlow::InstallUIProceed() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
const Extension* extension = service->GetExtensionById(extension_id_, true);
if (!extension) {
delegate_->ExtensionEnableFlowAborted(true);
return;
}
service->GrantPermissionsAndEnableExtension(extension);
delegate_->ExtensionEnableFlowFinished();
}
void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) {
delegate_->ExtensionEnableFlowAborted(user_initiated);
}
content::WebContents* ExtensionEnableFlow::OpenURL(
const content::OpenURLParams& params) {
chrome::ScopedTabbedBrowserDisplayer displayer(
profile_, chrome::GetActiveDesktop());
return displayer.browser()->OpenURL(params);
}