Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_manager_util.cc

Issue 11028121: Convert wallpaper picker to v2 app (Closed) Base URL: http://git.chromium.org/chromium/src.git@AppsV2
Patch Set: Review this patch Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "chrome/browser/ui/chrome_pages.h" 13 #include "chrome/browser/ui/chrome_pages.h"
14 #include "chrome/browser/ui/extensions/application_launch.h"
17 #include "chrome/browser/ui/host_desktop.h" 15 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension_constants.h" 17 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/web_contents.h"
24 #include "ui/gfx/screen.h"
25 19
26 namespace wallpaper_manager_util { 20 namespace wallpaper_manager_util {
27 namespace {
28
29 Browser* GetBrowserForUrl(GURL target_url) {
30 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
31 browser_iterator != BrowserList::end(); ++browser_iterator) {
32 Browser* browser = *browser_iterator;
33 TabStripModel* tab_strip = browser->tab_strip_model();
34 for (int idx = 0; idx < tab_strip->count(); idx++) {
35 content::WebContents* web_contents =
36 tab_strip->GetTabContentsAt(idx)->web_contents();
37 const GURL& url = web_contents->GetURL();
38 if (url == target_url)
39 return browser;
40 }
41 }
42 return NULL;
43 }
44
45 } // namespace
46 21
47 void OpenWallpaperManager() { 22 void OpenWallpaperManager() {
48 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 23 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
49 // Hides the new UI container behind a flag. 24 // Hides the new UI container behind a flag.
50 if (!CommandLine::ForCurrentProcess()->HasSwitch( 25 if (!CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kDisableNewWallpaperUI)) { 26 switches::kDisableNewWallpaperUI)) {
52 std::string url = chrome::kChromeUIWallpaperURL; 27 std::string url = chrome::kChromeUIWallpaperURL;
53 ExtensionService* service = profile->GetExtensionService(); 28 ExtensionService* service = profile->GetExtensionService();
54 if (!service) 29 if (!service)
55 return; 30 return;
56 31
57 const extensions::Extension* extension = 32 const extensions::Extension* extension =
58 service->GetExtensionById(extension_misc::kWallpaperManagerId, false); 33 service->GetExtensionById(extension_misc::kWallpaperManagerId, false);
59 if (!extension) 34 if (!extension)
60 return; 35 return;
61 36
62 GURL wallpaper_picker_url(url); 37 application_launch::LaunchParams params(profile, extension,
63 int width = extension->launch_width(); 38 extension_misc::LAUNCH_WINDOW,
64 int height = extension->launch_height(); 39 NEW_FOREGROUND_TAB);
65 const gfx::Size screen = gfx::Screen::GetPrimaryDisplay().size(); 40 params.override_url = GURL(url);
Mihai Parparita -not on Chrome 2012/10/12 00:48:47 This should not be necessary, launching of v2 apps
bshe 2012/10/12 16:28:30 Done.
66 const gfx::Rect bounds((screen.width() - width) / 2, 41 application_launch::OpenApplication(params);
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 } else { 42 } else {
85 Browser* browser = browser::FindOrCreateTabbedBrowser( 43 Browser* browser = browser::FindOrCreateTabbedBrowser(
86 ProfileManager::GetDefaultProfileOrOffTheRecord(), 44 ProfileManager::GetDefaultProfileOrOffTheRecord(),
87 chrome::HOST_DESKTOP_TYPE_ASH); 45 chrome::HOST_DESKTOP_TYPE_ASH);
88 chrome::ShowSettingsSubPage(browser, "setWallpaper"); 46 chrome::ShowSettingsSubPage(browser, "setWallpaper");
89 } 47 }
90 } 48 }
91 49
92 } // namespace wallpaper_manager_util 50 } // namespace wallpaper_manager_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698