Chromium Code Reviews| 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 "base/logging.h" | |
| 8 #include "base/string_util.h" | |
| 7 #include "chrome/browser/extensions/browser_event_router.h" | 9 #include "chrome/browser/extensions/browser_event_router.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/sessions/session_id.h" | 13 #include "chrome/browser/sessions/session_id.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_action.h" | 16 #include "chrome/common/extensions/extension_action.h" |
| 15 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
| 16 #include "chrome/common/extensions/extension_set.h" | 18 #include "chrome/common/extensions/extension_set.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
| 20 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "googleurl/src/gurl.h" | |
| 23 #include "ipc/ipc_message.h" | 26 #include "ipc/ipc_message.h" |
| 24 #include "ipc/ipc_message_macros.h" | 27 #include "ipc/ipc_message_macros.h" |
| 25 | 28 |
| 26 namespace extensions { | 29 namespace extensions { |
| 27 | 30 |
| 28 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents, | 31 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents, |
| 29 ScriptExecutor* script_executor) | 32 ScriptExecutor* script_executor) |
| 30 : ScriptExecutor::Observer(script_executor), | 33 : ScriptExecutor::Observer(script_executor), |
| 31 content::WebContentsObserver(tab_contents->web_contents()), | 34 content::WebContentsObserver(tab_contents->web_contents()), |
| 32 tab_contents_(tab_contents) { | 35 tab_contents_(tab_contents) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 99 |
| 97 return extension->ShowConfigureContextMenus() ? | 100 return extension->ShowConfigureContextMenus() ? |
| 98 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | 101 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
| 99 } | 102 } |
| 100 | 103 |
| 101 return ACTION_NONE; | 104 return ACTION_NONE; |
| 102 } | 105 } |
| 103 | 106 |
| 104 void ScriptBadgeController::OnExecuteScriptFinished( | 107 void ScriptBadgeController::OnExecuteScriptFinished( |
| 105 const std::string& extension_id, | 108 const std::string& extension_id, |
| 106 bool success, | |
| 107 int32 page_id, | |
| 108 const std::string& error, | 109 const std::string& error, |
| 110 int32 on_page_id, | |
| 111 const GURL& on_url, | |
| 109 const base::ListValue& script_results) { | 112 const base::ListValue& script_results) { |
| 110 if (success && page_id == GetPageID()) { | 113 int32 current_page_id = GetPageID(); |
| 114 | |
| 115 // Tracking down http://crbug.com/138323. | |
| 116 CHECK_GE(current_page_id, 0) << | |
| 117 "Expect a page ID of " << on_page_id << ", on URL \"" << on_url << | |
|
Jeffrey Yasskin
2012/08/06 11:39:02
Re "buffer on the stack", I assume you'll copy on_
| |
| 118 "\", but there was no navigation entry. Current URL=\"" << | |
| 119 tab_contents_->web_contents()->GetURL() << "\", " << | |
| 120 "extension_id=" << extension_id; | |
| 121 | |
| 122 if (error.empty() && on_page_id == current_page_id) { | |
| 111 if (MarkExtensionExecuting(extension_id)) | 123 if (MarkExtensionExecuting(extension_id)) |
| 112 NotifyChange(); | 124 NotifyChange(); |
| 113 } | 125 } |
| 114 } | 126 } |
| 115 | 127 |
| 116 ExtensionService* ScriptBadgeController::GetExtensionService() { | 128 ExtensionService* ScriptBadgeController::GetExtensionService() { |
| 117 return extensions::ExtensionSystem::Get( | 129 return extensions::ExtensionSystem::Get( |
| 118 tab_contents_->profile())->extension_service(); | 130 tab_contents_->profile())->extension_service(); |
| 119 } | 131 } |
| 120 | 132 |
| 121 int32 ScriptBadgeController::GetPageID() { | 133 int32 ScriptBadgeController::GetPageID() { |
| 122 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> | 134 content::NavigationEntry* nav_entry = |
| 123 GetPageID(); | 135 tab_contents_->web_contents()->GetController().GetActiveEntry(); |
| 136 return nav_entry ? nav_entry->GetPageID() : -1; | |
| 124 } | 137 } |
| 125 | 138 |
| 126 void ScriptBadgeController::NotifyChange() { | 139 void ScriptBadgeController::NotifyChange() { |
| 127 content::NotificationService::current()->Notify( | 140 content::NotificationService::current()->Notify( |
| 128 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 141 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 129 content::Source<Profile>(tab_contents_->profile()), | 142 content::Source<Profile>(tab_contents_->profile()), |
| 130 content::Details<TabContents>(tab_contents_)); | 143 content::Details<TabContents>(tab_contents_)); |
| 131 } | 144 } |
| 132 | 145 |
| 133 void ScriptBadgeController::DidNavigateMainFrame( | 146 void ScriptBadgeController::DidNavigateMainFrame( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 153 bool ScriptBadgeController::OnMessageReceived(const IPC::Message& message) { | 166 bool ScriptBadgeController::OnMessageReceived(const IPC::Message& message) { |
| 154 bool handled = true; | 167 bool handled = true; |
| 155 IPC_BEGIN_MESSAGE_MAP(ScriptBadgeController, message) | 168 IPC_BEGIN_MESSAGE_MAP(ScriptBadgeController, message) |
| 156 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 169 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
| 157 OnContentScriptsExecuting) | 170 OnContentScriptsExecuting) |
| 158 IPC_MESSAGE_UNHANDLED(handled = false) | 171 IPC_MESSAGE_UNHANDLED(handled = false) |
| 159 IPC_END_MESSAGE_MAP() | 172 IPC_END_MESSAGE_MAP() |
| 160 return handled; | 173 return handled; |
| 161 } | 174 } |
| 162 | 175 |
| 176 namespace { | |
| 177 std::string JoinExtensionIDs(const std::set<std::string>& ids) { | |
| 178 std::vector<std::string> as_vector(ids.begin(), ids.end()); | |
| 179 return "[" + JoinString(as_vector, ',') + "]"; | |
| 180 } | |
| 181 } // namespace | |
| 182 | |
| 163 void ScriptBadgeController::OnContentScriptsExecuting( | 183 void ScriptBadgeController::OnContentScriptsExecuting( |
| 164 const std::set<std::string>& extension_ids, int32 page_id) { | 184 const std::set<std::string>& extension_ids, |
| 165 if (page_id != GetPageID()) | 185 int32 on_page_id, |
| 186 const GURL& on_url) { | |
| 187 int32 current_page_id = GetPageID(); | |
| 188 | |
| 189 // Tracking down http://crbug.com/138323. | |
| 190 CHECK_GE(current_page_id, 0) << | |
| 191 "Expect a page ID of " << on_page_id << ", on URL \"" << on_url << | |
| 192 "\", but there was no navigation entry. Current URL=\"" << | |
| 193 tab_contents_->web_contents()->GetURL() << "\", " << | |
| 194 "extension_ids=" << JoinExtensionIDs(extension_ids); | |
| 195 | |
| 196 if (on_page_id != current_page_id) | |
| 166 return; | 197 return; |
| 167 | 198 |
| 168 bool changed = false; | 199 bool changed = false; |
| 169 for (std::set<std::string>::const_iterator it = extension_ids.begin(); | 200 for (std::set<std::string>::const_iterator it = extension_ids.begin(); |
| 170 it != extension_ids.end(); ++it) { | 201 it != extension_ids.end(); ++it) { |
| 171 changed |= MarkExtensionExecuting(*it); | 202 changed |= MarkExtensionExecuting(*it); |
| 172 } | 203 } |
| 173 if (changed) | 204 if (changed) |
| 174 NotifyChange(); | 205 NotifyChange(); |
| 175 } | 206 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 current_actions_.erase(it); | 252 current_actions_.erase(it); |
| 222 break; | 253 break; |
| 223 } | 254 } |
| 224 } | 255 } |
| 225 | 256 |
| 226 CHECK_EQ(size_before, current_actions_.size() + 1); | 257 CHECK_EQ(size_before, current_actions_.size() + 1); |
| 227 return true; | 258 return true; |
| 228 } | 259 } |
| 229 | 260 |
| 230 } // namespace extensions | 261 } // namespace extensions |
| OLD | NEW |