OLD | NEW |
---|---|
(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/location_bar_controller.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/extensions/active_script_controller.h" | |
9 #include "chrome/browser/extensions/extension_action.h" | |
10 #include "chrome/browser/extensions/page_action_controller.h" | |
11 #include "chrome/common/extensions/api/extension_action/action_info.h" | |
12 #include "content/public/browser/invalidate_type.h" | |
13 #include "content/public/browser/navigation_details.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "extensions/browser/extension_registry.h" | |
16 | |
17 namespace extensions { | |
18 | |
19 LocationBarController::LocationBarController( | |
20 content::WebContents* web_contents) | |
21 : WebContentsObserver(web_contents), | |
22 web_contents_(web_contents), | |
23 active_script_controller_(new ActiveScriptController(web_contents_)), | |
24 page_action_controller_(new PageActionController(web_contents_)) { | |
25 } | |
26 | |
27 LocationBarController::~LocationBarController() { | |
28 } | |
29 | |
30 std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { | |
31 const ExtensionSet& extensions = | |
32 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) | |
33 ->enabled_extensions(); | |
34 std::vector<ExtensionAction*> current_actions; | |
35 for (ExtensionSet::const_iterator iter = extensions.begin(); | |
36 iter != extensions.end(); | |
37 ++iter) { | |
38 // Right now, we can consolidate these actions because we only want to show | |
39 // one action per extension. If clicking on an active script action ever | |
40 // has a response, then we will need to split the actions. | |
41 ExtensionAction* action = | |
42 page_action_controller_->GetActionForExtension(*iter); | |
43 if (!action) | |
44 action = active_script_controller_->GetActionForExtension(*iter); | |
45 if (action) | |
46 current_actions.push_back(action); | |
47 } | |
48 | |
49 return current_actions; | |
50 } | |
51 | |
52 LocationBarController::Action LocationBarController::OnClicked( | |
53 const ExtensionAction* action) { | |
54 const Extension* extension = | |
55 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) | |
56 ->enabled_extensions().GetByID(action->extension_id()); | |
57 CHECK(extension); | |
58 | |
59 Action page_action = page_action_controller_->OnClicked(extension); | |
not at google - send to devlin
2014/05/08 20:47:09
It's a bit weird to be sending these events if the
Devlin
2014/05/08 23:01:00
We're already checking in each of the classes, and
| |
60 Action active_script_action = active_script_controller_->OnClicked(extension); | |
61 | |
62 // PageAction response takes priority. | |
63 return page_action != ACTION_NONE ? page_action : active_script_action; | |
64 } | |
65 | |
66 // static | |
67 void LocationBarController::NotifyChange(content::WebContents* web_contents) { | |
68 web_contents->NotifyNavigationStateChanged( | |
69 content::INVALIDATE_TYPE_PAGE_ACTIONS); | |
70 } | |
71 | |
72 void LocationBarController::DidNavigateMainFrame( | |
73 const content::LoadCommittedDetails& details, | |
74 const content::FrameNavigateParams& params) { | |
75 if (details.is_in_page) | |
76 return; | |
77 | |
78 page_action_controller_->OnNavigated(); | |
79 active_script_controller_->OnNavigated(); | |
80 } | |
81 | |
82 } // namespace extensions | |
OLD | NEW |