Chromium Code Reviews| Index: chrome/browser/extensions/script_badge_controller.cc |
| diff --git a/chrome/browser/extensions/script_badge_controller.cc b/chrome/browser/extensions/script_badge_controller.cc |
| index c416231475c317661a69832e7f200db18df61cac..566101871831a25b0dfd28fcaa61215cff435741 100644 |
| --- a/chrome/browser/extensions/script_badge_controller.cc |
| +++ b/chrome/browser/extensions/script_badge_controller.cc |
| @@ -92,13 +92,22 @@ LocationBarController::Action ScriptBadgeController::OnClicked( |
| void ScriptBadgeController::OnExecuteScriptFinished( |
| const std::string& extension_id, |
| bool success, |
| - int32 page_id, |
| + int32 on_page_id, |
| const std::string& error, |
| const base::ListValue& script_results) { |
| - if (success && page_id == GetPageID()) { |
| - if (MarkExtensionExecuting(extension_id)) |
| - NotifyChange(); |
| + if (!success) |
| + return; |
| + |
| + int current_page_id = GetPageID(); |
| + 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?
|
| + return; |
| + if (on_page_id > current_page_id) { |
| + future_actions_[on_page_id].push_back(extension_id); |
| + return; |
| } |
| + |
| + if (MarkExtensionExecuting(extension_id)) |
| + NotifyChange(); |
| } |
| ExtensionService* ScriptBadgeController::GetExtensionService() { |
| @@ -107,8 +116,9 @@ ExtensionService* ScriptBadgeController::GetExtensionService() { |
| } |
| int32 ScriptBadgeController::GetPageID() { |
| - return tab_contents_->web_contents()->GetController().GetActiveEntry()-> |
| - GetPageID(); |
| + content::NavigationEntry* active_entry = |
| + tab_contents_->web_contents()->GetController().GetActiveEntry(); |
| + return active_entry ? active_entry->GetPageID() : -1; |
| } |
| void ScriptBadgeController::NotifyChange() { |
| @@ -125,6 +135,32 @@ void ScriptBadgeController::DidNavigateMainFrame( |
| return; |
| extensions_in_current_actions_.clear(); |
| current_actions_.clear(); |
| + |
| + // Immediately process any actions that were made on this page before |
| + // the browser caught up to it. |
| + int current_page_id = GetPageID(); |
| + bool changed = false; |
| + |
| + FutureActionsMap::iterator actions = future_actions_.find(current_page_id); |
| + if (actions != future_actions_.end()) { |
| + for (std::vector<std::string>::iterator it = actions->second.begin(); |
| + it != actions->second.end(); ++it) { |
| + changed |= MarkExtensionExecuting(*it); |
| + } |
| + future_actions_.erase(actions); |
| + } |
| + |
| + // We might have skipped over a page ID. |
| + for (FutureActionsMap::iterator it = future_actions_.begin(); |
| + it != future_actions_.end();) { |
| + if (it->first < current_page_id) |
| + future_actions_.erase(it++); |
| + else |
| + ++it; |
| + } |
| + |
| + if (changed) |
| + NotifyChange(); |
| } |
| void ScriptBadgeController::Observe( |
| @@ -149,9 +185,18 @@ bool ScriptBadgeController::OnMessageReceived(const IPC::Message& message) { |
| } |
| void ScriptBadgeController::OnContentScriptsExecuting( |
| - const std::set<std::string>& extension_ids, int32 page_id) { |
| - if (page_id != GetPageID()) |
| + const std::set<std::string>& extension_ids, |
| + int32 on_page_id) { |
| + int current_page_id = GetPageID(); |
| + if (on_page_id < current_page_id) |
| return; |
| + if (on_page_id > current_page_id) { |
| + std::vector<std::string>& actions = future_actions_[on_page_id]; |
| + actions.insert(actions.end(), |
| + extension_ids.begin(), |
| + extension_ids.end()); |
| + return; |
| + } |
| bool changed = false; |
| for (std::set<std::string>::const_iterator it = extension_ids.begin(); |