OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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_CHROME_ACTIVE_DOCUMENT_H_ |
| 6 #define CHROME_FRAME_CHROME_ACTIVE_DOCUMENT_H_ |
| 7 |
| 8 #include <atlbase.h> |
| 9 #include <atlcom.h> |
| 10 #include <atlctl.h> |
| 11 #include <map> |
| 12 |
| 13 #include "base/scoped_ptr.h" |
| 14 #include "base/scoped_comptr_win.h" |
| 15 #include "base/thread.h" |
| 16 |
| 17 #include "chrome_frame/chrome_frame_activex_base.h" |
| 18 #include "chrome_frame/com_type_info_holder.h" |
| 19 #include "chrome_frame/find_dialog.h" |
| 20 #include "chrome_frame/in_place_menu.h" |
| 21 #include "chrome_frame/ole_document_impl.h" |
| 22 #include "chrome_frame/resource.h" |
| 23 #include "chrome_frame/extra_system_apis.h" |
| 24 |
| 25 class Thread; |
| 26 class TabProxy; |
| 27 class ChromeActiveDocument; |
| 28 |
| 29 // A call to IOleCommandTarget::Exec on the webbrowser with this command id |
| 30 // and a command group of CGID_EXPLORER causes IE to finalize the current |
| 31 // travel log entry and move to a new location (pruning any forward entries |
| 32 // if needed) |
| 33 #define INTERNAL_CMDID_FINALIZE_TRAVEL_LOG (38) |
| 34 |
| 35 // To set the lock icon status call IOleCommandTarget::Exec on site with |
| 36 // this command id and a command group of CGID_EXPLORER The in arg is one of |
| 37 // the values: SECURELOCK_SET_UNSECURE, SECURELOCK_SET_MIXED, |
| 38 // SECURELOCK_SET_SECURE128BIT etc declared in shdeprecated.h |
| 39 #define INTERNAL_CMDID_SET_SSL_LOCK (37) |
| 40 |
| 41 // A call to IOleCommandTarget::Exec on the webbrowser with this command id |
| 42 // and a command group of CGID_EXPLORER causes IE to replace the URL in the |
| 43 // current travel log entry |
| 44 #define UNDOC_CMDID_REPLACE_CURRENT_TRAVEL_LOG_ENTRY_URL (40) |
| 45 |
| 46 #define UNDOC_IE_CONTEXTMENU_ADDFAV (2261) |
| 47 #define UNDOC_IE_CONTEXTMENU_VIEWSOURCE (2139) |
| 48 #define UNDOC_IE_CONTEXTMENU_REFRESH (6042) |
| 49 |
| 50 // This macro should be defined in the public section of the class. |
| 51 #define BEGIN_EXEC_COMMAND_MAP(theClass) \ |
| 52 public: \ |
| 53 HRESULT ProcessExecCommand(const GUID* cmd_group_guid, DWORD command_id, \ |
| 54 DWORD cmd_exec_opt, VARIANT* in_args, \ |
| 55 VARIANT* out_args) { \ |
| 56 HRESULT hr = OLECMDERR_E_NOTSUPPORTED; \ |
| 57 switch (command_id) { |
| 58 |
| 59 |
| 60 #define EXEC_COMMAND_HANDLER(id, handler) \ |
| 61 case id: { \ |
| 62 hr = S_OK; \ |
| 63 handler(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args) \ |
| 64 break; \ |
| 65 } |
| 66 |
| 67 #define EXEC_COMMAND_HANDLER_NO_ARGS(id, handler) \ |
| 68 case id: { \ |
| 69 hr = S_OK; \ |
| 70 handler(); \ |
| 71 break; \ |
| 72 } |
| 73 |
| 74 #define EXEC_COMMAND_HANDLER_GENERIC(id, code) \ |
| 75 case id: { \ |
| 76 hr = S_OK; \ |
| 77 code; \ |
| 78 break; \ |
| 79 } |
| 80 |
| 81 #define END_EXEC_COMMAND_MAP() \ |
| 82 default: \ |
| 83 break; \ |
| 84 } \ |
| 85 return hr; \ |
| 86 } |
| 87 |
| 88 // ChromeActiveDocument: Implementation of the Active Document object that is |
| 89 // responsible for rendering pages in Chrome. This object delegates to |
| 90 // Chrome.exe (via the Chrome IPC-based automation mechanism) for the actual |
| 91 // rendering |
| 92 class ATL_NO_VTABLE ChromeActiveDocument |
| 93 : public ChromeFrameActivexBase<ChromeActiveDocument, |
| 94 CLSID_ChromeActiveDocument>, |
| 95 public IOleDocumentImpl<ChromeActiveDocument>, |
| 96 public IOleDocumentViewImpl<ChromeActiveDocument>, |
| 97 public IPersistMoniker, |
| 98 public IOleCommandTarget, |
| 99 public InPlaceMenu<ChromeActiveDocument>, |
| 100 public IWebBrowserEventsUrlService { |
| 101 public: |
| 102 typedef ChromeFrameActivexBase<ChromeActiveDocument, |
| 103 CLSID_ChromeActiveDocument> Base; |
| 104 ChromeActiveDocument(); |
| 105 ~ChromeActiveDocument(); |
| 106 |
| 107 DECLARE_REGISTRY_RESOURCEID(IDR_CHROMEACTIVEDOCUMENT) |
| 108 |
| 109 BEGIN_COM_MAP(ChromeActiveDocument) |
| 110 COM_INTERFACE_ENTRY(IOleDocument) |
| 111 COM_INTERFACE_ENTRY(IOleDocumentView) |
| 112 COM_INTERFACE_ENTRY(IPersistMoniker) |
| 113 COM_INTERFACE_ENTRY(IOleCommandTarget) |
| 114 COM_INTERFACE_ENTRY(IWebBrowserEventsUrlService) |
| 115 COM_INTERFACE_ENTRY_CHAIN(Base) |
| 116 END_COM_MAP() |
| 117 |
| 118 BEGIN_MSG_MAP(ChromeActiveDocument) |
| 119 CHAIN_MSG_MAP(Base) |
| 120 END_MSG_MAP() |
| 121 |
| 122 HRESULT FinalConstruct(); |
| 123 |
| 124 #define FORWARD_TAB_COMMAND(id, command) \ |
| 125 EXEC_COMMAND_HANDLER_GENERIC(id, GetTabProxy() ? GetTabProxy()->command() : 1) |
| 126 |
| 127 BEGIN_EXEC_COMMAND_MAP(ChromeActiveDocument) |
| 128 EXEC_COMMAND_HANDLER_GENERIC(OLECMDID_PRINT, automation_client_->PrintTab()) |
| 129 EXEC_COMMAND_HANDLER_NO_ARGS(OLECMDID_FIND, OnFindInPage) |
| 130 EXEC_COMMAND_HANDLER_NO_ARGS(UNDOC_IE_CONTEXTMENU_VIEWSOURCE, OnViewSource) |
| 131 FORWARD_TAB_COMMAND(OLECMDID_SELECTALL, SelectAll) |
| 132 FORWARD_TAB_COMMAND(OLECMDID_CUT, Cut) |
| 133 FORWARD_TAB_COMMAND(OLECMDID_COPY, Copy) |
| 134 FORWARD_TAB_COMMAND(OLECMDID_PASTE, Paste) |
| 135 FORWARD_TAB_COMMAND(OLECMDID_REFRESH, ReloadAsync) |
| 136 FORWARD_TAB_COMMAND(OLECMDID_STOP, StopAsync) |
| 137 END_EXEC_COMMAND_MAP() |
| 138 |
| 139 // IPCs from automation server. |
| 140 virtual void OnNavigationStateChanged(int tab_handle, int flags, |
| 141 const IPC::NavigationInfo& nav_info); |
| 142 virtual void OnUpdateTargetUrl(int tab_handle, |
| 143 const std::wstring& new_target_url); |
| 144 virtual void OnAcceleratorPressed(int tab_handle, const MSG& accel_message); |
| 145 virtual void OnTabbedOut(int tab_handle, bool reverse); |
| 146 virtual void OnDidNavigate(int tab_handle, |
| 147 const IPC::NavigationInfo& nav_info); |
| 148 |
| 149 void OnFindInPage(); |
| 150 |
| 151 // Override DoVerb |
| 152 STDMETHOD(DoVerb)(LONG verb, |
| 153 LPMSG msg, |
| 154 IOleClientSite* active_site, |
| 155 LONG index, |
| 156 HWND parent_window, |
| 157 LPCRECT pos); |
| 158 STDMETHOD(InPlaceDeactivate)(void); |
| 159 |
| 160 // Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate |
| 161 STDMETHOD(OnDocWindowActivate)(BOOL activate); |
| 162 STDMETHOD(TranslateAccelerator)(MSG* msg); |
| 163 |
| 164 // IPersistMoniker methods |
| 165 STDMETHOD(GetClassID)(CLSID* class_id); |
| 166 STDMETHOD(IsDirty)(); |
| 167 STDMETHOD(GetCurMoniker)(IMoniker** moniker_name); |
| 168 STDMETHOD(Load)(BOOL fully_avalable, |
| 169 IMoniker* moniker_name, |
| 170 LPBC bind_context, |
| 171 DWORD mode); |
| 172 STDMETHOD(Save)(IMoniker* moniker_name, |
| 173 LPBC bind_context, |
| 174 BOOL remember); |
| 175 STDMETHOD(SaveCompleted)(IMoniker* moniker_name, |
| 176 LPBC bind_context); |
| 177 |
| 178 // IOleCommandTarget methods |
| 179 STDMETHOD(QueryStatus)(const GUID* cmd_group_guid, |
| 180 ULONG number_of_commands, |
| 181 OLECMD commands[], |
| 182 OLECMDTEXT* command_text); |
| 183 STDMETHOD(Exec)(const GUID* cmd_group_guid, DWORD command_id, |
| 184 DWORD cmd_exec_opt, |
| 185 VARIANT* in_args, |
| 186 VARIANT* out_args); |
| 187 |
| 188 // IWebBrowserEventsUrlService methods |
| 189 STDMETHOD(GetUrlForEvents)(BSTR* url); |
| 190 |
| 191 // ChromeFrameActivexBase overrides |
| 192 HRESULT IOleObject_SetClientSite(IOleClientSite* client_site); |
| 193 |
| 194 HRESULT ActiveXDocActivate(LONG verb); |
| 195 |
| 196 // Callbacks from ChromeFramePlugin<T> |
| 197 bool PreProcessContextMenu(HMENU menu); |
| 198 bool HandleContextMenuCommand(UINT cmd); |
| 199 |
| 200 // Should connections initiated by this class try to block |
| 201 // responses served with the X-Frame-Options header? |
| 202 bool is_frame_busting_enabled(); |
| 203 |
| 204 protected: |
| 205 // ChromeFrameActivexBase overrides |
| 206 virtual void OnOpenURL(int tab_handle, const GURL& url_to_open, |
| 207 int open_disposition); |
| 208 |
| 209 virtual void OnLoad(int tab_handle, const GURL& url); |
| 210 |
| 211 // A helper method that updates our internal navigation state |
| 212 // as well as IE's navigation state (viz Title and current URL). |
| 213 // The navigation_flags is a TabContents::InvalidateTypes enum |
| 214 void UpdateNavigationState(const IPC::NavigationInfo& nav_info); |
| 215 |
| 216 TabProxy* GetTabProxy() const { |
| 217 if (automation_client_.get()) |
| 218 return automation_client_->tab(); |
| 219 return NULL; |
| 220 } |
| 221 |
| 222 // Exec command handlers |
| 223 void OnViewSource(); |
| 224 |
| 225 // Call exec on our site's command target |
| 226 HRESULT IEExec(const GUID* cmd_group_guid, DWORD command_id, |
| 227 DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args); |
| 228 |
| 229 protected: |
| 230 typedef std::map<int, bool> EnabledCommandsMap; |
| 231 |
| 232 IPC::NavigationInfo navigation_info_; |
| 233 bool is_doc_object_; |
| 234 |
| 235 // This indicates whether this is the first navigation in this |
| 236 // active document. It is initalize to true and it is set to false |
| 237 // after we get a navigation notification from Chrome |
| 238 bool first_navigation_; |
| 239 |
| 240 // Our find dialog |
| 241 CFFindDialog find_dialog_; |
| 242 |
| 243 // Contains the list of enabled commands ids. |
| 244 EnabledCommandsMap enabled_commands_map_; |
| 245 |
| 246 // Set to true if the automation_client_ member is initialized from |
| 247 // an existing ChromeActiveDocument instance which is going away and |
| 248 // a new ChromeActiveDocument instance is taking its place. |
| 249 bool is_automation_client_reused_; |
| 250 |
| 251 public: |
| 252 ScopedComPtr<IOleInPlaceFrame> in_place_frame_; |
| 253 OLEINPLACEFRAMEINFO frame_info_; |
| 254 }; |
| 255 |
| 256 OBJECT_ENTRY_AUTO(__uuidof(ChromeActiveDocument), ChromeActiveDocument) |
| 257 |
| 258 #endif // CHROME_FRAME_CHROME_ACTIVE_DOCUMENT_H_ |
OLD | NEW |