summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/profiles/profile.cc3
-rw-r--r--chrome/browser/profiles/profile.h3
-rw-r--r--chrome/browser/ui/views/accessibility_event_router_views_unittest.cc9
-rw-r--r--chrome/browser/ui/views/bookmark_bar_view_test.cc9
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.cc43
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.h13
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc9
-rw-r--r--views/test/test_views_delegate.h13
-rw-r--r--views/views_delegate.h10
-rw-r--r--views/window/window.h6
-rw-r--r--views/window/window_delegate.cc6
-rw-r--r--views/window/window_gtk.cc8
-rw-r--r--views/window/window_gtk.h2
-rw-r--r--views/window/window_win.cc8
-rw-r--r--views/window/window_win.h2
15 files changed, 106 insertions, 38 deletions
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index 86a1eaa..eaa2e94 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -80,6 +80,9 @@ Profile::Profile()
}
// static
+const char* Profile::kProfileKey = "__PROFILE__";
+
+// static
const ProfileId Profile::InvalidProfileId = static_cast<ProfileId>(0);
// static
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 618d44b..81c895e 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -133,6 +133,9 @@ class Profile {
IMPLICIT_ACCESS
};
+ // Key used to bind profile to the widget with which it is associated.
+ static const char* kProfileKey;
+
// Value that represents no profile Id.
static const ProfileId InvalidProfileId;
diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
index 3ee061a..58bf624 100644
--- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
+++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
@@ -35,15 +35,18 @@ class AccessibilityViewsDelegate : public views::ViewsDelegate {
// Overridden from views::ViewsDelegate:
virtual ui::Clipboard* GetClipboard() const { return NULL; }
- virtual void SaveWindowPlacement(const std::wstring& window_name,
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized) {
}
- virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const {
return false;
}
- virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
bool* maximized) const {
return false;
}
diff --git a/chrome/browser/ui/views/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmark_bar_view_test.cc
index b360363..e51a009 100644
--- a/chrome/browser/ui/views/bookmark_bar_view_test.cc
+++ b/chrome/browser/ui/views/bookmark_bar_view_test.cc
@@ -68,14 +68,17 @@ class ViewsDelegateImpl : public views::ViewsDelegate {
public:
ViewsDelegateImpl() {}
virtual ui::Clipboard* GetClipboard() const { return NULL; }
- virtual void SaveWindowPlacement(const std::wstring& window_name,
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized) {}
- virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const {
return false;
}
- virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
bool* maximized) const {
return false;
}
diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc
index 2d0a95e..1e2e8ba 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.cc
+++ b/chrome/browser/ui/views/chrome_views_delegate.cc
@@ -15,6 +15,7 @@
#include "chrome/common/pref_names.h"
#include "gfx/rect.h"
#include "ui/base/clipboard/clipboard.h"
+#include "views/window/window.h"
#if defined(OS_WIN)
#include "chrome/browser/app_icon_win.h"
@@ -22,21 +23,21 @@
namespace {
-// Some window data should be stored in local state, instead of by profile; use
-// the window_name to differentiate between storage types. This function may
-// return NULL if the necessary PrefService has not yet been initialized.
-// TODO(mirandac): This function will also serve to separate windows by profile
-// in a multiprofile environment.
-PrefService* GetPrefsForWindow(const std::wstring& window_name) {
- if (LowerCaseEqualsASCII(window_name, prefs::kTaskManagerWindowPlacement)) {
+// If the given window has a profile associated with it, use that profile's
+// preference service. Otherwise, store and retrieve the data from Local State.
+// This function may return NULL if the necessary pref service has not yet
+// been initialized.
+// TODO(mirandac): This function will also separate windows by profile in a
+// multi-profile environment.
+PrefService* GetPrefsForWindow(views::Window* window) {
+ Profile* profile =
+ reinterpret_cast<Profile*>(window->GetNativeWindowProperty(
+ Profile::kProfileKey));
+ if (!profile) {
+ // Use local state for windows that have no explicit profile.
return g_browser_process->local_state();
- } else {
- if (!g_browser_process->profile_manager()) {
- return NULL;
- }
- return g_browser_process->profile_manager()->GetDefaultProfile()->
- GetPrefs();
}
+ return profile->GetPrefs();
}
} // namespace
@@ -48,13 +49,15 @@ ui::Clipboard* ChromeViewsDelegate::GetClipboard() const {
return g_browser_process->clipboard();
}
-void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
+void ChromeViewsDelegate::SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized) {
- PrefService* prefs = GetPrefsForWindow(window_name);
+ PrefService* prefs = GetPrefsForWindow(window);
if (!prefs)
return;
+ DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str()));
DictionaryValue* window_preferences =
prefs->GetMutableDictionary(WideToUTF8(window_name).c_str());
window_preferences->SetInteger("left", bounds.x());
@@ -73,12 +76,14 @@ void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
window_preferences->SetInteger("work_area_bottom", work_area.bottom());
}
-bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name,
+bool ChromeViewsDelegate::GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const {
- PrefService* prefs = GetPrefsForWindow(window_name);
+ PrefService* prefs = GetPrefsForWindow(window);
if (!prefs)
return false;
+ DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str()));
const DictionaryValue* dictionary =
prefs->GetDictionary(WideToUTF8(window_name).c_str());
int left, top, right, bottom;
@@ -93,12 +98,14 @@ bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name,
}
bool ChromeViewsDelegate::GetSavedMaximizedState(
+ views::Window* window,
const std::wstring& window_name,
bool* maximized) const {
- PrefService* prefs = GetPrefsForWindow(window_name);
+ PrefService* prefs = GetPrefsForWindow(window);
if (!prefs)
return false;
+ DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str()));
const DictionaryValue* dictionary =
prefs->GetDictionary(WideToUTF8(window_name).c_str());
diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h
index dd2e8a8..c48f07b 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.h
+++ b/chrome/browser/ui/views/chrome_views_delegate.h
@@ -10,6 +10,10 @@
#include "build/build_config.h"
#include "views/views_delegate.h"
+namespace views {
+class Window;
+}
+
class ChromeViewsDelegate : public views::ViewsDelegate {
public:
ChromeViewsDelegate() {}
@@ -17,12 +21,15 @@ class ChromeViewsDelegate : public views::ViewsDelegate {
// Overridden from views::ViewsDelegate:
virtual ui::Clipboard* GetClipboard() const;
- virtual void SaveWindowPlacement(const std::wstring& window_name,
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized);
- virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const;
- virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
bool* maximized) const;
virtual void NotifyAccessibilityEvent(
views::View* view, AccessibilityTypes::Event event_type);
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index e68c163..06d8389 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1863,10 +1863,15 @@ void BrowserView::Init() {
this, browser_->profile()));
SetLayoutManager(CreateLayoutManager());
- // Stow a pointer to this object onto the window handle so that we can get
- // at it later when all we have is a native view.
+ // Stow a pointer to this object onto the window handle so that we can get at
+ // it later when all we have is a native view.
GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this);
+ // Stow a pointer to the browser's profile onto the window handle so that we
+ // can get it later when all we have is a native view.
+ GetWindow()->SetNativeWindowProperty(Profile::kProfileKey,
+ browser_->profile());
+
// Start a hung plugin window detector for this browser object (as long as
// hang detection is not disabled).
if (!CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/views/test/test_views_delegate.h b/views/test/test_views_delegate.h
index 7b379f8..cae1a64f 100644
--- a/views/test/test_views_delegate.h
+++ b/views/test/test_views_delegate.h
@@ -6,6 +6,10 @@
#include "ui/base/clipboard/clipboard.h"
#include "views/views_delegate.h"
+namespace views {
+class Window;
+}
+
class TestViewsDelegate : public views::ViewsDelegate {
public:
TestViewsDelegate() {}
@@ -19,15 +23,18 @@ class TestViewsDelegate : public views::ViewsDelegate {
}
return clipboard_.get();
}
- virtual void SaveWindowPlacement(const std::wstring& window_name,
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized) {
}
- virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const {
return false;
}
- virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
bool* maximized) const {
return false;
}
diff --git a/views/views_delegate.h b/views/views_delegate.h
index 66d91a7..98b734e 100644
--- a/views/views_delegate.h
+++ b/views/views_delegate.h
@@ -24,6 +24,7 @@ class Clipboard;
namespace views {
class View;
+class Window;
// ViewsDelegate is an interface implemented by an object using the views
// framework. It is used to obtain various high level application utilities
@@ -40,18 +41,21 @@ class ViewsDelegate {
// Saves the position, size and maximized state for the window with the
// specified name.
- virtual void SaveWindowPlacement(const std::wstring& window_name,
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
const gfx::Rect& bounds,
bool maximized) = 0;
// Retrieves the saved position and size for the window with the specified
// name.
- virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
gfx::Rect* bounds) const = 0;
// Retrieves the saved maximized state for the window with the specified
// name.
- virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
bool* maximized) const = 0;
// Notify the delegate that an accessibility event has happened in
diff --git a/views/window/window.h b/views/window/window.h
index 1d5ffea..e8bd7c0 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -75,6 +75,12 @@ class Window {
// Push/PopForceHidden.
virtual void HideWindow() = 0;
+ // Sets/Gets a native window property on the underlying native window object.
+ // Returns NULL if the property does not exist. Setting the property value to
+ // NULL removes the property.
+ virtual void SetNativeWindowProperty(const char* name, void* value) = 0;
+ virtual void* GetNativeWindowProperty(const char* name) = 0;
+
#if defined(OS_WIN)
// Hides the window if it hasn't already been force-hidden. The force hidden
// count is tracked, so calling multiple times is allowed, you just have to
diff --git a/views/window/window_delegate.cc b/views/window/window_delegate.cc
index 1701da7..69bcc03 100644
--- a/views/window/window_delegate.cc
+++ b/views/window/window_delegate.cc
@@ -33,7 +33,7 @@ void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds,
return;
ViewsDelegate::views_delegate->SaveWindowPlacement(
- window_name, bounds, maximized);
+ window_, window_name, bounds, maximized);
}
bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const {
@@ -42,7 +42,7 @@ bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const {
return false;
return ViewsDelegate::views_delegate->GetSavedWindowBounds(
- window_name, bounds);
+ window_, window_name, bounds);
}
bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const {
@@ -51,7 +51,7 @@ bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const {
return false;
return ViewsDelegate::views_delegate->GetSavedMaximizedState(
- window_name, maximized);
+ window_, window_name, maximized);
}
bool WindowDelegate::ShouldRestoreWindowSize() const {
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc
index adc714c..962331d 100644
--- a/views/window/window_gtk.cc
+++ b/views/window/window_gtk.cc
@@ -127,6 +127,14 @@ void WindowGtk::HideWindow() {
Hide();
}
+void WindowGtk::SetNativeWindowProperty(const char* name, void* value) {
+ WidgetGtk::SetNativeWindowProperty(name, value);
+}
+
+void* WindowGtk::GetNativeWindowProperty(const char* name) {
+ return WidgetGtk::GetNativeWindowProperty(name);
+}
+
void WindowGtk::Activate() {
gtk_window_present(GTK_WINDOW(GetNativeView()));
}
diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h
index 907ab7c..9f1af0d 100644
--- a/views/window/window_gtk.h
+++ b/views/window/window_gtk.h
@@ -32,6 +32,8 @@ class WindowGtk : public WidgetGtk, public Window {
gfx::NativeWindow other_window);
virtual void Show();
virtual void HideWindow();
+ virtual void SetNativeWindowProperty(const char* name, void* value);
+ virtual void* GetNativeWindowProperty(const char* name);
virtual void Activate();
virtual void Deactivate();
virtual void Close();
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 64dde6c..adf6946 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -273,6 +273,14 @@ void WindowWin::HideWindow() {
Hide();
}
+void WindowWin::SetNativeWindowProperty(const char* name, void* value) {
+ WidgetWin::SetNativeWindowProperty(name, value);
+}
+
+void* WindowWin::GetNativeWindowProperty(const char* name) {
+ return WidgetWin::GetNativeWindowProperty(name);
+}
+
void WindowWin::PushForceHidden() {
if (force_hidden_count_++ == 0)
Hide();
diff --git a/views/window/window_win.h b/views/window/window_win.h
index 6b20667a..5cd2bdd 100644
--- a/views/window/window_win.h
+++ b/views/window/window_win.h
@@ -70,6 +70,8 @@ class WindowWin : public WidgetWin,
gfx::NativeWindow other_window);
virtual void Show();
virtual void HideWindow();
+ virtual void SetNativeWindowProperty(const char* name, void* value);
+ virtual void* GetNativeWindowProperty(const char* name);
virtual void PushForceHidden();
virtual void PopForceHidden();
virtual void Activate();