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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 navigation_state.IsMainFrame(parent_frame_id), | 791 navigation_state.IsMainFrame(parent_frame_id), |
792 parent_frame_id.frame_num); | 792 parent_frame_id.frame_num); |
793 frame->process_id = frame_id.render_view_host->GetProcess()->GetID(); | 793 frame->process_id = frame_id.render_view_host->GetProcess()->GetID(); |
794 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); | 794 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); |
795 result_list.push_back(frame); | 795 result_list.push_back(frame); |
796 } | 796 } |
797 results_ = GetAllFrames::Results::Create(result_list); | 797 results_ = GetAllFrames::Results::Create(result_list); |
798 return true; | 798 return true; |
799 } | 799 } |
800 | 800 |
801 WebNavigationAPI::WebNavigationAPI(Profile* profile) | 801 WebNavigationAPI::WebNavigationAPI(content::BrowserContext* context) |
802 : profile_(profile) { | 802 : browser_context_(context) { |
803 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 803 EventRouter* event_router = |
804 this, web_navigation::OnBeforeNavigate::kEventName); | 804 ExtensionSystem::Get(browser_context_)->event_router(); |
805 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 805 event_router->RegisterObserver(this, |
806 this, web_navigation::OnCommitted::kEventName); | 806 web_navigation::OnBeforeNavigate::kEventName); |
807 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 807 event_router->RegisterObserver(this, web_navigation::OnCommitted::kEventName); |
808 this, web_navigation::OnCompleted::kEventName); | 808 event_router->RegisterObserver(this, web_navigation::OnCompleted::kEventName); |
809 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 809 event_router->RegisterObserver( |
810 this, web_navigation::OnCreatedNavigationTarget::kEventName); | 810 this, web_navigation::OnCreatedNavigationTarget::kEventName); |
811 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 811 event_router->RegisterObserver( |
812 this, web_navigation::OnDOMContentLoaded::kEventName); | 812 this, web_navigation::OnDOMContentLoaded::kEventName); |
813 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 813 event_router->RegisterObserver( |
814 this, web_navigation::OnHistoryStateUpdated::kEventName); | 814 this, web_navigation::OnHistoryStateUpdated::kEventName); |
815 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 815 event_router->RegisterObserver(this, |
816 this, web_navigation::OnErrorOccurred::kEventName); | 816 web_navigation::OnErrorOccurred::kEventName); |
817 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 817 event_router->RegisterObserver( |
818 this, web_navigation::OnReferenceFragmentUpdated::kEventName); | 818 this, web_navigation::OnReferenceFragmentUpdated::kEventName); |
819 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 819 event_router->RegisterObserver(this, |
820 this, web_navigation::OnTabReplaced::kEventName); | 820 web_navigation::OnTabReplaced::kEventName); |
821 } | 821 } |
822 | 822 |
823 WebNavigationAPI::~WebNavigationAPI() { | 823 WebNavigationAPI::~WebNavigationAPI() { |
824 } | 824 } |
825 | 825 |
826 void WebNavigationAPI::Shutdown() { | 826 void WebNavigationAPI::Shutdown() { |
827 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 827 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( |
| 828 this); |
828 } | 829 } |
829 | 830 |
830 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > | 831 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > |
831 g_factory = LAZY_INSTANCE_INITIALIZER; | 832 g_factory = LAZY_INSTANCE_INITIALIZER; |
832 | 833 |
833 // static | 834 // static |
834 ProfileKeyedAPIFactory<WebNavigationAPI>* | 835 ProfileKeyedAPIFactory<WebNavigationAPI>* |
835 WebNavigationAPI::GetFactoryInstance() { | 836 WebNavigationAPI::GetFactoryInstance() { |
836 return g_factory.Pointer(); | 837 return g_factory.Pointer(); |
837 } | 838 } |
838 | 839 |
839 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { | 840 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { |
840 web_navigation_event_router_.reset(new WebNavigationEventRouter(profile_)); | 841 web_navigation_event_router_.reset(new WebNavigationEventRouter( |
841 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 842 Profile::FromBrowserContext(browser_context_))); |
| 843 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( |
| 844 this); |
842 } | 845 } |
843 | 846 |
844 #endif // OS_ANDROID | 847 #endif // OS_ANDROID |
845 | 848 |
846 } // namespace extensions | 849 } // namespace extensions |
OLD | NEW |