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

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

Issue 10821120: Send user gesture to extensions for page and browser action clicks. (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
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/browser_event_router.h" 5 #include "chrome/browser/extensions/browser_event_router.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
11 #include "chrome/browser/extensions/event_names.h" 11 #include "chrome/browser/extensions/event_names.h"
12 #include "chrome/browser/extensions/event_router.h"
13 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/window_controller.h" 15 #include "chrome/browser/extensions/window_controller.h"
17 #include "chrome/browser/extensions/window_event_router.h" 16 #include "chrome/browser/extensions/window_event_router.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_tabstrip.h" 20 #include "chrome/browser/ui/browser_tabstrip.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (service) { 159 if (service) {
161 service->window_event_router()->OnActiveWindowChanged( 160 service->window_event_router()->OnActiveWindowChanged(
162 browser ? browser->extension_window_controller() : NULL); 161 browser ? browser->extension_window_controller() : NULL);
163 } 162 }
164 } 163 }
165 164
166 void BrowserEventRouter::TabCreatedAt(WebContents* contents, 165 void BrowserEventRouter::TabCreatedAt(WebContents* contents,
167 int index, 166 int index,
168 bool active) { 167 bool active) {
169 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 168 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
170 DispatchEventWithTab(profile, "", events::kOnTabCreated, contents, active); 169 DispatchEventWithTab(profile, "", events::kOnTabCreated, contents, active,
170 EventRouter::USER_GESTURE_NOT_ENABLED);
171 171
172 RegisterForTabNotifications(contents); 172 RegisterForTabNotifications(contents);
173 } 173 }
174 174
175 void BrowserEventRouter::TabInsertedAt(TabContents* contents, 175 void BrowserEventRouter::TabInsertedAt(TabContents* contents,
176 int index, 176 int index,
177 bool active) { 177 bool active) {
178 // If tab is new, send created event. 178 // If tab is new, send created event.
179 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); 179 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents());
180 if (!GetTabEntry(contents->web_contents())) { 180 if (!GetTabEntry(contents->web_contents())) {
181 tab_entries_[tab_id] = TabEntry(); 181 tab_entries_[tab_id] = TabEntry();
182 182
183 TabCreatedAt(contents->web_contents(), index, active); 183 TabCreatedAt(contents->web_contents(), index, active);
184 return; 184 return;
185 } 185 }
186 186
187 ListValue args; 187 ListValue args;
188 args.Append(Value::CreateIntegerValue(tab_id)); 188 args.Append(Value::CreateIntegerValue(tab_id));
189 189
190 DictionaryValue* object_args = new DictionaryValue(); 190 DictionaryValue* object_args = new DictionaryValue();
191 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( 191 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue(
192 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 192 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
193 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( 193 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue(
194 index)); 194 index));
195 args.Append(object_args); 195 args.Append(object_args);
196 196
197 std::string json_args; 197 std::string json_args;
198 base::JSONWriter::Write(&args, &json_args); 198 base::JSONWriter::Write(&args, &json_args);
199 199
200 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args); 200 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args,
201 EventRouter::USER_GESTURE_UNKNOWN);
201 } 202 }
202 203
203 void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) { 204 void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) {
204 if (!GetTabEntry(contents->web_contents())) { 205 if (!GetTabEntry(contents->web_contents())) {
205 // The tab was removed. Don't send detach event. 206 // The tab was removed. Don't send detach event.
206 return; 207 return;
207 } 208 }
208 209
209 ListValue args; 210 ListValue args;
210 args.Append(Value::CreateIntegerValue( 211 args.Append(Value::CreateIntegerValue(
211 ExtensionTabUtil::GetTabId(contents->web_contents()))); 212 ExtensionTabUtil::GetTabId(contents->web_contents())));
212 213
213 DictionaryValue* object_args = new DictionaryValue(); 214 DictionaryValue* object_args = new DictionaryValue();
214 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( 215 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue(
215 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 216 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
216 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( 217 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue(
217 index)); 218 index));
218 args.Append(object_args); 219 args.Append(object_args);
219 220
220 std::string json_args; 221 std::string json_args;
221 base::JSONWriter::Write(&args, &json_args); 222 base::JSONWriter::Write(&args, &json_args);
222 223
223 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args); 224 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args,
225 EventRouter::USER_GESTURE_UNKNOWN);
224 } 226 }
225 227
226 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, 228 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
227 TabContents* contents, 229 TabContents* contents,
228 int index) { 230 int index) {
229 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); 231 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents());
230 232
231 ListValue args; 233 ListValue args;
232 args.Append(Value::CreateIntegerValue(tab_id)); 234 args.Append(Value::CreateIntegerValue(tab_id));
233 235
234 DictionaryValue* object_args = new DictionaryValue(); 236 DictionaryValue* object_args = new DictionaryValue();
235 object_args->SetBoolean(tab_keys::kWindowClosing, 237 object_args->SetBoolean(tab_keys::kWindowClosing,
236 tab_strip_model->closing_all()); 238 tab_strip_model->closing_all());
237 args.Append(object_args); 239 args.Append(object_args);
238 240
239 std::string json_args; 241 std::string json_args;
240 base::JSONWriter::Write(&args, &json_args); 242 base::JSONWriter::Write(&args, &json_args);
241 243
242 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args); 244 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args,
245 EventRouter::USER_GESTURE_UNKNOWN);
243 246
244 int removed_count = tab_entries_.erase(tab_id); 247 int removed_count = tab_entries_.erase(tab_id);
245 DCHECK_GT(removed_count, 0); 248 DCHECK_GT(removed_count, 0);
246 249
247 UnregisterForTabNotifications(contents->web_contents()); 250 UnregisterForTabNotifications(contents->web_contents());
248 } 251 }
249 252
250 void BrowserEventRouter::ActiveTabChanged(TabContents* old_contents, 253 void BrowserEventRouter::ActiveTabChanged(TabContents* old_contents,
251 TabContents* new_contents, 254 TabContents* new_contents,
252 int index, 255 int index,
(...skipping 12 matching lines...) Expand all
265 std::string old_json_args; 268 std::string old_json_args;
266 base::JSONWriter::Write(&args, &old_json_args); 269 base::JSONWriter::Write(&args, &old_json_args);
267 270
268 // The onActivated event takes one argument: {windowId, tabId}. 271 // The onActivated event takes one argument: {windowId, tabId}.
269 std::string new_json_args; 272 std::string new_json_args;
270 args.Remove(0, NULL); 273 args.Remove(0, NULL);
271 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); 274 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id));
272 base::JSONWriter::Write(&args, &new_json_args); 275 base::JSONWriter::Write(&args, &new_json_args);
273 276
274 Profile* profile = new_contents->profile(); 277 Profile* profile = new_contents->profile();
275 DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args); 278 EventRouter::UserGestureState gesture = user_gesture ?
276 DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args); 279 EventRouter::USER_GESTURE_ENABLED : EventRouter::USER_GESTURE_NOT_ENABLED;
Matt Perry 2012/08/01 11:57:17 Hmm... yes, technically a user gesture caused this
Greg Billock 2012/08/01 16:43:43 I think this is an accurate propagation. That is,
277 DispatchEvent(profile, events::kOnTabActivated, new_json_args); 280 DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args,
281 gesture);
282 DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args, gesture);
283 DispatchEvent(profile, events::kOnTabActivated, new_json_args, gesture);
278 } 284 }
279 285
280 void BrowserEventRouter::TabSelectionChanged( 286 void BrowserEventRouter::TabSelectionChanged(
281 TabStripModel* tab_strip_model, 287 TabStripModel* tab_strip_model,
282 const TabStripSelectionModel& old_model) { 288 const TabStripSelectionModel& old_model) {
283 TabStripSelectionModel::SelectedIndices new_selection = 289 TabStripSelectionModel::SelectedIndices new_selection =
284 tab_strip_model->selection_model().selected_indices(); 290 tab_strip_model->selection_model().selected_indices();
285 ListValue* all = new ListValue(); 291 ListValue* all = new ListValue();
286 292
287 for (size_t i = 0; i < new_selection.size(); ++i) { 293 for (size_t i = 0; i < new_selection.size(); ++i) {
(...skipping 12 matching lines...) Expand all
300 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); 306 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model)));
301 307
302 select_info->Set(tab_keys::kTabIdsKey, all); 308 select_info->Set(tab_keys::kTabIdsKey, all);
303 args.Append(select_info); 309 args.Append(select_info);
304 310
305 std::string json_args; 311 std::string json_args;
306 base::JSONWriter::Write(&args, &json_args); 312 base::JSONWriter::Write(&args, &json_args);
307 313
308 // The onHighlighted event replaced onHighlightChanged. 314 // The onHighlighted event replaced onHighlightChanged.
309 Profile* profile = tab_strip_model->profile(); 315 Profile* profile = tab_strip_model->profile();
310 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args); 316 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args,
311 DispatchEvent(profile, events::kOnTabHighlighted, json_args); 317 EventRouter::USER_GESTURE_UNKNOWN);
318 DispatchEvent(profile, events::kOnTabHighlighted, json_args,
319 EventRouter::USER_GESTURE_UNKNOWN);
312 } 320 }
313 321
314 void BrowserEventRouter::TabMoved(TabContents* contents, 322 void BrowserEventRouter::TabMoved(TabContents* contents,
315 int from_index, 323 int from_index,
316 int to_index) { 324 int to_index) {
317 ListValue args; 325 ListValue args;
318 args.Append(Value::CreateIntegerValue( 326 args.Append(Value::CreateIntegerValue(
319 ExtensionTabUtil::GetTabId(contents->web_contents()))); 327 ExtensionTabUtil::GetTabId(contents->web_contents())));
320 328
321 DictionaryValue* object_args = new DictionaryValue(); 329 DictionaryValue* object_args = new DictionaryValue();
322 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( 330 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
323 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 331 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
324 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( 332 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue(
325 from_index)); 333 from_index));
326 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( 334 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue(
327 to_index)); 335 to_index));
328 args.Append(object_args); 336 args.Append(object_args);
329 337
330 std::string json_args; 338 std::string json_args;
331 base::JSONWriter::Write(&args, &json_args); 339 base::JSONWriter::Write(&args, &json_args);
332 340
333 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args); 341 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args,
342 EventRouter::USER_GESTURE_UNKNOWN);
334 } 343 }
335 344
336 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { 345 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) {
337 TabEntry* entry = GetTabEntry(contents); 346 TabEntry* entry = GetTabEntry(contents);
338 DictionaryValue* changed_properties = NULL; 347 DictionaryValue* changed_properties = NULL;
339 348
340 DCHECK(entry); 349 DCHECK(entry);
341 350
342 if (did_navigate) 351 if (did_navigate)
343 changed_properties = entry->DidNavigate(contents); 352 changed_properties = entry->DidNavigate(contents);
344 else 353 else
345 changed_properties = entry->UpdateLoadState(contents); 354 changed_properties = entry->UpdateLoadState(contents);
346 355
347 if (changed_properties) 356 if (changed_properties)
348 DispatchTabUpdatedEvent(contents, changed_properties); 357 DispatchTabUpdatedEvent(contents, changed_properties);
349 } 358 }
350 359
351 void BrowserEventRouter::DispatchEvent(Profile* profile, 360 void BrowserEventRouter::DispatchEvent(
352 const char* event_name, 361 Profile* profile,
353 const std::string& json_args) { 362 const char* event_name,
363 const std::string& json_args,
364 EventRouter::UserGestureState user_gesture) {
354 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) 365 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter())
355 return; 366 return;
356 367
357 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 368 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
358 event_name, json_args, profile, GURL(), EventFilteringInfo()); 369 event_name, json_args, profile, GURL(), user_gesture);
359 } 370 }
360 371
361 void BrowserEventRouter::DispatchEventToExtension( 372 void BrowserEventRouter::DispatchEventToExtension(
362 Profile* profile, 373 Profile* profile,
363 const std::string& extension_id, 374 const std::string& extension_id,
364 const char* event_name, 375 const char* event_name,
365 const std::string& json_args) { 376 const std::string& json_args,
377 EventRouter::UserGestureState user_gesture) {
366 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) 378 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter())
367 return; 379 return;
368 380
369 profile->GetExtensionEventRouter()->DispatchEventToExtension( 381 profile->GetExtensionEventRouter()->DispatchEventToExtension(
370 extension_id, event_name, json_args, profile, GURL()); 382 extension_id, event_name, json_args, profile, GURL(), user_gesture);
371 } 383 }
372 384
373 void BrowserEventRouter::DispatchEventsAcrossIncognito( 385 void BrowserEventRouter::DispatchEventsAcrossIncognito(
374 Profile* profile, 386 Profile* profile,
375 const char* event_name, 387 const char* event_name,
376 const std::string& json_args, 388 const std::string& json_args,
377 const std::string& cross_incognito_args) { 389 const std::string& cross_incognito_args) {
378 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) 390 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter())
379 return; 391 return;
380 392
381 profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito( 393 profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito(
382 event_name, json_args, profile, cross_incognito_args, GURL()); 394 event_name, json_args, profile, cross_incognito_args, GURL());
383 } 395 }
384 396
385 void BrowserEventRouter::DispatchEventWithTab(Profile* profile, 397 void BrowserEventRouter::DispatchEventWithTab(
386 const std::string& extension_id, 398 Profile* profile,
387 const char* event_name, 399 const std::string& extension_id,
388 const WebContents* web_contents, 400 const char* event_name,
389 bool active) { 401 const WebContents* web_contents,
402 bool active,
403 EventRouter::UserGestureState user_gesture) {
390 if (!profile_->IsSameProfile(profile)) 404 if (!profile_->IsSameProfile(profile))
391 return; 405 return;
392 406
393 ListValue args; 407 ListValue args;
394 args.Append(ExtensionTabUtil::CreateTabValueActive( 408 args.Append(ExtensionTabUtil::CreateTabValueActive(
395 web_contents, active)); 409 web_contents, active));
396 std::string json_args; 410 std::string json_args;
397 base::JSONWriter::Write(&args, &json_args); 411 base::JSONWriter::Write(&args, &json_args);
398 if (!extension_id.empty()) { 412 if (!extension_id.empty()) {
399 DispatchEventToExtension(profile, extension_id, event_name, json_args); 413 DispatchEventToExtension(profile, extension_id, event_name, json_args,
414 user_gesture);
400 } else { 415 } else {
401 DispatchEvent(profile, event_name, json_args); 416 DispatchEvent(profile, event_name, json_args, user_gesture);
402 } 417 }
403 } 418 }
404 419
405 void BrowserEventRouter::DispatchSimpleBrowserEvent( 420 void BrowserEventRouter::DispatchSimpleBrowserEvent(
406 Profile* profile, const int window_id, const char* event_name) { 421 Profile* profile, const int window_id, const char* event_name) {
407 if (!profile_->IsSameProfile(profile)) 422 if (!profile_->IsSameProfile(profile))
408 return; 423 return;
409 424
410 ListValue args; 425 ListValue args;
411 args.Append(Value::CreateIntegerValue(window_id)); 426 args.Append(Value::CreateIntegerValue(window_id));
412 427
413 std::string json_args; 428 std::string json_args;
414 base::JSONWriter::Write(&args, &json_args); 429 base::JSONWriter::Write(&args, &json_args);
415 430
416 DispatchEvent(profile, event_name, json_args); 431 DispatchEvent(profile, event_name, json_args,
432 EventRouter::USER_GESTURE_UNKNOWN);
417 } 433 }
418 434
419 void BrowserEventRouter::DispatchTabUpdatedEvent( 435 void BrowserEventRouter::DispatchTabUpdatedEvent(
420 WebContents* contents, DictionaryValue* changed_properties) { 436 WebContents* contents, DictionaryValue* changed_properties) {
421 DCHECK(changed_properties); 437 DCHECK(changed_properties);
422 DCHECK(contents); 438 DCHECK(contents);
423 439
424 // The state of the tab (as seen from the extension point of view) has 440 // The state of the tab (as seen from the extension point of view) has
425 // changed. Send a notification to the extension. 441 // changed. Send a notification to the extension.
426 ListValue args; 442 ListValue args;
427 443
428 // First arg: The id of the tab that changed. 444 // First arg: The id of the tab that changed.
429 args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); 445 args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
430 446
431 // Second arg: An object containing the changes to the tab state. 447 // Second arg: An object containing the changes to the tab state.
432 args.Append(changed_properties); 448 args.Append(changed_properties);
433 449
434 // Third arg: An object containing the state of the tab. 450 // Third arg: An object containing the state of the tab.
435 args.Append(ExtensionTabUtil::CreateTabValue(contents)); 451 args.Append(ExtensionTabUtil::CreateTabValue(contents));
436 452
437 std::string json_args; 453 std::string json_args;
438 base::JSONWriter::Write(&args, &json_args); 454 base::JSONWriter::Write(&args, &json_args);
439 455
440 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 456 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
441 DispatchEvent(profile, events::kOnTabUpdated, json_args); 457 DispatchEvent(profile, events::kOnTabUpdated, json_args,
458 EventRouter::USER_GESTURE_UNKNOWN);
442 } 459 }
443 460
444 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( 461 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry(
445 const WebContents* contents) { 462 const WebContents* contents) {
446 int tab_id = ExtensionTabUtil::GetTabId(contents); 463 int tab_id = ExtensionTabUtil::GetTabId(contents);
447 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); 464 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id);
448 if (tab_entries_.end() == i) 465 if (tab_entries_.end() == i)
449 return NULL; 466 return NULL;
450 return &i->second; 467 return &i->second;
451 } 468 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 528
512 DictionaryValue* data = new DictionaryValue(); 529 DictionaryValue* data = new DictionaryValue();
513 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); 530 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id));
514 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); 531 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url));
515 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); 532 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button));
516 args.Append(data); 533 args.Append(data);
517 534
518 std::string json_args; 535 std::string json_args;
519 base::JSONWriter::Write(&args, &json_args); 536 base::JSONWriter::Write(&args, &json_args);
520 537
521 DispatchEventToExtension(profile, extension_id, "pageActions", json_args); 538 DispatchEventToExtension(profile, extension_id, "pageActions", json_args,
539 EventRouter::USER_GESTURE_ENABLED);
522 } 540 }
523 541
524 void BrowserEventRouter::BrowserActionExecuted( 542 void BrowserEventRouter::BrowserActionExecuted(
525 const ExtensionAction& browser_action, 543 const ExtensionAction& browser_action,
526 Browser* browser) { 544 Browser* browser) {
527 Profile* profile = browser->profile(); 545 Profile* profile = browser->profile();
528 TabContents* tab_contents = NULL; 546 TabContents* tab_contents = NULL;
529 int tab_id = 0; 547 int tab_id = 0;
530 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) 548 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id))
531 return; 549 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 const std::string& extension_id, 581 const std::string& extension_id,
564 const std::string& command) { 582 const std::string& command) {
565 ListValue args; 583 ListValue args;
566 args.Append(Value::CreateStringValue(command)); 584 args.Append(Value::CreateStringValue(command));
567 std::string json_args; 585 std::string json_args;
568 base::JSONWriter::Write(&args, &json_args); 586 base::JSONWriter::Write(&args, &json_args);
569 587
570 DispatchEventToExtension(profile, 588 DispatchEventToExtension(profile,
571 extension_id, 589 extension_id,
572 "experimental.commands.onCommand", 590 "experimental.commands.onCommand",
573 json_args); 591 json_args,
592 EventRouter::USER_GESTURE_ENABLED);
574 } 593 }
575 594
576 void BrowserEventRouter::ExtensionActionExecuted( 595 void BrowserEventRouter::ExtensionActionExecuted(
577 Profile* profile, 596 Profile* profile,
578 const ExtensionAction& extension_action, 597 const ExtensionAction& extension_action,
579 TabContents* tab_contents) { 598 TabContents* tab_contents) {
580 const char* event_name = NULL; 599 const char* event_name = NULL;
581 switch (extension_action.action_type()) { 600 switch (extension_action.action_type()) {
582 case ExtensionAction::TYPE_BROWSER: 601 case ExtensionAction::TYPE_BROWSER:
583 event_name = "browserAction.onClicked"; 602 event_name = "browserAction.onClicked";
584 break; 603 break;
585 case ExtensionAction::TYPE_PAGE: 604 case ExtensionAction::TYPE_PAGE:
586 event_name = "pageAction.onClicked"; 605 event_name = "pageAction.onClicked";
587 break; 606 break;
588 case ExtensionAction::TYPE_SCRIPT_BADGE: 607 case ExtensionAction::TYPE_SCRIPT_BADGE:
589 event_name = "scriptBadge.onClicked"; 608 event_name = "scriptBadge.onClicked";
590 break; 609 break;
591 } 610 }
592 611
593 if (event_name) { 612 if (event_name) {
594 DispatchEventWithTab(profile, 613 DispatchEventWithTab(profile,
595 extension_action.extension_id(), 614 extension_action.extension_id(),
596 event_name, 615 event_name,
597 tab_contents->web_contents(), 616 tab_contents->web_contents(),
598 true); 617 true,
618 EventRouter::USER_GESTURE_ENABLED);
599 } 619 }
600 } 620 }
601 621
602 } // namespace extensions 622 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/browser_event_router.h ('k') | chrome/browser/extensions/event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698