Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Unified Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 10949023: Add switch to provide app window size on startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove hack Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/startup/startup_browser_creator_impl.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
index 1e3a348a6c32b7373a583b2467ec101e0fcb84fb..b2c80958efb1d228e61e22a450150eef889a4653 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
@@ -4,6 +4,9 @@
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
+#include <algorithm>
+#include <vector>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
@@ -85,6 +88,12 @@
#include "grit/locale_settings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
+
+#if defined(USE_ASH)
+#include "ash/launcher/launcher_types.h"
+#endif
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
@@ -209,6 +218,25 @@ bool GetAppLaunchContainer(
return true;
}
+// Parse two comma-separated integers from string. Return true on success.
+bool ParseCommaSeparatedIntegers(const std::string& str,
+ int* ret_num1,
+ int* ret_num2) {
+ std::vector<std::string> dimensions;
+ base::SplitString(str, ',', &dimensions);
+ if (dimensions.size() != 2)
+ return false;
+
+ int num1, num2;
+ if (!base::StringToInt(dimensions[0], &num1) ||
+ !base::StringToInt(dimensions[1], &num2))
+ return false;
+
+ *ret_num1 = num1;
+ *ret_num2 = num2;
+ return true;
+}
+
void RecordCmdLineAppHistogram() {
AppLauncherHandler::RecordAppLaunchType(
extension_misc::APP_LAUNCH_CMD_LINE_APP);
@@ -403,6 +431,26 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile,
return true;
}
+void StartupBrowserCreatorImpl::ExtractOptionalAppWindowSize(
+ gfx::Rect* bounds) {
+ if (command_line_.HasSwitch(switches::kAppWindowSize)) {
+ int width, height;
+ width = height = 0;
+ std::string switch_value =
+ command_line_.GetSwitchValueASCII(switches::kAppWindowSize);
+ if (ParseCommaSeparatedIntegers(switch_value, &width, &height)) {
+ const gfx::Rect work_area = gfx::Screen::GetPrimaryDisplay().work_area();
+ width = std::min(width, work_area.width());
+ height = std::min(height, work_area.height());
+ bounds->set_size(gfx::Size(width, height));
+ bounds->set_x((work_area.width() - bounds->width()) / 2);
+ // TODO(nkostylev): work_area does include launcher but should not.
+ // Launcher auto hide pref is synced and is most likely not applied here.
+ bounds->set_y((work_area.height() - bounds->height()) / 2);
+ }
+ }
+}
+
bool StartupBrowserCreatorImpl::IsAppLaunch(std::string* app_url,
std::string* app_id) {
if (command_line_.HasSwitch(switches::kApp)) {
@@ -509,9 +557,13 @@ bool StartupBrowserCreatorImpl::OpenApplicationWindow(
extension_misc::APP_LAUNCH_CMD_LINE_APP_LEGACY);
}
+ gfx::Rect override_bounds;
+ ExtractOptionalAppWindowSize(&override_bounds);
+
WebContents* app_tab = application_launch::OpenAppShortcutWindow(
profile,
- url);
+ url,
+ override_bounds);
if (out_app_contents)
*out_app_contents = app_tab;
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698