| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 7 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 ExtensionWebNavigationEventRouter::~ExtensionWebNavigationEventRouter() {} | 337 ExtensionWebNavigationEventRouter::~ExtensionWebNavigationEventRouter() {} |
| 338 | 338 |
| 339 void ExtensionWebNavigationEventRouter::Init() { | 339 void ExtensionWebNavigationEventRouter::Init() { |
| 340 if (registrar_.IsEmpty()) { | 340 if (registrar_.IsEmpty()) { |
| 341 registrar_.Add(this, | 341 registrar_.Add(this, |
| 342 content::NOTIFICATION_RETARGETING, | 342 content::NOTIFICATION_RETARGETING, |
| 343 Source<Profile>(profile_)); | 343 Source<Profile>(profile_)); |
| 344 registrar_.Add(this, | 344 registrar_.Add(this, |
| 345 content::NOTIFICATION_TAB_ADDED, | 345 content::NOTIFICATION_TAB_ADDED, |
| 346 NotificationService::AllSources()); | 346 NotificationService::AllSources()); |
| 347 registrar_.Add(this, |
| 348 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 349 NotificationService::AllSources()); |
| 347 } | 350 } |
| 348 } | 351 } |
| 349 | 352 |
| 350 void ExtensionWebNavigationEventRouter::Observe( | 353 void ExtensionWebNavigationEventRouter::Observe( |
| 351 int type, | 354 int type, |
| 352 const NotificationSource& source, | 355 const NotificationSource& source, |
| 353 const NotificationDetails& details) { | 356 const NotificationDetails& details) { |
| 354 switch (type) { | 357 switch (type) { |
| 355 case content::NOTIFICATION_RETARGETING: | 358 case content::NOTIFICATION_RETARGETING: |
| 356 Retargeting(Details<const content::RetargetingDetails>(details).ptr()); | 359 Retargeting(Details<const content::RetargetingDetails>(details).ptr()); |
| 357 break; | 360 break; |
| 358 | 361 |
| 359 case content::NOTIFICATION_TAB_ADDED: | 362 case content::NOTIFICATION_TAB_ADDED: |
| 360 TabAdded(Details<TabContents>(details).ptr()); | 363 TabAdded(Details<TabContents>(details).ptr()); |
| 361 break; | 364 break; |
| 362 | 365 |
| 366 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: |
| 367 TabDestroyed(Source<TabContents>(source).ptr()); |
| 368 break; |
| 369 |
| 363 default: | 370 default: |
| 364 NOTREACHED(); | 371 NOTREACHED(); |
| 365 } | 372 } |
| 366 } | 373 } |
| 367 | 374 |
| 368 void ExtensionWebNavigationEventRouter::Retargeting( | 375 void ExtensionWebNavigationEventRouter::Retargeting( |
| 369 const content::RetargetingDetails* details) { | 376 const content::RetargetingDetails* details) { |
| 370 if (details->source_frame_id == 0) | 377 if (details->source_frame_id == 0) |
| 371 return; | 378 return; |
| 372 ExtensionWebNavigationTabObserver* tab_observer = | 379 ExtensionWebNavigationTabObserver* tab_observer = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 419 |
| 413 DispatchOnBeforeRetarget(iter->second.source_tab_contents, | 420 DispatchOnBeforeRetarget(iter->second.source_tab_contents, |
| 414 iter->second.target_tab_contents->browser_context(), | 421 iter->second.target_tab_contents->browser_context(), |
| 415 iter->second.source_frame_id, | 422 iter->second.source_frame_id, |
| 416 iter->second.source_frame_is_main_frame, | 423 iter->second.source_frame_is_main_frame, |
| 417 iter->second.target_tab_contents, | 424 iter->second.target_tab_contents, |
| 418 iter->second.target_url); | 425 iter->second.target_url); |
| 419 pending_tab_contents_.erase(iter); | 426 pending_tab_contents_.erase(iter); |
| 420 } | 427 } |
| 421 | 428 |
| 429 void ExtensionWebNavigationEventRouter::TabDestroyed( |
| 430 TabContents* tab_contents) { |
| 431 pending_tab_contents_.erase(tab_contents); |
| 432 for (std::map<TabContents*, PendingTabContents>::iterator i = |
| 433 pending_tab_contents_.begin(); i != pending_tab_contents_.end(); ) { |
| 434 if (i->second.source_tab_contents == tab_contents) |
| 435 pending_tab_contents_.erase(i++); |
| 436 else |
| 437 ++i; |
| 438 } |
| 439 } |
| 422 | 440 |
| 423 // ExtensionWebNavigationTabObserver ------------------------------------------ | 441 // ExtensionWebNavigationTabObserver ------------------------------------------ |
| 424 | 442 |
| 425 ExtensionWebNavigationTabObserver::ExtensionWebNavigationTabObserver( | 443 ExtensionWebNavigationTabObserver::ExtensionWebNavigationTabObserver( |
| 426 TabContents* tab_contents) | 444 TabContents* tab_contents) |
| 427 : TabContentsObserver(tab_contents) { | 445 : TabContentsObserver(tab_contents) { |
| 428 g_tab_observer.Get().insert(TabObserverMap::value_type(tab_contents, this)); | 446 g_tab_observer.Get().insert(TabObserverMap::value_type(tab_contents, this)); |
| 429 } | 447 } |
| 430 | 448 |
| 431 ExtensionWebNavigationTabObserver::~ExtensionWebNavigationTabObserver() {} | 449 ExtensionWebNavigationTabObserver::~ExtensionWebNavigationTabObserver() {} |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 DictionaryValue* resultDict = new DictionaryValue(); | 624 DictionaryValue* resultDict = new DictionaryValue(); |
| 607 resultDict->SetString( | 625 resultDict->SetString( |
| 608 keys::kUrlKey, | 626 keys::kUrlKey, |
| 609 frame_navigation_state.GetUrl(frame_id).spec()); | 627 frame_navigation_state.GetUrl(frame_id).spec()); |
| 610 resultDict->SetBoolean( | 628 resultDict->SetBoolean( |
| 611 keys::kErrorOccurredKey, | 629 keys::kErrorOccurredKey, |
| 612 frame_navigation_state.GetErrorOccurredInFrame(frame_id)); | 630 frame_navigation_state.GetErrorOccurredInFrame(frame_id)); |
| 613 result_.reset(resultDict); | 631 result_.reset(resultDict); |
| 614 return true; | 632 return true; |
| 615 } | 633 } |
| OLD | NEW |