diff options
26 files changed, 166 insertions, 100 deletions
diff --git a/apps/app_lifetime_monitor.cc b/apps/app_lifetime_monitor.cc index 41d7f6b..f2bb345 100644 --- a/apps/app_lifetime_monitor.cc +++ b/apps/app_lifetime_monitor.cc @@ -82,8 +82,8 @@ void AppLifetimeMonitor::OnShellWindowAdded(ShellWindow* shell_window) { return; ShellWindowRegistry::ShellWindowList windows = - ShellWindowRegistry::Get(shell_window->profile())-> - GetShellWindowsForApp(shell_window->extension_id()); + ShellWindowRegistry::Get(shell_window->browser_context()) + ->GetShellWindowsForApp(shell_window->extension_id()); if (windows.size() == 1) NotifyAppActivated(shell_window->extension_id()); } @@ -92,8 +92,8 @@ void AppLifetimeMonitor::OnShellWindowIconChanged(ShellWindow* shell_window) {} void AppLifetimeMonitor::OnShellWindowRemoved(ShellWindow* shell_window) { ShellWindowRegistry::ShellWindowList windows = - ShellWindowRegistry::Get(shell_window->profile())-> - GetShellWindowsForApp(shell_window->extension_id()); + ShellWindowRegistry::Get(shell_window->browser_context()) + ->GetShellWindowsForApp(shell_window->extension_id()); if (windows.empty()) NotifyAppDeactivated(shell_window->extension_id()); } diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h index 2e73181..0ecde07 100644 --- a/apps/app_shim/app_shim_handler_mac.h +++ b/apps/app_shim/app_shim_handler_mac.h @@ -11,8 +11,6 @@ #include "apps/app_shim/app_shim_launch.h" #include "base/files/file_path.h" -class Profile; - namespace apps { // Registrar, and interface for services that can handle interactions with OSX diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc index 4a580a5e..d9917bc 100644 --- a/apps/app_shim/extension_app_shim_handler_mac.cc +++ b/apps/app_shim/extension_app_shim_handler_mac.cc @@ -230,14 +230,16 @@ void ExtensionAppShimHandler::QuitAppForWindow(ShellWindow* shell_window) { ExtensionAppShimHandler* handler = g_browser_process->platform_part()->app_shim_host_manager()-> extension_app_shim_handler(); - Host* host = handler->FindHost(shell_window->profile(), - shell_window->extension_id()); + Host* host = handler->FindHost( + Profile::FromBrowserContext(shell_window->browser_context()), + shell_window->extension_id()); if (host) { handler->OnShimQuit(host); } else { // App shims might be disabled or the shim is still starting up. - ShellWindowRegistry::Get(shell_window->profile())-> - CloseAllShellWindowsForApp(shell_window->extension_id()); + ShellWindowRegistry::Get( + Profile::FromBrowserContext(shell_window->browser_context())) + ->CloseAllShellWindowsForApp(shell_window->extension_id()); } } @@ -245,7 +247,8 @@ void ExtensionAppShimHandler::HideAppForWindow(ShellWindow* shell_window) { ExtensionAppShimHandler* handler = g_browser_process->platform_part()->app_shim_host_manager()-> extension_app_shim_handler(); - Profile* profile = shell_window->profile(); + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); Host* host = handler->FindHost(profile, shell_window->extension_id()); if (host) host->OnAppHide(); @@ -258,7 +261,8 @@ void ExtensionAppShimHandler::FocusAppForWindow(ShellWindow* shell_window) { ExtensionAppShimHandler* handler = g_browser_process->platform_part()->app_shim_host_manager()-> extension_app_shim_handler(); - Profile* profile = shell_window->profile(); + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); const std::string& app_id = shell_window->extension_id(); Host* host = handler->FindHost(profile, app_id); if (host) { @@ -277,7 +281,8 @@ bool ExtensionAppShimHandler::RequestUserAttentionForWindow( ExtensionAppShimHandler* handler = g_browser_process->platform_part()->app_shim_host_manager()-> extension_app_shim_handler(); - Profile* profile = shell_window->profile(); + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); Host* host = handler->FindHost(profile, shell_window->extension_id()); if (host) { // Bring the window to the front without showing it. diff --git a/apps/app_window_contents.cc b/apps/app_window_contents.cc index e3ddf7c..fbe70cc 100644 --- a/apps/app_window_contents.cc +++ b/apps/app_window_contents.cc @@ -6,9 +6,9 @@ #include "apps/ui/native_app_window.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/app_window.h" #include "chrome/common/extensions/extension_messages.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -28,15 +28,16 @@ AppWindowContents::AppWindowContents(ShellWindow* host) AppWindowContents::~AppWindowContents() { } -void AppWindowContents::Initialize(Profile* profile, const GURL& url) { +void AppWindowContents::Initialize(content::BrowserContext* context, + const GURL& url) { url_ = url; extension_function_dispatcher_.reset( - new ExtensionFunctionDispatcher(profile, this)); + new ExtensionFunctionDispatcher(context, this)); - web_contents_.reset(content::WebContents::Create( - content::WebContents::CreateParams( - profile, content::SiteInstance::CreateForURL(profile, url_)))); + web_contents_.reset( + content::WebContents::Create(content::WebContents::CreateParams( + context, content::SiteInstance::CreateForURL(context, url_)))); content::WebContentsObserver::Observe(web_contents_.get()); web_contents_->GetMutableRendererPrefs()-> diff --git a/apps/app_window_contents.h b/apps/app_window_contents.h index 80b95de..ea09f83 100644 --- a/apps/app_window_contents.h +++ b/apps/app_window_contents.h @@ -17,7 +17,7 @@ class GURL; namespace content { -class RenderViewHost; +class BrowserContext; } namespace extensions { @@ -38,7 +38,8 @@ class AppWindowContents : public ShellWindowContents, virtual ~AppWindowContents(); // ShellWindowContents - virtual void Initialize(Profile* profile, const GURL& url) OVERRIDE; + virtual void Initialize(content::BrowserContext* context, + const GURL& url) OVERRIDE; virtual void LoadContents(int32 creator_process_id) OVERRIDE; virtual void NativeWindowChanged(NativeAppWindow* native_app_window) OVERRIDE; virtual void NativeWindowClosed() OVERRIDE; diff --git a/apps/shell/browser/shell_extensions_browser_client.cc b/apps/shell/browser/shell_extensions_browser_client.cc index ec64cdf..2c9a56f 100644 --- a/apps/shell/browser/shell_extensions_browser_client.cc +++ b/apps/shell/browser/shell_extensions_browser_client.cc @@ -82,6 +82,10 @@ BrowserContext* ShellExtensionsBrowserClient::GetOriginalContext( return context; } +bool ShellExtensionsBrowserClient::IsGuestSession(BrowserContext* context) { + return false; +} + bool ShellExtensionsBrowserClient::IsExtensionIncognitoEnabled( const std::string& extension_id, content::BrowserContext* context) const { diff --git a/apps/shell/browser/shell_extensions_browser_client.h b/apps/shell/browser/shell_extensions_browser_client.h index d48ca9e..206d189 100644 --- a/apps/shell/browser/shell_extensions_browser_client.h +++ b/apps/shell/browser/shell_extensions_browser_client.h @@ -33,6 +33,7 @@ class ShellExtensionsBrowserClient : public ExtensionsBrowserClient { content::BrowserContext* context) OVERRIDE; virtual content::BrowserContext* GetOriginalContext( content::BrowserContext* context) OVERRIDE; + virtual bool IsGuestSession(content::BrowserContext* context) OVERRIDE; virtual bool IsExtensionIncognitoEnabled( const std::string& extension_id, content::BrowserContext* context) const OVERRIDE; diff --git a/apps/shell_window.cc b/apps/shell_window.cc index d1ad0fe..8bb6262 100644 --- a/apps/shell_window.cc +++ b/apps/shell_window.cc @@ -15,11 +15,11 @@ #include "chrome/browser/extensions/extension_web_contents_observer.h" #include "chrome/browser/extensions/suggest_permission_util.h" #include "chrome/browser/lifetime/application_lifetime.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/manifest_handlers/icons_handler.h" #include "components/web_modal/web_contents_modal_dialog_manager.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" @@ -32,6 +32,7 @@ #include "content/public/browser/web_contents_view.h" #include "content/public/common/media_stream_request.h" #include "extensions/browser/extension_system.h" +#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/process_manager.h" #include "extensions/browser/view_type_utils.h" #include "extensions/common/extension.h" @@ -43,6 +44,7 @@ #include "base/prefs/pref_service.h" #endif +using content::BrowserContext; using content::ConsoleMessageLevel; using content::WebContents; using extensions::APIPermission; @@ -137,10 +139,10 @@ ShellWindow::CreateParams::~CreateParams() {} ShellWindow::Delegate::~Delegate() {} -ShellWindow::ShellWindow(Profile* profile, +ShellWindow::ShellWindow(BrowserContext* context, Delegate* delegate, const extensions::Extension* extension) - : profile_(profile), + : browser_context_(context), extension_(extension), extension_id_(extension->id()), window_type_(WINDOW_TYPE_DEFAULT), @@ -150,7 +152,9 @@ ShellWindow::ShellWindow(Profile* profile, show_on_first_paint_(false), first_paint_complete_(false), cached_always_on_top_(false) { - CHECK(!profile->IsGuestSession() || profile->IsOffTheRecord()) + extensions::ExtensionsBrowserClient* client = + extensions::ExtensionsBrowserClient::Get(); + CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord()) << "Only off the record window may be opened in the guest mode."; } @@ -159,7 +163,7 @@ void ShellWindow::Init(const GURL& url, const CreateParams& params) { // Initialize the render interface and web contents shell_window_contents_.reset(shell_window_contents); - shell_window_contents_->Initialize(profile(), url); + shell_window_contents_->Initialize(browser_context(), url); WebContents* web_contents = shell_window_contents_->GetWebContents(); if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableAppsShowOnFirstPaint)) { @@ -207,8 +211,12 @@ void ShellWindow::Init(const GURL& url, // about it in case it has any setup to do to make the renderer appear // properly. In particular, on Windows, the view's clickthrough region needs // to be set. - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, - content::Source<Profile>(profile_->GetOriginalProfile())); + extensions::ExtensionsBrowserClient* client = + extensions::ExtensionsBrowserClient::Get(); + registrar_.Add(this, + chrome::NOTIFICATION_EXTENSION_UNLOADED, + content::Source<content::BrowserContext>( + client->GetOriginalContext(browser_context_))); // Close when the browser process is exiting. registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, content::NotificationService::AllSources()); @@ -229,7 +237,7 @@ void ShellWindow::Init(const GURL& url, UpdateExtensionAppIcon(); - ShellWindowRegistry::Get(profile_)->AddShellWindow(this); + ShellWindowRegistry::Get(browser_context_)->AddShellWindow(this); } ShellWindow::~ShellWindow() { @@ -272,8 +280,8 @@ WebContents* ShellWindow::OpenURLFromTab(WebContents* source, return NULL; } - WebContents* contents = delegate_->OpenURLFromTab(profile_, source, - params); + WebContents* contents = + delegate_->OpenURLFromTab(browser_context_, source, params); if (!contents) { AddMessageToDevToolsConsole( content::CONSOLE_MESSAGE_LEVEL_ERROR, @@ -291,10 +299,13 @@ void ShellWindow::AddNewContents(WebContents* source, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked) { - DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == - profile_); - delegate_->AddNewContents(profile_, new_contents, disposition, - initial_pos, user_gesture, was_blocked); + DCHECK(new_contents->GetBrowserContext() == browser_context_); + delegate_->AddNewContents(browser_context_, + new_contents, + disposition, + initial_pos, + user_gesture, + was_blocked); } bool ShellWindow::PreHandleKeyboardEvent( @@ -366,7 +377,7 @@ void ShellWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) { } void ShellWindow::OnNativeClose() { - ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); + ShellWindowRegistry::Get(browser_context_)->RemoveShellWindow(this); if (shell_window_contents_) { WebContents* web_contents = shell_window_contents_->GetWebContents(); WebContentsModalDialogManager::FromWebContents(web_contents)-> @@ -394,7 +405,7 @@ void ShellWindow::OnNativeWindowChanged() { } void ShellWindow::OnNativeWindowActivated() { - ShellWindowRegistry::Get(profile_)->ShellWindowActivated(this); + ShellWindowRegistry::Get(browser_context_)->ShellWindowActivated(this); } content::WebContents* ShellWindow::web_contents() const { @@ -488,13 +499,16 @@ void ShellWindow::UpdateAppIcon(const gfx::Image& image) { return; app_icon_ = image; native_app_window_->UpdateWindowIcon(); - ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); + ShellWindowRegistry::Get(browser_context_)->ShellWindowIconChanged(this); } void ShellWindow::Fullscreen() { #if !defined(OS_MACOSX) // Do not enter fullscreen mode if disallowed by pref. - if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) + PrefService* prefs = + extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( + browser_context()); + if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) return; #endif fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API; @@ -521,7 +535,10 @@ void ShellWindow::Restore() { void ShellWindow::OSFullscreen() { #if !defined(OS_MACOSX) // Do not enter fullscreen mode if disallowed by pref. - if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) + PrefService* prefs = + extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( + browser_context()); + if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) return; #endif fullscreen_types_ |= FULLSCREEN_TYPE_OS; @@ -667,13 +684,13 @@ void ShellWindow::UpdateExtensionAppIcon() { // Avoid using any previous app icons were being downloaded. image_loader_ptr_factory_.InvalidateWeakPtrs(); - app_icon_image_.reset(new extensions::IconImage( - profile(), - extension(), - extensions::IconsInfo::GetIcons(extension()), - delegate_->PreferredIconSize(), - extensions::IconsInfo::GetDefaultAppIcon(), - this)); + app_icon_image_.reset( + new extensions::IconImage(browser_context(), + extension(), + extensions::IconsInfo::GetIcons(extension()), + delegate_->PreferredIconSize(), + extensions::IconsInfo::GetDefaultAppIcon(), + this)); // Triggers actual image loading with 1x resources. The 2x resource will // be handled by IconImage class when requested. @@ -786,8 +803,10 @@ void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, // Do not enter fullscreen mode if disallowed by pref. // TODO(bartfab): Add a test once it becomes possible to simulate a user // gesture. http://crbug.com/174178 - if (enter_fullscreen && - !profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) { + PrefService* prefs = + extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( + browser_context()); + if (enter_fullscreen && !prefs->GetBoolean(prefs::kAppFullscreenAllowed)) { return; } #endif @@ -863,7 +882,8 @@ void ShellWindow::SaveWindowPosition() { if (!native_app_window_) return; - ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); + ShellWindowGeometryCache* cache = + ShellWindowGeometryCache::Get(browser_context()); gfx::Rect bounds = native_app_window_->GetRestoredBounds(); bounds.Inset(native_app_window_->GetFrameInsets()); @@ -919,7 +939,8 @@ ShellWindow::CreateParams ShellWindow::LoadDefaultsAndConstrain( // Load cached state if it exists. if (!params.window_key.empty()) { - ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); + ShellWindowGeometryCache* cache = + ShellWindowGeometryCache::Get(browser_context()); gfx::Rect cached_bounds; gfx::Rect cached_screen_bounds; diff --git a/apps/shell_window.h b/apps/shell_window.h index 8be7a595..2901376 100644 --- a/apps/shell_window.h +++ b/apps/shell_window.h @@ -21,7 +21,6 @@ #include "ui/gfx/rect.h" class GURL; -class Profile; class SkRegion; namespace base { @@ -29,6 +28,7 @@ class DictionaryValue; } namespace content { +class BrowserContext; class WebContents; } @@ -58,7 +58,8 @@ class ShellWindowContents { virtual ~ShellWindowContents() {} // Called to initialize the WebContents, before the app window is created. - virtual void Initialize(Profile* profile, const GURL& url) = 0; + virtual void Initialize(content::BrowserContext* context, + const GURL& url) = 0; // Called to load the contents, after the app window is created. virtual void LoadContents(int32 creator_process_id) = 0; @@ -201,10 +202,10 @@ class ShellWindow : public content::NotificationObserver, // Link handling. virtual content::WebContents* OpenURLFromTab( - Profile* profile, + content::BrowserContext* context, content::WebContents* source, const content::OpenURLParams& params) = 0; - virtual void AddNewContents(Profile* profile, + virtual void AddNewContents(content::BrowserContext* context, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, @@ -239,7 +240,7 @@ class ShellWindow : public content::NotificationObserver, // with a non-standard render interface (e.g. v1 apps using Ash Panels). // Normally ShellWindow::Create should be used. // The constructed shell window takes ownership of |delegate|. - ShellWindow(Profile* profile, + ShellWindow(content::BrowserContext* context, Delegate* delegate, const extensions::Extension* extension); @@ -260,7 +261,7 @@ class ShellWindow : public content::NotificationObserver, return (window_type_ == WINDOW_TYPE_PANEL || window_type_ == WINDOW_TYPE_V1_PANEL); } - Profile* profile() const { return profile_; } + content::BrowserContext* browser_context() const { return browser_context_; } const gfx::Image& app_icon() const { return app_icon_; } const GURL& app_icon_url() const { return app_icon_url_; } const gfx::Image& badge_icon() const { return badge_icon_; } @@ -488,7 +489,10 @@ class ShellWindow : public content::NotificationObserver, virtual void OnExtensionIconImageChanged( extensions::IconImage* image) OVERRIDE; - Profile* profile_; // weak pointer - owned by ProfileManager. + // The browser context with which this window is associated. ShellWindow does + // not own this object. + content::BrowserContext* browser_context_; + // weak pointer - owned by ExtensionService. const extensions::Extension* extension_; const std::string extension_id_; diff --git a/chrome/browser/extensions/api/app_window/app_window_api.cc b/chrome/browser/extensions/api/app_window/app_window_api.cc index 1bc4da4..b709e6b 100644 --- a/chrome/browser/extensions/api/app_window/app_window_api.cc +++ b/chrome/browser/extensions/api/app_window/app_window_api.cc @@ -14,6 +14,7 @@ #include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/extensions/window_controller.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" #include "chrome/common/extensions/api/app_window.h" #include "chrome/common/extensions/features/feature_channel.h" diff --git a/chrome/browser/extensions/api/tabs/ash_panel_contents.cc b/chrome/browser/extensions/api/tabs/ash_panel_contents.cc index 408f29f..b3f2891 100644 --- a/chrome/browser/extensions/api/tabs/ash_panel_contents.cc +++ b/chrome/browser/extensions/api/tabs/ash_panel_contents.cc @@ -15,6 +15,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_tab_helper.h" #include "chrome/common/extensions/extension_messages.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "extensions/common/extension.h" @@ -167,15 +168,16 @@ AshPanelContents::AshPanelContents(ShellWindow* host) AshPanelContents::~AshPanelContents() { } -void AshPanelContents::Initialize(Profile* profile, const GURL& url) { +void AshPanelContents::Initialize(content::BrowserContext* context, + const GURL& url) { url_ = url; extension_function_dispatcher_.reset( - new ExtensionFunctionDispatcher(profile, this)); + new ExtensionFunctionDispatcher(context, this)); - web_contents_.reset(content::WebContents::Create( - content::WebContents::CreateParams( - profile, content::SiteInstance::CreateForURL(profile, url_)))); + web_contents_.reset( + content::WebContents::Create(content::WebContents::CreateParams( + context, content::SiteInstance::CreateForURL(context, url_)))); // Needed to give the web contents a Window ID. Extension APIs expect web // contents to have a Window ID. Also required for FaviconTabHelper to @@ -195,8 +197,8 @@ void AshPanelContents::Initialize(Profile* profile, const GURL& url) { void AshPanelContents::LoadContents(int32 creator_process_id) { // This must be created after the native window has been created. - window_controller_.reset( - new AshPanelWindowController(host_, host_->profile())); + window_controller_.reset(new AshPanelWindowController( + host_, Profile::FromBrowserContext(host_->browser_context()))); web_contents_->GetController().LoadURL( url_, content::Referrer(), content::PAGE_TRANSITION_LINK, diff --git a/chrome/browser/extensions/api/tabs/ash_panel_contents.h b/chrome/browser/extensions/api/tabs/ash_panel_contents.h index 0ccc9c9..021e6a6 100644 --- a/chrome/browser/extensions/api/tabs/ash_panel_contents.h +++ b/chrome/browser/extensions/api/tabs/ash_panel_contents.h @@ -39,7 +39,8 @@ class AshPanelContents : public apps::ShellWindowContents, virtual ~AshPanelContents(); // apps::ShellWindowContents - virtual void Initialize(Profile* profile, const GURL& url) OVERRIDE; + virtual void Initialize(content::BrowserContext* context, + const GURL& url) OVERRIDE; virtual void LoadContents(int32 creator_process_id) OVERRIDE; virtual void NativeWindowChanged(apps::NativeAppWindow* native_app_window) OVERRIDE; diff --git a/chrome/browser/extensions/chrome_extensions_browser_client.cc b/chrome/browser/extensions/chrome_extensions_browser_client.cc index fa93a50..d1e9f83 100644 --- a/chrome/browser/extensions/chrome_extensions_browser_client.cc +++ b/chrome/browser/extensions/chrome_extensions_browser_client.cc @@ -81,6 +81,11 @@ content::BrowserContext* ChromeExtensionsBrowserClient::GetOriginalContext( return static_cast<Profile*>(context)->GetOriginalProfile(); } +bool ChromeExtensionsBrowserClient::IsGuestSession( + content::BrowserContext* context) { + return static_cast<Profile*>(context)->IsGuestSession(); +} + bool ChromeExtensionsBrowserClient::IsExtensionIncognitoEnabled( const std::string& extension_id, content::BrowserContext* context) const { diff --git a/chrome/browser/extensions/chrome_extensions_browser_client.h b/chrome/browser/extensions/chrome_extensions_browser_client.h index b89bef6..d74c1cd 100644 --- a/chrome/browser/extensions/chrome_extensions_browser_client.h +++ b/chrome/browser/extensions/chrome_extensions_browser_client.h @@ -44,6 +44,7 @@ class ChromeExtensionsBrowserClient : public ExtensionsBrowserClient { content::BrowserContext* context) OVERRIDE; virtual content::BrowserContext* GetOriginalContext( content::BrowserContext* context) OVERRIDE; + virtual bool IsGuestSession(content::BrowserContext* context) OVERRIDE; virtual bool IsExtensionIncognitoEnabled( const std::string& extension_id, content::BrowserContext* context) const OVERRIDE; diff --git a/chrome/browser/ui/apps/chrome_shell_window_delegate.cc b/chrome/browser/ui/apps/chrome_shell_window_delegate.cc index 4d12672..30e83bd 100644 --- a/chrome/browser/ui/apps/chrome_shell_window_delegate.cc +++ b/chrome/browser/ui/apps/chrome_shell_window_delegate.cc @@ -9,6 +9,7 @@ #include "chrome/browser/file_select_helper.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -16,6 +17,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/common/render_messages.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -39,7 +41,7 @@ bool disable_external_open_for_testing_ = false; // Opens a URL with Chromium (not external browser) with the right profile. content::WebContents* OpenURLFromTabInternal( - Profile* profile, + content::BrowserContext* context, content::WebContents* source, const content::OpenURLParams& params) { // Force all links to open in a new tab, even if they were trying to open a @@ -49,7 +51,7 @@ content::WebContents* OpenURLFromTabInternal( new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB ? params.disposition : NEW_FOREGROUND_TAB; - new_tab_params.initiating_profile = profile; + new_tab_params.initiating_profile = Profile::FromBrowserContext(context); chrome::Navigate(&new_tab_params); return new_tab_params.target_contents; @@ -148,14 +150,14 @@ apps::NativeAppWindow* ChromeShellWindowDelegate::CreateNativeAppWindow( } content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( - Profile* profile, + content::BrowserContext* context, content::WebContents* source, const content::OpenURLParams& params) { - return OpenURLFromTabInternal(profile, source, params); + return OpenURLFromTabInternal(context, source, params); } void ChromeShellWindowDelegate::AddNewContents( - Profile* profile, + content::BrowserContext* context, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, @@ -168,7 +170,7 @@ void ChromeShellWindowDelegate::AddNewContents( return; } chrome::ScopedTabbedBrowserDisplayer displayer( - profile, chrome::GetActiveDesktop()); + Profile::FromBrowserContext(context), chrome::GetActiveDesktop()); // Force all links to open in a new tab, even if they were trying to open a // new window. disposition = diff --git a/chrome/browser/ui/apps/chrome_shell_window_delegate.h b/chrome/browser/ui/apps/chrome_shell_window_delegate.h index 1cd3fd7..026e67c 100644 --- a/chrome/browser/ui/apps/chrome_shell_window_delegate.h +++ b/chrome/browser/ui/apps/chrome_shell_window_delegate.h @@ -7,12 +7,15 @@ #include "apps/shell_window.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/profiles/profile.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "ui/base/window_open_disposition.h" #include "ui/gfx/rect.h" +namespace content { +class BrowserContext; +} + class ShellWindowLinkDelegate : public content::WebContentsDelegate { public: ShellWindowLinkDelegate(); @@ -40,10 +43,10 @@ class ChromeShellWindowDelegate : public apps::ShellWindow::Delegate { apps::ShellWindow* window, const apps::ShellWindow::CreateParams& params) OVERRIDE; virtual content::WebContents* OpenURLFromTab( - Profile* profile, + content::BrowserContext* context, content::WebContents* source, const content::OpenURLParams& params) OVERRIDE; - virtual void AddNewContents(Profile* profile, + virtual void AddNewContents(content::BrowserContext* context, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, diff --git a/chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_controller.cc index 13280a9..dd171f1 100644 --- a/chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/multi_profile_shell_window_launcher_controller.cc @@ -43,14 +43,18 @@ void MultiProfileShellWindowLauncherController::ActiveUserChanged( for (ShellWindowList::iterator it = shell_window_list_.begin(); it != shell_window_list_.end(); ++it) { apps::ShellWindow* shell_window = *it; - if (!multi_user_util::IsProfileFromActiveUser(shell_window->profile()) && + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); + if (!multi_user_util::IsProfileFromActiveUser(profile) && IsRegisteredApp(shell_window->GetNativeWindow())) UnregisterApp(shell_window->GetNativeWindow()); } for (ShellWindowList::iterator it = shell_window_list_.begin(); it != shell_window_list_.end(); ++it) { apps::ShellWindow* shell_window = *it; - if (multi_user_util::IsProfileFromActiveUser(shell_window->profile()) && + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); + if (multi_user_util::IsProfileFromActiveUser(profile) && !IsRegisteredApp(shell_window->GetNativeWindow())) RegisterApp(*it); } @@ -69,7 +73,9 @@ void MultiProfileShellWindowLauncherController::OnShellWindowAdded( if (!ControlsWindow(shell_window->GetNativeWindow())) return; shell_window_list_.push_back(shell_window); - if (multi_user_util::IsProfileFromActiveUser(shell_window->profile())) + Profile* profile = + Profile::FromBrowserContext(shell_window->browser_context()); + if (multi_user_util::IsProfileFromActiveUser(profile)) RegisterApp(shell_window); } diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h index b83f5fe..b0f6775 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h @@ -18,7 +18,6 @@ #include "ui/gfx/rect.h" class ExtensionKeybindingRegistryCocoa; -class Profile; class NativeAppWindowCocoa; @class ShellNSWindow; class SkRegion; diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm index 54dedd36..790cb5f 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm @@ -365,7 +365,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa( UpdateWindowMinMaxSize(); extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( - shell_window_->profile(), + Profile::FromBrowserContext(shell_window_->browser_context()), window, extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, shell_window)); diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm index 13afc2e..35bbfad 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm @@ -30,8 +30,11 @@ class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { content::WindowedNotificationObserver app_loaded_observer( content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, content::NotificationService::AllSources()); - OpenApplication(AppLaunchParams( - profile(), app_, extensions::LAUNCH_CONTAINER_NONE, NEW_WINDOW)); + OpenApplication( + AppLaunchParams(profile(), + app_, + extensions::LAUNCH_CONTAINER_NONE, + NEW_WINDOW)); app_loaded_observer.Wait(); } } diff --git a/chrome/browser/ui/gtk/apps/native_app_window_gtk.cc b/chrome/browser/ui/gtk/apps/native_app_window_gtk.cc index a35491f..9242e94 100644 --- a/chrome/browser/ui/gtk/apps/native_app_window_gtk.cc +++ b/chrome/browser/ui/gtk/apps/native_app_window_gtk.cc @@ -146,7 +146,7 @@ NativeAppWindowGtk::NativeAppWindowGtk(ShellWindow* shell_window, // Add the keybinding registry. extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryGtk( - shell_window_->profile(), + Profile::FromBrowserContext(shell_window_->browser_context()), window_, extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, shell_window_)); @@ -624,7 +624,8 @@ bool NativeAppWindowGtk::IsDetached() const { } void NativeAppWindowGtk::UpdateWindowIcon() { - Profile* profile = shell_window_->profile(); + Profile* profile = + Profile::FromBrowserContext(shell_window_->browser_context()); gfx::Image app_icon = shell_window_->app_icon(); if (!app_icon.IsEmpty()) gtk_util::SetWindowIcon(window_, profile, app_icon.ToGdkPixbuf()); diff --git a/chrome/browser/ui/gtk/apps/native_app_window_gtk.h b/chrome/browser/ui/gtk/apps/native_app_window_gtk.h index 2e6504f..ac15a4e 100644 --- a/chrome/browser/ui/gtk/apps/native_app_window_gtk.h +++ b/chrome/browser/ui/gtk/apps/native_app_window_gtk.h @@ -20,7 +20,6 @@ #include "ui/gfx/x/x11_atom_cache.h" class ExtensionKeybindingRegistryGtk; -class Profile; namespace extensions { class Extension; diff --git a/chrome/browser/ui/views/apps/native_app_window_views.cc b/chrome/browser/ui/views/apps/native_app_window_views.cc index 0d90452..6adc3a6 100644 --- a/chrome/browser/ui/views/apps/native_app_window_views.cc +++ b/chrome/browser/ui/views/apps/native_app_window_views.cc @@ -266,12 +266,11 @@ void NativeAppWindowViews::Init( } else { InitializeDefaultWindow(create_params); } - extension_keybinding_registry_.reset( - new ExtensionKeybindingRegistryViews( - profile(), - window_->GetFocusManager(), - extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, - shell_window_)); + extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( + Profile::FromBrowserContext(browser_context()), + window_->GetFocusManager(), + extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, + shell_window_)); OnViewWasResized(); window_->AddObserver(this); @@ -362,11 +361,15 @@ void NativeAppWindowViews::InitializeDefaultWindow( #if defined(OS_WIN) base::string16 app_name_wide = base::UTF8ToWide(app_name); HWND hwnd = GetNativeAppWindowHWND(); - ui::win::SetAppIdForWindow(ShellIntegration::GetAppModelIdForProfile( - app_name_wide, profile()->GetPath()), hwnd); + ui::win::SetAppIdForWindow( + ShellIntegration::GetAppModelIdForProfile( + app_name_wide, + Profile::FromBrowserContext(browser_context())->GetPath()), + hwnd); web_app::UpdateShortcutInfoAndIconForApp( - *extension(), profile(), + *extension(), + Profile::FromBrowserContext(browser_context()), base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded, weak_ptr_factory_.GetWeakPtr())); #endif diff --git a/chrome/browser/ui/views/apps/native_app_window_views.h b/chrome/browser/ui/views/apps/native_app_window_views.h index 9934fa0..4bd3fb6 100644 --- a/chrome/browser/ui/views/apps/native_app_window_views.h +++ b/chrome/browser/ui/views/apps/native_app_window_views.h @@ -29,13 +29,13 @@ class ImmersiveFullscreenController; #endif class ExtensionKeybindingRegistryViews; -class Profile; namespace apps { class ShellWindowFrameView; } namespace content { +class BrowserContext; class RenderViewHost; class WebContents; } @@ -76,7 +76,10 @@ class NativeAppWindowViews : public apps::NativeAppWindow, virtual void Show() OVERRIDE; virtual void Activate() OVERRIDE; - Profile* profile() { return shell_window_->profile(); } + content::BrowserContext* browser_context() { + return shell_window_->browser_context(); + } + const extensions::Extension* extension() { return shell_window_->extension(); } diff --git a/chrome/browser/ui/views/apps/native_app_window_views_win.cc b/chrome/browser/ui/views/apps/native_app_window_views_win.cc index 5bdf999..21b7fbb 100644 --- a/chrome/browser/ui/views/apps/native_app_window_views_win.cc +++ b/chrome/browser/ui/views/apps/native_app_window_views_win.cc @@ -10,7 +10,6 @@ #include "chrome/browser/apps/per_app_settings_service.h" #include "chrome/browser/apps/per_app_settings_service_factory.h" #include "chrome/browser/metro_utils/metro_chrome_win.h" -#include "chrome/browser/profiles/profile.h" #include "extensions/common/extension.h" #include "ui/aura/remote_root_window_host_win.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" @@ -40,15 +39,15 @@ void NativeAppWindowViewsWin::OnBeforeWidgetInit( // If an app has any existing windows, ensure new ones are created on the // same desktop. apps::ShellWindow* any_existing_window = - apps::ShellWindowRegistry::Get(profile())-> - GetCurrentShellWindowForApp(extension()->id()); + apps::ShellWindowRegistry::Get(browser_context()) + ->GetCurrentShellWindowForApp(extension()->id()); chrome::HostDesktopType desktop_type; if (any_existing_window) { desktop_type = chrome::GetHostDesktopTypeForNativeWindow( any_existing_window->GetNativeWindow()); } else { PerAppSettingsService* settings = - PerAppSettingsServiceFactory::GetForBrowserContext(profile()); + PerAppSettingsServiceFactory::GetForBrowserContext(browser_context()); if (settings->HasDesktopLastLaunchedFrom(extension()->id())) { desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id()); } else { diff --git a/extensions/browser/extensions_browser_client.h b/extensions/browser/extensions_browser_client.h index dc75e91..08ffa58 100644 --- a/extensions/browser/extensions_browser_client.h +++ b/extensions/browser/extensions_browser_client.h @@ -69,6 +69,9 @@ class ExtensionsBrowserClient { virtual content::BrowserContext* GetOriginalContext( content::BrowserContext* context) = 0; + // Returns true if |context| corresponds to a guest session. + virtual bool IsGuestSession(content::BrowserContext* context) = 0; + // Returns true if |extension_id| can run in an incognito window. virtual bool IsExtensionIncognitoEnabled( const std::string& extension_id, |