| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/apps/chrome_shell_window_delegate.h" | 5 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" | 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 9 #include "chrome/browser/file_select_helper.h" | 9 #include "chrome/browser/file_select_helper.h" |
| 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #if defined(USE_ASH) | 22 #if defined(USE_ASH) |
| 23 #include "ash/launcher/launcher_types.h" | 23 #include "ash/launcher/launcher_types.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace chrome { | 26 namespace chrome { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool disable_external_open_for_testing_ = false; | 30 bool disable_external_open_for_testing_ = false; |
| 31 | 31 |
| 32 class ShellWindowLinkDelegate : public content::WebContentsDelegate { | 32 } // namespace |
| 33 public: | |
| 34 ShellWindowLinkDelegate(); | |
| 35 | |
| 36 private: | |
| 37 virtual content::WebContents* OpenURLFromTab( | |
| 38 content::WebContents* source, | |
| 39 const content::OpenURLParams& params) OVERRIDE; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(ShellWindowLinkDelegate); | |
| 42 }; | |
| 43 | 33 |
| 44 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} | 34 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} |
| 45 | 35 |
| 36 ShellWindowLinkDelegate::~ShellWindowLinkDelegate() {} |
| 37 |
| 46 // TODO(rockot): Add a test that exercises this code. See | 38 // TODO(rockot): Add a test that exercises this code. See |
| 47 // http://crbug.com/254260. | 39 // http://crbug.com/254260. |
| 48 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( | 40 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( |
| 49 content::WebContents* source, | 41 content::WebContents* source, |
| 50 const content::OpenURLParams& params) { | 42 const content::OpenURLParams& params) { |
| 51 platform_util::OpenExternal(params.url); | 43 platform_util::OpenExternal(params.url); |
| 52 delete source; | 44 delete source; |
| 53 return NULL; | 45 return NULL; |
| 54 } | 46 } |
| 55 | 47 |
| 56 } // namespace | |
| 57 | |
| 58 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} | 48 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} |
| 59 | 49 |
| 60 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} | 50 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} |
| 61 | 51 |
| 62 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { | 52 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { |
| 63 disable_external_open_for_testing_ = true; | 53 disable_external_open_for_testing_ = true; |
| 64 } | 54 } |
| 65 | 55 |
| 66 void ChromeShellWindowDelegate::InitWebContents( | 56 void ChromeShellWindowDelegate::InitWebContents( |
| 67 content::WebContents* web_contents) { | 57 content::WebContents* web_contents) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 } | 75 } |
| 86 | 76 |
| 87 void ChromeShellWindowDelegate::AddNewContents( | 77 void ChromeShellWindowDelegate::AddNewContents( |
| 88 Profile* profile, | 78 Profile* profile, |
| 89 content::WebContents* new_contents, | 79 content::WebContents* new_contents, |
| 90 WindowOpenDisposition disposition, | 80 WindowOpenDisposition disposition, |
| 91 const gfx::Rect& initial_pos, | 81 const gfx::Rect& initial_pos, |
| 92 bool user_gesture, | 82 bool user_gesture, |
| 93 bool* was_blocked) { | 83 bool* was_blocked) { |
| 94 if (!disable_external_open_for_testing_) { | 84 if (!disable_external_open_for_testing_) { |
| 95 new_contents->SetDelegate(new ShellWindowLinkDelegate()); | 85 if (!shell_window_link_delegate_.get()) |
| 86 shell_window_link_delegate_.reset(new ShellWindowLinkDelegate()); |
| 87 new_contents->SetDelegate(shell_window_link_delegate_.get()); |
| 96 return; | 88 return; |
| 97 } | 89 } |
| 98 Browser* browser = | 90 Browser* browser = |
| 99 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); | 91 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); |
| 100 // Force all links to open in a new tab, even if they were trying to open a | 92 // Force all links to open in a new tab, even if they were trying to open a |
| 101 // new window. | 93 // new window. |
| 102 disposition = | 94 disposition = |
| 103 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 95 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 104 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | 96 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| 105 user_gesture, was_blocked); | 97 user_gesture, was_blocked); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 host->GetRoutingID(), blocked)); | 136 host->GetRoutingID(), blocked)); |
| 145 } | 137 } |
| 146 } | 138 } |
| 147 | 139 |
| 148 bool ChromeShellWindowDelegate::IsWebContentsVisible( | 140 bool ChromeShellWindowDelegate::IsWebContentsVisible( |
| 149 content::WebContents* web_contents) { | 141 content::WebContents* web_contents) { |
| 150 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); | 142 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); |
| 151 } | 143 } |
| 152 | 144 |
| 153 } // namespace chrome | 145 } // namespace chrome |
| OLD | NEW |