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 "apps/shell_window_geometry_cache.h" | 7 #include "apps/shell_window_geometry_cache.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/app_window_contents.h" | 10 #include "chrome/browser/extensions/app_window_contents.h" |
11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/image_loader.h" | 13 #include "chrome/browser/extensions/image_loader.h" |
14 #include "chrome/browser/extensions/shell_window_registry.h" | 14 #include "chrome/browser/extensions/shell_window_registry.h" |
15 #include "chrome/browser/extensions/suggest_permission_util.h" | 15 #include "chrome/browser/extensions/suggest_permission_util.h" |
16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 16 #include "chrome/browser/favicon/favicon_tab_helper.h" |
17 #include "chrome/browser/file_select_helper.h" | 17 #include "chrome/browser/file_select_helper.h" |
18 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
19 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 19 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
20 #include "chrome/browser/platform_util.h" | |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/sessions/session_id.h" | 22 #include "chrome/browser/sessions/session_id.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 24 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/extensions/native_app_window.h" | 28 #include "chrome/browser/ui/extensions/native_app_window.h" |
28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
60 const int kDefaultWidth = 512; | 61 const int kDefaultWidth = 512; |
61 const int kDefaultHeight = 384; | 62 const int kDefaultHeight = 384; |
62 | 63 |
63 // The preferred icon size for displaying the app icon. | 64 // The preferred icon size for displaying the app icon. |
64 #if defined(USE_ASH) | 65 #if defined(USE_ASH) |
65 const int kPreferredIconSize = ash::kLauncherPreferredSize; | 66 const int kPreferredIconSize = ash::kLauncherPreferredSize; |
66 #else | 67 #else |
67 const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; | 68 const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; |
68 #endif | 69 #endif |
69 | 70 |
71 static bool disable_external_open_for_testing_ = false; | |
72 | |
73 class ShellWindowLinkDelegate : public content::WebContentsDelegate { | |
74 private: | |
75 virtual content::WebContents* OpenURLFromTab( | |
76 content::WebContents* source, | |
77 const content::OpenURLParams& params) OVERRIDE; | |
78 }; | |
79 | |
80 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( | |
81 content::WebContents* source, | |
82 const content::OpenURLParams& params) { | |
83 platform_util::OpenExternal(params.url); | |
84 delete source; | |
85 return NULL; | |
miket_OOO
2013/06/03 21:12:38
Hmmm. Is this a common pattern? Fine if it is; it
Ken Rockot(use gerrit already)
2013/06/03 21:24:47
It's not terribly common, but it's not unheard of.
| |
86 } | |
87 | |
70 } // namespace | 88 } // namespace |
71 | 89 |
72 ShellWindow::CreateParams::CreateParams() | 90 ShellWindow::CreateParams::CreateParams() |
73 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 91 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
74 frame(ShellWindow::FRAME_CHROME), | 92 frame(ShellWindow::FRAME_CHROME), |
75 transparent_background(false), | 93 transparent_background(false), |
76 bounds(INT_MIN, INT_MIN, 0, 0), | 94 bounds(INT_MIN, INT_MIN, 0, 0), |
77 creator_process_id(0), | 95 creator_process_id(0), |
78 state(ui::SHOW_STATE_DEFAULT), | 96 state(ui::SHOW_STATE_DEFAULT), |
79 hidden(false), | 97 hidden(false), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 295 } |
278 | 296 |
279 void ShellWindow::AddNewContents(WebContents* source, | 297 void ShellWindow::AddNewContents(WebContents* source, |
280 WebContents* new_contents, | 298 WebContents* new_contents, |
281 WindowOpenDisposition disposition, | 299 WindowOpenDisposition disposition, |
282 const gfx::Rect& initial_pos, | 300 const gfx::Rect& initial_pos, |
283 bool user_gesture, | 301 bool user_gesture, |
284 bool* was_blocked) { | 302 bool* was_blocked) { |
285 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 303 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
286 profile_); | 304 profile_); |
305 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | |
306 if (disable_external_open_for_testing_) { | |
307 Browser* browser = | |
308 chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); | |
309 // Force all links to open in a new tab, even if they were trying to open a | |
310 // new window. | |
311 disposition = | |
312 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
313 chrome::AddWebContents(browser, NULL, new_contents, disposition, | |
314 initial_pos, user_gesture, was_blocked); | |
315 } else { | |
316 new_contents->SetDelegate(new ShellWindowLinkDelegate()); | |
317 } | |
318 #else | |
287 Browser* browser = | 319 Browser* browser = |
288 chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); | 320 chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); |
289 // Force all links to open in a new tab, even if they were trying to open a | 321 // Force all links to open in a new tab, even if they were trying to open a |
290 // new window. | 322 // new window. |
291 disposition = | 323 disposition = |
292 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 324 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
293 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | 325 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
294 user_gesture, was_blocked); | 326 user_gesture, was_blocked); |
327 #endif | |
295 } | 328 } |
296 | 329 |
297 void ShellWindow::HandleKeyboardEvent( | 330 void ShellWindow::HandleKeyboardEvent( |
298 WebContents* source, | 331 WebContents* source, |
299 const content::NativeWebKeyboardEvent& event) { | 332 const content::NativeWebKeyboardEvent& event) { |
300 native_app_window_->HandleKeyboardEvent(event); | 333 native_app_window_->HandleKeyboardEvent(event); |
301 } | 334 } |
302 | 335 |
303 void ShellWindow::RequestToLockMouse(WebContents* web_contents, | 336 void ShellWindow::RequestToLockMouse(WebContents* web_contents, |
304 bool user_gesture, | 337 bool user_gesture, |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 const extensions::DraggableRegion& region = *iter; | 631 const extensions::DraggableRegion& region = *iter; |
599 sk_region->op( | 632 sk_region->op( |
600 region.bounds.x(), | 633 region.bounds.x(), |
601 region.bounds.y(), | 634 region.bounds.y(), |
602 region.bounds.right(), | 635 region.bounds.right(), |
603 region.bounds.bottom(), | 636 region.bounds.bottom(), |
604 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 637 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
605 } | 638 } |
606 return sk_region; | 639 return sk_region; |
607 } | 640 } |
641 | |
642 void ShellWindow::DisableExternalOpenForTesting() { | |
643 disable_external_open_for_testing_ = true; | |
644 } | |
645 | |
OLD | NEW |