extension_webnavigation_api.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Defines the Chrome Extensions WebNavigation API functions for observing and 6// intercepting navigation events, as specified in 7// chrome/common/extensions/api/extension_api.json. 8 9#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ 10#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ 11#pragma once 12 13#include <map> 14 15#include "base/singleton.h" 16#include "chrome/browser/extensions/extension_function.h" 17#include "chrome/common/notification_observer.h" 18#include "chrome/common/notification_registrar.h" 19#include "googleurl/src/gurl.h" 20 21class NavigationController; 22class ProvisionalLoadDetails; 23class TabContents; 24 25// Observes navigation notifications and routes them as events to the extension 26// system. 27class ExtensionWebNavigationEventRouter : public NotificationObserver { 28 public: 29 // Single instance of the event router. 30 static ExtensionWebNavigationEventRouter* GetInstance(); 31 32 void Init(); 33 34 private: 35 friend struct DefaultSingletonTraits<ExtensionWebNavigationEventRouter>; 36 37 ExtensionWebNavigationEventRouter() {} 38 virtual ~ExtensionWebNavigationEventRouter() {} 39 40 // NotificationObserver implementation. 41 virtual void Observe(NotificationType type, 42 const NotificationSource& source, 43 const NotificationDetails& details); 44 45 // Handler for the FRAME_PROVISIONAL_LOAD_START event. The method takes the 46 // details of such an event and constructs a suitable JSON formatted extension 47 // event from it. 48 void FrameProvisionalLoadStart(NavigationController* controller, 49 ProvisionalLoadDetails* details); 50 51 // Handler for the FRAME_PROVISIONAL_LOAD_COMMITTED event. The method takes 52 // the details of such an event and constructs a suitable JSON formatted 53 // extension event from it. 54 void FrameProvisionalLoadCommitted(NavigationController* controller, 55 ProvisionalLoadDetails* details); 56 57 // Handler for the FAIL_PROVISIONAL_LOAD_WITH_ERROR event. The method takes 58 // the details of such an event and constructs a suitable JSON formatted 59 // extension event from it. 60 void FailProvisionalLoadWithError(NavigationController* controller, 61 ProvisionalLoadDetails* details); 62 63 // This method dispatches events to the extension message service. 64 void DispatchEvent(Profile* context, 65 const char* event_name, 66 const std::string& json_args); 67 68 // Used for tracking registrations to navigation notifications. 69 NotificationRegistrar registrar_; 70 71 DISALLOW_COPY_AND_ASSIGN(ExtensionWebNavigationEventRouter); 72}; 73 74#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_ 75