app_list_controller_delegate_win.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win.h"
6
7#include "chrome/browser/ui/app_list/app_list_icon_win.h"
8#include "chrome/browser/ui/browser_commands.h"
9#include "chrome/browser/ui/browser_dialogs.h"
10#include "chrome/browser/ui/extensions/application_launch.h"
11#include "chrome/browser/ui/views/app_list/win/app_list_service_win.h"
12#include "chrome/common/extensions/extension.h"
13#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
14#include "net/base/url_util.h"
15#include "ui/base/resource/resource_bundle.h"
16
17AppListControllerDelegateWin::AppListControllerDelegateWin(
18    AppListServiceWin* service)
19    : service_(service) {
20}
21
22AppListControllerDelegateWin::~AppListControllerDelegateWin() {}
23
24void AppListControllerDelegateWin::DismissView() {
25  service_->DismissAppList();
26}
27
28void AppListControllerDelegateWin::ViewClosing() {
29  service_->OnAppListClosing();
30}
31
32gfx::NativeWindow AppListControllerDelegateWin::GetAppListWindow() {
33  return service_->GetAppListWindow();
34}
35
36gfx::ImageSkia AppListControllerDelegateWin::GetWindowIcon() {
37  gfx::ImageSkia* resource = ResourceBundle::GetSharedInstance().
38      GetImageSkiaNamed(GetAppListIconResourceId());
39  return *resource;
40}
41
42AppListControllerDelegate::Pinnable
43    AppListControllerDelegateWin::GetPinnable() {
44  return NO_PIN;
45}
46
47void AppListControllerDelegateWin::ShowForProfileByPath(
48    const base::FilePath& profile_path) {
49  service_->SetProfilePath(profile_path);
50  service_->Show();
51}
52
53void AppListControllerDelegateWin::OnShowExtensionPrompt() {
54  service_->set_can_close(false);
55}
56
57void AppListControllerDelegateWin::OnCloseExtensionPrompt() {
58  service_->set_can_close(true);
59}
60
61bool AppListControllerDelegateWin::CanDoCreateShortcutsFlow() {
62  return true;
63}
64
65void AppListControllerDelegateWin::CreateNewWindow(Profile* profile,
66                                                   bool incognito) {
67  Profile* window_profile = incognito ?
68      profile->GetOffTheRecordProfile() : profile;
69  chrome::NewEmptyWindow(window_profile, chrome::GetActiveDesktop());
70}
71
72void AppListControllerDelegateWin::ActivateApp(
73    Profile* profile,
74    const extensions::Extension* extension,
75    AppListSource source,
76    int event_flags) {
77  LaunchApp(profile, extension, source, event_flags);
78}
79
80void AppListControllerDelegateWin::LaunchApp(
81    Profile* profile,
82    const extensions::Extension* extension,
83    AppListSource source,
84    int event_flags) {
85  AppListServiceImpl::RecordAppListAppLaunch();
86
87  AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
88  params.desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
89
90  if (source != LAUNCH_FROM_UNKNOWN &&
91      extension->id() == extension_misc::kWebStoreAppId) {
92    // Set an override URL to include the source.
93    GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
94    params.override_url = net::AppendQueryParameter(
95        extension_url,
96        extension_urls::kWebstoreSourceField,
97        AppListSourceToString(source));
98  }
99
100  OpenApplication(params);
101}
102
103