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_app_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" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/shell_integration.h" | 13 #include "chrome/browser/shell_integration.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 virtual bool IsOwnedByWorker() OVERRIDE { return true; } | 92 virtual bool IsOwnedByWorker() OVERRIDE { return true; } |
93 | 93 |
94 private: | 94 private: |
95 content::WebContents* source_; | 95 content::WebContents* source_; |
96 const content::OpenURLParams params_; | 96 const content::OpenURLParams params_; |
97 }; | 97 }; |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} | 101 AppWindowLinkDelegate::AppWindowLinkDelegate() {} |
102 | 102 |
103 ShellWindowLinkDelegate::~ShellWindowLinkDelegate() {} | 103 AppWindowLinkDelegate::~AppWindowLinkDelegate() {} |
104 | 104 |
105 // TODO(rockot): Add a test that exercises this code. See | 105 // TODO(rockot): Add a test that exercises this code. See |
106 // http://crbug.com/254260. | 106 // http://crbug.com/254260. |
107 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( | 107 content::WebContents* AppWindowLinkDelegate::OpenURLFromTab( |
108 content::WebContents* source, | 108 content::WebContents* source, |
109 const content::OpenURLParams& params) { | 109 const content::OpenURLParams& params) { |
110 if (source) { | 110 if (source) { |
111 scoped_refptr<ShellIntegration::DefaultWebClientWorker> | 111 scoped_refptr<ShellIntegration::DefaultWebClientWorker> |
112 check_if_default_browser_worker = | 112 check_if_default_browser_worker = |
113 new ShellIntegration::DefaultBrowserWorker( | 113 new ShellIntegration::DefaultBrowserWorker( |
114 new OpenURLFromTabBasedOnBrowserDefault(source, params)); | 114 new OpenURLFromTabBasedOnBrowserDefault(source, params)); |
115 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned | 115 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned |
116 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime | 116 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime |
117 // ownership of check_if_default_browser_worker and will clean up after | 117 // ownership of check_if_default_browser_worker and will clean up after |
118 // the asynchronous tasks. | 118 // the asynchronous tasks. |
119 check_if_default_browser_worker->StartCheckIsDefault(); | 119 check_if_default_browser_worker->StartCheckIsDefault(); |
120 } | 120 } |
121 return NULL; | 121 return NULL; |
122 } | 122 } |
123 | 123 |
124 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} | 124 ChromeAppWindowDelegate::ChromeAppWindowDelegate() {} |
125 | 125 |
126 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} | 126 ChromeAppWindowDelegate::~ChromeAppWindowDelegate() {} |
127 | 127 |
128 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { | 128 void ChromeAppWindowDelegate::DisableExternalOpenForTesting() { |
129 disable_external_open_for_testing_ = true; | 129 disable_external_open_for_testing_ = true; |
130 } | 130 } |
131 | 131 |
132 void ChromeShellWindowDelegate::InitWebContents( | 132 void ChromeAppWindowDelegate::InitWebContents( |
133 content::WebContents* web_contents) { | 133 content::WebContents* web_contents) { |
134 FaviconTabHelper::CreateForWebContents(web_contents); | 134 FaviconTabHelper::CreateForWebContents(web_contents); |
135 | 135 |
136 #if defined(ENABLE_PRINTING) | 136 #if defined(ENABLE_PRINTING) |
137 #if defined(ENABLE_FULL_PRINTING) | 137 #if defined(ENABLE_FULL_PRINTING) |
138 printing::PrintViewManager::CreateForWebContents(web_contents); | 138 printing::PrintViewManager::CreateForWebContents(web_contents); |
139 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); | 139 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); |
140 #else | 140 #else |
141 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); | 141 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); |
142 #endif // defined(ENABLE_FULL_PRINTING) | 142 #endif // defined(ENABLE_FULL_PRINTING) |
143 #endif // defined(ENABLE_PRINTING) | 143 #endif // defined(ENABLE_PRINTING) |
144 } | 144 } |
145 | 145 |
146 apps::NativeAppWindow* ChromeShellWindowDelegate::CreateNativeAppWindow( | 146 apps::NativeAppWindow* ChromeAppWindowDelegate::CreateNativeAppWindow( |
147 apps::AppWindow* window, | 147 apps::AppWindow* window, |
148 const apps::AppWindow::CreateParams& params) { | 148 const apps::AppWindow::CreateParams& params) { |
149 return CreateNativeAppWindowImpl(window, params); | 149 return CreateNativeAppWindowImpl(window, params); |
150 } | 150 } |
151 | 151 |
152 content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( | 152 content::WebContents* ChromeAppWindowDelegate::OpenURLFromTab( |
153 content::BrowserContext* context, | 153 content::BrowserContext* context, |
154 content::WebContents* source, | 154 content::WebContents* source, |
155 const content::OpenURLParams& params) { | 155 const content::OpenURLParams& params) { |
156 return OpenURLFromTabInternal(context, source, params); | 156 return OpenURLFromTabInternal(context, source, params); |
157 } | 157 } |
158 | 158 |
159 void ChromeShellWindowDelegate::AddNewContents( | 159 void ChromeAppWindowDelegate::AddNewContents(content::BrowserContext* context, |
160 content::BrowserContext* context, | 160 content::WebContents* new_contents, |
161 content::WebContents* new_contents, | 161 WindowOpenDisposition disposition, |
162 WindowOpenDisposition disposition, | 162 const gfx::Rect& initial_pos, |
163 const gfx::Rect& initial_pos, | 163 bool user_gesture, |
164 bool user_gesture, | 164 bool* was_blocked) { |
165 bool* was_blocked) { | |
166 if (!disable_external_open_for_testing_) { | 165 if (!disable_external_open_for_testing_) { |
167 if (!shell_window_link_delegate_.get()) | 166 if (!app_window_link_delegate_.get()) |
168 shell_window_link_delegate_.reset(new ShellWindowLinkDelegate()); | 167 app_window_link_delegate_.reset(new AppWindowLinkDelegate()); |
169 new_contents->SetDelegate(shell_window_link_delegate_.get()); | 168 new_contents->SetDelegate(app_window_link_delegate_.get()); |
170 return; | 169 return; |
171 } | 170 } |
172 chrome::ScopedTabbedBrowserDisplayer displayer( | 171 chrome::ScopedTabbedBrowserDisplayer displayer( |
173 Profile::FromBrowserContext(context), chrome::GetActiveDesktop()); | 172 Profile::FromBrowserContext(context), chrome::GetActiveDesktop()); |
174 // Force all links to open in a new tab, even if they were trying to open a | 173 // Force all links to open in a new tab, even if they were trying to open a |
175 // new window. | 174 // new window. |
176 disposition = | 175 disposition = |
177 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 176 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
178 chrome::AddWebContents(displayer.browser(), NULL, new_contents, disposition, | 177 chrome::AddWebContents(displayer.browser(), NULL, new_contents, disposition, |
179 initial_pos, user_gesture, was_blocked); | 178 initial_pos, user_gesture, was_blocked); |
180 } | 179 } |
181 | 180 |
182 content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( | 181 content::ColorChooser* ChromeAppWindowDelegate::ShowColorChooser( |
183 content::WebContents* web_contents, | 182 content::WebContents* web_contents, |
184 SkColor initial_color) { | 183 SkColor initial_color) { |
185 return chrome::ShowColorChooser(web_contents, initial_color); | 184 return chrome::ShowColorChooser(web_contents, initial_color); |
186 } | 185 } |
187 | 186 |
188 void ChromeShellWindowDelegate::RunFileChooser( | 187 void ChromeAppWindowDelegate::RunFileChooser( |
189 content::WebContents* tab, | 188 content::WebContents* tab, |
190 const content::FileChooserParams& params) { | 189 const content::FileChooserParams& params) { |
191 FileSelectHelper::RunFileChooser(tab, params); | 190 FileSelectHelper::RunFileChooser(tab, params); |
192 } | 191 } |
193 | 192 |
194 void ChromeShellWindowDelegate::RequestMediaAccessPermission( | 193 void ChromeAppWindowDelegate::RequestMediaAccessPermission( |
195 content::WebContents* web_contents, | 194 content::WebContents* web_contents, |
196 const content::MediaStreamRequest& request, | 195 const content::MediaStreamRequest& request, |
197 const content::MediaResponseCallback& callback, | 196 const content::MediaResponseCallback& callback, |
198 const extensions::Extension* extension) { | 197 const extensions::Extension* extension) { |
199 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 198 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
200 web_contents, request, callback, extension); | 199 web_contents, request, callback, extension); |
201 } | 200 } |
202 | 201 |
203 int ChromeShellWindowDelegate::PreferredIconSize() { | 202 int ChromeAppWindowDelegate::PreferredIconSize() { |
204 #if defined(USE_ASH) | 203 #if defined(USE_ASH) |
205 return ash::kShelfPreferredSize; | 204 return ash::kShelfPreferredSize; |
206 #else | 205 #else |
207 return extension_misc::EXTENSION_ICON_SMALL; | 206 return extension_misc::EXTENSION_ICON_SMALL; |
208 #endif | 207 #endif |
209 } | 208 } |
210 | 209 |
211 void ChromeShellWindowDelegate::SetWebContentsBlocked( | 210 void ChromeAppWindowDelegate::SetWebContentsBlocked( |
212 content::WebContents* web_contents, | 211 content::WebContents* web_contents, |
213 bool blocked) { | 212 bool blocked) { |
214 // RenderViewHost may be NULL during shutdown. | 213 // RenderViewHost may be NULL during shutdown. |
215 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | 214 content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
216 if (host) { | 215 if (host) { |
217 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( | 216 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( |
218 host->GetRoutingID(), blocked)); | 217 host->GetRoutingID(), blocked)); |
219 } | 218 } |
220 } | 219 } |
221 | 220 |
222 bool ChromeShellWindowDelegate::IsWebContentsVisible( | 221 bool ChromeAppWindowDelegate::IsWebContentsVisible( |
223 content::WebContents* web_contents) { | 222 content::WebContents* web_contents) { |
224 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); | 223 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); |
225 } | 224 } |
OLD | NEW |