| 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/extension_browser_event_router.h" | 5 #include "chrome/browser/extensions/extension_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/extension_event_names.h" | 9 #include "chrome/browser/extensions/extension_event_names.h" |
| 10 #include "chrome/browser/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { | 172 void ExtensionBrowserEventRouter::OnBrowserWindowReady(const Browser* browser) { |
| 173 ListValue args; | 173 ListValue args; |
| 174 | 174 |
| 175 DCHECK(browser->extension_window_controller()); | 175 DCHECK(browser->extension_window_controller()); |
| 176 DictionaryValue* window_dictionary = | 176 DictionaryValue* window_dictionary = |
| 177 browser->extension_window_controller()->CreateWindowValue(); | 177 browser->extension_window_controller()->CreateWindowValue(); |
| 178 args.Append(window_dictionary); | 178 args.Append(window_dictionary); |
| 179 | 179 |
| 180 std::string json_args; | 180 std::string json_args; |
| 181 base::JSONWriter::Write(&args, false, &json_args); | 181 base::JSONWriter::Write(&args, &json_args); |
| 182 | 182 |
| 183 DispatchEvent(browser->profile(), events::kOnWindowCreated, json_args); | 183 DispatchEvent(browser->profile(), events::kOnWindowCreated, json_args); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) { | 186 void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) { |
| 187 if (!profile_->IsSameProfile(browser->profile())) | 187 if (!profile_->IsSameProfile(browser->profile())) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 // Stop listening to TabStripModel events for this browser. | 190 // Stop listening to TabStripModel events for this browser. |
| 191 browser->tabstrip_model()->RemoveObserver(this); | 191 browser->tabstrip_model()->RemoveObserver(this); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 // window_profile is either this profile's default profile, its | 228 // window_profile is either this profile's default profile, its |
| 229 // incognito profile, or NULL iff this profile is losing focus. | 229 // incognito profile, or NULL iff this profile is losing focus. |
| 230 Profile* previous_focused_profile = focused_profile_; | 230 Profile* previous_focused_profile = focused_profile_; |
| 231 focused_profile_ = window_profile; | 231 focused_profile_ = window_profile; |
| 232 focused_window_id_ = window_id; | 232 focused_window_id_ = window_id; |
| 233 | 233 |
| 234 ListValue real_args; | 234 ListValue real_args; |
| 235 real_args.Append(Value::CreateIntegerValue(window_id)); | 235 real_args.Append(Value::CreateIntegerValue(window_id)); |
| 236 std::string real_json_args; | 236 std::string real_json_args; |
| 237 base::JSONWriter::Write(&real_args, false, &real_json_args); | 237 base::JSONWriter::Write(&real_args, &real_json_args); |
| 238 | 238 |
| 239 // When switching between windows in the default and incognitoi profiles, | 239 // When switching between windows in the default and incognitoi profiles, |
| 240 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that | 240 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that |
| 241 // can't see the new focused window across the incognito boundary. | 241 // can't see the new focused window across the incognito boundary. |
| 242 // See crbug.com/46610. | 242 // See crbug.com/46610. |
| 243 std::string none_json_args; | 243 std::string none_json_args; |
| 244 if (focused_profile_ != NULL && previous_focused_profile != NULL && | 244 if (focused_profile_ != NULL && previous_focused_profile != NULL && |
| 245 focused_profile_ != previous_focused_profile) { | 245 focused_profile_ != previous_focused_profile) { |
| 246 ListValue none_args; | 246 ListValue none_args; |
| 247 none_args.Append( | 247 none_args.Append( |
| 248 Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); | 248 Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); |
| 249 base::JSONWriter::Write(&none_args, false, &none_json_args); | 249 base::JSONWriter::Write(&none_args, &none_json_args); |
| 250 } | 250 } |
| 251 | 251 |
| 252 DispatchEventsAcrossIncognito((focused_profile_ ? focused_profile_ : | 252 DispatchEventsAcrossIncognito((focused_profile_ ? focused_profile_ : |
| 253 previous_focused_profile), | 253 previous_focused_profile), |
| 254 events::kOnWindowFocusedChanged, | 254 events::kOnWindowFocusedChanged, |
| 255 real_json_args, | 255 real_json_args, |
| 256 none_json_args); | 256 none_json_args); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ExtensionBrowserEventRouter::TabCreatedAt(WebContents* contents, | 259 void ExtensionBrowserEventRouter::TabCreatedAt(WebContents* contents, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 281 args.Append(Value::CreateIntegerValue(tab_id)); | 281 args.Append(Value::CreateIntegerValue(tab_id)); |
| 282 | 282 |
| 283 DictionaryValue* object_args = new DictionaryValue(); | 283 DictionaryValue* object_args = new DictionaryValue(); |
| 284 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( | 284 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( |
| 285 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 285 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
| 286 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( | 286 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( |
| 287 index)); | 287 index)); |
| 288 args.Append(object_args); | 288 args.Append(object_args); |
| 289 | 289 |
| 290 std::string json_args; | 290 std::string json_args; |
| 291 base::JSONWriter::Write(&args, false, &json_args); | 291 base::JSONWriter::Write(&args, &json_args); |
| 292 | 292 |
| 293 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args); | 293 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void ExtensionBrowserEventRouter::TabDetachedAt(TabContentsWrapper* contents, | 296 void ExtensionBrowserEventRouter::TabDetachedAt(TabContentsWrapper* contents, |
| 297 int index) { | 297 int index) { |
| 298 if (!GetTabEntry(contents->web_contents())) { | 298 if (!GetTabEntry(contents->web_contents())) { |
| 299 // The tab was removed. Don't send detach event. | 299 // The tab was removed. Don't send detach event. |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 | 302 |
| 303 ListValue args; | 303 ListValue args; |
| 304 args.Append(Value::CreateIntegerValue( | 304 args.Append(Value::CreateIntegerValue( |
| 305 ExtensionTabUtil::GetTabId(contents->web_contents()))); | 305 ExtensionTabUtil::GetTabId(contents->web_contents()))); |
| 306 | 306 |
| 307 DictionaryValue* object_args = new DictionaryValue(); | 307 DictionaryValue* object_args = new DictionaryValue(); |
| 308 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( | 308 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( |
| 309 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 309 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
| 310 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( | 310 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( |
| 311 index)); | 311 index)); |
| 312 args.Append(object_args); | 312 args.Append(object_args); |
| 313 | 313 |
| 314 std::string json_args; | 314 std::string json_args; |
| 315 base::JSONWriter::Write(&args, false, &json_args); | 315 base::JSONWriter::Write(&args, &json_args); |
| 316 | 316 |
| 317 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args); | 317 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 320 void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
| 321 TabContentsWrapper* contents, | 321 TabContentsWrapper* contents, |
| 322 int index) { | 322 int index) { |
| 323 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); | 323 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); |
| 324 | 324 |
| 325 ListValue args; | 325 ListValue args; |
| 326 args.Append(Value::CreateIntegerValue(tab_id)); | 326 args.Append(Value::CreateIntegerValue(tab_id)); |
| 327 | 327 |
| 328 DictionaryValue* object_args = new DictionaryValue(); | 328 DictionaryValue* object_args = new DictionaryValue(); |
| 329 object_args->SetBoolean(tab_keys::kWindowClosing, | 329 object_args->SetBoolean(tab_keys::kWindowClosing, |
| 330 tab_strip_model->closing_all()); | 330 tab_strip_model->closing_all()); |
| 331 args.Append(object_args); | 331 args.Append(object_args); |
| 332 | 332 |
| 333 std::string json_args; | 333 std::string json_args; |
| 334 base::JSONWriter::Write(&args, false, &json_args); | 334 base::JSONWriter::Write(&args, &json_args); |
| 335 | 335 |
| 336 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args); | 336 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args); |
| 337 | 337 |
| 338 int removed_count = tab_entries_.erase(tab_id); | 338 int removed_count = tab_entries_.erase(tab_id); |
| 339 DCHECK_GT(removed_count, 0); | 339 DCHECK_GT(removed_count, 0); |
| 340 | 340 |
| 341 UnregisterForTabNotifications(contents->web_contents()); | 341 UnregisterForTabNotifications(contents->web_contents()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void ExtensionBrowserEventRouter::ActiveTabChanged( | 344 void ExtensionBrowserEventRouter::ActiveTabChanged( |
| 345 TabContentsWrapper* old_contents, | 345 TabContentsWrapper* old_contents, |
| 346 TabContentsWrapper* new_contents, | 346 TabContentsWrapper* new_contents, |
| 347 int index, | 347 int index, |
| 348 bool user_gesture) { | 348 bool user_gesture) { |
| 349 ListValue args; | 349 ListValue args; |
| 350 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); | 350 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); |
| 351 args.Append(Value::CreateIntegerValue(tab_id)); | 351 args.Append(Value::CreateIntegerValue(tab_id)); |
| 352 | 352 |
| 353 DictionaryValue* object_args = new DictionaryValue(); | 353 DictionaryValue* object_args = new DictionaryValue(); |
| 354 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 354 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
| 355 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); | 355 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); |
| 356 args.Append(object_args); | 356 args.Append(object_args); |
| 357 | 357 |
| 358 // The onActivated event replaced onActiveChanged and onSelectionChanged. The | 358 // The onActivated event replaced onActiveChanged and onSelectionChanged. The |
| 359 // deprecated events take two arguments: tabId, {windowId}. | 359 // deprecated events take two arguments: tabId, {windowId}. |
| 360 std::string old_json_args; | 360 std::string old_json_args; |
| 361 base::JSONWriter::Write(&args, false, &old_json_args); | 361 base::JSONWriter::Write(&args, &old_json_args); |
| 362 | 362 |
| 363 // The onActivated event takes one argument: {windowId, tabId}. | 363 // The onActivated event takes one argument: {windowId, tabId}. |
| 364 std::string new_json_args; | 364 std::string new_json_args; |
| 365 args.Remove(0, NULL); | 365 args.Remove(0, NULL); |
| 366 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | 366 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
| 367 base::JSONWriter::Write(&args, false, &new_json_args); | 367 base::JSONWriter::Write(&args, &new_json_args); |
| 368 | 368 |
| 369 Profile* profile = new_contents->profile(); | 369 Profile* profile = new_contents->profile(); |
| 370 DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args); | 370 DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args); |
| 371 DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args); | 371 DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args); |
| 372 DispatchEvent(profile, events::kOnTabActivated, new_json_args); | 372 DispatchEvent(profile, events::kOnTabActivated, new_json_args); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void ExtensionBrowserEventRouter::TabSelectionChanged( | 375 void ExtensionBrowserEventRouter::TabSelectionChanged( |
| 376 TabStripModel* tab_strip_model, | 376 TabStripModel* tab_strip_model, |
| 377 const TabStripSelectionModel& old_model) { | 377 const TabStripSelectionModel& old_model) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 391 ListValue args; | 391 ListValue args; |
| 392 DictionaryValue* select_info = new DictionaryValue(); | 392 DictionaryValue* select_info = new DictionaryValue(); |
| 393 | 393 |
| 394 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 394 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
| 395 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); | 395 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
| 396 | 396 |
| 397 select_info->Set(tab_keys::kTabIdsKey, all); | 397 select_info->Set(tab_keys::kTabIdsKey, all); |
| 398 args.Append(select_info); | 398 args.Append(select_info); |
| 399 | 399 |
| 400 std::string json_args; | 400 std::string json_args; |
| 401 base::JSONWriter::Write(&args, false, &json_args); | 401 base::JSONWriter::Write(&args, &json_args); |
| 402 | 402 |
| 403 // The onHighlighted event replaced onHighlightChanged. | 403 // The onHighlighted event replaced onHighlightChanged. |
| 404 Profile* profile = tab_strip_model->profile(); | 404 Profile* profile = tab_strip_model->profile(); |
| 405 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args); | 405 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args); |
| 406 DispatchEvent(profile, events::kOnTabHighlighted, json_args); | 406 DispatchEvent(profile, events::kOnTabHighlighted, json_args); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void ExtensionBrowserEventRouter::TabMoved(TabContentsWrapper* contents, | 409 void ExtensionBrowserEventRouter::TabMoved(TabContentsWrapper* contents, |
| 410 int from_index, | 410 int from_index, |
| 411 int to_index) { | 411 int to_index) { |
| 412 ListValue args; | 412 ListValue args; |
| 413 args.Append(Value::CreateIntegerValue( | 413 args.Append(Value::CreateIntegerValue( |
| 414 ExtensionTabUtil::GetTabId(contents->web_contents()))); | 414 ExtensionTabUtil::GetTabId(contents->web_contents()))); |
| 415 | 415 |
| 416 DictionaryValue* object_args = new DictionaryValue(); | 416 DictionaryValue* object_args = new DictionaryValue(); |
| 417 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 417 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
| 418 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 418 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
| 419 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( | 419 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( |
| 420 from_index)); | 420 from_index)); |
| 421 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( | 421 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( |
| 422 to_index)); | 422 to_index)); |
| 423 args.Append(object_args); | 423 args.Append(object_args); |
| 424 | 424 |
| 425 std::string json_args; | 425 std::string json_args; |
| 426 base::JSONWriter::Write(&args, false, &json_args); | 426 base::JSONWriter::Write(&args, &json_args); |
| 427 | 427 |
| 428 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args); | 428 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void ExtensionBrowserEventRouter::TabUpdated(WebContents* contents, | 431 void ExtensionBrowserEventRouter::TabUpdated(WebContents* contents, |
| 432 bool did_navigate) { | 432 bool did_navigate) { |
| 433 TabEntry* entry = GetTabEntry(contents); | 433 TabEntry* entry = GetTabEntry(contents); |
| 434 DictionaryValue* changed_properties = NULL; | 434 DictionaryValue* changed_properties = NULL; |
| 435 | 435 |
| 436 DCHECK(entry); | 436 DCHECK(entry); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 const char* event_name, | 484 const char* event_name, |
| 485 const WebContents* web_contents, | 485 const WebContents* web_contents, |
| 486 bool active) { | 486 bool active) { |
| 487 if (!profile_->IsSameProfile(profile)) | 487 if (!profile_->IsSameProfile(profile)) |
| 488 return; | 488 return; |
| 489 | 489 |
| 490 ListValue args; | 490 ListValue args; |
| 491 args.Append(ExtensionTabUtil::CreateTabValueActive( | 491 args.Append(ExtensionTabUtil::CreateTabValueActive( |
| 492 web_contents, active)); | 492 web_contents, active)); |
| 493 std::string json_args; | 493 std::string json_args; |
| 494 base::JSONWriter::Write(&args, false, &json_args); | 494 base::JSONWriter::Write(&args, &json_args); |
| 495 if (!extension_id.empty()) { | 495 if (!extension_id.empty()) { |
| 496 DispatchEventToExtension(profile, extension_id, event_name, json_args); | 496 DispatchEventToExtension(profile, extension_id, event_name, json_args); |
| 497 } else { | 497 } else { |
| 498 DispatchEvent(profile, event_name, json_args); | 498 DispatchEvent(profile, event_name, json_args); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 void ExtensionBrowserEventRouter::DispatchSimpleBrowserEvent( | 502 void ExtensionBrowserEventRouter::DispatchSimpleBrowserEvent( |
| 503 Profile* profile, const int window_id, const char* event_name) { | 503 Profile* profile, const int window_id, const char* event_name) { |
| 504 if (!profile_->IsSameProfile(profile)) | 504 if (!profile_->IsSameProfile(profile)) |
| 505 return; | 505 return; |
| 506 | 506 |
| 507 ListValue args; | 507 ListValue args; |
| 508 args.Append(Value::CreateIntegerValue(window_id)); | 508 args.Append(Value::CreateIntegerValue(window_id)); |
| 509 | 509 |
| 510 std::string json_args; | 510 std::string json_args; |
| 511 base::JSONWriter::Write(&args, false, &json_args); | 511 base::JSONWriter::Write(&args, &json_args); |
| 512 | 512 |
| 513 DispatchEvent(profile, event_name, json_args); | 513 DispatchEvent(profile, event_name, json_args); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void ExtensionBrowserEventRouter::DispatchTabUpdatedEvent( | 516 void ExtensionBrowserEventRouter::DispatchTabUpdatedEvent( |
| 517 WebContents* contents, DictionaryValue* changed_properties) { | 517 WebContents* contents, DictionaryValue* changed_properties) { |
| 518 DCHECK(changed_properties); | 518 DCHECK(changed_properties); |
| 519 DCHECK(contents); | 519 DCHECK(contents); |
| 520 | 520 |
| 521 // The state of the tab (as seen from the extension point of view) has | 521 // The state of the tab (as seen from the extension point of view) has |
| 522 // changed. Send a notification to the extension. | 522 // changed. Send a notification to the extension. |
| 523 ListValue args; | 523 ListValue args; |
| 524 | 524 |
| 525 // First arg: The id of the tab that changed. | 525 // First arg: The id of the tab that changed. |
| 526 args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); | 526 args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
| 527 | 527 |
| 528 // Second arg: An object containing the changes to the tab state. | 528 // Second arg: An object containing the changes to the tab state. |
| 529 args.Append(changed_properties); | 529 args.Append(changed_properties); |
| 530 | 530 |
| 531 // Third arg: An object containing the state of the tab. | 531 // Third arg: An object containing the state of the tab. |
| 532 args.Append(ExtensionTabUtil::CreateTabValue(contents)); | 532 args.Append(ExtensionTabUtil::CreateTabValue(contents)); |
| 533 | 533 |
| 534 std::string json_args; | 534 std::string json_args; |
| 535 base::JSONWriter::Write(&args, false, &json_args); | 535 base::JSONWriter::Write(&args, &json_args); |
| 536 | 536 |
| 537 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 537 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 538 DispatchEvent(profile, events::kOnTabUpdated, json_args); | 538 DispatchEvent(profile, events::kOnTabUpdated, json_args); |
| 539 } | 539 } |
| 540 | 540 |
| 541 ExtensionBrowserEventRouter::TabEntry* ExtensionBrowserEventRouter::GetTabEntry( | 541 ExtensionBrowserEventRouter::TabEntry* ExtensionBrowserEventRouter::GetTabEntry( |
| 542 const WebContents* contents) { | 542 const WebContents* contents) { |
| 543 int tab_id = ExtensionTabUtil::GetTabId(contents); | 543 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 544 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 544 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
| 545 if (tab_entries_.end() == i) | 545 if (tab_entries_.end() == i) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 ListValue args; | 616 ListValue args; |
| 617 args.Append(Value::CreateStringValue(page_action_id)); | 617 args.Append(Value::CreateStringValue(page_action_id)); |
| 618 | 618 |
| 619 DictionaryValue* data = new DictionaryValue(); | 619 DictionaryValue* data = new DictionaryValue(); |
| 620 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | 620 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
| 621 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); | 621 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); |
| 622 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); | 622 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); |
| 623 args.Append(data); | 623 args.Append(data); |
| 624 | 624 |
| 625 std::string json_args; | 625 std::string json_args; |
| 626 base::JSONWriter::Write(&args, false, &json_args); | 626 base::JSONWriter::Write(&args, &json_args); |
| 627 | 627 |
| 628 DispatchEventToExtension(profile, extension_id, "pageActions", json_args); | 628 DispatchEventToExtension(profile, extension_id, "pageActions", json_args); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void ExtensionBrowserEventRouter::PageActionExecuted( | 631 void ExtensionBrowserEventRouter::PageActionExecuted( |
| 632 Profile* profile, | 632 Profile* profile, |
| 633 const std::string& extension_id, | 633 const std::string& extension_id, |
| 634 const std::string& page_action_id, | 634 const std::string& page_action_id, |
| 635 int tab_id, | 635 int tab_id, |
| 636 const std::string& url, | 636 const std::string& url, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 656 tab_contents->web_contents(), true); | 656 tab_contents->web_contents(), true); |
| 657 } | 657 } |
| 658 | 658 |
| 659 void ExtensionBrowserEventRouter::CommandExecuted( | 659 void ExtensionBrowserEventRouter::CommandExecuted( |
| 660 Profile* profile, | 660 Profile* profile, |
| 661 const std::string& extension_id, | 661 const std::string& extension_id, |
| 662 const std::string& command) { | 662 const std::string& command) { |
| 663 ListValue args; | 663 ListValue args; |
| 664 args.Append(Value::CreateStringValue(command)); | 664 args.Append(Value::CreateStringValue(command)); |
| 665 std::string json_args; | 665 std::string json_args; |
| 666 base::JSONWriter::Write(&args, false, &json_args); | 666 base::JSONWriter::Write(&args, &json_args); |
| 667 | 667 |
| 668 DispatchEventToExtension(profile, | 668 DispatchEventToExtension(profile, |
| 669 extension_id, | 669 extension_id, |
| 670 "experimental.keybinding.onCommand", | 670 "experimental.keybinding.onCommand", |
| 671 json_args); | 671 json_args); |
| 672 } | 672 } |
| OLD | NEW |