OLD | NEW |
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/script_badge_controller.h" | 5 #include "chrome/browser/extensions/script_badge_controller.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_browser_event_router.h" | 7 #include "chrome/browser/extensions/extension_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/extension_tab_helper.h" | 10 #include "chrome/browser/extensions/extension_tab_helper.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_action.h" | 13 #include "chrome/common/extensions/extension_action.h" |
14 #include "chrome/common/extensions/extension_messages.h" | 14 #include "chrome/common/extensions/extension_messages.h" |
15 #include "chrome/common/extensions/extension_set.h" | 15 #include "chrome/common/extensions/extension_set.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents) | 26 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents, |
27 : content::WebContentsObserver(tab_contents->web_contents()), | 27 ScriptExecutor* script_executor) |
28 script_executor_(tab_contents->web_contents()), | 28 : ScriptExecutor::Observer(script_executor), |
| 29 content::WebContentsObserver(tab_contents->web_contents()), |
29 tab_contents_(tab_contents) { | 30 tab_contents_(tab_contents) { |
30 registrar_.Add(this, | 31 registrar_.Add(this, |
31 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 32 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
32 content::Source<Profile>(tab_contents->profile())); | 33 content::Source<Profile>(tab_contents->profile())); |
33 } | 34 } |
34 | 35 |
35 ScriptBadgeController::~ScriptBadgeController() {} | 36 ScriptBadgeController::~ScriptBadgeController() {} |
36 | 37 |
37 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() const { | 38 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() const { |
38 return current_actions_; | 39 return current_actions_; |
(...skipping 23 matching lines...) Expand all Loading... |
62 tab_contents_->extension_tab_helper()->tab_id()); | 63 tab_contents_->extension_tab_helper()->tab_id()); |
63 return ACTION_NONE; | 64 return ACTION_NONE; |
64 case 3: // right | 65 case 3: // right |
65 return extension->ShowConfigureContextMenus() ? | 66 return extension->ShowConfigureContextMenus() ? |
66 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | 67 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
67 } | 68 } |
68 | 69 |
69 return ACTION_NONE; | 70 return ACTION_NONE; |
70 } | 71 } |
71 | 72 |
72 void ScriptBadgeController::ExecuteScript( | |
73 const std::string& extension_id, | |
74 ScriptExecutor::ScriptType script_type, | |
75 const std::string& code, | |
76 ScriptExecutor::FrameScope frame_scope, | |
77 UserScript::RunLocation run_at, | |
78 ScriptExecutor::WorldType world_type, | |
79 const ExecuteScriptCallback& callback) { | |
80 ExecuteScriptCallback this_callback = base::Bind( | |
81 &ScriptBadgeController::OnExecuteScriptFinished, | |
82 this, | |
83 extension_id, | |
84 callback); | |
85 | |
86 script_executor_.ExecuteScript(extension_id, | |
87 script_type, | |
88 code, | |
89 frame_scope, | |
90 run_at, | |
91 world_type, | |
92 this_callback); | |
93 } | |
94 | |
95 void ScriptBadgeController::OnExecuteScriptFinished( | 73 void ScriptBadgeController::OnExecuteScriptFinished( |
96 const std::string& extension_id, | 74 const std::string& extension_id, |
97 const ExecuteScriptCallback& callback, | |
98 bool success, | 75 bool success, |
99 int32 page_id, | 76 int32 page_id, |
100 const std::string& error) { | 77 const std::string& error) { |
101 if (success && page_id == GetPageID()) { | 78 if (success && page_id == GetPageID()) { |
102 if (InsertExtension(extension_id)) | 79 if (InsertExtension(extension_id)) |
103 NotifyChange(); | 80 NotifyChange(); |
104 } | 81 } |
105 | |
106 callback.Run(success, page_id, error); | |
107 } | 82 } |
108 | 83 |
109 ExtensionService* ScriptBadgeController::GetExtensionService() { | 84 ExtensionService* ScriptBadgeController::GetExtensionService() { |
110 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); | 85 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
111 } | 86 } |
112 | 87 |
113 int32 ScriptBadgeController::GetPageID() { | 88 int32 ScriptBadgeController::GetPageID() { |
114 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> | 89 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> |
115 GetPageID(); | 90 GetPageID(); |
116 } | 91 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 current_actions_.erase(it); | 177 current_actions_.erase(it); |
203 break; | 178 break; |
204 } | 179 } |
205 } | 180 } |
206 | 181 |
207 CHECK_EQ(size_before, current_actions_.size() + 1); | 182 CHECK_EQ(size_before, current_actions_.size() + 1); |
208 return true; | 183 return true; |
209 } | 184 } |
210 | 185 |
211 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |