Chromium Code Reviews| Index: apps/shell_window.cc |
| diff --git a/apps/shell_window.cc b/apps/shell_window.cc |
| index d1ad0fe93751bae04bccffc578ecd3e79a1264af..26e8e183a07173a3966261cdca3ac4e08a8a1a73 100644 |
| --- a/apps/shell_window.cc |
| +++ b/apps/shell_window.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
James Cook
2014/02/12 00:46:41
ditto
Ken Rockot(use gerrit already)
2014/02/12 01:05:46
Done.
|
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -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; |