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

Unified Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 10871086: First part of remembering platform app window geometry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: return error instead of truncating id Created 8 years, 4 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
Index: chrome/browser/ui/extensions/shell_window.cc
diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc
index da858acec0c294be43baf41133ee3a0245abfac7..c9fa4a6dbc55d1f39c9bd6bcaf6c39419881e0d9 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/chrome/browser/ui/extensions/shell_window.cc
@@ -6,6 +6,8 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/shell_window_geometry_cache.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
@@ -63,7 +65,11 @@ void SuspendRenderViewHost(RenderViewHost* rvh) {
ShellWindow::CreateParams::CreateParams()
: frame(ShellWindow::CreateParams::FRAME_CHROME),
- bounds(10, 10, kDefaultWidth, kDefaultHeight) {
+ bounds(-1, -1, kDefaultWidth, kDefaultHeight),
+ restorePosition(true), restoreSize(true) {
+}
+
+ShellWindow::CreateParams::~CreateParams() {
}
ShellWindow* ShellWindow::Create(Profile* profile,
@@ -101,6 +107,30 @@ void ShellWindow::Init(const GURL& url,
native_window_.reset(NativeShellWindow::Create(this, params));
+ if (!params.window_key.empty()) {
+ window_key_ = params.window_key;
+
+ if (params.restorePosition || params.restoreSize) {
+ // restore geometry
Mihai Parparita -not on Chrome 2012/08/29 21:39:14 Extraneous comment.
Marijn Kruisselbrink 2012/08/29 22:31:33 Done.
+ extensions::ShellWindowGeometryCache* cache =
+ extensions::ExtensionSystem::Get(profile())->
+ shell_window_geometry_cache();
+ gfx::Rect cached_bounds;
+ if (cache->GetGeometry(extension()->id(), params.window_key,
+ &cached_bounds)) {
+ gfx::Rect bounds = native_window_->GetBounds();
+
+ if (params.restorePosition)
+ bounds.set_origin(cached_bounds.origin());
+ if (params.restoreSize)
+ bounds.set_size(cached_bounds.size());
+
+ native_window_->SetBounds(bounds);
+ }
+ }
+ }
+
+
// Block the created RVH from loading anything until the background page
// has had a chance to do any initialization it wants.
SuspendRenderViewHost(web_contents_->GetRenderViewHost());
@@ -376,3 +406,16 @@ void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level,
rvh->Send(new ExtensionMsg_AddMessageToConsole(
rvh->GetRoutingID(), level, message));
}
+
+void ShellWindow::SaveWindowPosition()
+{
+ if (!window_key_.empty()) {
Mihai Parparita -not on Chrome 2012/08/29 21:39:14 Nit: turn this into an early return, so that the b
Marijn Kruisselbrink 2012/08/29 22:31:33 Done.
+ extensions::ShellWindowGeometryCache* cache =
+ extensions::ExtensionSystem::Get(profile())->
+ shell_window_geometry_cache();
+
+ gfx::Rect bounds = native_window_->GetBounds();
+ cache->SaveGeometry(extension()->id(), window_key_, bounds);
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698