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

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

Issue 270153004: Introduce ActiveScriptController; track active extension scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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/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);
not at google - send to devlin 2014/05/08 23:33:19 << action->extension_id();
Devlin 2014/05/09 00:15:32 Done.
58
59 Action page_action =
60 page_action_controller_->GetActionForExtension(extension) ?
61 page_action_controller_->OnClicked(extension) :
62 ACTION_NONE;
63 Action active_script_action =
64 active_script_controller_->GetActionForExtension(extension) ?
65 active_script_controller_->OnClicked(extension) :
66 ACTION_NONE;
67
68 // PageAction response takes priority.
69 return page_action != ACTION_NONE ? page_action : active_script_action;
70 }
71
72 // static
73 void LocationBarController::NotifyChange(content::WebContents* web_contents) {
74 web_contents->NotifyNavigationStateChanged(
75 content::INVALIDATE_TYPE_PAGE_ACTIONS);
76 }
77
78 void LocationBarController::DidNavigateMainFrame(
79 const content::LoadCommittedDetails& details,
80 const content::FrameNavigateParams& params) {
81 if (details.is_in_page)
82 return;
83
84 page_action_controller_->OnNavigated();
85 active_script_controller_->OnNavigated();
86 }
87
88 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698