• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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#import <Cocoa/Cocoa.h>
6
7#include "base/i18n/rtl.h"
8#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
9#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
10#include "chrome/browser/ui/browser.h"
11#include "chrome/browser/ui/browser_dialogs.h"
12#include "chrome/browser/ui/browser_list.h"
13#include "chrome/browser/ui/browser_window.h"
14#import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controller.h"
15#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16#include "chrome/common/extensions/extension.h"
17#include "chrome/common/extensions/extension_action.h"
18#include "grit/generated_resources.h"
19#include "ui/base/l10n/l10n_util.h"
20
21// When an extension is installed on Mac with neither browser action nor
22// page action icons, show an infobar instead of a popup bubble.
23static void ShowGenericExtensionInstalledInfoBar(
24    const Extension* new_extension,
25    SkBitmap icon,
26    Profile* profile) {
27  Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
28  if (!browser)
29    return;
30
31  TabContents* tab_contents = browser->GetSelectedTabContents();
32  if (!tab_contents)
33    return;
34
35  string16 extension_name = UTF8ToUTF16(new_extension->name());
36  base::i18n::AdjustStringForLocaleDirection(&extension_name);
37  string16 msg =
38      l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING,
39                                 extension_name) +
40      UTF8ToUTF16(" ") +
41      l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO_MAC);
42  InfoBarDelegate* delegate = new SimpleAlertInfoBarDelegate(tab_contents,
43      new SkBitmap(icon), msg, true);
44  tab_contents->AddInfoBar(delegate);
45}
46
47namespace browser {
48
49void ShowExtensionInstalledBubble(
50    const Extension* extension,
51    Browser* browser,
52    const SkBitmap& icon,
53    Profile* profile) {
54  if ((extension->browser_action()) || !extension->omnibox_keyword().empty() ||
55      (extension->page_action() &&
56      !extension->page_action()->default_icon_path().empty())) {
57    // The controller is deallocated when the window is closed, so no need to
58    // worry about it here.
59    [[ExtensionInstalledBubbleController alloc]
60        initWithParentWindow:browser->window()->GetNativeHandle()
61                   extension:extension
62                     browser:browser
63                        icon:icon];
64  } else {
65    // If the extension is of type GENERIC, meaning it doesn't have a UI
66    // surface to display for this window, launch infobar instead of popup
67    // bubble, because we have no guaranteed wrench menu button to point to.
68    ShowGenericExtensionInstalledInfoBar(extension, icon, profile);
69  }
70}
71
72} // namespace browser
73