Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/extensions/extension_action_test_util.cc

Issue 516633002: Stop showing page actions in the location bar with redesign enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 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.
4
5 #include "chrome/browser/extensions/extension_action_test_util.h"
6
7 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/extensions/extension_action_manager.h"
9 #include "chrome/browser/extensions/extension_toolbar_model.h"
10 #include "chrome/browser/extensions/location_bar_controller.h"
11 #include "chrome/browser/extensions/tab_helper.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "content/public/browser/web_contents.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/common/feature_switch.h"
17
18 namespace extensions {
19 namespace extension_action_test_util {
20
21 namespace {
22
23 size_t GetPageActionCount(content::WebContents* web_contents,
24 bool only_count_visible) {
25 DCHECK(web_contents);
26 std::vector<ExtensionAction*> page_actions;
27 // Page actions are either stored in the location bar (and provided by the
28 // LocationBarController), or in the main toolbar (and provided by the
29 // ExtensionToolbarModel), depending on whether or not the extension action
30 // redesign is enabled.
31 if (!FeatureSwitch::extension_action_redesign()->IsEnabled()) {
32 page_actions =
33 TabHelper::FromWebContents(web_contents)->
34 location_bar_controller()->GetCurrentActions();
35 } else {
36 ExtensionToolbarModel* toolbar_model =
37 ExtensionToolbarModel::Get(
38 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
39 const ExtensionList& toolbar_extensions = toolbar_model->toolbar_items();
40 ExtensionActionManager* action_manager =
41 ExtensionActionManager::Get(web_contents->GetBrowserContext());
42 for (ExtensionList::const_iterator iter = toolbar_extensions.begin();
43 iter != toolbar_extensions.end(); ++iter) {
44 ExtensionAction* extension_action = action_manager->GetPageAction(**iter);
45 if (extension_action)
46 page_actions.push_back(extension_action);
Finnur 2014/08/28 11:35:34 Isn't it more efficient (and clearer) to check vis
Devlin 2014/08/28 18:08:53 I was torn (and originally had it that way). The
Finnur 2014/08/29 12:10:41 Yeah, I think this is a little bit better.
47 }
48 }
49
50 size_t count = page_actions.size();
51
52 // Trim any invisible page actions, if necessary.
53 if (only_count_visible) {
54 int tab_id = SessionTabHelper::IdForTab(web_contents);
55 for (std::vector<ExtensionAction*>::iterator iter = page_actions.begin();
56 iter != page_actions.end();) {
57 if (!(*iter)->GetIsVisible(tab_id))
58 --count;
59 }
60 }
61
62 return count;
63 }
64
65 } // namespace
66
67 size_t GetVisiblePageActionCount(content::WebContents* web_contents) {
68 return GetPageActionCount(web_contents, true);
69 }
70
71 size_t GetTotalPageActionCount(content::WebContents* web_contents) {
72 return GetPageActionCount(web_contents, false);
73 }
74
75 } // namespace extension_action_test_util
76 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698