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

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

Issue 10855064: In ScriptBadgeController, don't CHECK for a valid page ID if there was an error, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/script_badge_controller.h" 5 #include "chrome/browser/extensions/script_badge_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/extensions/browser_event_router.h" 10 #include "chrome/browser/extensions/browser_event_router.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 return ACTION_NONE; 105 return ACTION_NONE;
106 } 106 }
107 107
108 void ScriptBadgeController::OnExecuteScriptFinished( 108 void ScriptBadgeController::OnExecuteScriptFinished(
109 const std::string& extension_id, 109 const std::string& extension_id,
110 const std::string& error, 110 const std::string& error,
111 int32 on_page_id, 111 int32 on_page_id,
112 const GURL& on_url, 112 const GURL& on_url,
113 const base::ListValue& script_results) { 113 const base::ListValue& script_results) {
114 if (!error.empty())
115 return;
116
114 int32 current_page_id = GetPageID(); 117 int32 current_page_id = GetPageID();
115 118
116 // Tracking down http://crbug.com/138323. 119 if (on_page_id == current_page_id) {
117 if (current_page_id < 0) { 120 if (MarkExtensionExecuting(extension_id))
121 NotifyChange();
122 } else if (current_page_id < 0) {
123 // Tracking down http://crbug.com/138323.
118 std::string message = base::StringPrintf( 124 std::string message = base::StringPrintf(
119 "Expected a page ID of %d on URL \"%s\", but there was no navigation " 125 "Expected a page ID of %d but there was no navigation entry. "
120 "entry. Current URL is \"%s\", extension ID is %s.", 126 "Extension ID is %s.",
121 on_page_id, 127 on_page_id,
122 on_url.spec().c_str(),
123 tab_contents_->web_contents()->GetURL().spec().c_str(),
124 extension_id.c_str()); 128 extension_id.c_str());
125 char buf[1024]; 129 char buf[1024];
126 base::snprintf(buf, arraysize(buf), "%s", message.c_str()); 130 base::snprintf(buf, arraysize(buf), "%s", message.c_str());
127 CHECK(false) << message; 131 CHECK(false) << message;
128 } 132 }
129
130 if (error.empty() && on_page_id == current_page_id) {
131 if (MarkExtensionExecuting(extension_id))
132 NotifyChange();
133 }
134 } 133 }
135 134
136 ExtensionService* ScriptBadgeController::GetExtensionService() { 135 ExtensionService* ScriptBadgeController::GetExtensionService() {
137 return extensions::ExtensionSystem::Get( 136 return extensions::ExtensionSystem::Get(
138 tab_contents_->profile())->extension_service(); 137 tab_contents_->profile())->extension_service();
139 } 138 }
140 139
141 int32 ScriptBadgeController::GetPageID() { 140 int32 ScriptBadgeController::GetPageID() {
142 content::NavigationEntry* nav_entry = 141 content::NavigationEntry* nav_entry =
143 tab_contents_->web_contents()->GetController().GetActiveEntry(); 142 tab_contents_->web_contents()->GetController().GetActiveEntry();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::vector<std::string> as_vector(ids.begin(), ids.end()); 185 std::vector<std::string> as_vector(ids.begin(), ids.end());
187 return "[" + JoinString(as_vector, ',') + "]"; 186 return "[" + JoinString(as_vector, ',') + "]";
188 } 187 }
189 } // namespace 188 } // namespace
190 189
191 void ScriptBadgeController::OnContentScriptsExecuting( 190 void ScriptBadgeController::OnContentScriptsExecuting(
192 const std::set<std::string>& extension_ids, 191 const std::set<std::string>& extension_ids,
193 int32 on_page_id, 192 int32 on_page_id,
194 const GURL& on_url) { 193 const GURL& on_url) {
195 int32 current_page_id = GetPageID(); 194 int32 current_page_id = GetPageID();
195 if (on_page_id != current_page_id)
196 return;
196 197
197 // Tracking down http://crbug.com/138323.
198 if (current_page_id < 0) { 198 if (current_page_id < 0) {
199 // Tracking down http://crbug.com/138323.
199 std::string message = base::StringPrintf( 200 std::string message = base::StringPrintf(
200 "Expected a page ID of %d on URL \"%s\", but there was no navigation " 201 "Expected a page ID of %d but there was no navigation entry. "
201 "entry. Current URL is \"%s\", extension IDs are %s.", 202 "Extension IDs are %s.",
202 on_page_id, 203 on_page_id,
203 on_url.spec().c_str(),
204 tab_contents_->web_contents()->GetURL().spec().c_str(),
205 JoinExtensionIDs(extension_ids).c_str()); 204 JoinExtensionIDs(extension_ids).c_str());
206 char buf[1024]; 205 char buf[1024];
207 base::snprintf(buf, arraysize(buf), "%s", message.c_str()); 206 base::snprintf(buf, arraysize(buf), "%s", message.c_str());
208 CHECK(false) << message; 207 CHECK(false) << message;
209 } 208 }
210 209
211 if (on_page_id != current_page_id)
212 return;
213
214 bool changed = false; 210 bool changed = false;
215 for (std::set<std::string>::const_iterator it = extension_ids.begin(); 211 for (std::set<std::string>::const_iterator it = extension_ids.begin();
216 it != extension_ids.end(); ++it) { 212 it != extension_ids.end(); ++it) {
217 changed |= MarkExtensionExecuting(*it); 213 changed |= MarkExtensionExecuting(*it);
218 } 214 }
219 if (changed) 215 if (changed)
220 NotifyChange(); 216 NotifyChange();
221 } 217 }
222 218
223 ExtensionAction* ScriptBadgeController::AddExtensionToCurrentActions( 219 ExtensionAction* ScriptBadgeController::AddExtensionToCurrentActions(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 current_actions_.erase(it); 263 current_actions_.erase(it);
268 break; 264 break;
269 } 265 }
270 } 266 }
271 267
272 CHECK_EQ(size_before, current_actions_.size() + 1); 268 CHECK_EQ(size_before, current_actions_.size() + 1);
273 return true; 269 return true;
274 } 270 }
275 271
276 } // namespace extensions 272 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698