| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" | 5 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" |
| 7 #include "chrome/browser/extensions/settings_api_bubble_controller.h" | 8 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
| 8 #include "chrome/browser/extensions/settings_api_helpers.h" | 9 #include "chrome/browser/extensions/settings_api_helpers.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" | 12 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" | 14 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" |
| 13 #include "chrome/browser/ui/views/toolbar/home_button.h" | 15 #include "chrome/browser/ui/views/toolbar/home_button.h" |
| 14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 15 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" | 17 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" |
| 18 #include "chrome/common/url_constants.h" |
| 19 #include "content/public/browser/browser_url_handler.h" |
| 20 #include "content/public/browser/navigation_entry.h" |
| 16 | 21 |
| 17 namespace { | 22 namespace { |
| 18 | 23 |
| 19 void ShowSettingsApiBubble(extensions::SettingsApiOverrideType type, | 24 void ShowSettingsApiBubble(extensions::SettingsApiOverrideType type, |
| 20 const std::string& extension_id, | 25 const std::string& extension_id, |
| 21 Profile* profile, | 26 Profile* profile, |
| 22 views::View* anchor_view, | 27 views::View* anchor_view, |
| 23 views::BubbleBorder::Arrow arrow) { | 28 views::BubbleBorder::Arrow arrow) { |
| 24 scoped_ptr<extensions::SettingsApiBubbleController> settings_api_bubble( | 29 scoped_ptr<extensions::SettingsApiBubbleController> settings_api_bubble( |
| 25 new extensions::SettingsApiBubbleController(profile, type)); | 30 new extensions::SettingsApiBubbleController(profile, type)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void MaybeShowExtensionControlledSearchNotification( | 68 void MaybeShowExtensionControlledSearchNotification( |
| 64 Profile* profile, | 69 Profile* profile, |
| 65 content::WebContents* web_contents, | 70 content::WebContents* web_contents, |
| 66 const AutocompleteMatch& match) { | 71 const AutocompleteMatch& match) { |
| 67 #if !defined(OS_WIN) | 72 #if !defined(OS_WIN) |
| 68 return; | 73 return; |
| 69 #endif | 74 #endif |
| 70 | 75 |
| 71 if (AutocompleteMatch::IsSearchType(match.type) && | 76 if (AutocompleteMatch::IsSearchType(match.type) && |
| 72 match.type != AutocompleteMatchType::SEARCH_OTHER_ENGINE) { | 77 match.type != AutocompleteMatchType::SEARCH_OTHER_ENGINE) { |
| 73 const extensions::Extension* extension = | 78 const Extension* extension = |
| 74 OverridesSearchEngine(profile, NULL); | 79 OverridesSearchEngine(profile, NULL); |
| 75 if (extension) { | 80 if (extension) { |
| 76 ToolbarView* toolbar = | 81 ToolbarView* toolbar = |
| 77 BrowserView::GetBrowserViewForBrowser( | 82 BrowserView::GetBrowserViewForBrowser( |
| 78 chrome::FindBrowserWithWebContents(web_contents))->toolbar(); | 83 chrome::FindBrowserWithWebContents(web_contents))->toolbar(); |
| 79 ShowSettingsApiBubble(BUBBLE_TYPE_SEARCH_ENGINE, | 84 ShowSettingsApiBubble(BUBBLE_TYPE_SEARCH_ENGINE, |
| 80 extension->id(), | 85 extension->id(), |
| 81 profile, | 86 profile, |
| 82 toolbar->app_menu(), | 87 toolbar->app_menu(), |
| 83 views::BubbleBorder::TOP_RIGHT); | 88 views::BubbleBorder::TOP_RIGHT); |
| 84 } | 89 } |
| 85 } | 90 } |
| 86 } | 91 } |
| 87 | 92 |
| 93 void MaybeShowExtensionControlledNewTabPage( |
| 94 Browser* browser, content::WebContents* web_contents) { |
| 95 #if !defined(OS_WIN) |
| 96 return; |
| 97 #endif |
| 98 |
| 99 content::NavigationEntry* entry = |
| 100 web_contents->GetController().GetActiveEntry(); |
| 101 if (!entry) |
| 102 return; |
| 103 GURL active_url = entry->GetURL(); |
| 104 if (!active_url.SchemeIs("chrome-extension")) |
| 105 return; // Not a URL that we care about. |
| 106 |
| 107 // See if the current active URL matches a transformed NewTab URL. |
| 108 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 109 bool ignored_param; |
| 110 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 111 &ntp_url, |
| 112 web_contents->GetBrowserContext(), |
| 113 &ignored_param); |
| 114 if (ntp_url != active_url) |
| 115 return; // Not being overridden by an extension. |
| 116 |
| 117 scoped_ptr<NtpOverriddenBubbleController> ntp_overridden_bubble( |
| 118 new NtpOverriddenBubbleController(browser->profile())); |
| 119 if (!ntp_overridden_bubble->ShouldShow(ntp_url.host())) |
| 120 return; |
| 121 |
| 122 NtpOverriddenBubbleController* controller = ntp_overridden_bubble.get(); |
| 123 ExtensionMessageBubbleView* bubble_delegate = |
| 124 new ExtensionMessageBubbleView( |
| 125 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(), |
| 126 views::BubbleBorder::TOP_RIGHT, |
| 127 ntp_overridden_bubble.PassAs< |
| 128 ExtensionMessageBubbleController>()); |
| 129 views::BubbleDelegateView::CreateBubble(bubble_delegate); |
| 130 controller->Show(bubble_delegate); |
| 131 } |
| 132 |
| 88 } // namespace extensions | 133 } // namespace extensions |
| OLD | NEW |