summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/extensions/wallpaper_manager_util.cc
blob: e9fb98d4a73d0e447264aee9152e1116630ff982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"

#include "base/command_line.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"

namespace wallpaper_manager_util {

void OpenWallpaperManager() {
  Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
  // Hides the new UI container behind a flag.
  if (!CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kDisableNewWallpaperUI)) {
    std::string url = chrome::kChromeUIWallpaperURL;
    ExtensionService* service = profile->GetExtensionService();
    if (!service)
      return;

    const extensions::Extension* extension =
        service->GetExtensionById(extension_misc::kWallpaperManagerId, false);
    if (!extension)
      return;

    application_launch::LaunchParams params(profile, extension,
                                            extension_misc::LAUNCH_WINDOW,
                                            NEW_FOREGROUND_TAB);
    params.override_url = GURL(url);
    application_launch::OpenApplication(params);
  } else {
    Browser* browser = browser::FindOrCreateTabbedBrowser(
        ProfileManager::GetDefaultProfileOrOffTheRecord());
    chrome::ShowSettingsSubPage(browser, "setWallpaper");
  }
}

}  // namespace wallpaper_manager_util