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/chromeos/extensions/wallpaper_manager_util.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_list.h" | |
15 #include "chrome/browser/ui/browser_tabstrip.h" | |
16 #include "chrome/browser/ui/browser_window.h" | |
17 #include "chrome/browser/ui/chrome_pages.h" | 14 #include "chrome/browser/ui/chrome_pages.h" |
| 15 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
21 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
23 #include "chrome/common/url_constants.h" | |
24 #include "content/public/browser/web_contents.h" | |
25 #include "ui/gfx/screen.h" | |
26 | 19 |
27 namespace wallpaper_manager_util { | 20 namespace wallpaper_manager_util { |
28 namespace { | |
29 | |
30 Browser* GetBrowserForUrl(GURL target_url) { | |
31 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); | |
32 browser_iterator != BrowserList::end(); ++browser_iterator) { | |
33 Browser* browser = *browser_iterator; | |
34 TabStripModel* tab_strip = browser->tab_strip_model(); | |
35 for (int idx = 0; idx < tab_strip->count(); idx++) { | |
36 content::WebContents* web_contents = | |
37 tab_strip->GetTabContentsAt(idx)->web_contents(); | |
38 const GURL& url = web_contents->GetURL(); | |
39 if (url == target_url) | |
40 return browser; | |
41 } | |
42 } | |
43 return NULL; | |
44 } | |
45 | |
46 } // namespace | |
47 | 21 |
48 void OpenWallpaperManager() { | 22 void OpenWallpaperManager() { |
49 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 23 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
50 std::string url = chrome::kChromeUIWallpaperURL; | |
51 ExtensionService* service = profile->GetExtensionService(); | 24 ExtensionService* service = profile->GetExtensionService(); |
52 if (!service) | 25 if (!service) |
53 return; | 26 return; |
54 | 27 |
55 const extensions::Extension* extension = | 28 const extensions::Extension* extension = |
56 service->GetExtensionById(extension_misc::kWallpaperManagerId, false); | 29 service->GetExtensionById(extension_misc::kWallpaperManagerId, false); |
57 if (!extension) | 30 if (!extension) |
58 return; | 31 return; |
59 | 32 |
60 GURL wallpaper_picker_url(url); | 33 application_launch::LaunchParams params(profile, extension, |
61 int width = extension->launch_width(); | 34 extension_misc::LAUNCH_WINDOW, |
62 int height = extension->launch_height(); | 35 NEW_WINDOW); |
63 // TODO(oshima|bshe): Open WallpaperManager in the display is is requested. | 36 application_launch::OpenApplication(params); |
64 const gfx::Size screen = | |
65 ash::Shell::GetScreen()->GetPrimaryDisplay().size(); | |
66 const gfx::Rect bounds((screen.width() - width) / 2, | |
67 (screen.height() - height) / 2, | |
68 width, | |
69 height); | |
70 | |
71 Browser* browser = GetBrowserForUrl(wallpaper_picker_url); | |
72 | |
73 if (!browser) { | |
74 browser = new Browser( | |
75 Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, | |
76 extension->name(), | |
77 bounds, | |
78 profile)); | |
79 | |
80 chrome::AddSelectedTabWithURL(browser, wallpaper_picker_url, | |
81 content::PAGE_TRANSITION_LINK); | |
82 } | |
83 browser->window()->Show(); | |
84 } | 37 } |
85 | 38 |
86 } // namespace wallpaper_manager_util | 39 } // namespace wallpaper_manager_util |
OLD | NEW |