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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/shell_window.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/shell_window_geometry_cache.h"
9 #include "chrome/browser/extensions/shell_window_registry.h" 11 #include "chrome/browser/extensions/shell_window_registry.h"
10 #include "chrome/browser/file_select_helper.h" 12 #include "chrome/browser/file_select_helper.h"
11 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/infobars/infobar_tab_helper.h"
12 #include "chrome/browser/intents/web_intents_util.h" 14 #include "chrome/browser/intents/web_intents_util.h"
13 #include "chrome/browser/lifetime/application_lifetime.h" 15 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/session_id.h" 17 #include "chrome/browser/sessions/session_id.h"
16 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_tabstrip.h" 20 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 58 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
57 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, 59 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute,
58 base::Unretained(ResourceDispatcherHost::Get()), 60 base::Unretained(ResourceDispatcherHost::Get()),
59 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); 61 rvh->GetProcess()->GetID(), rvh->GetRoutingID()));
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 ShellWindow::CreateParams::CreateParams() 66 ShellWindow::CreateParams::CreateParams()
65 : frame(ShellWindow::CreateParams::FRAME_CHROME), 67 : frame(ShellWindow::CreateParams::FRAME_CHROME),
66 bounds(10, 10, kDefaultWidth, kDefaultHeight) { 68 bounds(-1, -1, kDefaultWidth, kDefaultHeight),
69 restorePosition(true), restoreSize(true) {
70 }
71
72 ShellWindow::CreateParams::~CreateParams() {
67 } 73 }
68 74
69 ShellWindow* ShellWindow::Create(Profile* profile, 75 ShellWindow* ShellWindow::Create(Profile* profile,
70 const extensions::Extension* extension, 76 const extensions::Extension* extension,
71 const GURL& url, 77 const GURL& url,
72 const ShellWindow::CreateParams& params) { 78 const ShellWindow::CreateParams& params) {
73 // This object will delete itself when the window is closed. 79 // This object will delete itself when the window is closed.
74 ShellWindow* window = new ShellWindow(profile, extension); 80 ShellWindow* window = new ShellWindow(profile, extension);
75 window->Init(url, params); 81 window->Init(url, params);
76 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); 82 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window);
(...skipping 17 matching lines...) Expand all
94 contents_.reset(TabContents::Factory::CreateTabContents(web_contents_)); 100 contents_.reset(TabContents::Factory::CreateTabContents(web_contents_));
95 content::WebContentsObserver::Observe(web_contents_); 101 content::WebContentsObserver::Observe(web_contents_);
96 web_contents_->SetDelegate(this); 102 web_contents_->SetDelegate(this);
97 chrome::SetViewType(web_contents_, chrome::VIEW_TYPE_APP_SHELL); 103 chrome::SetViewType(web_contents_, chrome::VIEW_TYPE_APP_SHELL);
98 web_contents_->GetMutableRendererPrefs()-> 104 web_contents_->GetMutableRendererPrefs()->
99 browser_handles_all_top_level_requests = true; 105 browser_handles_all_top_level_requests = true;
100 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 106 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
101 107
102 native_window_.reset(NativeShellWindow::Create(this, params)); 108 native_window_.reset(NativeShellWindow::Create(this, params));
103 109
110 if (!params.window_key.empty()) {
111 window_key_ = params.window_key;
112
113 if (params.restorePosition || params.restoreSize) {
114 // restore geometry
Mihai Parparita -not on Chrome 2012/08/29 21:39:14 Extraneous comment.
Marijn Kruisselbrink 2012/08/29 22:31:33 Done.
115 extensions::ShellWindowGeometryCache* cache =
116 extensions::ExtensionSystem::Get(profile())->
117 shell_window_geometry_cache();
118 gfx::Rect cached_bounds;
119 if (cache->GetGeometry(extension()->id(), params.window_key,
120 &cached_bounds)) {
121 gfx::Rect bounds = native_window_->GetBounds();
122
123 if (params.restorePosition)
124 bounds.set_origin(cached_bounds.origin());
125 if (params.restoreSize)
126 bounds.set_size(cached_bounds.size());
127
128 native_window_->SetBounds(bounds);
129 }
130 }
131 }
132
133
104 // Block the created RVH from loading anything until the background page 134 // Block the created RVH from loading anything until the background page
105 // has had a chance to do any initialization it wants. 135 // has had a chance to do any initialization it wants.
106 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); 136 SuspendRenderViewHost(web_contents_->GetRenderViewHost());
107 137
108 // TODO(jeremya): there's a bug where navigating a web contents to an 138 // TODO(jeremya): there's a bug where navigating a web contents to an
109 // extension URL causes it to create a new RVH and discard the old (perfectly 139 // extension URL causes it to create a new RVH and discard the old (perfectly
110 // usable) one. To work around this, we watch for a RVH_CHANGED message from 140 // usable) one. To work around this, we watch for a RVH_CHANGED message from
111 // the web contents (which will be sent during LoadURL) and suspend resource 141 // the web contents (which will be sent during LoadURL) and suspend resource
112 // requests on the new RVH to ensure that we block the new RVH from loading 142 // requests on the new RVH to ensure that we block the new RVH from loading
113 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED 143 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 extension_function_dispatcher_.Dispatch(params, 399 extension_function_dispatcher_.Dispatch(params,
370 web_contents_->GetRenderViewHost()); 400 web_contents_->GetRenderViewHost());
371 } 401 }
372 402
373 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, 403 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level,
374 const std::string& message) { 404 const std::string& message) {
375 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 405 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
376 rvh->Send(new ExtensionMsg_AddMessageToConsole( 406 rvh->Send(new ExtensionMsg_AddMessageToConsole(
377 rvh->GetRoutingID(), level, message)); 407 rvh->GetRoutingID(), level, message));
378 } 408 }
409
410 void ShellWindow::SaveWindowPosition()
411 {
412 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.
413 extensions::ShellWindowGeometryCache* cache =
414 extensions::ExtensionSystem::Get(profile())->
415 shell_window_geometry_cache();
416
417 gfx::Rect bounds = native_window_->GetBounds();
418 cache->SaveGeometry(extension()->id(), window_key_, bounds);
419 }
420 }
421
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698