Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / settings_api_bubble_helper_views.cc
blob341dc6124bff781ab9d1861ac6e3c582ef118f0b
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 const std::string& extension_id,
29 Profile* profile,
30 views::View* anchor_view,
31 views::BubbleBorder::Arrow arrow) {
32 scoped_ptr<SettingsApiBubbleController> settings_api_bubble(
33 new SettingsApiBubbleController(profile, type));
34 if (!settings_api_bubble->ShouldShow(extension_id))
35 return;
37 SettingsApiBubbleController* controller = settings_api_bubble.get();
38 ExtensionMessageBubbleView* bubble_delegate = new ExtensionMessageBubbleView(
39 anchor_view, arrow, settings_api_bubble.Pass());
40 views::BubbleDelegateView::CreateBubble(bubble_delegate);
41 controller->Show(bubble_delegate);
44 } // namespace
46 void MaybeShowExtensionControlledHomeNotification(Browser* browser) {
47 #if !defined(OS_WIN)
48 return;
49 #endif
51 const Extension* extension =
52 GetExtensionOverridingHomepage(browser->profile());
53 if (extension) {
54 // The bubble will try to anchor itself against the home button
55 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)->
56 toolbar()->home_button();
57 ShowSettingsApiBubble(BUBBLE_TYPE_HOME_PAGE,
58 extension->id(),
59 browser->profile(),
60 anchor_view,
61 views::BubbleBorder::TOP_LEFT);
65 void MaybeShowExtensionControlledSearchNotification(
66 Profile* profile,
67 content::WebContents* web_contents,
68 const AutocompleteMatch& match) {
69 #if !defined(OS_WIN)
70 return;
71 #endif
73 if (AutocompleteMatch::IsSearchType(match.type) &&
74 match.type != AutocompleteMatchType::SEARCH_OTHER_ENGINE) {
75 const Extension* extension = GetExtensionOverridingSearchEngine(profile);
76 if (extension) {
77 ToolbarView* toolbar =
78 BrowserView::GetBrowserViewForBrowser(
79 chrome::FindBrowserWithWebContents(web_contents))->toolbar();
80 ShowSettingsApiBubble(BUBBLE_TYPE_SEARCH_ENGINE,
81 extension->id(),
82 profile,
83 toolbar->app_menu(),
84 views::BubbleBorder::TOP_RIGHT);
89 void MaybeShowExtensionControlledNewTabPage(
90 Browser* browser, content::WebContents* web_contents) {
91 #if !defined(OS_WIN)
92 return;
93 #endif
95 content::NavigationEntry* entry =
96 web_contents->GetController().GetActiveEntry();
97 if (!entry)
98 return;
99 GURL active_url = entry->GetURL();
100 if (!active_url.SchemeIs("chrome-extension"))
101 return; // Not a URL that we care about.
103 // See if the current active URL matches a transformed NewTab URL.
104 GURL ntp_url(chrome::kChromeUINewTabURL);
105 bool ignored_param;
106 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
107 &ntp_url,
108 web_contents->GetBrowserContext(),
109 &ignored_param);
110 if (ntp_url != active_url)
111 return; // Not being overridden by an extension.
113 scoped_ptr<NtpOverriddenBubbleController> ntp_overridden_bubble(
114 new NtpOverriddenBubbleController(browser->profile()));
115 if (!ntp_overridden_bubble->ShouldShow(ntp_url.host()))
116 return;
118 NtpOverriddenBubbleController* controller = ntp_overridden_bubble.get();
119 ExtensionMessageBubbleView* bubble_delegate = new ExtensionMessageBubbleView(
120 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(),
121 views::BubbleBorder::TOP_RIGHT,
122 ntp_overridden_bubble.Pass());
123 views::BubbleDelegateView::CreateBubble(bubble_delegate);
124 controller->Show(bubble_delegate);
127 } // namespace extensions