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/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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 return extension->ShowConfigureContextMenus() ? | 85 return extension->ShowConfigureContextMenus() ? |
86 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | 86 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
87 } | 87 } |
88 | 88 |
89 return ACTION_NONE; | 89 return ACTION_NONE; |
90 } | 90 } |
91 | 91 |
92 void ScriptBadgeController::OnExecuteScriptFinished( | 92 void ScriptBadgeController::OnExecuteScriptFinished( |
93 const std::string& extension_id, | 93 const std::string& extension_id, |
94 bool success, | 94 bool success, |
95 int32 page_id, | 95 int32 on_page_id, |
96 const std::string& error, | 96 const std::string& error, |
97 const base::ListValue& script_results) { | 97 const base::ListValue& script_results) { |
98 if (success && page_id == GetPageID()) { | 98 if (!success) |
99 if (MarkExtensionExecuting(extension_id)) | 99 return; |
100 NotifyChange(); | 100 |
101 int current_page_id = GetPageID(); | |
102 if (on_page_id < current_page_id) | |
Jeffrey Yasskin
2012/07/25 22:22:39
Is there documentation that the page id monotonica
not at google - send to devlin
2012/07/26 08:52:46
Yeah, I don't know. @jam do you know?
| |
103 return; | |
104 if (on_page_id > current_page_id) { | |
105 future_actions_[on_page_id].push_back(extension_id); | |
106 return; | |
101 } | 107 } |
108 | |
109 if (MarkExtensionExecuting(extension_id)) | |
110 NotifyChange(); | |
102 } | 111 } |
103 | 112 |
104 ExtensionService* ScriptBadgeController::GetExtensionService() { | 113 ExtensionService* ScriptBadgeController::GetExtensionService() { |
105 return extensions::ExtensionSystem::Get( | 114 return extensions::ExtensionSystem::Get( |
106 tab_contents_->profile())->extension_service(); | 115 tab_contents_->profile())->extension_service(); |
107 } | 116 } |
108 | 117 |
109 int32 ScriptBadgeController::GetPageID() { | 118 int32 ScriptBadgeController::GetPageID() { |
110 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> | 119 content::NavigationEntry* active_entry = |
111 GetPageID(); | 120 tab_contents_->web_contents()->GetController().GetActiveEntry(); |
121 return active_entry ? active_entry->GetPageID() : -1; | |
112 } | 122 } |
113 | 123 |
114 void ScriptBadgeController::NotifyChange() { | 124 void ScriptBadgeController::NotifyChange() { |
115 content::NotificationService::current()->Notify( | 125 content::NotificationService::current()->Notify( |
116 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 126 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
117 content::Source<Profile>(tab_contents_->profile()), | 127 content::Source<Profile>(tab_contents_->profile()), |
118 content::Details<TabContents>(tab_contents_)); | 128 content::Details<TabContents>(tab_contents_)); |
119 } | 129 } |
120 | 130 |
121 void ScriptBadgeController::DidNavigateMainFrame( | 131 void ScriptBadgeController::DidNavigateMainFrame( |
122 const content::LoadCommittedDetails& details, | 132 const content::LoadCommittedDetails& details, |
123 const content::FrameNavigateParams& params) { | 133 const content::FrameNavigateParams& params) { |
124 if (details.is_in_page) | 134 if (details.is_in_page) |
125 return; | 135 return; |
126 extensions_in_current_actions_.clear(); | 136 extensions_in_current_actions_.clear(); |
127 current_actions_.clear(); | 137 current_actions_.clear(); |
138 | |
139 // Immediately process any actions that were made on this page before | |
140 // the browser caught up to it. | |
141 int current_page_id = GetPageID(); | |
142 bool changed = false; | |
143 | |
144 FutureActionsMap::iterator actions = future_actions_.find(current_page_id); | |
145 if (actions != future_actions_.end()) { | |
146 for (std::vector<std::string>::iterator it = actions->second.begin(); | |
147 it != actions->second.end(); ++it) { | |
148 changed |= MarkExtensionExecuting(*it); | |
149 } | |
150 future_actions_.erase(actions); | |
151 } | |
152 | |
153 // We might have skipped over a page ID. | |
154 for (FutureActionsMap::iterator it = future_actions_.begin(); | |
155 it != future_actions_.end();) { | |
156 if (it->first < current_page_id) | |
157 future_actions_.erase(it++); | |
158 else | |
159 ++it; | |
160 } | |
161 | |
162 if (changed) | |
163 NotifyChange(); | |
128 } | 164 } |
129 | 165 |
130 void ScriptBadgeController::Observe( | 166 void ScriptBadgeController::Observe( |
131 int type, | 167 int type, |
132 const content::NotificationSource& source, | 168 const content::NotificationSource& source, |
133 const content::NotificationDetails& details) { | 169 const content::NotificationDetails& details) { |
134 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); | 170 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); |
135 const Extension* extension = | 171 const Extension* extension = |
136 content::Details<UnloadedExtensionInfo>(details)->extension; | 172 content::Details<UnloadedExtensionInfo>(details)->extension; |
137 if (EraseExtension(extension)) | 173 if (EraseExtension(extension)) |
138 NotifyChange(); | 174 NotifyChange(); |
139 } | 175 } |
140 | 176 |
141 bool ScriptBadgeController::OnMessageReceived(const IPC::Message& message) { | 177 bool ScriptBadgeController::OnMessageReceived(const IPC::Message& message) { |
142 bool handled = true; | 178 bool handled = true; |
143 IPC_BEGIN_MESSAGE_MAP(ScriptBadgeController, message) | 179 IPC_BEGIN_MESSAGE_MAP(ScriptBadgeController, message) |
144 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 180 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
145 OnContentScriptsExecuting) | 181 OnContentScriptsExecuting) |
146 IPC_MESSAGE_UNHANDLED(handled = false) | 182 IPC_MESSAGE_UNHANDLED(handled = false) |
147 IPC_END_MESSAGE_MAP() | 183 IPC_END_MESSAGE_MAP() |
148 return handled; | 184 return handled; |
149 } | 185 } |
150 | 186 |
151 void ScriptBadgeController::OnContentScriptsExecuting( | 187 void ScriptBadgeController::OnContentScriptsExecuting( |
152 const std::set<std::string>& extension_ids, int32 page_id) { | 188 const std::set<std::string>& extension_ids, |
153 if (page_id != GetPageID()) | 189 int32 on_page_id) { |
190 int current_page_id = GetPageID(); | |
191 if (on_page_id < current_page_id) | |
154 return; | 192 return; |
193 if (on_page_id > current_page_id) { | |
194 std::vector<std::string>& actions = future_actions_[on_page_id]; | |
195 actions.insert(actions.end(), | |
196 extension_ids.begin(), | |
197 extension_ids.end()); | |
198 return; | |
199 } | |
155 | 200 |
156 bool changed = false; | 201 bool changed = false; |
157 for (std::set<std::string>::const_iterator it = extension_ids.begin(); | 202 for (std::set<std::string>::const_iterator it = extension_ids.begin(); |
158 it != extension_ids.end(); ++it) { | 203 it != extension_ids.end(); ++it) { |
159 changed |= MarkExtensionExecuting(*it); | 204 changed |= MarkExtensionExecuting(*it); |
160 } | 205 } |
161 if (changed) | 206 if (changed) |
162 NotifyChange(); | 207 NotifyChange(); |
163 } | 208 } |
164 | 209 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 current_actions_.erase(it); | 254 current_actions_.erase(it); |
210 break; | 255 break; |
211 } | 256 } |
212 } | 257 } |
213 | 258 |
214 CHECK_EQ(size_before, current_actions_.size() + 1); | 259 CHECK_EQ(size_before, current_actions_.size() + 1); |
215 return true; | 260 return true; |
216 } | 261 } |
217 | 262 |
218 } // namespace extensions | 263 } // namespace extensions |
OLD | NEW |