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