Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / settings_api_bubble_helper_views.cc
blobbac9adb31f3d5cc093e3fde2fb543ee092daced8
1 // Copyright (c) 2014 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.
5 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
7 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h"
8 #include "chrome/browser/extensions/settings_api_bubble_controller.h"
9 #include "chrome/browser/extensions/settings_api_helpers.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
15 #include "chrome/browser/ui/views/toolbar/home_button.h"
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
17 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
18 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/browser_url_handler.h"
21 #include "content/public/browser/navigation_entry.h"
23 namespace extensions {
25 namespace {
27 void ShowSettingsApiBubble(SettingsApiOverrideType type,
28 Browser* browser,
29 views::View* anchor_view,
30 views::BubbleBorder::Arrow arrow) {
31 scoped_ptr<SettingsApiBubbleController> settings_api_bubble(
32 new SettingsApiBubbleController(browser, type));
33 if (!settings_api_bubble->ShouldShow())
34 return;
36 SettingsApiBubbleController* controller = settings_api_bubble.get();
37 ExtensionMessageBubbleView* bubble_delegate = new ExtensionMessageBubbleView(
38 anchor_view, arrow, settings_api_bubble.Pass());
39 views::BubbleDelegateView::CreateBubble(bubble_delegate);
40 controller->Show(bubble_delegate);
43 } // namespace
45 void MaybeShowExtensionControlledHomeNotification(Browser* browser) {
46 #if !defined(OS_WIN)
47 return;
48 #endif
50 // The bubble will try to anchor itself against the home button
51 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)->
52 toolbar()->home_button();
53 ShowSettingsApiBubble(BUBBLE_TYPE_HOME_PAGE,
54 browser,
55 anchor_view,
56 views::BubbleBorder::TOP_LEFT);
59 void MaybeShowExtensionControlledSearchNotification(
60 Profile* profile,
61 content::WebContents* web_contents,
62 const AutocompleteMatch& match) {
63 #if !defined(OS_WIN)
64 return;
65 #endif
67 if (AutocompleteMatch::IsSearchType(match.type) &&
68 match.type != AutocompleteMatchType::SEARCH_OTHER_ENGINE) {
69 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
70 ToolbarView* toolbar =
71 BrowserView::GetBrowserViewForBrowser(browser)->toolbar();
72 ShowSettingsApiBubble(BUBBLE_TYPE_SEARCH_ENGINE,
73 browser,
74 toolbar->app_menu(),
75 views::BubbleBorder::TOP_RIGHT);
79 void MaybeShowExtensionControlledNewTabPage(
80 Browser* browser, content::WebContents* web_contents) {
81 #if !defined(OS_WIN)
82 return;
83 #endif
85 content::NavigationEntry* entry =
86 web_contents->GetController().GetActiveEntry();
87 if (!entry)
88 return;
89 GURL active_url = entry->GetURL();
90 if (!active_url.SchemeIs("chrome-extension"))
91 return; // Not a URL that we care about.
93 // See if the current active URL matches a transformed NewTab URL.
94 GURL ntp_url(chrome::kChromeUINewTabURL);
95 bool ignored_param;
96 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
97 &ntp_url,
98 web_contents->GetBrowserContext(),
99 &ignored_param);
100 if (ntp_url != active_url)
101 return; // Not being overridden by an extension.
103 scoped_ptr<NtpOverriddenBubbleController> ntp_overridden_bubble(
104 new NtpOverriddenBubbleController(browser));
105 if (!ntp_overridden_bubble->ShouldShow(ntp_url.host()))
106 return;
108 NtpOverriddenBubbleController* controller = ntp_overridden_bubble.get();
109 ExtensionMessageBubbleView* bubble_delegate = new ExtensionMessageBubbleView(
110 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(),
111 views::BubbleBorder::TOP_RIGHT,
112 ntp_overridden_bubble.Pass());
113 views::BubbleDelegateView::CreateBubble(bubble_delegate);
114 controller->Show(bubble_delegate);
117 } // namespace extensions