diff options
| author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 21:50:01 +0000 |
|---|---|---|
| committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 21:50:01 +0000 |
| commit | 32fc4ff7d286f7a6ee80d969672cdadaa8d3e8d0 (patch) | |
| tree | c7e59d81962c173d61083003c07819c2805fd042 /chrome/browser/ui | |
| parent | 080245fa243e0c04ccea332660d3058f710a090c (diff) | |
| download | chromium_src-32fc4ff7d286f7a6ee80d969672cdadaa8d3e8d0.zip chromium_src-32fc4ff7d286f7a6ee80d969672cdadaa8d3e8d0.tar.gz chromium_src-32fc4ff7d286f7a6ee80d969672cdadaa8d3e8d0.tar.bz2 | |
Remove BrowserList::GetLastActive from extensions install dialog code by plumbing through the Browser window. In two places (file_manager_util.cc and download_crx_util.cc) there is no context so I left those with FindLastActiveWithProfile for now.
BUG=129187
Review URL: https://chromiumcodereview.appspot.com/10548057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
10 files changed, 49 insertions, 58 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 0dbe830e..f5f7d91 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3835,7 +3835,7 @@ void Browser::OnInstallApplication(TabContents* source, scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( extension_service, extension_service->show_extensions_prompts() ? - new ExtensionInstallPrompt(profile()) : NULL)); + new ExtensionInstallPrompt(this) : NULL)); installer->InstallWebApp(web_app); } diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h index 8d5c8fd..1150d6c 100644 --- a/chrome/browser/ui/browser_list.h +++ b/chrome/browser/ui/browser_list.h @@ -110,16 +110,12 @@ class BrowserList { friend class BrowserView; friend class CertificateViewerDialog; friend class ChromeShellDelegate; - friend class ExtensionInstallDialogView; friend class FeedbackHandler; - friend class GtkThemeService; friend class NetworkProfileBubble; friend class PrintPreviewHandler; - friend class QueryTabsFunction; friend class SelectFileDialogExtension; friend class StartupBrowserCreatorImpl; friend class TaskManager; - friend class TestingAutomationProvider; friend class WindowSizer; friend class browser::BrowserActivityObserver; #if defined(OS_CHROMEOS) @@ -128,9 +124,6 @@ class BrowserList { #if defined(OS_MACOSX) friend Browser* browser::GetLastActiveBrowser(); #endif -#if defined(TOOLKIT_GTK) - friend class browser::ExtensionInstallDialog; -#endif #if defined(USE_ASH) friend content::WebContents* GetActiveWebContents(); #endif diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h index 9c8429f..2ec83f3 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h @@ -15,7 +15,7 @@ #include "chrome/browser/extensions/extension_install_prompt.h" #include "ui/gfx/image/image_skia.h" -class Profile; +class Browser; // Displays the extension or bundle install prompt, and notifies the // ExtensionInstallPrompt::Delegate of success or failure. @@ -38,7 +38,7 @@ class Profile; IBOutlet NSTextField* userCountField_; NSWindow* parentWindow_; // weak - Profile* profile_; // weak + Browser* browser_; // weak ExtensionInstallPrompt::Delegate* delegate_; // weak scoped_ptr<ExtensionInstallPrompt::Prompt> prompt_; } @@ -57,7 +57,7 @@ class Profile; @property(nonatomic, readonly) NSTextField* userCountField; - (id)initWithParentWindow:(NSWindow*)window - profile:(Profile*)profile + browser:(Browser*)browser delegate:(ExtensionInstallPrompt::Delegate*)delegate prompt:(const ExtensionInstallPrompt::Prompt&)prompt; - (void)runAsModalSheet; diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm index 0561ca2..313b8fb 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm @@ -89,7 +89,7 @@ void AppendRatingStarsShim(const gfx::ImageSkia* skiaImage, void* data) { @synthesize userCountField = userCountField_; - (id)initWithParentWindow:(NSWindow*)window - profile:(Profile*)profile + browser:(Browser*)browser delegate:(ExtensionInstallPrompt::Delegate*)delegate prompt:(const ExtensionInstallPrompt::Prompt&)prompt { NSString* nibpath = nil; @@ -117,7 +117,7 @@ void AppendRatingStarsShim(const gfx::ImageSkia* skiaImage, void* data) { if ((self = [super initWithWindowNibPath:nibpath owner:self])) { parentWindow_ = window; - profile_ = profile; + browser_ = browser; delegate_ = delegate; prompt_.reset(new ExtensionInstallPrompt::Prompt(prompt)); } @@ -135,7 +135,7 @@ void AppendRatingStarsShim(const gfx::ImageSkia* skiaImage, void* data) { - (IBAction)storeLinkClicked:(id)sender { GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() + prompt_->extension()->id()); - browser::FindLastActiveWithProfile(profile_)->OpenURL(OpenURLParams( + browser_->OpenURL(OpenURLParams( store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); @@ -318,15 +318,9 @@ void AppendRatingStarsShim(const gfx::ImageSkia* skiaImage, void* data) { @end // ExtensionInstallDialogController void ShowExtensionInstallDialogImpl( - Profile* profile, + Browser* browser, ExtensionInstallPrompt::Delegate* delegate, const ExtensionInstallPrompt::Prompt& prompt) { - Browser* browser = browser::FindLastActiveWithProfile(profile); - if (!browser) { - delegate->InstallUIAbort(false); - return; - } - BrowserWindow* window = browser->window(); if (!window) { delegate->InstallUIAbort(false); @@ -338,7 +332,7 @@ void ShowExtensionInstallDialogImpl( ExtensionInstallDialogController* controller = [[ExtensionInstallDialogController alloc] initWithParentWindow:native_window - profile:profile + browser:browser delegate:delegate prompt:prompt]; diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm index 4ddb9db..fc9266d 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_unittest.mm @@ -119,9 +119,9 @@ TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalCancel) { scoped_nsobject<ExtensionInstallDialogController> controller([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() - delegate:&delegate - prompt:prompt]); + browser:browser() + delegate:&delegate + prompt:prompt]); [controller window]; // force nib load @@ -175,7 +175,7 @@ TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalOK) { scoped_nsobject<ExtensionInstallDialogController> controller([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() + browser:browser() delegate:&delegate prompt:prompt]); @@ -210,7 +210,7 @@ TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { scoped_nsobject<ExtensionInstallDialogController> controller1([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() + browser:browser() delegate:&delegate1 prompt:one_warning_prompt]); @@ -219,7 +219,7 @@ TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { scoped_nsobject<ExtensionInstallDialogController> controller2([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() + browser:browser() delegate:&delegate2 prompt:two_warnings_prompt]); @@ -255,7 +255,7 @@ TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { scoped_nsobject<ExtensionInstallDialogController> controller([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() + browser:browser() delegate:&delegate prompt:no_warnings_prompt]); @@ -301,7 +301,7 @@ TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { scoped_nsobject<ExtensionInstallDialogController> controller([[ExtensionInstallDialogController alloc] initWithParentWindow:test_window() - profile:profile() + browser:browser() delegate:&delegate prompt:inline_prompt]); diff --git a/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc index 3df8f3a..53fb89b 100644 --- a/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc @@ -57,7 +57,8 @@ namespace browser { // ExtensionInstallPrompt::Delegate instance. class ExtensionInstallDialog { public: - ExtensionInstallDialog(GtkWindow* parent, + ExtensionInstallDialog(Browser* browser, + GtkWindow* parent, ExtensionInstallPrompt::Delegate *delegate, const ExtensionInstallPrompt::Prompt& prompt); private: @@ -66,16 +67,19 @@ class ExtensionInstallDialog { CHROMEGTK_CALLBACK_1(ExtensionInstallDialog, void, OnResponse, int); CHROMEGTK_CALLBACK_0(ExtensionInstallDialog, void, OnStoreLinkClick); + Browser* browser_; ExtensionInstallPrompt::Delegate* delegate_; std::string extension_id_; // Set for INLINE_INSTALL_PROMPT. GtkWidget* dialog_; }; ExtensionInstallDialog::ExtensionInstallDialog( + Browser* browser, GtkWindow* parent, ExtensionInstallPrompt::Delegate *delegate, const ExtensionInstallPrompt::Prompt& prompt) - : delegate_(delegate), + : browser_(browser), + delegate_(delegate), dialog_(NULL) { bool show_permissions = prompt.GetPermissionCount() > 0; bool is_inline_install = @@ -257,7 +261,7 @@ void ExtensionInstallDialog::OnResponse(GtkWidget* dialog, int response_id) { void ExtensionInstallDialog::OnStoreLinkClick(GtkWidget* sender) { GURL store_url( extension_urls::GetWebstoreItemDetailURLPrefix() + extension_id_); - BrowserList::GetLastActive()->OpenURL(OpenURLParams( + browser_->OpenURL(OpenURLParams( store_url, content::Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); @@ -267,15 +271,9 @@ void ExtensionInstallDialog::OnStoreLinkClick(GtkWidget* sender) { } // namespace browser void ShowExtensionInstallDialogImpl( - Profile* profile, + Browser* browser, ExtensionInstallPrompt::Delegate* delegate, const ExtensionInstallPrompt::Prompt& prompt) { - Browser* browser = browser::FindLastActiveWithProfile(profile); - if (!browser) { - delegate->InstallUIAbort(false); - return; - } - BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( browser->window()); if (!browser_window) { @@ -283,6 +281,6 @@ void ShowExtensionInstallDialogImpl( return; } - new browser::ExtensionInstallDialog(browser_window->window(), delegate, - prompt); + new browser::ExtensionInstallDialog(browser, browser_window->window(), + delegate, prompt); } diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc index 9391873..d233019 100644 --- a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc @@ -75,7 +75,8 @@ void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { class ExtensionInstallDialogView : public views::DialogDelegateView, public views::LinkListener { public: - ExtensionInstallDialogView(ExtensionInstallPrompt::Delegate* delegate, + ExtensionInstallDialogView(Browser* browser, + ExtensionInstallPrompt::Delegate* delegate, const ExtensionInstallPrompt::Prompt& prompt); virtual ~ExtensionInstallDialogView(); @@ -102,6 +103,7 @@ class ExtensionInstallDialogView : public views::DialogDelegateView, return prompt_.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; } + Browser* browser_; ExtensionInstallPrompt::Delegate* delegate_; ExtensionInstallPrompt::Prompt prompt_; @@ -109,9 +111,11 @@ class ExtensionInstallDialogView : public views::DialogDelegateView, }; ExtensionInstallDialogView::ExtensionInstallDialogView( + Browser* browser, ExtensionInstallPrompt::Delegate* delegate, const ExtensionInstallPrompt::Prompt& prompt) - : delegate_(delegate), + : browser_(browser), + delegate_(delegate), prompt_(prompt) { // Possible grid layouts: // Inline install @@ -345,20 +349,14 @@ void ExtensionInstallDialogView::LinkClicked(views::Link* source, OpenURLParams params( store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); - BrowserList::GetLastActive()->OpenURL(params); + browser_->OpenURL(params); GetWidget()->Close(); } void ShowExtensionInstallDialogImpl( - Profile* profile, + Browser* browser, ExtensionInstallPrompt::Delegate* delegate, const ExtensionInstallPrompt::Prompt& prompt) { - Browser* browser = browser::FindLastActiveWithProfile(profile); - if (!browser) { - delegate->InstallUIAbort(false); - return; - } - BrowserWindow* browser_window = browser->window(); if (!browser_window) { delegate->InstallUIAbort(false); @@ -366,7 +364,7 @@ void ShowExtensionInstallDialogImpl( } ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( - delegate, prompt); + browser, delegate, prompt); views::Widget* window = views::Widget::CreateWindowWithParent( dialog, browser_window->GetNativeWindow()); diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc index 6e01596..1605be8 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc @@ -28,6 +28,7 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/background_contents.h" +#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/view_type_utils.h" #include "chrome/common/chrome_notification_types.h" @@ -45,6 +46,7 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" +#include "content/public/browser/web_ui.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -600,8 +602,10 @@ void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { if (enable_str == "true") { ExtensionPrefs* prefs = extension_service_->extension_prefs(); if (prefs->DidExtensionEscalatePermissions(extension_id)) { + Browser* browser = browser::FindBrowserWithWebContents( + web_ui()->GetWebContents()); extensions::ShowExtensionDisabledDialog( - extension_service_, Profile::FromWebUI(web_ui()), extension); + extension_service_, browser, extension); } else { extension_service_->EnableExtension(extension_id); } diff --git a/chrome/browser/ui/webui/extensions/install_extension_handler.cc b/chrome/browser/ui/webui/extensions/install_extension_handler.cc index 3a53ff6..78b1b2c 100644 --- a/chrome/browser/ui/webui/extensions/install_extension_handler.cc +++ b/chrome/browser/ui/webui/extensions/install_extension_handler.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser_finder.h" #include "chrome/common/extensions/extension_switch_utils.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -79,11 +80,13 @@ void InstallExtensionHandler::HandleInstallMessage(const ListValue* args) { return; } - Profile* profile = Profile::FromWebUI(web_ui()); + Browser* browser = browser::FindBrowserWithWebContents( + web_ui()->GetWebContents()); + Profile* profile = browser->profile(); scoped_refptr<CrxInstaller> crx_installer( CrxInstaller::Create( ExtensionSystem::Get(profile)->extension_service(), - new ExtensionInstallPrompt(profile))); + new ExtensionInstallPrompt(browser))); crx_installer->set_off_store_install_allow_reason( CrxInstaller::OffStoreInstallAllowedFromSettingsPage); diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index a07b3be..58a3aae 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -983,8 +983,9 @@ ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { if (!extension_install_ui_.get()) { - extension_install_ui_.reset( - new ExtensionInstallPrompt(Profile::FromWebUI(web_ui()))); + Browser* browser = browser::FindBrowserWithWebContents( + web_ui()->GetWebContents()); + extension_install_ui_.reset(new ExtensionInstallPrompt(browser)); } return extension_install_ui_.get(); } |
