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" |
11 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/shell_integration.h" | 12 #include "chrome/browser/shell_integration.h" |
14 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 14 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 17 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
19 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
20 #include "content/public/browser/browser_context.h" | |
21 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_view.h" | 21 #include "content/public/browser/web_contents_view.h" |
24 | 22 |
25 #if defined(USE_ASH) | 23 #if defined(USE_ASH) |
26 #include "ash/shelf/shelf_constants.h" | 24 #include "ash/shelf/shelf_constants.h" |
27 #endif | 25 #endif |
28 | 26 |
29 #if defined(ENABLE_PRINTING) | 27 #if defined(ENABLE_PRINTING) |
30 #if defined(ENABLE_FULL_PRINTING) | 28 #if defined(ENABLE_FULL_PRINTING) |
31 #include "chrome/browser/printing/print_preview_message_handler.h" | 29 #include "chrome/browser/printing/print_preview_message_handler.h" |
32 #include "chrome/browser/printing/print_view_manager.h" | 30 #include "chrome/browser/printing/print_view_manager.h" |
33 #else | 31 #else |
34 #include "chrome/browser/printing/print_view_manager_basic.h" | 32 #include "chrome/browser/printing/print_view_manager_basic.h" |
35 #endif // defined(ENABLE_FULL_PRINTING) | 33 #endif // defined(ENABLE_FULL_PRINTING) |
36 #endif // defined(ENABLE_PRINTING) | 34 #endif // defined(ENABLE_PRINTING) |
37 | 35 |
38 namespace { | 36 namespace { |
39 | 37 |
40 bool disable_external_open_for_testing_ = false; | 38 bool disable_external_open_for_testing_ = false; |
41 | 39 |
42 // Opens a URL with Chromium (not external browser) with the right profile. | 40 // Opens a URL with Chromium (not external browser) with the right profile. |
43 content::WebContents* OpenURLFromTabInternal( | 41 content::WebContents* OpenURLFromTabInternal( |
44 content::BrowserContext* context, | 42 Profile* profile, |
45 content::WebContents* source, | 43 content::WebContents* source, |
46 const content::OpenURLParams& params) { | 44 const content::OpenURLParams& params) { |
47 // Force all links to open in a new tab, even if they were trying to open a | 45 // Force all links to open in a new tab, even if they were trying to open a |
48 // window. | 46 // window. |
49 chrome::NavigateParams new_tab_params( | 47 chrome::NavigateParams new_tab_params( |
50 static_cast<Browser*>(NULL), params.url, params.transition); | 48 static_cast<Browser*>(NULL), params.url, params.transition); |
51 new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB | 49 new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB |
52 ? params.disposition | 50 ? params.disposition |
53 : NEW_FOREGROUND_TAB; | 51 : NEW_FOREGROUND_TAB; |
54 new_tab_params.initiating_profile = Profile::FromBrowserContext(context); | 52 new_tab_params.initiating_profile = profile; |
55 chrome::Navigate(&new_tab_params); | 53 chrome::Navigate(&new_tab_params); |
56 | 54 |
57 return new_tab_params.target_contents; | 55 return new_tab_params.target_contents; |
58 } | 56 } |
59 | 57 |
60 // Helper class that opens a URL based on if this browser instance is the | 58 // Helper class that opens a URL based on if this browser instance is the |
61 // default system browser. If it is the default, open the URL directly instead | 59 // default system browser. If it is the default, open the URL directly instead |
62 // of asking the system to open it. | 60 // of asking the system to open it. |
63 class OpenURLFromTabBasedOnBrowserDefault | 61 class OpenURLFromTabBasedOnBrowserDefault |
64 : public ShellIntegration::DefaultWebClientObserver { | 62 : public ShellIntegration::DefaultWebClientObserver { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 #endif // defined(ENABLE_PRINTING) | 141 #endif // defined(ENABLE_PRINTING) |
144 } | 142 } |
145 | 143 |
146 apps::NativeAppWindow* ChromeShellWindowDelegate::CreateNativeAppWindow( | 144 apps::NativeAppWindow* ChromeShellWindowDelegate::CreateNativeAppWindow( |
147 apps::ShellWindow* window, | 145 apps::ShellWindow* window, |
148 const apps::ShellWindow::CreateParams& params) { | 146 const apps::ShellWindow::CreateParams& params) { |
149 return CreateNativeAppWindowImpl(window, params); | 147 return CreateNativeAppWindowImpl(window, params); |
150 } | 148 } |
151 | 149 |
152 content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( | 150 content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( |
153 content::BrowserContext* context, | 151 Profile* profile, |
154 content::WebContents* source, | 152 content::WebContents* source, |
155 const content::OpenURLParams& params) { | 153 const content::OpenURLParams& params) { |
156 return OpenURLFromTabInternal(context, source, params); | 154 return OpenURLFromTabInternal(profile, source, params); |
157 } | 155 } |
158 | 156 |
159 void ChromeShellWindowDelegate::AddNewContents( | 157 void ChromeShellWindowDelegate::AddNewContents( |
160 content::BrowserContext* context, | 158 Profile* profile, |
161 content::WebContents* new_contents, | 159 content::WebContents* new_contents, |
162 WindowOpenDisposition disposition, | 160 WindowOpenDisposition disposition, |
163 const gfx::Rect& initial_pos, | 161 const gfx::Rect& initial_pos, |
164 bool user_gesture, | 162 bool user_gesture, |
165 bool* was_blocked) { | 163 bool* was_blocked) { |
166 if (!disable_external_open_for_testing_) { | 164 if (!disable_external_open_for_testing_) { |
167 if (!shell_window_link_delegate_.get()) | 165 if (!shell_window_link_delegate_.get()) |
168 shell_window_link_delegate_.reset(new ShellWindowLinkDelegate()); | 166 shell_window_link_delegate_.reset(new ShellWindowLinkDelegate()); |
169 new_contents->SetDelegate(shell_window_link_delegate_.get()); | 167 new_contents->SetDelegate(shell_window_link_delegate_.get()); |
170 return; | 168 return; |
171 } | 169 } |
172 chrome::ScopedTabbedBrowserDisplayer displayer( | 170 chrome::ScopedTabbedBrowserDisplayer displayer( |
173 Profile::FromBrowserContext(context), chrome::GetActiveDesktop()); | 171 profile, chrome::GetActiveDesktop()); |
174 // Force all links to open in a new tab, even if they were trying to open a | 172 // Force all links to open in a new tab, even if they were trying to open a |
175 // new window. | 173 // new window. |
176 disposition = | 174 disposition = |
177 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 175 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
178 chrome::AddWebContents(displayer.browser(), NULL, new_contents, disposition, | 176 chrome::AddWebContents(displayer.browser(), NULL, new_contents, disposition, |
179 initial_pos, user_gesture, was_blocked); | 177 initial_pos, user_gesture, was_blocked); |
180 } | 178 } |
181 | 179 |
182 content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( | 180 content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( |
183 content::WebContents* web_contents, | 181 content::WebContents* web_contents, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if (host) { | 214 if (host) { |
217 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( | 215 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( |
218 host->GetRoutingID(), blocked)); | 216 host->GetRoutingID(), blocked)); |
219 } | 217 } |
220 } | 218 } |
221 | 219 |
222 bool ChromeShellWindowDelegate::IsWebContentsVisible( | 220 bool ChromeShellWindowDelegate::IsWebContentsVisible( |
223 content::WebContents* web_contents) { | 221 content::WebContents* web_contents) { |
224 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); | 222 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); |
225 } | 223 } |
OLD | NEW |