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

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

Issue 10911105: Switch ScriptBadgeController and PageActionController to use WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/page_action_controller.h" 5 #include "chrome/browser/extensions/page_action_controller.h"
6 6
7 #include "chrome/browser/extensions/browser_event_router.h" 7 #include "chrome/browser/extensions/browser_event_router.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/tab_helper.h" 10 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/extensions/extension_tab_util.h" 11 #include "chrome/browser/extensions/extension_tab_util.h"
12 #include "chrome/browser/sessions/session_id.h" 12 #include "chrome/browser/sessions/session_id.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/extensions/extension_set.h" 14 #include "chrome/common/extensions/extension_set.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "content/public/browser/invalidate_type.h" 16 #include "content/public/browser/invalidate_type.h"
17 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 PageActionController::PageActionController(TabContents* tab_contents) 23 PageActionController::PageActionController(content::WebContents* web_contents)
24 : content::WebContentsObserver(tab_contents->web_contents()), 24 : content::WebContentsObserver(web_contents) {}
25 tab_contents_(tab_contents) {}
26 25
27 PageActionController::~PageActionController() {} 26 PageActionController::~PageActionController() {}
28 27
29 std::vector<ExtensionAction*> PageActionController::GetCurrentActions() const { 28 std::vector<ExtensionAction*> PageActionController::GetCurrentActions() const {
30 ExtensionService* service = GetExtensionService(); 29 ExtensionService* service = GetExtensionService();
31 if (!service) 30 if (!service)
32 return std::vector<ExtensionAction*>(); 31 return std::vector<ExtensionAction*>();
33 32
34 std::vector<ExtensionAction*> current_actions; 33 std::vector<ExtensionAction*> current_actions;
35 34
36 for (ExtensionSet::const_iterator i = service->extensions()->begin(); 35 for (ExtensionSet::const_iterator i = service->extensions()->begin();
37 i != service->extensions()->end(); ++i) { 36 i != service->extensions()->end(); ++i) {
38 ExtensionAction* action = (*i)->page_action(); 37 ExtensionAction* action = (*i)->page_action();
39 if (action) 38 if (action)
40 current_actions.push_back(action); 39 current_actions.push_back(action);
41 } 40 }
42 return current_actions; 41 return current_actions;
43 } 42 }
44 43
45 LocationBarController::Action PageActionController::OnClicked( 44 LocationBarController::Action PageActionController::OnClicked(
46 const std::string& extension_id, int mouse_button) { 45 const std::string& extension_id, int mouse_button) {
47 ExtensionService* service = GetExtensionService(); 46 ExtensionService* service = GetExtensionService();
48 if (!service) 47 if (!service)
49 return ACTION_NONE; 48 return ACTION_NONE;
50 49
51 const Extension* extension = service->extensions()->GetByID(extension_id); 50 const Extension* extension = service->extensions()->GetByID(extension_id);
52 CHECK(extension); 51 CHECK(extension);
53 ExtensionAction* page_action = extension->page_action(); 52 ExtensionAction* page_action = extension->page_action();
54 CHECK(page_action); 53 CHECK(page_action);
55 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); 54 int tab_id = ExtensionTabUtil::GetTabId(web_contents());
56 55
57 tab_contents_->extension_tab_helper()->active_tab_permission_manager()-> 56 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
57 tab_contents->extension_tab_helper()->active_tab_permission_manager()->
58 GrantIfRequested(extension); 58 GrantIfRequested(extension);
59 59
60 switch (mouse_button) { 60 switch (mouse_button) {
61 case 1: // left 61 case 1: // left
62 case 2: // middle 62 case 2: // middle
63 if (page_action->HasPopup(tab_id)) 63 if (page_action->HasPopup(tab_id))
64 return ACTION_SHOW_POPUP; 64 return ACTION_SHOW_POPUP;
65 65
66 GetExtensionService()->browser_event_router()->PageActionExecuted( 66 GetExtensionService()->browser_event_router()->PageActionExecuted(
67 tab_contents_->profile(), 67 tab_contents->profile(),
68 *page_action, 68 *page_action,
69 tab_id, 69 tab_id,
70 tab_contents_->web_contents()->GetURL().spec(), 70 web_contents()->GetURL().spec(),
71 mouse_button); 71 mouse_button);
72 return ACTION_NONE; 72 return ACTION_NONE;
73 73
74 case 3: // right 74 case 3: // right
75 return extension->ShowConfigureContextMenus() ? 75 return extension->ShowConfigureContextMenus() ?
76 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; 76 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE;
77 } 77 }
78 78
79 return ACTION_NONE; 79 return ACTION_NONE;
80 } 80 }
81 81
82 void PageActionController::NotifyChange() { 82 void PageActionController::NotifyChange() {
83 tab_contents_->web_contents()->NotifyNavigationStateChanged( 83 web_contents()->NotifyNavigationStateChanged(
84 content::INVALIDATE_TYPE_PAGE_ACTIONS); 84 content::INVALIDATE_TYPE_PAGE_ACTIONS);
85 } 85 }
86 86
87 void PageActionController::DidNavigateMainFrame( 87 void PageActionController::DidNavigateMainFrame(
88 const content::LoadCommittedDetails& details, 88 const content::LoadCommittedDetails& details,
89 const content::FrameNavigateParams& params) { 89 const content::FrameNavigateParams& params) {
90 if (details.is_in_page) 90 if (details.is_in_page)
91 return; 91 return;
92 92
93 const std::vector<ExtensionAction*> current_actions = GetCurrentActions(); 93 const std::vector<ExtensionAction*> current_actions = GetCurrentActions();
94 94
95 if (current_actions.empty()) 95 if (current_actions.empty())
96 return; 96 return;
97 97
98 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
98 for (size_t i = 0; i < current_actions.size(); ++i) { 99 for (size_t i = 0; i < current_actions.size(); ++i) {
99 current_actions[i]->ClearAllValuesForTab( 100 current_actions[i]->ClearAllValuesForTab(
100 SessionID::IdForTab(tab_contents_)); 101 SessionID::IdForTab(tab_contents));
101 } 102 }
102 103
103 NotifyChange(); 104 NotifyChange();
104 } 105 }
105 106
106 ExtensionService* PageActionController::GetExtensionService() const { 107 ExtensionService* PageActionController::GetExtensionService() const {
107 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); 108 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
109 return ExtensionSystem::Get(tab_contents->profile())->extension_service();
108 } 110 }
109 111
110 } // namespace extensions 112 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698