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/command_line.h" | |
| 8 #include "base/memory/singleton.h" | |
| 7 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | 12 #include "chrome/browser/extensions/shell_window_geometry_cache.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" | 13 #include "chrome/browser/extensions/shell_window_registry.h" |
| 12 #include "chrome/browser/file_select_helper.h" | 14 #include "chrome/browser/file_select_helper.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 15 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/intents/web_intents_util.h" | 16 #include "chrome/browser/intents/web_intents_util.h" |
| 15 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
| 18 #include "chrome/browser/platform_util.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sessions/session_id.h" | 20 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/extensions/native_shell_window.h" | 26 #include "chrome/browser/ui/extensions/native_shell_window.h" |
| 23 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 27 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/browser/view_type_utils.h" | 29 #include "chrome/browser/view_type_utils.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/extensions/extension_messages.h" | 32 #include "chrome/common/extensions/extension_messages.h" |
| 29 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 57 void SuspendRenderViewHost(RenderViewHost* rvh) { | 61 void SuspendRenderViewHost(RenderViewHost* rvh) { |
| 58 DCHECK(rvh); | 62 DCHECK(rvh); |
| 59 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 63 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 60 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, | 64 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, |
| 61 base::Unretained(ResourceDispatcherHost::Get()), | 65 base::Unretained(ResourceDispatcherHost::Get()), |
| 62 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); | 66 rvh->GetProcess()->GetID(), rvh->GetRoutingID())); |
| 63 } | 67 } |
| 64 | 68 |
| 65 } // namespace | 69 } // namespace |
| 66 | 70 |
| 71 // ExternalUrlController is a singleton class for link navigation. | |
| 72 // It helps to open URL in system default browser. | |
| 73 class ExternalUrlController : public content::WebContentsDelegate { | |
| 74 public: | |
| 75 static ExternalUrlController* GetInstance(); | |
| 76 | |
| 77 private: | |
| 78 ExternalUrlController() {} | |
| 79 friend struct DefaultSingletonTraits<ExternalUrlController>; | |
| 80 | |
| 81 // content::WebContentsDelegate implementation. | |
| 82 virtual content::WebContents* OpenURLFromTab( | |
| 83 content::WebContents* source, | |
| 84 const content::OpenURLParams& params) OVERRIDE; | |
| 85 | |
| 86 // For test usage. | |
| 87 content::WebContents* OpenInNewTab( | |
| 88 const content::OpenURLParams& params); | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(ExternalUrlController); | |
| 91 }; | |
| 92 | |
| 93 // static | |
| 94 ExternalUrlController* ExternalUrlController::GetInstance() { | |
| 95 return Singleton<ExternalUrlController>::get(); | |
| 96 } | |
| 97 | |
| 98 content::WebContents* ExternalUrlController::OpenURLFromTab( | |
| 99 content::WebContents* source, | |
| 100 const content::OpenURLParams& params) { | |
| 101 // Delete useless web content first to | |
| 102 // avoid a potential leak in a render process host. | |
| 103 delete source; | |
| 104 | |
| 105 // This should only happen in PlatformAppBrowserTest. | |
| 106 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 107 if (command_line->HasSwitch("OpenLinkTest")) { | |
|
Mihai Parparita -not on Chrome
2012/09/29 00:28:44
Test behavior is normally not overridden via comma
| |
| 108 return OpenInNewTab(params); | |
| 109 } | |
| 110 | |
| 111 #if defined(OS_MACOSX) | |
| 112 // This must run on the UI thread on OS X. | |
| 113 platform_util::OpenExternal(params.url); | |
| 114 #else | |
| 115 // Otherwise put this work on the file thread. On Windows ShellExecute may | |
| 116 // block for a significant amount of time, and it shouldn't hurt on Linux. | |
| 117 BrowserThread::PostTask( | |
| 118 BrowserThread::FILE, | |
| 119 FROM_HERE, | |
| 120 base::Bind(&platform_util::OpenExternal, params.url)); | |
| 121 #endif | |
| 122 | |
| 123 return NULL; | |
| 124 } | |
| 125 | |
| 126 content::WebContents* ExternalUrlController::OpenInNewTab( | |
| 127 const content::OpenURLParams& params) { | |
| 128 WindowOpenDisposition disposition = params.disposition; | |
| 129 content::OpenURLParams new_tab_params = params; | |
| 130 new_tab_params.disposition = | |
| 131 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
| 132 for (BrowserList::const_iterator i = BrowserList::begin(); | |
| 133 i != BrowserList::end(); ++i) { | |
| 134 if ((*i)->is_type_tabbed()) { | |
| 135 Browser* browser = *i; | |
| 136 WebContents* new_tab = browser->OpenURL(new_tab_params); | |
| 137 browser->window()->Show(); | |
| 138 return new_tab; | |
| 139 } | |
| 140 } | |
| 141 return NULL; | |
| 142 } | |
| 143 | |
| 67 ShellWindow::CreateParams::CreateParams() | 144 ShellWindow::CreateParams::CreateParams() |
| 68 : frame(ShellWindow::CreateParams::FRAME_CHROME), | 145 : frame(ShellWindow::CreateParams::FRAME_CHROME), |
| 69 bounds(-1, -1, kDefaultWidth, kDefaultHeight), | 146 bounds(-1, -1, kDefaultWidth, kDefaultHeight), |
| 70 restore_position(true), restore_size(true) { | 147 restore_position(true), restore_size(true) { |
| 71 } | 148 } |
| 72 | 149 |
| 73 ShellWindow::CreateParams::~CreateParams() { | 150 ShellWindow::CreateParams::~CreateParams() { |
| 74 } | 151 } |
| 75 | 152 |
| 76 ShellWindow* ShellWindow::Create(Profile* profile, | 153 ShellWindow* ShellWindow::Create(Profile* profile, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 333 |
| 257 void ShellWindow::AddNewContents(WebContents* source, | 334 void ShellWindow::AddNewContents(WebContents* source, |
| 258 WebContents* new_contents, | 335 WebContents* new_contents, |
| 259 WindowOpenDisposition disposition, | 336 WindowOpenDisposition disposition, |
| 260 const gfx::Rect& initial_pos, | 337 const gfx::Rect& initial_pos, |
| 261 bool user_gesture, | 338 bool user_gesture, |
| 262 bool* was_blocked) { | 339 bool* was_blocked) { |
| 263 DCHECK(source == web_contents_); | 340 DCHECK(source == web_contents_); |
| 264 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 341 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| 265 profile_); | 342 profile_); |
| 343 | |
| 344 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 345 new_contents->SetDelegate(ExternalUrlController::GetInstance()); | |
| 346 #else | |
| 266 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 347 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 267 // Force all links to open in a new tab, even if they were trying to open a | 348 // Force all links to open in a new tab, even if they were trying to open a |
| 268 // new window. | 349 // new window. |
| 269 disposition = | 350 disposition = |
| 270 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 351 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 271 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | 352 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| 272 user_gesture, was_blocked); | 353 user_gesture, was_blocked); |
| 354 #endif | |
| 273 } | 355 } |
| 274 | 356 |
| 275 void ShellWindow::HandleKeyboardEvent( | 357 void ShellWindow::HandleKeyboardEvent( |
| 276 WebContents* source, | 358 WebContents* source, |
| 277 const content::NativeWebKeyboardEvent& event) { | 359 const content::NativeWebKeyboardEvent& event) { |
| 278 DCHECK_EQ(source, web_contents_); | 360 DCHECK_EQ(source, web_contents_); |
| 279 native_window_->HandleKeyboardEvent(event); | 361 native_window_->HandleKeyboardEvent(event); |
| 280 } | 362 } |
| 281 | 363 |
| 282 void ShellWindow::OnNativeClose() { | 364 void ShellWindow::OnNativeClose() { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 if (window_key_.empty()) | 529 if (window_key_.empty()) |
| 448 return; | 530 return; |
| 449 | 531 |
| 450 extensions::ShellWindowGeometryCache* cache = | 532 extensions::ShellWindowGeometryCache* cache = |
| 451 extensions::ExtensionSystem::Get(profile())-> | 533 extensions::ExtensionSystem::Get(profile())-> |
| 452 shell_window_geometry_cache(); | 534 shell_window_geometry_cache(); |
| 453 | 535 |
| 454 gfx::Rect bounds = native_window_->GetBounds(); | 536 gfx::Rect bounds = native_window_->GetBounds(); |
| 455 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 537 cache->SaveGeometry(extension()->id(), window_key_, bounds); |
| 456 } | 538 } |
| OLD | NEW |