| 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 restorePosition(true), restoreSize(true) { |
| 67 } | 70 } |
| 68 | 71 |
| 69 ShellWindow* ShellWindow::Create(Profile* profile, | 72 ShellWindow* ShellWindow::Create(Profile* profile, |
| 70 const extensions::Extension* extension, | 73 const extensions::Extension* extension, |
| 71 const GURL& url, | 74 const GURL& url, |
| 72 const ShellWindow::CreateParams& params) { | 75 const ShellWindow::CreateParams& params) { |
| 73 // This object will delete itself when the window is closed. | 76 // This object will delete itself when the window is closed. |
| 74 ShellWindow* window = new ShellWindow(profile, extension); | 77 ShellWindow* window = new ShellWindow(profile, extension); |
| 75 window->Init(url, params); | 78 window->Init(url, params); |
| 76 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 79 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 94 contents_.reset(new TabContents(web_contents_)); | 97 contents_.reset(new TabContents(web_contents_)); |
| 95 content::WebContentsObserver::Observe(web_contents_); | 98 content::WebContentsObserver::Observe(web_contents_); |
| 96 web_contents_->SetDelegate(this); | 99 web_contents_->SetDelegate(this); |
| 97 chrome::SetViewType(web_contents_, chrome::VIEW_TYPE_APP_SHELL); | 100 chrome::SetViewType(web_contents_, chrome::VIEW_TYPE_APP_SHELL); |
| 98 web_contents_->GetMutableRendererPrefs()-> | 101 web_contents_->GetMutableRendererPrefs()-> |
| 99 browser_handles_all_top_level_requests = true; | 102 browser_handles_all_top_level_requests = true; |
| 100 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 103 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| 101 | 104 |
| 102 native_window_.reset(NativeShellWindow::Create(this, params)); | 105 native_window_.reset(NativeShellWindow::Create(this, params)); |
| 103 | 106 |
| 107 if (!params.window_key.empty()) { |
| 108 window_key_ = params.window_key; |
| 109 |
| 110 if (params.restorePosition || params.restoreSize) { |
| 111 // restore geometry |
| 112 extensions::ShellWindowGeometryCache* cache = |
| 113 extensions::ExtensionSystem::Get(profile())-> |
| 114 shell_window_geometry_cache(); |
| 115 gfx::Rect cached_bounds; |
| 116 if (cache->GetWindowGeometry(extension()->id(), params.window_key, |
| 117 &cached_bounds)) { |
| 118 gfx::Rect bounds = native_window_->GetBounds(); |
| 119 |
| 120 if (params.restorePosition) |
| 121 bounds.set_origin(cached_bounds.origin()); |
| 122 if (params.restoreSize) |
| 123 bounds.set_size(cached_bounds.size()); |
| 124 |
| 125 native_window_->SetBounds(bounds); |
| 126 } |
| 127 } |
| 128 } |
| 129 |
| 130 |
| 104 // Block the created RVH from loading anything until the background page | 131 // Block the created RVH from loading anything until the background page |
| 105 // has had a chance to do any initialization it wants. | 132 // has had a chance to do any initialization it wants. |
| 106 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 133 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); |
| 107 | 134 |
| 108 // TODO(jeremya): there's a bug where navigating a web contents to an | 135 // 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 | 136 // 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 | 137 // 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 | 138 // 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 | 139 // 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 | 140 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 extension_function_dispatcher_.Dispatch(params, | 389 extension_function_dispatcher_.Dispatch(params, |
| 363 web_contents_->GetRenderViewHost()); | 390 web_contents_->GetRenderViewHost()); |
| 364 } | 391 } |
| 365 | 392 |
| 366 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, | 393 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
| 367 const std::string& message) { | 394 const std::string& message) { |
| 368 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 395 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 369 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 396 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
| 370 rvh->GetRoutingID(), level, message)); | 397 rvh->GetRoutingID(), level, message)); |
| 371 } | 398 } |
| 399 |
| 400 void ShellWindow::SaveWindowPosition() |
| 401 { |
| 402 if (!window_key_.empty()) { |
| 403 extensions::ShellWindowGeometryCache* cache = |
| 404 extensions::ExtensionSystem::Get(profile())-> |
| 405 shell_window_geometry_cache(); |
| 406 |
| 407 gfx::Rect bounds = native_window_->GetBounds(); |
| 408 cache->SaveWindowGeometry(extension()->id(), window_key_, bounds); |
| 409 } |
| 410 } |
| 411 |
| OLD | NEW |