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 #if defined(OS_WIN) | |
8 #include <windows.h> | |
9 #include <shellapi.h> | |
10 #endif // OS_WIN | |
11 | |
12 #if defined(OS_POSIX) | |
13 #include "chrome/browser/shell_integration_linux.h" | |
14 #endif // OS_POSIX | |
15 | |
16 #if defined(OS_MACOSX) | |
17 #include <CoreFoundation/CFBundle.h> | |
18 #include <ApplicationServices/ApplicationServices.h> | |
19 #endif // OS_MACOSX | |
Marijn Kruisselbrink
2012/09/04 15:40:53
I think the chromium coding style says platform-sp
| |
20 | |
7 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_process_manager.h" | 22 #include "chrome/browser/extensions/extension_process_manager.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 23 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | 24 #include "chrome/browser/extensions/shell_window_geometry_cache.h" |
11 #include "chrome/browser/extensions/shell_window_registry.h" | 25 #include "chrome/browser/extensions/shell_window_registry.h" |
12 #include "chrome/browser/file_select_helper.h" | 26 #include "chrome/browser/file_select_helper.h" |
13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 27 #include "chrome/browser/infobars/infobar_tab_helper.h" |
14 #include "chrome/browser/intents/web_intents_util.h" | 28 #include "chrome/browser/intents/web_intents_util.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 extension()->HasAPIPermission(APIPermission::kVideoCapture) && | 208 extension()->HasAPIPermission(APIPermission::kVideoCapture) && |
195 !iter->second.empty()) { | 209 !iter->second.empty()) { |
196 devices.push_back(iter->second[0]); | 210 devices.push_back(iter->second[0]); |
197 } | 211 } |
198 | 212 |
199 callback.Run(devices); | 213 callback.Run(devices); |
200 } | 214 } |
201 | 215 |
202 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, | 216 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
203 const content::OpenURLParams& params) { | 217 const content::OpenURLParams& params) { |
218 #if defined(OS_WIN) | |
219 ShellExecuteA(NULL, "open", params.url.spec().c_str(), | |
220 NULL, NULL, SW_SHOWNORMAL); | |
221 #elif defined(OS_POSIX) | |
222 ShellIntegrationLinux::LaunchDefaultBrowser(params.url); | |
223 #elif defined(OS_MACOSX) | |
224 CFURLRef url = CFURLCreateWithBytes( | |
225 NULL, | |
226 (UInt8*)params.url.spec().c_str(), | |
227 params.url.spec().length(), | |
228 kCFStringEncodingASCII, | |
229 NULL | |
230 ); | |
231 LSOpenCFURLRef(url,0); | |
232 CFRelease(url); | |
jeremya
2012/09/03 02:42:29
It's kind of icky to have all these #ifdefs here.
| |
233 #else | |
204 DCHECK(source == web_contents_); | 234 DCHECK(source == web_contents_); |
205 | 235 |
206 if (params.url.host() == extension_->id()) { | 236 if (params.url.host() == extension_->id()) { |
207 AddMessageToDevToolsConsole( | 237 AddMessageToDevToolsConsole( |
208 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 238 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
209 base::StringPrintf( | 239 base::StringPrintf( |
210 "Can't navigate to \"%s\"; apps do not support navigation.", | 240 "Can't navigate to \"%s\"; apps do not support navigation.", |
211 params.url.spec().c_str())); | 241 params.url.spec().c_str())); |
212 return NULL; | 242 return NULL; |
213 } | 243 } |
(...skipping 21 matching lines...) Expand all Loading... | |
235 | 265 |
236 // Force all links to open in a new tab, even if they were trying to open a | 266 // Force all links to open in a new tab, even if they were trying to open a |
237 // window. | 267 // window. |
238 content::OpenURLParams new_tab_params = params; | 268 content::OpenURLParams new_tab_params = params; |
239 new_tab_params.disposition = | 269 new_tab_params.disposition = |
240 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 270 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
241 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 271 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
242 WebContents* new_tab = browser->OpenURL(new_tab_params); | 272 WebContents* new_tab = browser->OpenURL(new_tab_params); |
243 browser->window()->Show(); | 273 browser->window()->Show(); |
244 return new_tab; | 274 return new_tab; |
275 #endif | |
276 source->SetDelegate(NULL); | |
jeremya
2012/09/03 02:42:29
Rather than setting the delegate to the ShellWindo
| |
277 return NULL; | |
245 } | 278 } |
246 | 279 |
247 void ShellWindow::AddNewContents(WebContents* source, | 280 void ShellWindow::AddNewContents(WebContents* source, |
248 WebContents* new_contents, | 281 WebContents* new_contents, |
249 WindowOpenDisposition disposition, | 282 WindowOpenDisposition disposition, |
250 const gfx::Rect& initial_pos, | 283 const gfx::Rect& initial_pos, |
251 bool user_gesture) { | 284 bool user_gesture) { |
252 DCHECK(source == web_contents_); | 285 DCHECK(source == web_contents_); |
253 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 286 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
254 profile_); | 287 profile_); |
288 | |
289 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_POSIX) | |
290 new_contents->SetDelegate(this); | |
291 #else | |
255 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 292 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
256 // Force all links to open in a new tab, even if they were trying to open a | 293 // Force all links to open in a new tab, even if they were trying to open a |
257 // new window. | 294 // new window. |
258 disposition = | 295 disposition = |
259 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 296 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
260 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | 297 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
261 user_gesture); | 298 user_gesture); |
299 #endif | |
262 } | 300 } |
263 | 301 |
264 void ShellWindow::HandleKeyboardEvent( | 302 void ShellWindow::HandleKeyboardEvent( |
265 WebContents* source, | 303 WebContents* source, |
266 const content::NativeWebKeyboardEvent& event) { | 304 const content::NativeWebKeyboardEvent& event) { |
267 DCHECK_EQ(source, web_contents_); | 305 DCHECK_EQ(source, web_contents_); |
268 native_window_->HandleKeyboardEvent(event); | 306 native_window_->HandleKeyboardEvent(event); |
269 } | 307 } |
270 | 308 |
271 void ShellWindow::OnNativeClose() { | 309 void ShellWindow::OnNativeClose() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 return; | 452 return; |
415 | 453 |
416 extensions::ShellWindowGeometryCache* cache = | 454 extensions::ShellWindowGeometryCache* cache = |
417 extensions::ExtensionSystem::Get(profile())-> | 455 extensions::ExtensionSystem::Get(profile())-> |
418 shell_window_geometry_cache(); | 456 shell_window_geometry_cache(); |
419 | 457 |
420 gfx::Rect bounds = native_window_->GetBounds(); | 458 gfx::Rect bounds = native_window_->GetBounds(); |
421 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 459 cache->SaveGeometry(extension()->id(), window_key_, bounds); |
422 } | 460 } |
423 | 461 |
OLD | NEW |