This source file includes following definitions.
- ParseCommaSeparatedIntegers
- GetWindowPlacementKey
- ShouldSaveWindowPlacement
- SaveWindowPlacement
- GetSavedWindowBoundsAndShowState
#include "chrome/browser/ui/browser_window_state.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
namespace chrome {
namespace {
bool ParseCommaSeparatedIntegers(const std::string& str,
int* ret_num1,
int* ret_num2) {
size_t num1_size = str.find_first_of(',');
if (num1_size == std::string::npos)
return false;
size_t num2_pos = num1_size + 1;
size_t num2_size = str.size() - num2_pos;
int num1, num2;
if (!base::StringToInt(str.substr(0, num1_size), &num1) ||
!base::StringToInt(str.substr(num2_pos, num2_size), &num2))
return false;
*ret_num1 = num1;
*ret_num2 = num2;
return true;
}
}
std::string GetWindowPlacementKey(const Browser* browser) {
std::string name(prefs::kBrowserWindowPlacement);
if (!browser->app_name().empty()) {
name.append("_");
name.append(browser->app_name());
}
return name;
}
bool ShouldSaveWindowPlacement(const Browser* browser) {
switch (browser->type()) {
case Browser::TYPE_TABBED:
return true;
case Browser::TYPE_POPUP:
return browser_defaults::kRestorePopups || browser->is_devtools() ||
browser->is_app();
default:
return false;
}
}
void SaveWindowPlacement(const Browser* browser,
const gfx::Rect& bounds,
ui::WindowShowState show_state) {
SessionService* session_service =
SessionServiceFactory::GetForProfileIfExisting(browser->profile());
if (session_service)
session_service->SetWindowBounds(browser->session_id(), bounds, show_state);
}
void GetSavedWindowBoundsAndShowState(const Browser* browser,
gfx::Rect* bounds,
ui::WindowShowState* show_state) {
DCHECK(browser);
DCHECK(bounds);
DCHECK(show_state);
*bounds = browser->override_bounds();
WindowSizer::GetBrowserWindowBoundsAndShowState(browser->app_name(),
*bounds,
browser,
bounds,
show_state);
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
if (record_mode || playback_mode) {
*bounds = gfx::Rect(0, 0, 800, 600);
}
if (parsed_command_line.HasSwitch(switches::kWindowSize)) {
std::string str =
parsed_command_line.GetSwitchValueASCII(switches::kWindowSize);
int width, height;
if (ParseCommaSeparatedIntegers(str, &width, &height))
bounds->set_size(gfx::Size(width, height));
}
if (parsed_command_line.HasSwitch(switches::kWindowPosition)) {
std::string str =
parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition);
int x, y;
if (ParseCommaSeparatedIntegers(str, &x, &y))
bounds->set_origin(gfx::Point(x, y));
}
}
}