summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/process_util_win.cc6
-rw-r--r--chrome/app/chrome_dll_main.cc16
-rw-r--r--chrome/app/chrome_exe_main.cc8
-rw-r--r--chrome/app/client_util.h2
-rwxr-xr-xchrome/app/google_update_client.cc3
-rw-r--r--chrome/app/google_update_client.h4
-rw-r--r--chrome/browser/automation/automation_provider.cc5
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc5
-rw-r--r--chrome/browser/browser.cc298
-rw-r--r--chrome/browser/browser.h84
-rw-r--r--chrome/browser/browser_init.cc90
-rw-r--r--chrome/browser/browser_init.h24
-rw-r--r--chrome/browser/browser_main.cc7
-rw-r--r--chrome/browser/browser_window.h14
-rw-r--r--chrome/browser/profile_manager.cc9
-rw-r--r--chrome/browser/session_restore.cc32
-rw-r--r--chrome/browser/session_restore.h1
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc7
-rw-r--r--chrome/browser/tabs/tab_strip_model.h3
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc1
-rw-r--r--chrome/browser/task_manager.cc17
-rw-r--r--chrome/browser/task_manager.h7
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc17
-rw-r--r--chrome/browser/views/bookmark_manager_view.h7
-rw-r--r--chrome/browser/views/frame/aero_glass_frame.cc26
-rw-r--r--chrome/browser/views/frame/aero_glass_frame.h9
-rw-r--r--chrome/browser/views/frame/browser_frame.h4
-rw-r--r--chrome/browser/views/frame/browser_view.cc73
-rw-r--r--chrome/browser/views/frame/browser_view.h19
-rw-r--r--chrome/browser/views/frame/browser_window_factory.cc14
-rw-r--r--chrome/browser/views/frame/opaque_frame.cc8
-rw-r--r--chrome/browser/views/frame/opaque_frame.h3
-rw-r--r--chrome/browser/views/frame/opaque_non_client_view.cc3
-rw-r--r--chrome/browser/views/options/advanced_contents_view.cc11
-rw-r--r--chrome/browser/views/page_info_window.cc41
-rw-r--r--chrome/browser/views/page_info_window.h7
-rw-r--r--chrome/browser/web_app_launcher.cc15
-rw-r--r--chrome/browser/web_app_launcher.h7
-rw-r--r--chrome/browser/window_sizer.cc1
-rw-r--r--chrome/plugin/plugin_main.cc2
-rw-r--r--chrome/renderer/renderer_main.cc2
-rw-r--r--chrome/views/window.cc122
-rw-r--r--chrome/views/window.h31
-rw-r--r--chrome/views/window_delegate.cc60
-rw-r--r--chrome/views/window_delegate.h35
45 files changed, 529 insertions, 631 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index df485f4..d12f167 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -118,10 +118,8 @@ bool LaunchApp(const std::wstring& cmdline,
bool wait, bool start_hidden, ProcessHandle* process_handle) {
STARTUPINFO startup_info = {0};
startup_info.cb = sizeof(startup_info);
- if (start_hidden) {
- startup_info.dwFlags = STARTF_USESHOWWINDOW;
- startup_info.wShowWindow = SW_HIDE;
- }
+ startup_info.dwFlags = STARTF_USESHOWWINDOW;
+ startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW;
PROCESS_INFORMATION process_info;
if (!CreateProcess(NULL,
const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 0f0b29f..3e519d9 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -25,9 +25,9 @@
#include "sandbox/src/sandbox.h"
#include "tools/memory_watcher/memory_watcher.h"
-extern int BrowserMain(CommandLine &, int, sandbox::BrokerServices*);
-extern int RendererMain(CommandLine &, int, sandbox::TargetServices*);
-extern int PluginMain(CommandLine &, int, sandbox::TargetServices*);
+extern int BrowserMain(CommandLine&, sandbox::BrokerServices*);
+extern int RendererMain(CommandLine&, sandbox::TargetServices*);
+extern int PluginMain(CommandLine&, sandbox::TargetServices*);
// TODO(erikkay): isn't this already defined somewhere?
#define DLLEXPORT __declspec(dllexport)
@@ -36,7 +36,7 @@ extern int PluginMain(CommandLine &, int, sandbox::TargetServices*);
extern "C" {
DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info,
- TCHAR* command_line, int show_command);
+ TCHAR* command_line);
}
namespace {
@@ -90,7 +90,7 @@ void ChromeAssert(const std::string& str) {
DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info,
- TCHAR* command_line, int show_command) {
+ TCHAR* command_line) {
// Register the invalid param handler and pure call handler to be able to
// notify breakpad when it happens.
_set_invalid_parameter_handler(InvalidParameter);
@@ -215,13 +215,13 @@ DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
int rv;
if (process_type == switches::kRendererProcess) {
- rv = RendererMain(parsed_command_line, show_command, target_services);
+ rv = RendererMain(parsed_command_line, target_services);
} else if (process_type == switches::kPluginProcess) {
- rv = PluginMain(parsed_command_line, show_command, target_services);
+ rv = PluginMain(parsed_command_line, target_services);
} else if (process_type.empty()) {
int ole_result = OleInitialize(NULL);
DCHECK(ole_result == S_OK);
- rv = BrowserMain(parsed_command_line, show_command, broker_services);
+ rv = BrowserMain(parsed_command_line, broker_services);
OleUninitialize();
} else {
NOTREACHED() << "Unknown process type";
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc
index 2fe33ce..a8529e6 100644
--- a/chrome/app/chrome_exe_main.cc
+++ b/chrome/app/chrome_exe_main.cc
@@ -20,7 +20,7 @@
#include "sandbox/src/dep.h"
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
- wchar_t* command_line, int show_command) {
+ wchar_t* command_line, int) {
process_util::EnableTerminationOnHeapCorruption();
// The exit manager is in charge of calling the dtors of singletons.
@@ -62,8 +62,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
}
int ret = 0;
- if (client.Launch(instance, &sandbox_info, command_line, show_command,
- "ChromeMain", &ret)) {
+ if (client.Launch(instance, &sandbox_info, command_line, "ChromeMain",
+ &ret)) {
return ret;
}
#else
@@ -90,7 +90,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
client_util::DLL_MAIN entry = reinterpret_cast<client_util::DLL_MAIN>(
::GetProcAddress(dll_handle, "ChromeMain"));
if (NULL != entry)
- return (entry)(instance, &sandbox_info, command_line, show_command);
+ return (entry)(instance, &sandbox_info, command_line);
}
#endif
diff --git a/chrome/app/client_util.h b/chrome/app/client_util.h
index f0b75bb..44a9c43 100644
--- a/chrome/app/client_util.h
+++ b/chrome/app/client_util.h
@@ -16,7 +16,7 @@
namespace client_util {
typedef int (*DLL_MAIN)(HINSTANCE instance, sandbox::SandboxInterfaceInfo*,
- TCHAR*, int);
+ TCHAR*);
extern const wchar_t kProductVersionKey[];
diff --git a/chrome/app/google_update_client.cc b/chrome/app/google_update_client.cc
index 65acec6..019c401 100755
--- a/chrome/app/google_update_client.cc
+++ b/chrome/app/google_update_client.cc
@@ -48,7 +48,6 @@ const wchar_t* GoogleUpdateClient::GetVersion() const {
bool GoogleUpdateClient::Launch(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox,
wchar_t* command_line,
- int show_command,
const char* entry_name,
int* ret) {
if (client_util::FileExists(dll_path_)) {
@@ -90,7 +89,7 @@ bool GoogleUpdateClient::Launch(HINSTANCE instance,
::RegCloseKey(reg_key);
}
- int rc = (entry)(instance, sandbox, command_line, show_command);
+ int rc = (entry)(instance, sandbox, command_line);
if (ret) {
*ret = rc;
}
diff --git a/chrome/app/google_update_client.h b/chrome/app/google_update_client.h
index 664c4e5..e443367 100644
--- a/chrome/app/google_update_client.h
+++ b/chrome/app/google_update_client.h
@@ -50,14 +50,12 @@ class GoogleUpdateClient {
// - instance is handle to the current instance of application
// - sandbox provides information about sandbox services
// - command_line contains command line parameters
- // - show_command specifies how the window is to be shown
// - entry_name is the function of type DLL_MAIN that is called
// from chrome.dll
// - ret is an out param with the return value of entry
// Returns false if unable to load the dll or find entry_name's proc addr.
bool Launch(HINSTANCE instance, sandbox::SandboxInterfaceInfo* sandbox,
- wchar_t* command_line, int show_command, const char* entry_name,
- int* ret);
+ wchar_t* command_line, const char* entry_name, int* ret);
private:
// disallow copy ctor and operator=
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index d3ac4bb..3304de1 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -1954,7 +1954,10 @@ void AutomationProvider::GetDownloadDirectory(const IPC::Message& message,
void AutomationProvider::OpenNewBrowserWindow(int show_command) {
// We may have no current browser windows open so don't rely on
// asking an existing browser to execute the IDC_NEWWINDOW command
- Browser::OpenNewBrowserWindow(profile_, show_command);
+ Browser* browser = Browser::Create(profile_);
+ browser->AddBlankTab(true);
+ if (show_command != SW_HIDE)
+ browser->window()->Show();
}
void AutomationProvider::GetWindowForBrowser(const IPC::Message& message,
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 8aad4f1..ec96ce0 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -35,7 +35,7 @@ class NewBrowserPageNavigator : public PageNavigator {
virtual ~NewBrowserPageNavigator() {
if (browser_)
- browser_->Show();
+ browser_->window()->Show();
}
Browser* browser() const { return browser_; }
@@ -47,8 +47,7 @@ class NewBrowserPageNavigator : public PageNavigator {
if (!browser_) {
Profile* profile = (disposition == OFF_THE_RECORD) ?
profile_->GetOffTheRecordProfile() : profile_;
- browser_ = new Browser(gfx::Rect(), SW_SHOW, profile,
- BrowserType::TABBED_BROWSER, std::wstring());
+ browser_ = Browser::Create(profile);
// Always open the first tab in the foreground.
disposition = NEW_FOREGROUND_TAB;
}
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index b8715a3..30a7fd1 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/browser.h"
-
#include <windows.h>
#include <shellapi.h>
+#include "chrome/browser/browser.h"
+
#include "base/command_line.h"
#include "base/file_version_info.h"
#include "base/idle_timer.h"
@@ -152,38 +152,20 @@ struct Browser::UIUpdate {
///////////////////////////////////////////////////////////////////////////////
// Browser, Constructors, Creation, Showing:
-Browser::Browser(const gfx::Rect& initial_bounds,
- int show_command,
- Profile* profile,
- BrowserType::Type type,
- const std::wstring& app_name)
- : profile_(profile),
+Browser::Browser(BrowserType::Type type, Profile* profile)
+ : type_(type),
+ profile_(profile),
window_(NULL),
- initial_show_command_(show_command),
- is_attempting_to_close_browser_(false),
+ tabstrip_model_(this, profile),
controller_(this),
+ toolbar_model_(this),
chrome_updater_factory_(this),
+ is_attempting_to_close_browser_(false),
+ override_maximized_(false),
method_factory_(this),
- tabstrip_model_(this, profile),
- toolbar_model_(this),
- type_(type),
- app_name_(app_name),
- idle_task_(new BrowserIdleTimer()) {
+ idle_task_(new BrowserIdleTimer) {
tabstrip_model_.AddObserver(this);
- CommandLine parsed_command_line;
-
- gfx::Rect create_bounds;
- bool maximized = false;
- WindowSizer::GetBrowserWindowBounds(app_name_, initial_bounds,
- &create_bounds, &maximized);
- if (parsed_command_line.HasSwitch(switches::kStartMaximized))
- maximized = true;
- if (maximized)
- initial_show_command_ = SW_SHOWMAXIMIZED;
- window_ = BrowserWindow::CreateBrowserWindow(this, create_bounds,
- show_command);
-
NotificationService::current()->AddObserver(
this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources());
@@ -196,15 +178,6 @@ Browser::Browser(const gfx::Rect& initial_bounds,
// Trim browser memory on idle for low & medium memory models.
if (g_browser_process->memory_model() < BrowserProcess::HIGH_MEMORY_MODEL)
idle_task_->Start();
-
- // Show the First Run information bubble if we've been told to.
- PrefService* local_state = g_browser_process->local_state();
- if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) &&
- local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
- // Reset the preference so we don't show the bubble for subsequent windows.
- local_state->ClearPref(prefs::kShouldShowFirstRunBubble);
- GetLocationBarView()->ShowFirstRunBubble();
- }
}
Browser::~Browser() {
@@ -248,76 +221,76 @@ Browser::~Browser() {
select_file_dialog_->ListenerDestroyed();
}
-void Browser::Show() {
- // TODO(beng): this entire function should move to BrowserWindow.
+// static
+Browser* Browser::Create(Profile* profile) {
+ Browser* browser = new Browser(BrowserType::TABBED_BROWSER, profile);
+ browser->CreateBrowserWindow();
+ return browser;
+}
- // Only allow one call after the browser is created.
- if (initial_show_command_ < 0) {
- // The frame is already visible, we're being invoked again either by the
- // user clicking a link in another app or from a desktop shortcut.
- window_->Activate();
- return;
+// static
+Browser* Browser::CreateForPopup(Profile* profile) {
+ Browser* browser = new Browser(BrowserType::BROWSER, profile);
+ browser->CreateBrowserWindow();
+ return browser;
+}
+
+// static
+Browser* Browser::CreateForApp(const std::wstring& app_name,
+ Profile* profile) {
+ Browser* browser = new Browser(BrowserType::APPLICATION, profile);
+ browser->app_name_ = app_name;
+ browser->CreateBrowserWindow();
+ return browser;
+}
+
+void Browser::CreateBrowserWindow() {
+ DCHECK(!window_);
+ window_ = BrowserWindow::CreateBrowserWindow(this);
+
+ // Show the First Run information bubble if we've been told to.
+ PrefService* local_state = g_browser_process->local_state();
+ if (local_state->IsPrefRegistered(prefs::kShouldShowFirstRunBubble) &&
+ local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
+ // Reset the preference so we don't show the bubble for subsequent windows.
+ local_state->ClearPref(prefs::kShouldShowFirstRunBubble);
+ GetLocationBarView()->ShowFirstRunBubble();
}
- window_->Show(initial_show_command_, false);
- if ((initial_show_command_ == SW_SHOWNORMAL) ||
- (initial_show_command_ == SW_SHOWMAXIMIZED))
- window_->Activate();
- initial_show_command_ = -1;
-
- // Setting the focus doesn't work when the window is invisible, so any focus
- // initialization that happened before this will be lost.
- //
- // We really "should" restore the focus whenever the window becomes unhidden,
- // but I think initializing is the only time where this can happen where there
- // is some focus change we need to pick up, and this is easier than plumbing
- // through an unhide message all the way from the frame.
- //
- // If we do find there are cases where we need to restore the focus on show,
- // that should be added and this should be removed.
- TabContents* selected_tab_contents = GetSelectedTabContents();
- if (selected_tab_contents)
- selected_tab_contents->RestoreFocus();
}
///////////////////////////////////////////////////////////////////////////////
// Browser, Creation Helpers:
// static
-void Browser::OpenNewBrowserWindow(Profile* profile, int show_command) {
- Browser* browser = new Browser(gfx::Rect(), show_command, profile,
- BrowserType::TABBED_BROWSER, L"");
+void Browser::OpenEmptyWindow(Profile* profile) {
+ Browser* browser = Browser::Create(profile);
browser->AddBlankTab(true);
- browser->Show();
+ browser->window()->Show();
}
// static
void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) {
Profile* off_the_record_profile = profile->GetOffTheRecordProfile();
Browser* browser = BrowserList::FindBrowserWithType(
- off_the_record_profile, BrowserType::TABBED_BROWSER);
- if (browser == NULL) {
- browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, off_the_record_profile,
- BrowserType::TABBED_BROWSER, L"");
- }
+ off_the_record_profile,
+ BrowserType::TABBED_BROWSER);
+ if (!browser)
+ browser = Browser::Create(off_the_record_profile);
// TODO(eroman): should we have referrer here?
browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL);
- browser->Show();
- browser->window()->Activate();
+ browser->window()->Show();
}
// static
-void Browser::OpenWebApplication(Profile* profile,
- WebApp* app,
- int show_command) {
+void Browser::OpenWebApplication(Profile* profile, WebApp* app) {
const std::wstring& app_name =
app->name().empty() ? ComputeApplicationNameFromURL(app->url()) :
app->name();
-
RegisterAppPrefs(app_name);
- Browser* browser = new Browser(gfx::Rect(), show_command, profile,
- BrowserType::APPLICATION, app_name);
+
+ Browser* browser = Browser::CreateForApp(app_name, profile);
browser->AddWebApplicationTab(profile, app, false);
- browser->Show();
+ browser->window()->Show();
}
///////////////////////////////////////////////////////////////////////////////
@@ -356,7 +329,7 @@ HWND Browser::GetTopLevelHWND() const {
///////////////////////////////////////////////////////////////////////////////
// Browser, State Storage and Retrieval for UI:
-void Browser::SaveWindowPosition(const gfx::Rect& bounds, bool maximized) {
+void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) {
// We don't save window position for popups.
if (type() == BrowserType::BROWSER)
return;
@@ -390,9 +363,37 @@ void Browser::SaveWindowPosition(const gfx::Rect& bounds, bool maximized) {
}
}
-void Browser::RestoreWindowPosition(gfx::Rect* bounds, bool* maximized) {
- DCHECK(bounds && maximized);
- WindowSizer::GetBrowserWindowBounds(app_name_, *bounds, bounds, maximized);
+gfx::Rect Browser::GetSavedWindowBounds() const {
+ CommandLine parsed_command_line;
+ bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
+ bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
+ if (record_mode || playback_mode) {
+ // In playback/record mode we always fix the size of the browser and
+ // move it to (0,0). The reason for this is two reasons: First we want
+ // resize/moves in the playback to still work, and Second we want
+ // playbacks to work (as much as possible) on machines w/ different
+ // screen sizes.
+ return gfx::Rect(0, 0, 800, 600);
+ }
+
+ gfx::Rect restored_bounds = override_bounds_;
+ bool maximized;
+ WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds,
+ &restored_bounds, &maximized);
+ return restored_bounds;
+}
+
+// TODO(beng): obtain maximized state some other way so we don't need to go
+// through all this hassle.
+bool Browser::GetSavedMaximizedState() const {
+ if (CommandLine().HasSwitch(switches::kStartMaximized))
+ return true;
+
+ gfx::Rect restored_bounds;
+ bool maximized = override_maximized_;
+ WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds,
+ &restored_bounds, &maximized);
+ return maximized;
}
SkBitmap Browser::GetCurrentPageIcon() const {
@@ -661,10 +662,8 @@ void Browser::NewTab() {
AddBlankTab(true);
} else {
Browser* b = GetOrCreateTabbedBrowser();
- DCHECK(b);
- b->Show();
- b->window()->Activate();
b->AddBlankTab(true);
+ b->window()->Show();
}
}
@@ -680,14 +679,12 @@ void Browser::CloseApp() {
void Browser::NewWindow() {
UserMetrics::RecordAction(L"NewWindow", profile_);
- Browser::OpenNewBrowserWindow(profile_->GetOriginalProfile(),
- SW_SHOWNORMAL);
+ Browser::OpenEmptyWindow(profile_->GetOriginalProfile());
}
void Browser::NewIncognitoWindow() {
UserMetrics::RecordAction(L"NewIncognitoWindow", profile_);
- Browser::OpenNewBrowserWindow(profile_->GetOffTheRecordProfile(),
- SW_SHOWNORMAL);
+ Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile());
}
void Browser::CloseWindow() {
@@ -748,11 +745,9 @@ void Browser::ConvertPopupToTabbedBrowser() {
int tab_strip_index = tabstrip_model_.selected_index();
TabContents* contents = tabstrip_model_.DetachTabContentsAt(tab_strip_index);
- Browser* browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_,
- BrowserType::TABBED_BROWSER, L"");
- browser->AddNewContents(NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(),
- true);
- browser->Show();
+ Browser* browser = Browser::Create(profile_);
+ browser->tabstrip_model()->AppendTabContents(contents, true);
+ browser->window()->Show();
}
void Browser::Exit() {
@@ -1286,6 +1281,10 @@ void Browser::ExecuteCommand(int id) {
///////////////////////////////////////////////////////////////////////////////
// Browser, TabStripModelDelegate implementation:
+GURL Browser::GetBlankTabURL() const {
+ return NewTabUIURL();
+}
+
void Browser::CreateNewStripWithContents(TabContents* detached_contents,
const gfx::Point& drop_point) {
DCHECK(type_ == BrowserType::TABBED_BROWSER);
@@ -1300,13 +1299,11 @@ void Browser::CreateNewStripWithContents(TabContents* detached_contents,
rect.SetRect(drop_point.x(), drop_point.y(), browser_rect.Width(),
browser_rect.Height());
}
- Browser* new_window =
- new Browser(rect, SW_SHOWNORMAL, profile_, BrowserType::TABBED_BROWSER,
- std::wstring());
- // Append the TabContents before showing it so the window doesn't flash
- // black.
- new_window->tabstrip_model()->AppendTabContents(detached_contents, true);
- new_window->Show();
+ Browser* browser = new Browser(BrowserType::TABBED_BROWSER, profile_);
+ browser->set_override_bounds(rect);
+ browser->CreateBrowserWindow();
+ browser->tabstrip_model()->AppendTabContents(detached_contents, true);
+ browser->window()->Show();
// When we detach a tab we need to make sure any associated Find window moves
// along with it to its new home (basically we just make new_window the parent
@@ -1314,7 +1311,7 @@ void Browser::CreateNewStripWithContents(TabContents* detached_contents,
// TODO(brettw) this could probably be improved, see
// WebContentsView::ReparentFindWindow for more.
if (detached_contents->AsWebContents())
- detached_contents->AsWebContents()->view()->ReparentFindWindow(new_window);
+ detached_contents->AsWebContents()->view()->ReparentFindWindow(browser);
}
int Browser::GetDragActions() const {
@@ -1377,19 +1374,21 @@ void Browser::DuplicateContentsAt(int index) {
tabstrip_model_.AddTabContents(new_contents, index + 1,
PageTransition::LINK, true);
} else {
- Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile(),
- BrowserType::APPLICATION, app_name_);
+ Browser* browser = NULL;
+ if (type_ == BrowserType::APPLICATION) {
+ browser = Browser::CreateForApp(app_name_, profile_);
+ } else if (type_ == BrowserType::BROWSER) {
+ browser = Browser::CreateForPopup(profile_);
+ }
// We need to show the browser now. Otherwise ContainerWin assumes the
// TabContents is invisible and won't size it.
- new_browser->Show();
+ browser->window()->Show();
// The page transition below is only for the purpose of inserting the tab.
- new_contents = new_browser->AddTabWithNavigationController(
- contents->controller()->Clone(new_browser->GetTopLevelHWND()),
+ new_contents = browser->AddTabWithNavigationController(
+ contents->controller()->Clone(browser->GetTopLevelHWND()),
PageTransition::LINK);
-
- new_browser->window()->Activate();
}
if (profile_->HasSessionService()) {
@@ -1588,8 +1587,7 @@ void Browser::OpenURLFromTab(TabContents* source,
disposition = NEW_FOREGROUND_TAB;
b->OpenURL(url, referrer, disposition, transition);
- b->Show();
- b->window()->Activate();
+ b->window()->Show();
return;
}
@@ -1597,11 +1595,10 @@ void Browser::OpenURLFromTab(TabContents* source,
disposition = NEW_FOREGROUND_TAB;
if (disposition == NEW_WINDOW) {
- Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_,
- BrowserType::TABBED_BROWSER, L"");
- new_contents = new_browser->AddTabWithURL(url, referrer, transition, true,
- instance);
- new_browser->Show();
+ Browser* browser = Browser::Create(profile_);
+ new_contents = browser->AddTabWithURL(url, referrer, transition, true,
+ instance);
+ browser->window()->Show();
} else if ((disposition == CURRENT_TAB) && current_tab) {
if (transition == PageTransition::TYPED ||
transition == PageTransition::AUTO_BOOKMARK ||
@@ -1646,9 +1643,8 @@ void Browser::OpenURLFromTab(TabContents* source,
OpenURLOffTheRecord(profile_, url);
return;
} else if (disposition != SUPPRESS_OPEN) {
- new_contents =
- AddTabWithURL(url, referrer, transition,
- disposition != NEW_BACKGROUND_TAB, instance);
+ new_contents = AddTabWithURL(url, referrer, transition,
+ disposition != NEW_BACKGROUND_TAB, instance);
}
if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) {
@@ -1727,19 +1723,17 @@ void Browser::AddNewContents(TabContents* source,
if (type_ == BrowserType::APPLICATION)
transition = PageTransition::START_PAGE;
b->tabstrip_model()->AddTabContents(new_contents, -1, transition, true);
- b->Show();
- b->window()->Activate();
+ b->window()->Show();
return;
}
if (disposition == NEW_POPUP) {
BuildPopupWindow(source, new_contents, initial_pos);
} else if (disposition == NEW_WINDOW) {
- Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_,
- BrowserType::TABBED_BROWSER, L"");
- new_browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB,
- initial_pos, user_gesture);
- new_browser->Show();
+ Browser* browser = Browser::Create(profile_);
+ browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB,
+ initial_pos, user_gesture);
+ browser->window()->Show();
} else if (disposition == CURRENT_TAB) {
ReplaceContents(source, new_contents);
} else if (disposition != SUPPRESS_OPEN) {
@@ -1856,11 +1850,9 @@ void Browser::ConvertContentsToApplication(TabContents* contents) {
RegisterAppPrefs(app_name);
tabstrip_model_.DetachTabContentsAt(index);
- Browser* browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_,
- BrowserType::APPLICATION, app_name);
- browser->AddNewContents(
- NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), true);
- browser->Show();
+ Browser* browser = Browser::CreateForApp(app_name, profile_);
+ browser->tabstrip_model()->AppendTabContents(contents, true);
+ browser->window()->Show();
}
void Browser::ContentsStateChanged(TabContents* source) {
@@ -2406,10 +2398,8 @@ void Browser::ClearUnloadState(TabContents* tab) {
Browser* Browser::GetOrCreateTabbedBrowser() {
Browser* browser = BrowserList::FindBrowserWithType(
profile_, BrowserType::TABBED_BROWSER);
- if (!browser) {
- browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile_,
- BrowserType::TABBED_BROWSER, std::wstring());
- }
+ if (!browser)
+ browser = Browser::Create(profile_);
return browser;
}
@@ -2418,25 +2408,25 @@ void Browser::BuildPopupWindow(TabContents* source,
const gfx::Rect& initial_pos) {
BrowserType::Type type =
type_ == BrowserType::APPLICATION ? type_ : BrowserType::BROWSER;
- Browser* browser = new Browser(initial_pos, SW_SHOWNORMAL, profile_, type,
- std::wstring());
- browser->AddNewContents(source, new_contents,
- NEW_FOREGROUND_TAB, gfx::Rect(), true);
- browser->Show();
+ Browser* browser = new Browser(type, profile_);
+ browser->set_override_bounds(initial_pos);
+ browser->CreateBrowserWindow();
+ // TODO(beng): See if this can be made to use
+ // TabStripModel::AppendTabContents.
+ browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB,
+ gfx::Rect(), true);
+ browser->window()->Show();
}
GURL Browser::GetHomePage() {
- if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) {
+ if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
return NewTabUIURL();
- } else {
- GURL home_page = GURL(URLFixerUpper::FixupURL(
- profile_->GetPrefs()->GetString(prefs::kHomePage),
- std::wstring()));
- if (!home_page.is_valid())
- return NewTabUIURL();
-
- return home_page;
- }
+ GURL home_page = GURL(URLFixerUpper::FixupURL(
+ profile_->GetPrefs()->GetString(prefs::kHomePage),
+ std::wstring()));
+ if (!home_page.is_valid())
+ return NewTabUIURL();
+ return home_page;
}
void Browser::AdvanceFindSelection(bool forward_direction) {
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 510656f..278c39d 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -8,6 +8,7 @@
#include "chrome/browser/controller.h"
#include "chrome/browser/shell_dialogs.h"
#include "chrome/browser/browser_type.h"
+#include "chrome/browser/browser_window.h"
#include "chrome/browser/session_id.h"
#include "chrome/browser/tab_contents_delegate.h"
#include "chrome/browser/tabs/tab_strip_model.h"
@@ -24,7 +25,6 @@ class PrefService;
class Profile;
class StatusBubble;
struct TabNavigation;
-class WebContents;
class WebApp;
class Browser : public TabStripModelDelegate,
@@ -36,27 +36,35 @@ class Browser : public TabStripModelDelegate,
public:
// Constructors, Creation, Showing //////////////////////////////////////////
- // Creates a new browser with the given bounds. If the bounds are empty, the
- // system will try to find a saved size from a previous session, if none
- // exists, the operating system will be allowed to size the window.
- // |type| defines the kind of browser to create.
- //
- // Creating a browser does NOT show the window. You must manually call Show()
- // to display the window.
- Browser(const gfx::Rect& initial_bounds,
- int show_command,
- Profile* profile,
- BrowserType::Type browser_type,
- const std::wstring& app_name);
+ // Creates a new browser of the given |type| and for the given |profile|. The
+ // Browser has a NULL window after its construction, CreateBrowserWindow must
+ // be called after configuration for window() to be valid.
+ Browser(BrowserType::Type type, Profile* profile);
~Browser();
- // Shows the browser window. It is initially created hidden. It will be shown
- // with the show command passed to the constructor, or possibly another state
- // if it was overridden in the preferences.
- //
- // Ideally, this function is called after everything in the window is
- // initialized so that we do not have to repaint again.
- void Show();
+ // Creates a normal tabbed browser with the specified profile. The Browser's
+ // window is created by this function call.
+ static Browser* Create(Profile* profile);
+
+ // Like Create, but creates a tabstrip-less popup window.
+ static Browser* CreateForPopup(Profile* profile);
+
+ // Like Create, but creates a tabstrip-less and toolbar-less "app" window for
+ // the specified app.
+ static Browser* CreateForApp(const std::wstring& app_name, Profile* profile);
+
+ // Set overrides for the initial window bounds and maximized state.
+ void set_override_bounds(const gfx::Rect& bounds) {
+ override_bounds_ = bounds;
+ }
+ void set_override_maximized(bool maximized) {
+ override_maximized_ = maximized;
+ }
+
+ // Creates the Browser Window. Prefer to use the static helpers above where
+ // possible. This does not show the window. You need to call window()->Show()
+ // to show it.
+ void CreateBrowserWindow();
// Accessors ////////////////////////////////////////////////////////////////
@@ -69,9 +77,8 @@ class Browser : public TabStripModelDelegate,
// Browser Creation Helpers /////////////////////////////////////////////////
- // Opens a new browser window for the specified |profile|, shown according to
- // |show_command|
- static void OpenNewBrowserWindow(Profile* profile, int show_command);
+ // Opens a new window with the default blank tab.
+ static void OpenEmptyWindow(Profile* profile);
// Opens the specified URL in a new browser window in an incognito session.
// If there is already an existing active incognito session for the specified
@@ -79,9 +86,7 @@ class Browser : public TabStripModelDelegate,
static void OpenURLOffTheRecord(Profile* profile, const GURL& url);
// Opens the a new application window for the specified WebApp.
- static void OpenWebApplication(Profile* profile,
- WebApp* app,
- int show_command);
+ static void OpenWebApplication(Profile* profile, WebApp* app);
// Command API //////////////////////////////////////////////////////////////
@@ -98,8 +103,9 @@ class Browser : public TabStripModelDelegate,
// State Storage and Retrieval for UI ///////////////////////////////////////
// Save and restore the window position.
- void SaveWindowPosition(const gfx::Rect& bounds, bool maximized);
- void RestoreWindowPosition(gfx::Rect* bounds, bool* maximized);
+ void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized);
+ gfx::Rect GetSavedWindowBounds() const;
+ bool GetSavedMaximizedState() const;
// Gets the FavIcon of the page in the selected tab.
SkBitmap GetCurrentPageIcon() const;
@@ -288,14 +294,12 @@ class Browser : public TabStripModelDelegate,
virtual void ExecuteCommand(int id);
// Overridden from TabStripModelDelegate:
+ virtual GURL GetBlankTabURL() const;
virtual void CreateNewStripWithContents(TabContents* detached_contents,
const gfx::Point& drop_point);
virtual int GetDragActions() const;
// Construct a TabContents for a given URL, profile and transition type.
// If instance is not null, its process will be used to render the tab.
- // TODO(beng): remove this from TabStripDelegate, it's only used by
- // TabStripModel::AddBlankTab*, which should really live here
- // on Browser.
virtual TabContents* CreateTabContentsForURL(
const GURL& url,
const GURL& referrer,
@@ -499,16 +503,6 @@ class Browser : public TabStripModelDelegate,
// This Browser's window.
BrowserWindow* window_;
- // Controls how the window will appear when Show() is called. This is one
- // of the SW_* constants passed to ShowWindow, and will be initialized in the
- // constructor.
- //
- // After the first call to Show() succeeds, this is set to -1, indicating that
- // subsequent calls to Show() should be ignored.
- // TODO(beng): This should be removed (http://crbug.com/3557) and put into
- // BrowserView, or some more likely place.
- int initial_show_command_;
-
// This Browser's TabStripModel.
TabStripModel tabstrip_model_;
@@ -575,6 +569,14 @@ class Browser : public TabStripModelDelegate,
/////////////////////////////////////////////////////////////////////////////
+ // Override values for the bounds of the window and its maximized state.
+ // These are supplied by callers that don't want to use the default values.
+ // The default values are typically loaded from local state (last session),
+ // obtained from the last window of the same type, or obtained from the
+ // shell shortcut's startup info.
+ gfx::Rect override_bounds_;
+ bool override_maximized_;
+
// The following factory is used to close the frame at a later time.
ScopedRunnableMethodFactory<Browser> method_factory_;
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 1a2941d..ff9cb3f 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -104,12 +104,12 @@ BrowserInit::MessageWindow::~MessageWindow() {
DestroyWindow(window_);
}
-bool BrowserInit::MessageWindow::NotifyOtherProcess(int show_cmd) {
+bool BrowserInit::MessageWindow::NotifyOtherProcess() {
if (!remote_window_)
return false;
// Found another window, send our command line to it
- // format is "START\0<<<current directory>>>\0<<<commandline>>>\0show_cmd".
+ // format is "START\0<<<current directory>>>\0<<<commandline>>>".
std::wstring to_send(L"START\0", 6); // want the NULL in the string.
std::wstring cur_dir;
if (!PathService::Get(base::DIR_CURRENT, &cur_dir))
@@ -119,22 +119,6 @@ bool BrowserInit::MessageWindow::NotifyOtherProcess(int show_cmd) {
to_send.append(GetCommandLineW());
to_send.append(L"\0", 1); // Null separator.
- // Append the windows show_command flags.
- if (show_cmd == SW_SHOWDEFAULT) {
- // SW_SHOWDEFAULT makes no sense to the other process. We need to
- // use the SW_ flag from OUR STARTUPUNFO;
- STARTUPINFO startup_info = {0};
- startup_info.cb = sizeof(startup_info);
- GetStartupInfo(&startup_info);
- show_cmd = startup_info.wShowWindow;
- // In certain situations the window status above is returned as SW_HIDE.
- // In such cases we need to fall back to a default case of SW_SHOWNORMAL
- // so that user actually get to see the window.
- if (show_cmd != SW_SHOWNORMAL && show_cmd != SW_SHOWMAXIMIZED)
- show_cmd = SW_SHOWNORMAL;
- }
- StringAppendF(&to_send, L"%d", static_cast<uint8>(show_cmd));
-
// Allow the current running browser window making itself the foreground
// window (otherwise it will just flash in the taskbar).
DWORD process_id = 0;
@@ -266,15 +250,6 @@ LRESULT BrowserInit::MessageWindow::OnCopyData(HWND hwnd,
const std::wstring cmd_line =
msg.substr(second_null + 1, third_null - second_null);
- // The last component is probably null terminated but we don't require it
- // because everything here is based on counts.
- std::wstring show_cmd_str = msg.substr(third_null + 1);
- if (!show_cmd_str.empty() &&
- show_cmd_str[show_cmd_str.length() - 1] == L'\0')
- show_cmd_str.resize(cmd_line.length() - 1);
-
- int show_cmd = _wtoi(show_cmd_str.c_str());
-
CommandLine parsed_command_line(cmd_line);
PrefService* prefs = g_browser_process->local_state();
DCHECK(prefs);
@@ -289,8 +264,8 @@ LRESULT BrowserInit::MessageWindow::OnCopyData(HWND hwnd,
NOTREACHED();
return TRUE;
}
- ProcessCommandLine(parsed_command_line, cur_dir, prefs, show_cmd, false,
- profile, NULL);
+ ProcessCommandLine(parsed_command_line, cur_dir, prefs, false, profile,
+ NULL);
return TRUE;
}
return TRUE;
@@ -371,10 +346,8 @@ void BrowserInit::MessageWindow::HuntForZombieChromeProcesses() {
// LaunchWithProfile ----------------------------------------------------------
BrowserInit::LaunchWithProfile::LaunchWithProfile(const std::wstring& cur_dir,
- const std::wstring& cmd_line,
- int show_command)
+ const std::wstring& cmd_line)
: command_line_(cmd_line),
- show_command_(show_command),
cur_dir_(cur_dir) {
}
@@ -384,22 +357,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
profile_ = profile;
CommandLine parsed_command_line(command_line_);
- gfx::Rect start_position;
-
- bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
- bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
- if (record_mode || playback_mode) {
- // In playback/record mode we always fix the size of the browser and
- // move it to (0,0). The reason for this is two reasons: First we want
- // resize/moves in the playback to still work, and Second we want
- // playbacks to work (as much as possible) on machines w/ different
- // screen sizes.
- start_position_.set_height(800);
- start_position_.set_width(600);
- start_position_.set_x(0);
- start_position_.set_y(0);
- }
-
if (parsed_command_line.HasSwitch(switches::kDnsLogDetails))
chrome_browser_net::EnableDnsDetailedLog(true);
if (parsed_command_line.HasSwitch(switches::kDnsPrefetchDisable))
@@ -475,6 +432,11 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
if (!parsed_command_line.HasSwitch(switches::kNoEvents)) {
std::wstring script_path;
PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path);
+
+ bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
+ bool playback_mode =
+ parsed_command_line.HasSwitch(switches::kPlaybackMode);
+
if (record_mode && chrome::kRecordModeEnabled)
base::EventRecorder::current()->StartRecording(script_path);
if (playback_mode)
@@ -484,11 +446,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
return true;
}
-Browser* BrowserInit::LaunchWithProfile::CreateTabbedBrowser() {
- return new Browser(start_position_, show_command_, profile_,
- BrowserType::TABBED_BROWSER, std::wstring());
-}
-
bool BrowserInit::LaunchWithProfile::OpenStartupURLs(
bool is_process_startup,
const CommandLine& command_line,
@@ -507,8 +464,8 @@ bool BrowserInit::LaunchWithProfile::OpenStartupURLs(
// infobar.
return false;
}
- SessionRestore::RestoreSessionSynchronously(
- profile_, false, show_command_, urls_to_open);
+ SessionRestore::RestoreSessionSynchronously(profile_, false,
+ urls_to_open);
return true;
case SessionStartupPref::URLS:
@@ -533,7 +490,7 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
const std::vector<GURL>& urls) {
DCHECK(!urls.empty());
if (!browser || browser->type() != BrowserType::TABBED_BROWSER)
- browser = CreateTabbedBrowser();
+ browser = Browser::Create(profile_);
for (size_t i = 0; i < urls.size(); ++i) {
TabContents* tab = browser->AddTabWithURL(
@@ -541,7 +498,7 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
if (i == 0 && process_startup)
AddCrashedInfoBarIfNecessary(tab);
}
- browser->Show();
+ browser->window()->Show();
return browser;
}
@@ -592,8 +549,8 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
}
bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
- const std::wstring& cur_dir, PrefService* prefs, int show_command,
- bool process_startup, Profile* profile, int* return_code) {
+ const std::wstring& cur_dir, PrefService* prefs, bool process_startup,
+ Profile* profile, int* return_code) {
DCHECK(profile);
if (process_startup) {
const std::wstring popup_count_string =
@@ -655,19 +612,18 @@ bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
// If we don't want to launch a new browser window or tab (in the case
// of an automation request), we are done here.
if (!silent_launch) {
- return LaunchBrowser(parsed_command_line, profile, show_command, cur_dir,
+ return LaunchBrowser(parsed_command_line, profile, cur_dir,
process_startup, return_code);
}
return true;
}
bool BrowserInit::LaunchBrowser(const CommandLine& parsed_command_line,
- Profile* profile,
- int show_command, const std::wstring& cur_dir,
+ Profile* profile, const std::wstring& cur_dir,
bool process_startup, int* return_code) {
in_startup = process_startup;
- bool result = LaunchBrowserImpl(parsed_command_line, profile, show_command,
- cur_dir, process_startup, return_code);
+ bool result = LaunchBrowserImpl(parsed_command_line, profile, cur_dir,
+ process_startup, return_code);
in_startup = false;
return result;
}
@@ -689,7 +645,6 @@ void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id,
bool BrowserInit::LaunchBrowserImpl(const CommandLine& parsed_command_line,
Profile* profile,
- int show_command,
const std::wstring& cur_dir,
bool process_startup,
int* return_code) {
@@ -710,12 +665,11 @@ bool BrowserInit::LaunchBrowserImpl(const CommandLine& parsed_command_line,
if (url.SchemeIs("mailto"))
url = GURL("about:blank");
- WebAppLauncher::Launch(profile, url, show_command);
+ WebAppLauncher::Launch(profile, url);
return true;
}
- LaunchWithProfile lwp(cur_dir, parsed_command_line.command_line_string(),
- show_command);
+ LaunchWithProfile lwp(cur_dir, parsed_command_line.command_line_string());
bool launched = lwp.Launch(profile, process_startup);
if (!launched) {
LOG(ERROR) << "launch error";
diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h
index 424de15..8b27aa1 100644
--- a/chrome/browser/browser_init.h
+++ b/chrome/browser/browser_init.h
@@ -46,7 +46,7 @@ class BrowserInit {
// TODO(brettw): this will not handle all cases. If two process start up too
// close to each other, the window might not have been created yet for the
// first one, so this function won't find it.
- bool NotifyOtherProcess(int show_cmd);
+ bool NotifyOtherProcess();
// Create the toplevel message window for IPC.
void Create();
@@ -97,8 +97,7 @@ class BrowserInit {
class LaunchWithProfile {
public:
LaunchWithProfile(const std::wstring& cur_dir,
- const std::wstring& cmd_line,
- int show_command);
+ const std::wstring& cmd_line);
~LaunchWithProfile() { }
// Creates the necessary windows for startup. Returns true on success,
@@ -108,11 +107,6 @@ class BrowserInit {
bool Launch(Profile* profile, bool process_startup);
private:
- // Creates a new tabbed browser.
- //
- // Note that the window returned by this function may not be visible yet.
- Browser* CreateTabbedBrowser();
-
// Does the following:
// . If the user's startup pref is to restore the last session (or the
// command line flag is present to force using last session), it is
@@ -144,7 +138,6 @@ class BrowserInit {
std::wstring cur_dir_;
std::wstring command_line_;
- int show_command_;
Profile* profile_;
// Bounds for the browser.
@@ -160,16 +153,14 @@ class BrowserInit {
// the WM_COPYDATA handler.
static bool ProcessCommandLine(const CommandLine& parsed_command_line,
const std::wstring& cur_dir,
- PrefService* prefs, int show_command,
- bool process_startup, Profile* profile,
- int* return_code);
+ PrefService* prefs, bool process_startup,
+ Profile* profile, int* return_code);
// Helper function to launch a new browser based on command-line arguments
// This function takes in a specific profile to use.
static bool LaunchBrowser(const CommandLine& parsed_command_line,
- Profile* profile, int show_command,
- const std::wstring& cur_dir, bool process_startup,
- int* return_code);
+ Profile* profile, const std::wstring& cur_dir,
+ bool process_startup, int* return_code);
template <class AutomationProviderClass>
static void CreateAutomationProvider(const std::wstring& channel_id,
@@ -179,8 +170,7 @@ class BrowserInit {
private:
// Does the work of LaunchBrowser returning the result.
static bool LaunchBrowserImpl(const CommandLine& parsed_command_line,
- Profile* profile, int show_command,
- const std::wstring& cur_dir,
+ Profile* profile, const std::wstring& cur_dir,
bool process_startup, int* return_code);
// This class is for scoping purposes.
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index a60be84..f048c7a 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -259,7 +259,7 @@ void RecordBreakpadStatusUMA(MetricsService* metrics) {
} // namespace
// Main routine for running as the Browser process.
-int BrowserMain(CommandLine &parsed_command_line, int show_command,
+int BrowserMain(CommandLine &parsed_command_line,
sandbox::BrokerServices* broker_services) {
// WARNING: If we get a WM_ENDSESSION objects created on the stack here
// are NOT deleted. If you need something to run during WM_ENDSESSION add it
@@ -421,7 +421,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
return FirstRun::ImportNow(profile, parsed_command_line);
// When another process is running, use it instead of starting us.
- if (message_window.NotifyOtherProcess(show_command))
+ if (message_window.NotifyOtherProcess())
return ResultCodes::NORMAL_EXIT;
message_window.HuntForZombieChromeProcesses();
@@ -562,8 +562,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
int result_code = ResultCodes::NORMAL_EXIT;
if (BrowserInit::ProcessCommandLine(parsed_command_line, L"", local_state,
- show_command, true, profile,
- &result_code)) {
+ true, profile, &result_code)) {
MessageLoopForUI::current()->Run(browser_process->accelerator_handler());
}
diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h
index c76e553..97a8292 100644
--- a/chrome/browser/browser_window.h
+++ b/chrome/browser/browser_window.h
@@ -35,12 +35,8 @@ class BrowserWindow {
// Initialize the frame.
virtual void Init() = 0;
- // Show the window according to the given command, which is one of SW_*
- // passed to the Windows function ShowWindow.
- //
- // If adjust_to_fit is true, the window is resized and moved to be on the
- // default screen.
- virtual void Show(int command, bool adjust_to_fit) = 0;
+ // Show the window, or activates it if it's already visible.
+ virtual void Show() = 0;
// Closes the frame as soon as possible. If the frame is not in a drag
// session, it will close immediately; otherwise, it will move offscreen (so
@@ -85,7 +81,7 @@ class BrowserWindow {
// TODO(beng): RENAME (GetRestoredBounds)
// Returns the nonmaximized bounds of the frame (even if the frame is
// currently maximized or minimized) in terms of the screen coordinates.
- virtual gfx::Rect GetNormalBounds() = 0;
+ virtual gfx::Rect GetNormalBounds() const = 0;
// TODO(beng): REMOVE?
// Returns true if the frame is maximized (aka zoomed).
@@ -114,9 +110,7 @@ class BrowserWindow {
virtual bool IsBookmarkBarVisible() const = 0;
// Construct a BrowserWindow implementation for the specified |browser|.
- static BrowserWindow* CreateBrowserWindow(Browser* browser,
- const gfx::Rect& bounds,
- int show_command);
+ static BrowserWindow* CreateBrowserWindow(Browser* browser);
protected:
friend class BrowserList;
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc
index 99e09cf..d8c5099 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -123,12 +123,9 @@ Profile* ProfileManager::AddProfileByPath(const std::wstring& path) {
void ProfileManager::NewWindowWithProfile(Profile* profile) {
DCHECK(profile);
-
- Browser* new_browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile,
- BrowserType::TABBED_BROWSER, L"");
- new_browser->AddTabWithURL(GURL(), GURL(), PageTransition::TYPED, true,
- NULL);
- new_browser->Show();
+ Browser* browser = Browser::Create(profile);
+ browser->AddTabWithURL(GURL(), GURL(), PageTransition::TYPED, true, NULL);
+ browser->window()->Show();
}
Profile* ProfileManager::AddProfileByID(const std::wstring& id) {
diff --git a/chrome/browser/session_restore.cc b/chrome/browser/session_restore.cc
index dba5334ff..b8ec569 100644
--- a/chrome/browser/session_restore.cc
+++ b/chrome/browser/session_restore.cc
@@ -182,14 +182,12 @@ class SessionRestoreImpl : public NotificationObserver {
SessionRestoreImpl(Profile* profile,
Browser* browser,
bool use_saved_session,
- int show_command,
bool synchronous,
bool clobber_existing_window,
bool always_create_tabbed_browser,
const std::vector<GURL>& urls_to_open)
: profile_(profile),
browser_(browser),
- show_command_(show_command),
use_saved_session_(use_saved_session),
synchronous_(synchronous),
clobber_existing_window_(clobber_existing_window),
@@ -240,9 +238,7 @@ class SessionRestoreImpl : public NotificationObserver {
// have been loaded.
void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) {
if (!created_tabbed_browser && always_create_tabbed_browser_) {
- Browser* browser = new Browser(gfx::Rect(), show_command_, profile_,
- BrowserType::TABBED_BROWSER,
- std::wstring());
+ Browser* browser = Browser::Create(profile_);
if (urls_to_open_.empty()) {
// No tab browsers were created and no URLs were supplied on the command
// line. Add an empty URL, which is treated as opening the users home
@@ -250,7 +246,7 @@ class SessionRestoreImpl : public NotificationObserver {
urls_to_open_.push_back(GURL());
}
AppendURLsToBrowser(browser, urls_to_open_);
- browser->Show();
+ browser->window()->Show();
}
if (synchronous_)
@@ -303,10 +299,10 @@ class SessionRestoreImpl : public NotificationObserver {
}
}
if (!browser) {
- const int show_command =
- (*i)->is_maximized ? SW_SHOWMAXIMIZED : show_command_;
- browser = new Browser((*i)->bounds, show_command, profile_, (*i)->type,
- std::wstring());
+ browser = new Browser((*i)->type, profile_);
+ browser->set_override_bounds((*i)->bounds);
+ browser->set_override_maximized((*i)->is_maximized);
+ browser->CreateBrowserWindow();
}
if ((*i)->type == BrowserType::TABBED_BROWSER)
last_browser = browser;
@@ -363,7 +359,7 @@ class SessionRestoreImpl : public NotificationObserver {
browser->SelectTabContentsAt(
std::min(initial_tab_count + std::max(0, selected_session_index),
browser->tab_count() - 1), true);
- browser->Show();
+ browser->window()->Show();
}
void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) {
@@ -387,9 +383,6 @@ class SessionRestoreImpl : public NotificationObserver {
// The first browser to restore to, may be null.
Browser* browser_;
- // Used when creating windows. Passed to the window.
- const int show_command_;
-
// Whether we're restoring the saved session (true) or the last session
// (false).
const bool use_saved_session_;
@@ -427,7 +420,6 @@ size_t SessionRestore::num_tabs_to_load_ = 0;
static void Restore(Profile* profile,
Browser* browser,
bool use_saved_session,
- int show_command,
bool synchronous,
bool clobber_existing_window,
bool always_create_tabbed_browser,
@@ -437,7 +429,7 @@ static void Restore(Profile* profile,
return;
// SessionRestoreImpl takes care of deleting itself when done.
SessionRestoreImpl* restorer =
- new SessionRestoreImpl(profile, browser, use_saved_session, show_command,
+ new SessionRestoreImpl(profile, browser, use_saved_session,
synchronous, clobber_existing_window,
always_create_tabbed_browser,
urls_to_open);
@@ -451,16 +443,14 @@ void SessionRestore::RestoreSession(Profile* profile,
bool clobber_existing_window,
bool always_create_tabbed_browser,
const std::vector<GURL>& urls_to_open) {
- Restore(profile, browser, use_saved_session, SW_SHOW, false,
- clobber_existing_window, always_create_tabbed_browser, urls_to_open);
+ Restore(profile, browser, use_saved_session, false, clobber_existing_window,
+ always_create_tabbed_browser, urls_to_open);
}
// static
void SessionRestore::RestoreSessionSynchronously(
Profile* profile,
bool use_saved_session,
- int show_command,
const std::vector<GURL>& urls_to_open) {
- Restore(profile, NULL, use_saved_session, SW_SHOW, true, false, true,
- urls_to_open);
+ Restore(profile, NULL, use_saved_session, true, false, true, urls_to_open);
}
diff --git a/chrome/browser/session_restore.h b/chrome/browser/session_restore.h
index a8987ee..9ebe7d9 100644
--- a/chrome/browser/session_restore.h
+++ b/chrome/browser/session_restore.h
@@ -42,7 +42,6 @@ class SessionRestore {
static void RestoreSessionSynchronously(
Profile* profile,
bool use_saved_session,
- int show_command,
const std::vector<GURL>& urls_to_open);
// The max number of non-selected tabs SessionRestore loads when restoring
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 5f5a0bc..a7bd855 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -9,7 +9,6 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/navigation_controller.h"
#include "chrome/browser/navigation_entry.h"
@@ -334,7 +333,8 @@ bool TabStripModel::ShouldResetGroupOnSelect(TabContents* contents) const {
TabContents* TabStripModel::AddBlankTab(bool foreground) {
DCHECK(delegate_);
TabContents* contents = delegate_->CreateTabContentsForURL(
- NewTabUIURL(), GURL(), profile_, PageTransition::TYPED, false, NULL);
+ delegate_->GetBlankTabURL(), GURL(), profile_, PageTransition::TYPED,
+ false, NULL);
AddTabContents(contents, -1, PageTransition::TYPED, foreground);
return contents;
}
@@ -342,7 +342,8 @@ TabContents* TabStripModel::AddBlankTab(bool foreground) {
TabContents* TabStripModel::AddBlankTabAt(int index, bool foreground) {
DCHECK(delegate_);
TabContents* contents = delegate_->CreateTabContentsForURL(
- NewTabUIURL(), GURL(), profile_, PageTransition::LINK, false, NULL);
+ delegate_->GetBlankTabURL(), GURL(), profile_, PageTransition::LINK,
+ false, NULL);
AddTabContents(contents, index, PageTransition::LINK, foreground);
return contents;
}
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 52e3761..bd93a96 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -95,6 +95,9 @@ class TabStripModelObserver {
///////////////////////////////////////////////////////////////////////////////
class TabStripModelDelegate {
public:
+ // Retrieve the URL that should be used to construct blank tabs.
+ virtual GURL GetBlankTabURL() const = 0;
+
// Ask for a new TabStripModel to be created and the given tab contents to
// be added to it. Its presentation (e.g. a browser window) anchored at the
// specified creation point. It is left up to the delegate to decide how to
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index f3015a9..d438712 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -992,6 +992,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
virtual ~TabStripDummyDelegate() {}
// Overridden from TabStripModelDelegate:
+ virtual GURL GetBlankTabURL() const { return GURL("about:blank"); }
virtual void CreateNewStripWithContents(TabContents* contents,
const gfx::Point& creation_point) {}
virtual int GetDragActions() const { return 0; }
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index 7ff6997..fb55942 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -1062,21 +1062,8 @@ std::wstring TaskManager::GetWindowTitle() const {
return l10n_util::GetString(IDS_TASK_MANAGER_TITLE);
}
-void TaskManager::SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top) {
- window()->SaveWindowPositionToPrefService(g_browser_process->local_state(),
- prefs::kTaskManagerWindowPlacement,
- bounds, maximized, always_on_top);
-}
-
-bool TaskManager::RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- return window()->RestoreWindowPositionFromPrefService(
- g_browser_process->local_state(),
- prefs::kTaskManagerWindowPlacement,
- bounds, maximized, always_on_top);
+std::wstring TaskManager::GetWindowName() const {
+ return prefs::kTaskManagerWindowPlacement;
}
int TaskManager::GetDialogButtons() const {
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index eb288cc..26fc67e 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -130,12 +130,7 @@ class TaskManager : public views::DialogDelegate {
virtual bool IsAlwaysOnTop() const;
virtual bool HasAlwaysOnTopMenu() const;
virtual std::wstring GetWindowTitle() const;
- virtual void SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top);
- virtual bool RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top);
+ virtual std::wstring GetWindowName() const;
virtual int GetDialogButtons() const;
virtual void WindowClosing();
virtual views::View* GetContentsView();
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 9172b28..b1a5961 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -304,21 +304,8 @@ std::wstring BookmarkManagerView::GetWindowTitle() const {
return l10n_util::GetString(IDS_BOOKMARK_MANAGER_TITLE);
}
-void BookmarkManagerView::SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top) {
- window()->SaveWindowPositionToPrefService(g_browser_process->local_state(),
- prefs::kBookmarkManagerPlacement,
- bounds, maximized, always_on_top);
-}
-
-bool BookmarkManagerView::RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- return window()->RestoreWindowPositionFromPrefService(
- g_browser_process->local_state(),
- prefs::kBookmarkManagerPlacement,
- bounds, maximized, always_on_top);
+std::wstring BookmarkManagerView::GetWindowName() const {
+ return prefs::kBookmarkManagerPlacement;
}
void BookmarkManagerView::WindowClosing() {
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index be99a16..0a4fede 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -84,12 +84,7 @@ class BookmarkManagerView : public views::View,
virtual bool CanResize() const { return true; }
virtual bool CanMaximize() const { return true; }
virtual std::wstring GetWindowTitle() const;
- virtual void SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top);
- virtual bool RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top);
+ virtual std::wstring GetWindowName() const;
virtual View* GetContentsView() { return this; }
// TODO(sky): implement these when we have an icon.
//virtual SkBitmap GetWindowIcon();
diff --git a/chrome/browser/views/frame/aero_glass_frame.cc b/chrome/browser/views/frame/aero_glass_frame.cc
index 14170b8..0c5846a 100644
--- a/chrome/browser/views/frame/aero_glass_frame.cc
+++ b/chrome/browser/views/frame/aero_glass_frame.cc
@@ -45,8 +45,8 @@ AeroGlassFrame::AeroGlassFrame(BrowserView* browser_view)
AeroGlassFrame::~AeroGlassFrame() {
}
-void AeroGlassFrame::Init(const gfx::Rect& bounds) {
- Window::Init(NULL, bounds);
+void AeroGlassFrame::Init() {
+ Window::Init(NULL, gfx::Rect());
}
int AeroGlassFrame::GetMinimizeButtonOffset() const {
@@ -91,7 +91,16 @@ views::Window* AeroGlassFrame::GetWindow() {
}
///////////////////////////////////////////////////////////////////////////////
-// AeroGlassFrame, views::ContainerWin implementation:
+// AeroGlassFrame, views::ContainerWin overrides:
+
+bool AeroGlassFrame::AcceleratorPressed(views::Accelerator* accelerator) {
+ return browser_view_->AcceleratorPressed(*accelerator);
+}
+
+bool AeroGlassFrame::GetAccelerator(int cmd_id,
+ views::Accelerator* accelerator) {
+ return browser_view_->GetAccelerator(cmd_id, accelerator);
+}
void AeroGlassFrame::OnInitMenuPopup(HMENU menu, UINT position,
BOOL is_system_menu) {
@@ -179,15 +188,10 @@ LRESULT AeroGlassFrame::OnNCHitTest(const CPoint& pt) {
}
///////////////////////////////////////////////////////////////////////////////
-// AeroGlassFrame, views::ContainerWin overrides:
+// AeroGlassFrame, views::CustomFrameWindow overrides:
-bool AeroGlassFrame::AcceleratorPressed(views::Accelerator* accelerator) {
- return browser_view_->AcceleratorPressed(*accelerator);
-}
-
-bool AeroGlassFrame::GetAccelerator(int cmd_id,
- views::Accelerator* accelerator) {
- return browser_view_->GetAccelerator(cmd_id, accelerator);
+int AeroGlassFrame::GetShowState() const {
+ return browser_view_->GetShowState();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/views/frame/aero_glass_frame.h b/chrome/browser/views/frame/aero_glass_frame.h
index 0859b46..86df734 100644
--- a/chrome/browser/views/frame/aero_glass_frame.h
+++ b/chrome/browser/views/frame/aero_glass_frame.h
@@ -24,7 +24,7 @@ class AeroGlassFrame : public BrowserFrame,
explicit AeroGlassFrame(BrowserView* browser_view);
virtual ~AeroGlassFrame();
- void Init(const gfx::Rect& bounds);
+ void Init();
// Determine the distance of the left edge of the minimize button from the
// right edge of the window. Used in our Non-Client View's Layout.
@@ -38,12 +38,10 @@ class AeroGlassFrame : public BrowserFrame,
virtual void UpdateThrobber(bool running);
virtual views::Window* GetWindow();
+ protected:
// Overridden from views::ContainerWin:
virtual bool AcceleratorPressed(views::Accelerator* accelerator);
virtual bool GetAccelerator(int cmd_id, views::Accelerator* accelerator);
-
- protected:
- // Overridden from views::ContainerWin:
virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
virtual void OnEndSession(BOOL ending, UINT logoff);
virtual LRESULT OnMouseActivate(HWND window,
@@ -55,6 +53,9 @@ class AeroGlassFrame : public BrowserFrame,
virtual LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param);
virtual LRESULT OnNCHitTest(const CPoint& pt);
+ // Overridden from views::CustomFrameWindow:
+ virtual int GetShowState() const;
+
private:
// Updates the DWM with the frame bounds.
void UpdateDWMFrame();
diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h
index 7aa62bc..c0b18af 100644
--- a/chrome/browser/views/frame/browser_frame.h
+++ b/chrome/browser/views/frame/browser_frame.h
@@ -56,9 +56,7 @@ class BrowserFrame {
// Creates a BrowserFrame instance for the specified FrameType and
// BrowserView.
static BrowserFrame* CreateForBrowserView(FrameType type,
- BrowserView* browser_view,
- const gfx::Rect& bounds,
- int show_command);
+ BrowserView* browser_view);
};
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 41088fe..17127ba 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -123,6 +123,14 @@ BrowserView::~BrowserView() {
ticker_.UnregisterTickHandler(&hung_window_detector_);
}
+int BrowserView::GetShowState() const {
+ STARTUPINFO si = {0};
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ GetStartupInfo(&si);
+ return si.wShowWindow;
+}
+
void BrowserView::WindowMoved() {
// Cancel any tabstrip animations, some of them may be invalidated by the
// window being repositioned.
@@ -320,8 +328,31 @@ void BrowserView::Init() {
InitSystemMenu();
}
-void BrowserView::Show(int command, bool adjust_to_fit) {
- frame_->GetWindow()->Show(command);
+void BrowserView::Show() {
+ // If the window is already visible, just activate it.
+ if (frame_->GetWindow()->IsVisible()) {
+ frame_->GetWindow()->Activate();
+ return;
+ }
+
+ // Setting the focus doesn't work when the window is invisible, so any focus
+ // initialization that happened before this will be lost.
+ //
+ // We really "should" restore the focus whenever the window becomes unhidden,
+ // but I think initializing is the only time where this can happen where
+ // there is some focus change we need to pick up, and this is easier than
+ // plumbing through an un-hide message all the way from the frame.
+ //
+ // If we do find there are cases where we need to restore the focus on show,
+ // that should be added and this should be removed.
+ TabContents* selected_tab_contents = GetSelectedTabContents();
+ if (selected_tab_contents)
+ selected_tab_contents->RestoreFocus();
+
+ frame_->GetWindow()->Show();
+ int show_state = frame_->GetWindow()->GetShowState();
+ if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED)
+ frame_->GetWindow()->Activate();
}
void BrowserView::Close() {
@@ -378,7 +409,7 @@ void BrowserView::ValidateThrobber() {
}
}
-gfx::Rect BrowserView::GetNormalBounds() {
+gfx::Rect BrowserView::GetNormalBounds() const {
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp);
@@ -562,18 +593,13 @@ bool BrowserView::ExecuteWindowsCommand(int command_id) {
return false;
}
-void BrowserView::SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top) {
- browser_->SaveWindowPosition(gfx::Rect(bounds), maximized);
+void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top) {
+ browser_->SaveWindowPlacement(bounds, maximized);
}
-bool BrowserView::RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- DCHECK(bounds && maximized && always_on_top);
- *always_on_top = false;
-
+bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const {
if (browser_->type() == BrowserType::BROWSER) {
// We are a popup window. The value passed in |bounds| represents two
// pieces of information:
@@ -587,12 +613,12 @@ bool BrowserView::RestoreWindowPosition(CRect* bounds,
// its desired height, since the toolbar is considered part of the
// window's client area as far as GetWindowBoundsForClientBounds is
// concerned...
- bounds->bottom += toolbar_->GetPreferredSize().height();
+ bounds->set_height(
+ bounds->height() + toolbar_->GetPreferredSize().height());
}
- gfx::Rect window_rect =
- frame_->GetWindowBoundsForClientBounds(gfx::Rect(*bounds));
- window_rect.set_origin(gfx::Point(bounds->left, bounds->top));
+ gfx::Rect window_rect = frame_->GetWindowBoundsForClientBounds(*bounds);
+ window_rect.set_origin(gfx::Point(bounds->x(), bounds->y()));
// When we are given x/y coordinates of 0 on a created popup window,
// assume none were given by the window.open() command.
@@ -603,13 +629,9 @@ bool BrowserView::RestoreWindowPosition(CRect* bounds,
window_rect.set_origin(origin);
}
- *bounds = window_rect.ToRECT();
- *maximized = false;
+ *bounds = window_rect;
} else {
- // TODO(beng): (http://b/1317622) Make these functions take gfx::Rects.
- gfx::Rect b(*bounds);
- browser_->RestoreWindowPosition(&b, maximized);
- *bounds = b.ToRECT();
+ *bounds = browser_->GetSavedWindowBounds();
}
// We return true because we can _always_ locate reasonable bounds using the
@@ -619,6 +641,11 @@ bool BrowserView::RestoreWindowPosition(CRect* bounds,
return true;
}
+bool BrowserView::GetSavedMaximizedState(bool* maximized) const {
+ *maximized = browser_->GetSavedMaximizedState();
+ return true;
+}
+
void BrowserView::WindowClosing() {
}
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index 73ba719..549cbd6 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -43,6 +43,10 @@ class BrowserView : public BrowserWindow,
void set_frame(BrowserFrame* frame) { frame_ = frame; }
+ // Returns the show flag that should be used to show the frame containing
+ // this view.
+ int GetShowState() const;
+
// Called by the frame to notify the BrowserView that it was moved, and that
// any dependent popup windows should be repositioned.
void WindowMoved();
@@ -137,7 +141,7 @@ class BrowserView : public BrowserWindow,
// Overridden from BrowserWindow:
virtual void Init();
- virtual void Show(int command, bool adjust_to_fit);
+ virtual void Show();
virtual void Close();
virtual void Activate();
virtual void FlashFrame();
@@ -147,7 +151,7 @@ class BrowserView : public BrowserWindow,
virtual void SelectedTabToolbarSizeChanged(bool is_animating);
virtual void UpdateTitleBar();
virtual void ValidateThrobber();
- virtual gfx::Rect GetNormalBounds();
+ virtual gfx::Rect GetNormalBounds() const;
virtual bool IsMaximized();
virtual ToolbarStarToggle* GetStarButton() const;
virtual LocationBarView* GetLocationBarView() const;
@@ -182,12 +186,11 @@ class BrowserView : public BrowserWindow,
virtual SkBitmap GetWindowIcon();
virtual bool ShouldShowWindowIcon() const;
virtual bool ExecuteWindowsCommand(int command_id);
- virtual void SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top);
- virtual bool RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top);
+ virtual void SaveWindowPlacement(const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top);
+ virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const;
+ virtual bool GetSavedMaximizedState(bool* maximized) const;
virtual void WindowClosing();
virtual views::View* GetContentsView();
virtual views::ClientView* CreateClientView(views::Window* window);
diff --git a/chrome/browser/views/frame/browser_window_factory.cc b/chrome/browser/views/frame/browser_window_factory.cc
index 69c61bb..59a8d9d 100644
--- a/chrome/browser/views/frame/browser_window_factory.cc
+++ b/chrome/browser/views/frame/browser_window_factory.cc
@@ -17,12 +17,10 @@
// BrowserWindow, public:
// static
-BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser,
- const gfx::Rect& bounds,
- int show_command) {
+BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
BrowserView* browser_view = new BrowserView(browser);
BrowserFrame::CreateForBrowserView(BrowserFrame::GetActiveFrameType(),
- browser_view, bounds, show_command);
+ browser_view);
return browser_view;
}
@@ -37,16 +35,14 @@ BrowserFrame::FrameType BrowserFrame::GetActiveFrameType() {
// static
BrowserFrame* BrowserFrame::CreateForBrowserView(BrowserFrame::FrameType type,
- BrowserView* browser_view,
- const gfx::Rect& bounds,
- int show_command) {
+ BrowserView* browser_view) {
if (type == FRAMETYPE_OPAQUE) {
OpaqueFrame* frame = new OpaqueFrame(browser_view);
- frame->Init(NULL, bounds);
+ frame->Init();
return frame;
} else if (type == FRAMETYPE_AERO_GLASS) {
AeroGlassFrame* frame = new AeroGlassFrame(browser_view);
- frame->Init(bounds);
+ frame->Init();
return frame;
}
NOTREACHED() << "Unsupported frame type";
diff --git a/chrome/browser/views/frame/opaque_frame.cc b/chrome/browser/views/frame/opaque_frame.cc
index 1d1ce8f..3158af7 100644
--- a/chrome/browser/views/frame/opaque_frame.cc
+++ b/chrome/browser/views/frame/opaque_frame.cc
@@ -23,6 +23,10 @@ OpaqueFrame::OpaqueFrame(BrowserView* browser_view)
OpaqueFrame::~OpaqueFrame() {
}
+void OpaqueFrame::Init() {
+ CustomFrameWindow::Init(NULL, gfx::Rect());
+}
+
///////////////////////////////////////////////////////////////////////////////
// OpaqueFrame, BrowserFrame implementation:
@@ -62,6 +66,10 @@ void OpaqueFrame::UpdateWindowIcon() {
GetOpaqueNonClientView()->UpdateWindowIcon();
}
+int OpaqueFrame::GetShowState() const {
+ return browser_view_->GetShowState();
+}
+
///////////////////////////////////////////////////////////////////////////////
// OpaqueFrame, views::ContainerWin overrides:
diff --git a/chrome/browser/views/frame/opaque_frame.h b/chrome/browser/views/frame/opaque_frame.h
index 0a6d1ca..f28d782 100644
--- a/chrome/browser/views/frame/opaque_frame.h
+++ b/chrome/browser/views/frame/opaque_frame.h
@@ -29,6 +29,8 @@ class OpaqueFrame : public BrowserFrame,
explicit OpaqueFrame(BrowserView* browser_view);
virtual ~OpaqueFrame();
+ void Init();
+
protected:
// Overridden from BrowserFrame:
virtual gfx::Rect GetWindowBoundsForClientBounds(
@@ -40,6 +42,7 @@ class OpaqueFrame : public BrowserFrame,
// Overridden from views::CustomFrameWindow:
virtual void UpdateWindowIcon();
+ virtual int GetShowState() const;
// Overridden from views::ContainerWin:
virtual bool AcceleratorPressed(views::Accelerator* accelerator);
diff --git a/chrome/browser/views/frame/opaque_non_client_view.cc b/chrome/browser/views/frame/opaque_non_client_view.cc
index 877b8b5..460a1f8 100644
--- a/chrome/browser/views/frame/opaque_non_client_view.cc
+++ b/chrome/browser/views/frame/opaque_non_client_view.cc
@@ -467,7 +467,8 @@ gfx::Rect OpaqueNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
int tabstrip_width = minimize_button_->x() - tabstrip_x;
if (frame_->IsMaximized())
tabstrip_width -= kNewTabIconWindowControlsSpacing;
- return gfx::Rect(tabstrip_x, 0, tabstrip_width, tabstrip_height);
+ return gfx::Rect(tabstrip_x, 0, std::max(0, tabstrip_width),
+ tabstrip_height);
}
void OpaqueNonClientView::UpdateWindowIcon() {
diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc
index f2c68f1..af30d28 100644
--- a/chrome/browser/views/options/advanced_contents_view.cc
+++ b/chrome/browser/views/options/advanced_contents_view.cc
@@ -443,14 +443,9 @@ void PrivacySection::LinkActivated(views::Link* source, int event_flags) {
if (source == learn_more_link_) {
// We open a new browser window so the Options dialog doesn't get lost
// behind other windows.
- Browser* browser = new Browser(gfx::Rect(), SW_SHOWNORMAL, profile(),
- BrowserType::TABBED_BROWSER,
- std::wstring());
- browser->OpenURL(
- GURL(l10n_util::GetString(IDS_LEARN_MORE_PRIVACY_URL)),
- GURL(),
- NEW_WINDOW,
- PageTransition::LINK);
+ Browser* browser = Browser::Create(profile());
+ browser->OpenURL(GURL(l10n_util::GetString(IDS_LEARN_MORE_PRIVACY_URL)),
+ GURL(), NEW_WINDOW, PageTransition::LINK);
}
}
diff --git a/chrome/browser/views/page_info_window.cc b/chrome/browser/views/page_info_window.cc
index c7cbb8e..591e61b 100644
--- a/chrome/browser/views/page_info_window.cc
+++ b/chrome/browser/views/page_info_window.cc
@@ -554,11 +554,12 @@ void PageInfoWindow::Init(Profile* profile,
// There already is a PageInfo window opened. Let's shift the location of
// the new PageInfo window so they don't overlap entirely.
// Window::Init will position the window from the stored location.
- CRect bounds;
- bool maximized, always_on_top;
- if (RestoreWindowPosition(&bounds, &maximized, &always_on_top)) {
- CalculateWindowBounds(&bounds);
- SaveWindowPosition(bounds, maximized, always_on_top);
+ gfx::Rect bounds;
+ bool maximized = false;
+ if (GetSavedWindowBounds(&bounds) && GetSavedMaximizedState(&maximized)) {
+ CRect bounds_crect(bounds.ToRECT());
+ CalculateWindowBounds(&bounds_crect);
+ SaveWindowPlacement(gfx::Rect(bounds_crect), maximized, false);
}
}
@@ -604,34 +605,8 @@ std::wstring PageInfoWindow::GetWindowTitle() const {
return l10n_util::GetString(IDS_PAGEINFO_WINDOW_TITLE);
}
-void PageInfoWindow::SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top) {
- window()->SaveWindowPositionToPrefService(g_browser_process->local_state(),
- prefs::kPageInfoWindowPlacement,
- bounds, maximized, always_on_top);
-}
-
-bool PageInfoWindow::RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- bool restore = window()->RestoreWindowPositionFromPrefService(
- g_browser_process->local_state(),
- prefs::kPageInfoWindowPlacement,
- bounds, maximized, always_on_top);
-
- if (restore) {
- // Force the correct width and height in case we've changed it
- // or the pref got messed up (we know that some users will have
- // the wrong preference if they ran into bug 3509). This isn't
- // a resizable dialog, so overriding the saved width and height
- // shouldn't be noticable.
- gfx::Size size = contents_->GetPreferredSize();
- bounds->right = bounds->left + size.width();
- bounds->bottom = bounds->top + size.height();
- }
-
- return restore;
+std::wstring PageInfoWindow::GetWindowName() const {
+ return prefs::kPageInfoWindowPlacement;
}
views::View* PageInfoWindow::GetContentsView() {
diff --git a/chrome/browser/views/page_info_window.h b/chrome/browser/views/page_info_window.h
index 97b7a5d..6df7c09 100644
--- a/chrome/browser/views/page_info_window.h
+++ b/chrome/browser/views/page_info_window.h
@@ -68,12 +68,7 @@ class PageInfoWindow : public views::DialogDelegate,
// views::DialogDelegate methods:
virtual int GetDialogButtons() const;
virtual std::wstring GetWindowTitle() const;
- virtual void SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top);
- virtual bool RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top);
+ virtual std::wstring GetWindowName() const;
virtual views::View* GetContentsView();
private:
diff --git a/chrome/browser/web_app_launcher.cc b/chrome/browser/web_app_launcher.cc
index 99e820d..f783ea9 100644
--- a/chrome/browser/web_app_launcher.cc
+++ b/chrome/browser/web_app_launcher.cc
@@ -10,18 +10,13 @@
#include "chrome/browser/web_app.h"
// static
-void WebAppLauncher::Launch(Profile* profile,
- const GURL& url,
- int show_command) {
- (new WebAppLauncher(profile, url, show_command))->Run();
+void WebAppLauncher::Launch(Profile* profile, const GURL& url) {
+ (new WebAppLauncher(profile, url))->Run();
}
-WebAppLauncher::WebAppLauncher(Profile* profile,
- const GURL& url,
- int show_command)
+WebAppLauncher::WebAppLauncher(Profile* profile, const GURL& url)
: profile_(profile),
- url_(url),
- show_command_(show_command) {
+ url_(url) {
}
void WebAppLauncher::Run() {
@@ -45,7 +40,7 @@ void WebAppLauncher::OnGotApps(GearsShortcutList* apps) {
app = new WebApp(profile_, url_, std::wstring());
}
- Browser::OpenWebApplication(profile_, app, show_command_);
+ Browser::OpenWebApplication(profile_, app);
delete this;
}
diff --git a/chrome/browser/web_app_launcher.h b/chrome/browser/web_app_launcher.h
index f1a5a01..7b377bf 100644
--- a/chrome/browser/web_app_launcher.h
+++ b/chrome/browser/web_app_launcher.h
@@ -16,10 +16,10 @@ class WebAppLauncher {
public:
// Queries Gears for the name of the app, and when Gears callsback with the
// response creates a WebApp and Browser.
- static void Launch(Profile* profile, const GURL& url, int show_command);
+ static void Launch(Profile* profile, const GURL& url);
private:
- WebAppLauncher(Profile* profile, const GURL& url, int show_command);
+ WebAppLauncher(Profile* profile, const GURL& url);
// Invoked from the Launch method. Queries Gears for the apps. Gears callback
// to OnGotApps.
@@ -34,9 +34,6 @@ class WebAppLauncher {
// URL of the app.
const GURL url_;
- // How to show the app.
- const int show_command_;
-
DISALLOW_EVIL_CONSTRUCTORS(WebAppLauncher);
};
diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc
index 634fe9c..7b31a98 100644
--- a/chrome/browser/window_sizer.cc
+++ b/chrome/browser/window_sizer.cc
@@ -204,7 +204,6 @@ void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds,
*bounds = specified_bounds;
if (bounds->IsEmpty()) {
// See if there's saved placement information.
- *maximized = false; // Default off; GetSavedWindowBounds() may set this.
if (!GetLastWindowBounds(bounds)) {
if (!GetSavedWindowBounds(bounds, maximized)) {
// No saved placement, figure out some sensible default size based on
diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc
index cd94008..3fcdc91 100644
--- a/chrome/plugin/plugin_main.cc
+++ b/chrome/plugin/plugin_main.cc
@@ -13,7 +13,7 @@
#include "sandbox/src/sandbox.h"
// mainline routine for running as the plugin process
-int PluginMain(CommandLine &parsed_command_line, int show_command,
+int PluginMain(CommandLine &parsed_command_line,
sandbox::TargetServices* target_services) {
// The main thread of the plugin services IO.
MessageLoopForIO main_message_loop;
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index 169779d..21da042 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -43,7 +43,7 @@ static void HandleRendererErrorTestParameters(const CommandLine& command_line) {
}
// mainline routine for running as the Rendererer process
-int RendererMain(CommandLine &parsed_command_line, int show_command,
+int RendererMain(CommandLine &parsed_command_line,
sandbox::TargetServices* target_services) {
StatsScope<StatsCounterTimer>
startup_timer(chrome::Counters::renderer_main());
diff --git a/chrome/views/window.cc b/chrome/views/window.cc
index 2f7b4f6..fb7d945 100644
--- a/chrome/views/window.cc
+++ b/chrome/views/window.cc
@@ -85,14 +85,22 @@ gfx::Size Window::CalculateMaximumSize() const {
}
void Window::Show() {
- Show(SW_SHOW);
+ int show_state = GetShowState();
+ bool maximized = false;
+ if (window_delegate_->GetSavedMaximizedState(&maximized) && maximized)
+ show_state = SW_SHOWMAXIMIZED;
+ Show(show_state);
}
-void Window::Show(int show_style) {
- ShowWindow(show_style);
+void Window::Show(int show_state) {
+ ShowWindow(show_state);
SetInitialFocus();
}
+int Window::GetShowState() const {
+ return SW_SHOWNORMAL;
+}
+
void Window::Activate() {
if (IsMinimized())
::ShowWindow(GetHWND(), SW_RESTORE);
@@ -193,56 +201,6 @@ void Window::ExecuteSystemMenuCommand(int command) {
}
// static
-bool Window::SaveWindowPositionToPrefService(PrefService* pref_service,
- const std::wstring& entry,
- const CRect& bounds,
- bool maximized,
- bool always_on_top) {
- DCHECK(pref_service);
- DictionaryValue* win_pref = pref_service->GetMutableDictionary(entry.c_str());
- DCHECK(win_pref);
-
- win_pref->SetInteger(L"left", bounds.left);
- win_pref->SetInteger(L"top", bounds.top);
- win_pref->SetInteger(L"right", bounds.right);
- win_pref->SetInteger(L"bottom", bounds.bottom);
- win_pref->SetBoolean(L"maximized", maximized);
- win_pref->SetBoolean(L"always_on_top", always_on_top);
- return true;
-}
-
-// static
-bool Window::RestoreWindowPositionFromPrefService(PrefService* pref_service,
- const std::wstring& entry,
- CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- DCHECK(pref_service);
- DCHECK(bounds);
- DCHECK(maximized);
- DCHECK(always_on_top);
-
- const DictionaryValue* dictionary = pref_service->GetDictionary(entry.c_str());
- if (!dictionary)
- return false;
-
- int left, top, right, bottom;
- bool temp_maximized, temp_always_on_top;
- if (!dictionary || !dictionary->GetInteger(L"left", &left) ||
- !dictionary->GetInteger(L"top", &top) ||
- !dictionary->GetInteger(L"right", &right) ||
- !dictionary->GetInteger(L"bottom", &bottom) ||
- !dictionary->GetBoolean(L"maximized", &temp_maximized) ||
- !dictionary->GetBoolean(L"always_on_top", &temp_always_on_top))
- return false;
-
- bounds->SetRect(left, top, right, bottom);
- *maximized = temp_maximized;
- *always_on_top = temp_always_on_top;
- return true;
-}
-
-// static
gfx::Size Window::GetLocalizedContentsSize(int col_resource_id,
int row_resource_id) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -312,9 +270,7 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) {
SetClientView(window_delegate_->CreateClientView(this));
SetInitialBounds(bounds);
-
- if (window_delegate_->HasAlwaysOnTopMenu())
- AddAlwaysOnTopSystemMenuItem();
+ InitAlwaysOnTopState();
}
void Window::SetClientView(ClientView* client_view) {
@@ -513,35 +469,25 @@ void Window::SetInitialFocus() {
void Window::SetInitialBounds(const gfx::Rect& create_bounds) {
// Restore the window's placement from the controller.
- CRect saved_bounds(create_bounds.ToRECT());
- bool maximized = false;
- if (window_delegate_->RestoreWindowPosition(&saved_bounds,
- &maximized,
- &is_always_on_top_)) {
+ gfx::Rect saved_bounds(create_bounds.ToRECT());
+ if (window_delegate_->GetSavedWindowBounds(&saved_bounds)) {
// Make sure the bounds are at least the minimum size.
- if (saved_bounds.Width() < minimum_size_.cx) {
- saved_bounds.SetRect(saved_bounds.left, saved_bounds.top,
- saved_bounds.right + minimum_size_.cx -
- saved_bounds.Width(),
- saved_bounds.bottom);
+ if (saved_bounds.width() < minimum_size_.cx) {
+ saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
+ saved_bounds.right() + minimum_size_.cx -
+ saved_bounds.width(),
+ saved_bounds.bottom());
}
- if (saved_bounds.Height() < minimum_size_.cy) {
- saved_bounds.SetRect(saved_bounds.left, saved_bounds.top,
- saved_bounds.right,
- saved_bounds.bottom + minimum_size_.cy -
- saved_bounds.Height());
+ if (saved_bounds.height() < minimum_size_.cy) {
+ saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
+ saved_bounds.right(),
+ saved_bounds.bottom() + minimum_size_.cy -
+ saved_bounds.height());
}
- WINDOWPLACEMENT placement = {0};
- placement.length = sizeof(WINDOWPLACEMENT);
- placement.rcNormalPosition = saved_bounds;
- if (maximized)
- placement.showCmd = SW_SHOWMAXIMIZED;
- ::SetWindowPlacement(GetHWND(), &placement);
-
- if (is_always_on_top_ != window_delegate_->IsAlwaysOnTop())
- AlwaysOnTopChanged();
+ // "Show state" (maximized, minimized, etc) is handled by Show().
+ SetBounds(saved_bounds, NULL);
} else {
if (create_bounds.IsEmpty()) {
// No initial bounds supplied, so size the window to its content and
@@ -554,6 +500,17 @@ void Window::SetInitialBounds(const gfx::Rect& create_bounds) {
}
}
+void Window::InitAlwaysOnTopState() {
+ is_always_on_top_ = false;
+ if (window_delegate_->GetSavedAlwaysOnTopState(&is_always_on_top_) &&
+ is_always_on_top_ != window_delegate_->IsAlwaysOnTop()) {
+ AlwaysOnTopChanged();
+ }
+
+ if (window_delegate_->HasAlwaysOnTopMenu())
+ AddAlwaysOnTopSystemMenuItem();
+}
+
void Window::AddAlwaysOnTopSystemMenuItem() {
// The Win32 API requires that we own the text.
always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP);
@@ -643,9 +600,8 @@ void Window::SaveWindowPosition() {
bool maximized = (win_placement.showCmd == SW_SHOWMAXIMIZED);
CRect window_bounds(win_placement.rcNormalPosition);
- window_delegate_->SaveWindowPosition(window_bounds,
- maximized,
- is_always_on_top_);
+ window_delegate_->SaveWindowPlacement(
+ gfx::Rect(win_placement.rcNormalPosition), maximized, is_always_on_top_);
}
void Window::InitClass() {
diff --git a/chrome/views/window.h b/chrome/views/window.h
index 533bc27..ad8f020 100644
--- a/chrome/views/window.h
+++ b/chrome/views/window.h
@@ -52,7 +52,14 @@ class Window : public ContainerWin {
// Show the window.
void Show();
- void Show(int show_style);
+ void Show(int show_state);
+
+ // Retrieve the show state of the window. This is one of the SW_SHOW* flags
+ // passed into Windows' ShowWindow method. For normal windows this defaults
+ // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this
+ // method to provide different values (e.g. retrieve the user's specified
+ // show state from the shortcut starutp info).
+ virtual int GetShowState() const;
// Activate the window, assuming it already exists and is visible.
void Activate();
@@ -104,24 +111,6 @@ class Window : public ContainerWin {
// The parent of this window.
HWND owning_window() const { return owning_hwnd_; }
- // Convenience methods for storing/retrieving window location information
- // to/from a PrefService using the specified |entry| name.
- // WindowDelegate instances can use these methods in their implementation of
- // SaveWindowPosition/RestoreWindowPosition to save windows' location to
- // preferences.
- static bool SaveWindowPositionToPrefService(PrefService* pref_service,
- const std::wstring& entry,
- const CRect& bounds,
- bool maximized,
- bool always_on_top);
- // Returns true if the window location was retrieved from the PrefService and
- // set in |bounds|, |maximized| and |always_on_top|.
- static bool RestoreWindowPositionFromPrefService(PrefService* pref_service,
- const std::wstring& entry,
- CRect* bounds,
- bool* maximized,
- bool* always_on_top);
-
// Returns the preferred size of the contents view of this window based on
// its localized size data. The width in cols is held in a localized string
// resource identified by |col_resource_id|, the height in the same fashion.
@@ -195,6 +184,10 @@ class Window : public ContainerWin {
// bounds used when the window was created.
void SetInitialBounds(const gfx::Rect& create_bounds);
+ // Restore saved always on stop state and add the always on top system menu
+ // if needed.
+ void InitAlwaysOnTopState();
+
// Add an item for "Always on Top" to the System Menu.
void AddAlwaysOnTopSystemMenuItem();
diff --git a/chrome/views/window_delegate.cc b/chrome/views/window_delegate.cc
index 555c5ec..7ce676e 100644
--- a/chrome/views/window_delegate.cc
+++ b/chrome/views/window_delegate.cc
@@ -4,6 +4,9 @@
#include "chrome/views/window_delegate.h"
+// TODO(beng): hrmp. Fix this in http://crbug.com/4406
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/pref_service.h"
#include "chrome/views/client_view.h"
#include "chrome/views/window.h"
#include "skia/include/SkBitmap.h"
@@ -22,6 +25,63 @@ SkBitmap WindowDelegate::GetWindowIcon() {
return SkBitmap();
}
+void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top) {
+ std::wstring window_name = GetWindowName();
+ if (window_name.empty())
+ return;
+
+ DictionaryValue* window_preferences =
+ g_browser_process->local_state()->GetMutableDictionary(
+ window_name.c_str());
+ window_preferences->SetInteger(L"left", bounds.x());
+ window_preferences->SetInteger(L"top", bounds.y());
+ window_preferences->SetInteger(L"right", bounds.right());
+ window_preferences->SetInteger(L"bottom", bounds.bottom());
+ window_preferences->SetBoolean(L"maximized", maximized);
+ window_preferences->SetBoolean(L"always_on_top", always_on_top);
+}
+
+bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const {
+ std::wstring window_name = GetWindowName();
+ if (window_name.empty())
+ return false;
+
+ const DictionaryValue* dictionary =
+ g_browser_process->local_state()->GetDictionary(window_name.c_str());
+ int left, top, right, bottom;
+ if (!dictionary || !dictionary->GetInteger(L"left", &left) ||
+ !dictionary->GetInteger(L"top", &top) ||
+ !dictionary->GetInteger(L"right", &right) ||
+ !dictionary->GetInteger(L"bottom", &bottom))
+ return false;
+
+ bounds->SetRect(left, top, right, bottom);
+ return true;
+}
+
+bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const {
+ std::wstring window_name = GetWindowName();
+ if (window_name.empty())
+ return false;
+
+ const DictionaryValue* dictionary =
+ g_browser_process->local_state()->GetDictionary(window_name.c_str());
+ return dictionary && dictionary->GetBoolean(L"maximized", maximized);
+}
+
+bool WindowDelegate::GetSavedAlwaysOnTopState(bool* always_on_top) const {
+ std::wstring window_name = GetWindowName();
+ if (window_name.empty())
+ return false;
+
+ const DictionaryValue* dictionary =
+ g_browser_process->local_state()->GetDictionary(window_name.c_str());
+ return dictionary && dictionary->GetBoolean(L"always_on_top", always_on_top);
+}
+
+
ClientView* WindowDelegate::CreateClientView(Window* window) {
return new ClientView(window, GetContentsView());
}
diff --git a/chrome/views/window_delegate.h b/chrome/views/window_delegate.h
index 49cf5d0..d10dbf6 100644
--- a/chrome/views/window_delegate.h
+++ b/chrome/views/window_delegate.h
@@ -11,6 +11,9 @@
class SkBitmap;
+namespace gfx {
+class Rect;
+}
// TODO(maruel): Remove once gfx::Rect is used instead.
namespace WTL {
class CRect;
@@ -96,20 +99,28 @@ class WindowDelegate {
// was handled, false if it was not.
virtual bool ExecuteWindowsCommand(int command_id) { return false; }
- // Saves the specified bounds, maximized and always on top state as the
- // window's position to/ be restored the next time it is shown.
- virtual void SaveWindowPosition(const CRect& bounds,
- bool maximized,
- bool always_on_top) { }
-
- // returns true if there was a saved position, false if there was none and
- // the default should be used.
- virtual bool RestoreWindowPosition(CRect* bounds,
- bool* maximized,
- bool* always_on_top) {
- return false;
+ // Returns the window's name identifier. Used to identify this window for
+ // state restoration.
+ virtual std::wstring GetWindowName() const {
+ return std::wstring();
}
+ // Saves the window's bounds, maximized and always-on-top states. By default
+ // this uses the process' local state keyed by window name (See GetWindowName
+ // above). This behavior can be overridden to provide additional
+ // functionality.
+ virtual void SaveWindowPlacement(const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top);
+
+ // Retreives the window's bounds, maximized and always-on-top states. By
+ // default, this uses the process' local state keyed by window name (See
+ // GetWindowName above). This behavior can be overridden to provide
+ // additional functionality.
+ virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const;
+ virtual bool GetSavedMaximizedState(bool* maximized) const;
+ virtual bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
+
// Called when the window closes.
virtual void WindowClosing() { }