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" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" | 11 #include "chrome/browser/extensions/shell_window_registry.h" |
| 12 #include "chrome/browser/file_select_helper.h" | 12 #include "chrome/browser/file_select_helper.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/intents/web_intents_util.h" | 14 #include "chrome/browser/intents/web_intents_util.h" |
| 15 #include "chrome/browser/lifetime/application_lifetime.h" | 15 #include "chrome/browser/lifetime/application_lifetime.h" |
| 16 #include "chrome/browser/platform_util.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/extensions/native_shell_window.h" | 23 #include "chrome/browser/ui/extensions/native_shell_window.h" |
| 23 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 24 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/browser/view_type_utils.h" | 26 #include "chrome/browser/view_type_utils.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 56 void SuspendRenderViewHost(RenderViewHost* rvh) { | 57 void SuspendRenderViewHost(RenderViewHost* rvh) { |
| 57 DCHECK(rvh); | 58 DCHECK(rvh); |
| 58 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 59 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 59 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, | 60 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, |
| 60 base::Unretained(ResourceDispatcherHost::Get()), | 61 base::Unretained(ResourceDispatcherHost::Get()), |
| 61 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); | 62 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 | 66 |
| 67 // ExternalWebContentImpl is Web content delegate for link navigation. | |
| 68 // It helps to open URL in system default browser. | |
| 69 class ExternalWebContentImpl : public content::WebContentsDelegate { | |
| 70 public: | |
| 71 ExternalWebContentImpl() {} | |
| 72 virtual ~ExternalWebContentImpl() {} | |
| 73 | |
| 74 private: | |
| 75 // content::WebContentsDelegate implementation. | |
| 76 virtual content::WebContents* OpenURLFromTab( | |
| 77 content::WebContents* source, | |
| 78 const content::OpenURLParams& params) OVERRIDE; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(ExternalWebContentImpl); | |
| 81 }; | |
| 82 | |
| 83 content::WebContents* ExternalWebContentImpl::OpenURLFromTab( | |
| 84 content::WebContents* source, | |
| 85 const content::OpenURLParams& params) { | |
| 86 #if defined(OS_MACOSX) | |
| 87 // This must run on the UI thread on OS X. | |
| 88 platform_util::OpenExternal(params.url); | |
| 89 #else | |
| 90 // Otherwise put this work on the file thread. On Windows ShellExecute may | |
| 91 // block for a significant amount of time, and it shouldn't hurt on Linux. | |
| 92 BrowserThread::PostTask( | |
| 93 BrowserThread::FILE, | |
| 94 FROM_HERE, | |
| 95 base::Bind(&platform_util::OpenExternal, params.url)); | |
| 96 #endif | |
| 97 | |
| 98 return NULL; | |
| 99 } | |
| 100 | |
| 66 ShellWindow::CreateParams::CreateParams() | 101 ShellWindow::CreateParams::CreateParams() |
| 67 : frame(ShellWindow::CreateParams::FRAME_CHROME), | 102 : frame(ShellWindow::CreateParams::FRAME_CHROME), |
| 68 bounds(-1, -1, kDefaultWidth, kDefaultHeight), | 103 bounds(-1, -1, kDefaultWidth, kDefaultHeight), |
| 69 restore_position(true), restore_size(true) { | 104 restore_position(true), restore_size(true) { |
| 70 } | 105 } |
| 71 | 106 |
| 72 ShellWindow::CreateParams::~CreateParams() { | 107 ShellWindow::CreateParams::~CreateParams() { |
| 73 } | 108 } |
| 74 | 109 |
| 75 ShellWindow* ShellWindow::Create(Profile* profile, | 110 ShellWindow* ShellWindow::Create(Profile* profile, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 } | 287 } |
| 253 | 288 |
| 254 void ShellWindow::AddNewContents(WebContents* source, | 289 void ShellWindow::AddNewContents(WebContents* source, |
| 255 WebContents* new_contents, | 290 WebContents* new_contents, |
| 256 WindowOpenDisposition disposition, | 291 WindowOpenDisposition disposition, |
| 257 const gfx::Rect& initial_pos, | 292 const gfx::Rect& initial_pos, |
| 258 bool user_gesture) { | 293 bool user_gesture) { |
| 259 DCHECK(source == web_contents_); | 294 DCHECK(source == web_contents_); |
| 260 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 295 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| 261 profile_); | 296 profile_); |
| 297 | |
| 298 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_POSIX) | |
|
Mihai Parparita -not on Chrome
2012/09/05 18:15:10
What platform are you looking to avoid here? Chrom
| |
| 299 if (!external_content_delegate_.get()) | |
| 300 external_content_delegate_.reset(new ExternalWebContentImpl()); | |
|
Mihai Parparita -not on Chrome
2012/09/05 18:15:10
Seems like ExternalWebContentImpl could be a singl
| |
| 301 new_contents->SetDelegate(external_content_delegate_.get()); | |
| 302 #else | |
| 262 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 303 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 263 // Force all links to open in a new tab, even if they were trying to open a | 304 // Force all links to open in a new tab, even if they were trying to open a |
| 264 // new window. | 305 // new window. |
| 265 disposition = | 306 disposition = |
| 266 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 307 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 267 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | 308 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| 268 user_gesture); | 309 user_gesture); |
| 310 #endif | |
| 269 } | 311 } |
| 270 | 312 |
| 271 void ShellWindow::HandleKeyboardEvent( | 313 void ShellWindow::HandleKeyboardEvent( |
| 272 WebContents* source, | 314 WebContents* source, |
| 273 const content::NativeWebKeyboardEvent& event) { | 315 const content::NativeWebKeyboardEvent& event) { |
| 274 DCHECK_EQ(source, web_contents_); | 316 DCHECK_EQ(source, web_contents_); |
| 275 native_window_->HandleKeyboardEvent(event); | 317 native_window_->HandleKeyboardEvent(event); |
| 276 } | 318 } |
| 277 | 319 |
| 278 void ShellWindow::OnNativeClose() { | 320 void ShellWindow::OnNativeClose() { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 return; | 463 return; |
| 422 | 464 |
| 423 extensions::ShellWindowGeometryCache* cache = | 465 extensions::ShellWindowGeometryCache* cache = |
| 424 extensions::ExtensionSystem::Get(profile())-> | 466 extensions::ExtensionSystem::Get(profile())-> |
| 425 shell_window_geometry_cache(); | 467 shell_window_geometry_cache(); |
| 426 | 468 |
| 427 gfx::Rect bounds = native_window_->GetBounds(); | 469 gfx::Rect bounds = native_window_->GetBounds(); |
| 428 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 470 cache->SaveGeometry(extension()->id(), window_key_, bounds); |
| 429 } | 471 } |
| 430 | 472 |
| OLD | NEW |