summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/ash/extension_utils.cc
blob: b4823a30d51c5cc98ca802d960c32ee325a7ae81 (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
// 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/ui/ash/extension_utils.h"

#include "chrome/browser/event_disposition.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/extensions/extension.h"
#include "googleurl/src/gurl.h"

namespace extension_utils {

// Opens an extension.  |event_flags| holds the flags of the event
// which invokes this extension.
void OpenExtension(Profile* profile,
                   const extensions::Extension* extension,
                   int event_flags) {
  DCHECK(profile);
  DCHECK(extension);

  WindowOpenDisposition disposition =
      chrome::DispositionFromEventFlags(event_flags);
  extension_misc::LaunchContainer container;

  if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
    container = extension_misc::LAUNCH_TAB;
  } else if (disposition == NEW_WINDOW) {
    container = extension_misc::LAUNCH_WINDOW;
  } else {
    // Look at preference to find the right launch container.  If no preference
    // is set, launch as a regular tab.
    container =
        profile->GetExtensionService()->extension_prefs()->GetLaunchContainer(
            extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT);
    disposition = NEW_FOREGROUND_TAB;
  }

  application_launch::OpenApplication(application_launch::LaunchParams(
          profile, extension, container, disposition));
}

}  // namespace extension_utils