OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_FRAME_READY_MODE_INTERNAL_READY_MODE_WEB_BROWSER_ADAPTER_H_ | |
6 #define CHROME_FRAME_READY_MODE_INTERNAL_READY_MODE_WEB_BROWSER_ADAPTER_H_ | |
7 | |
8 #include <atlbase.h> | |
9 #include <atlcom.h> | |
10 #include <exdisp.h> | |
11 #include <exdispid.h> | |
12 | |
13 #include <string> | |
14 | |
15 #include "base/basictypes.h" | |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/win/scoped_comptr.h" | |
18 | |
19 // Observes navigation and rendering in an IWebBrowser2 instance and reports | |
20 // activity to an observer. | |
21 class ATL_NO_VTABLE ReadyModeWebBrowserAdapter | |
22 : public CComObjectRootEx<CComSingleThreadModel>, | |
23 public IDispEventSimpleImpl<0, ReadyModeWebBrowserAdapter, | |
24 &DIID_DWebBrowserEvents2> { | |
25 public: | |
26 // Receives notification of navigation and rendering activity in the | |
27 // IWebBrowser2 instance. | |
28 class Observer { | |
29 public: | |
30 virtual ~Observer() {} | |
31 | |
32 // Receives notification when the browser begins navigating. | |
33 virtual void OnNavigateTo(const std::wstring& url) = 0; | |
34 | |
35 // Receives notification when the browser has rendered a page in Chrome | |
36 // Frame. | |
37 virtual void OnRenderInChromeFrame(const std::wstring& url) = 0; | |
38 | |
39 // Receives notification when the browser has rendered a page in the host | |
40 // renderer. | |
41 virtual void OnRenderInHost(const std::wstring& url) = 0; | |
42 }; // class Observer | |
43 | |
44 ReadyModeWebBrowserAdapter(); | |
45 | |
46 // Begins observation of the specified IWebBrowser2 instance, reporting | |
47 // activity to the observer. Takes ownership of observer and deletes it | |
48 // either upon failure to initialize, during Uninstall(), or when the browser | |
49 // quits. | |
50 bool Initialize(IWebBrowser2* web_browser_, Observer* observer); | |
51 | |
52 // Stops observing the IWebBrowser2. | |
53 void Uninitialize(); | |
54 | |
55 DECLARE_NOT_AGGREGATABLE(ReadyModeWebBrowserAdapter) | |
56 | |
57 BEGIN_COM_MAP(ReadyModeWebBrowserAdapter) | |
58 END_COM_MAP() | |
59 | |
60 BEGIN_SINK_MAP(ReadyModeWebBrowserAdapter) | |
61 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, | |
62 BeforeNavigate2, &kBeforeNavigate2Info) | |
63 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, | |
64 DocumentComplete, &kDocumentCompleteInfo) | |
65 SINK_ENTRY_INFO(0, DIID_DWebBrowserEvents2, DISPID_ONQUIT, | |
66 OnQuit, &kOnQuitInfo) | |
67 END_SINK_MAP() | |
68 | |
69 private: | |
70 // IWebBrowser2 event handlers | |
71 STDMETHOD(BeforeNavigate2)(IDispatch* dispatch, VARIANT* url, VARIANT* flags, | |
72 VARIANT* target_frame_name, VARIANT* post_data, VARIANT* headers, | |
73 VARIANT_BOOL* cancel); | |
74 STDMETHOD_(void, DocumentComplete)(IDispatch* dispatch, VARIANT* url); | |
75 STDMETHOD_(void, OnQuit)(); | |
76 | |
77 scoped_ptr<Observer> observer_; | |
78 base::win::ScopedComPtr<IWebBrowser2> web_browser_; | |
79 | |
80 static _ATL_FUNC_INFO kBeforeNavigate2Info; | |
81 static _ATL_FUNC_INFO kDocumentCompleteInfo; | |
82 static _ATL_FUNC_INFO kOnQuitInfo; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(ReadyModeWebBrowserAdapter); | |
85 }; // class ReadyModeWebBrowserAdapter | |
86 | |
87 #endif // CHROME_FRAME_READY_MODE_INTERNAL_READY_MODE_WEB_BROWSER_ADAPTER_H_ | |
OLD | NEW |