Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 restore_position(true), restore_size(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 Loading... | |
| 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.restore_position || params.restore_size) { | |
| 114 extensions::ShellWindowGeometryCache* cache = | |
| 115 extensions::ExtensionSystem::Get(profile())-> | |
| 116 shell_window_geometry_cache(); | |
| 117 gfx::Rect cached_bounds; | |
| 118 if (cache->GetGeometry(extension()->id(), params.window_key, | |
| 119 &cached_bounds)) { | |
|
jeremya
2012/08/30 04:49:33
nit: indentation
Marijn Kruisselbrink
2012/08/30 17:15:05
Done.
| |
| 120 gfx::Rect bounds = native_window_->GetBounds(); | |
| 121 | |
| 122 if (params.restore_position) | |
| 123 bounds.set_origin(cached_bounds.origin()); | |
| 124 if (params.restore_size) | |
| 125 bounds.set_size(cached_bounds.size()); | |
| 126 | |
| 127 native_window_->SetBounds(bounds); | |
|
jeremya
2012/08/30 04:49:33
Will this set the bounds after the window has alre
Marijn Kruisselbrink
2012/08/30 17:15:05
In theory I guess this could indeed result in the
jeremya
2012/08/31 04:36:12
Yes, this should be fixed :) (please add a TODO he
| |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 | |
| 104 // Block the created RVH from loading anything until the background page | 133 // Block the created RVH from loading anything until the background page |
| 105 // has had a chance to do any initialization it wants. | 134 // has had a chance to do any initialization it wants. |
| 106 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 135 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); |
| 107 | 136 |
| 108 // TODO(jeremya): there's a bug where navigating a web contents to an | 137 // 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 | 138 // 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 | 139 // 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 | 140 // 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 | 141 // 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 | 142 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 extension_function_dispatcher_.Dispatch(params, | 398 extension_function_dispatcher_.Dispatch(params, |
| 370 web_contents_->GetRenderViewHost()); | 399 web_contents_->GetRenderViewHost()); |
| 371 } | 400 } |
| 372 | 401 |
| 373 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, | 402 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
| 374 const std::string& message) { | 403 const std::string& message) { |
| 375 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 404 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 376 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 405 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
| 377 rvh->GetRoutingID(), level, message)); | 406 rvh->GetRoutingID(), level, message)); |
| 378 } | 407 } |
| 408 | |
| 409 void ShellWindow::SaveWindowPosition() | |
| 410 { | |
| 411 if (window_key_.empty()) | |
| 412 return; | |
| 413 | |
| 414 extensions::ShellWindowGeometryCache* cache = | |
| 415 extensions::ExtensionSystem::Get(profile())-> | |
| 416 shell_window_geometry_cache(); | |
|
jeremya
2012/08/30 04:49:33
nit: 4 spaces here too, i believe
Marijn Kruisselbrink
2012/08/30 17:15:05
Yeah, I wasn't sure about indentation here. Is tha
jeremya
2012/08/31 04:36:12
I meant 2 more :)
| |
| 417 | |
| 418 gfx::Rect bounds = native_window_->GetBounds(); | |
| 419 cache->SaveGeometry(extension()->id(), window_key_, bounds); | |
| 420 } | |
| 421 | |
| OLD | NEW |