[email protected] | 92c79d3 | 2011-04-06 18:41:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Implementation of ChromeActiveDocument |
| 6 | #include "chrome_frame/chrome_active_document.h" |
| 7 | |
| 8 | #include <hlink.h> |
| 9 | #include <htiface.h> |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 10 | #include <initguid.h> |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 11 | #include <mshtmcid.h> |
| 12 | #include <shdeprecated.h> |
| 13 | #include <shlguid.h> |
[email protected] | 48dc9e1 | 2010-08-26 19:49:57 | [diff] [blame] | 14 | #include <shlobj.h> |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 15 | #include <shobjidl.h> |
| 16 | #include <tlogstg.h> |
| 17 | #include <urlmon.h> |
| 18 | #include <wininet.h> |
| 19 | |
| 20 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 21 | #include "base/debug/trace_event.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 22 | #include "base/logging.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 23 | #include "base/string_util.h" |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 24 | #include "base/utf_string_conversions.h" |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 25 | #include "base/win/scoped_variant.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 26 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | cccd376 | 2010-11-12 18:40:01 | [diff] [blame] | 27 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 28 | #include "chrome/common/automation_messages.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 29 | #include "chrome/common/chrome_constants.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 30 | #include "chrome/test/automation/browser_proxy.h" |
| 31 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 32 | #include "chrome_frame/bho.h" |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 33 | #include "chrome_frame/bind_context_info.h" |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 34 | #include "chrome_frame/buggy_bho_handling.h" |
[email protected] | 9607f6a8 | 2010-06-12 17:24:41 | [diff] [blame] | 35 | #include "chrome_frame/crash_reporting/crash_metrics.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 36 | #include "chrome_frame/utils.h" |
[email protected] | 21f1168 | 2011-03-02 16:45:42 | [diff] [blame] | 37 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 38 | #include "content/common/page_zoom.h" |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 39 | #include "grit/generated_resources.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 40 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 41 | DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, |
| 42 | 0x46); |
| 43 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 44 | bool g_first_launch_by_process_ = true; |
| 45 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 46 | const DWORD kIEEncodingIdArray[] = { |
| 47 | #define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name, |
| 48 | INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY) |
| 49 | #undef DEFINE_ENCODING_ID_ARRAY |
| 50 | 0 // The Last data must be 0 to indicate the end of the encoding id array. |
| 51 | }; |
| 52 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 53 | ChromeActiveDocument::ChromeActiveDocument() |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 54 | : navigation_info_(new NavigationInfo()), |
| 55 | first_navigation_(true), |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 56 | is_automation_client_reused_(false), |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 57 | popup_allowed_(false), |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 58 | accelerator_table_(NULL) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 59 | TRACE_EVENT_BEGIN_ETW("chromeframe.createactivedocument", this, ""); |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 60 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 61 | url_fetcher_->set_frame_busting(false); |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 62 | memset(navigation_info_.get(), 0, sizeof(NavigationInfo)); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | HRESULT ChromeActiveDocument::FinalConstruct() { |
[email protected] | e67d0817 | 2011-08-17 19:22:21 | [diff] [blame] | 66 | // The FinalConstruct implementation in the ChromeFrameActivexBase class |
| 67 | // i.e. Base creates an instance of the ChromeFrameAutomationClient class |
| 68 | // and initializes it, which would spawn a new Chrome process, etc. |
| 69 | // We don't want to be doing this if we have a cached document, whose |
| 70 | // automation client instance can be reused. |
| 71 | HRESULT hr = BaseActiveX::FinalConstruct(); |
| 72 | if (FAILED(hr)) |
| 73 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 74 | |
[email protected] | e1081d9 | 2010-09-10 20:29:11 | [diff] [blame] | 75 | InitializeAutomationSettings(); |
[email protected] | 8f56e61 | 2010-09-09 17:03:14 | [diff] [blame] | 76 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 77 | find_dialog_.Init(automation_client_.get()); |
| 78 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 79 | OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED); |
| 80 | |
| 81 | null_group_commands_map_[OLECMDID_PRINT] = flags; |
| 82 | null_group_commands_map_[OLECMDID_FIND] = flags; |
| 83 | null_group_commands_map_[OLECMDID_CUT] = flags; |
| 84 | null_group_commands_map_[OLECMDID_COPY] = flags; |
| 85 | null_group_commands_map_[OLECMDID_PASTE] = flags; |
| 86 | null_group_commands_map_[OLECMDID_SELECTALL] = flags; |
| 87 | null_group_commands_map_[OLECMDID_SAVEAS] = flags; |
| 88 | |
| 89 | mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags; |
| 90 | mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags; |
| 91 | mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags; |
| 92 | mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags; |
| 93 | mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags; |
[email protected] | b252972 | 2010-12-01 02:49:07 | [diff] [blame] | 94 | mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags; |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 95 | |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 96 | HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 97 | accelerator_table_ = |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 98 | LoadAccelerators(this_module, |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 99 | MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB)); |
| 100 | DCHECK(accelerator_table_ != NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 101 | return S_OK; |
| 102 | } |
| 103 | |
| 104 | ChromeActiveDocument::~ChromeActiveDocument() { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 105 | DVLOG(1) << __FUNCTION__; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 106 | if (find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 107 | find_dialog_.DestroyWindow(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 108 | // ChromeFramePlugin |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 109 | BaseActiveX::Uninitialize(); |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 110 | |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 111 | TRACE_EVENT_END_ETW("chromeframe.createactivedocument", this, ""); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | // Override DoVerb |
| 115 | STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb, |
| 116 | LPMSG msg, |
| 117 | IOleClientSite* active_site, |
| 118 | LONG index, |
| 119 | HWND parent_window, |
| 120 | LPCRECT pos) { |
| 121 | // IE will try and in-place activate us in some cases. This happens when |
| 122 | // the user opens a new IE window with a URL that has us as the DocObject. |
| 123 | // Here we refuse to be activated in-place and we will force IE to UIActivate |
| 124 | // us. |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 125 | if (OLEIVERB_INPLACEACTIVATE == verb) |
[email protected] | 23b3361 | 2010-11-09 23:47:01 | [diff] [blame] | 126 | return OLEOBJ_E_INVALIDVERB; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 127 | // Check if we should activate as a docobject or not |
| 128 | // (client supports IOleDocumentSite) |
| 129 | if (doc_site_) { |
| 130 | switch (verb) { |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 131 | case OLEIVERB_SHOW: { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 132 | base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 133 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 134 | if (doc_host_handler.get()) |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 135 | doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL); |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 136 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 137 | case OLEIVERB_OPEN: |
| 138 | case OLEIVERB_UIACTIVATE: |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 139 | if (!m_bUIActive) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 140 | return doc_site_->ActivateMe(NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | } |
| 144 | return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb, |
| 145 | msg, |
| 146 | active_site, |
| 147 | index, |
| 148 | parent_window, |
| 149 | pos); |
| 150 | } |
| 151 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 152 | // Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate |
| 153 | STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 154 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 155 | return S_OK; |
| 156 | } |
| 157 | |
| 158 | STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 159 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 160 | if (msg == NULL) |
| 161 | return E_POINTER; |
| 162 | |
| 163 | if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) { |
| 164 | HWND focus = ::GetFocus(); |
| 165 | if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) { |
| 166 | // The call to SetFocus triggers a WM_SETFOCUS that makes the base class |
| 167 | // set focus to the correct element in Chrome. |
| 168 | ::SetFocus(m_hWnd); |
| 169 | return S_OK; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return S_FALSE; |
| 174 | } |
| 175 | // Override IPersistStorageImpl::IsDirty |
| 176 | STDMETHODIMP ChromeActiveDocument::IsDirty() { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 177 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 178 | return S_FALSE; |
| 179 | } |
| 180 | |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 181 | void ChromeActiveDocument::OnAutomationServerReady() { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 182 | BaseActiveX::OnAutomationServerReady(); |
[email protected] | 1fd4569 | 2010-04-19 21:01:18 | [diff] [blame] | 183 | BaseActiveX::GiveFocusToChrome(true); |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 186 | STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable, |
| 187 | IMoniker* moniker_name, |
| 188 | LPBC bind_context, |
| 189 | DWORD mode) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 190 | if (NULL == moniker_name) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 191 | return E_INVALIDARG; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 192 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 193 | base::win::ScopedComPtr<IOleClientSite> client_site; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 194 | if (bind_context) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 195 | base::win::ScopedComPtr<IUnknown> site; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 196 | bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM, |
| 197 | site.Receive()); |
| 198 | if (site) |
| 199 | client_site.QueryFrom(site); |
| 200 | } |
| 201 | |
| 202 | if (client_site) { |
| 203 | SetClientSite(client_site); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 204 | DoQueryService(IID_INewWindowManager, client_site, |
| 205 | popup_manager_.Receive()); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 206 | |
| 207 | // See if mshtml parsed the html header for us. If so, we need to |
| 208 | // clear the browser service flag that we use to indicate that this |
| 209 | // browser instance is navigating to a CF document. |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 210 | base::win::ScopedComPtr<IBrowserService> browser_service; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 211 | DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive()); |
| 212 | if (browser_service) { |
| 213 | bool flagged = CheckForCFNavigation(browser_service, true); |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 214 | DVLOG_IF(1, flagged) << "Cleared flagged browser service"; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 215 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 216 | } |
| 217 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 218 | NavigationManager* mgr = NavigationManager::GetThreadInstance(); |
[email protected] | 21b4e6d | 2010-07-14 18:19:59 | [diff] [blame] | 219 | DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager"; |
[email protected] | 7e3544b | 2010-01-22 00:02:34 | [diff] [blame] | 220 | |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 221 | std::wstring url; |
| 222 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 223 | base::win::ScopedComPtr<BindContextInfo> info; |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 224 | BindContextInfo::FromBindContext(bind_context, info.Receive()); |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 225 | DCHECK(info); |
[email protected] | 4f45d458 | 2011-02-22 23:27:27 | [diff] [blame] | 226 | if (info && !info->GetUrl().empty()) { |
| 227 | url = info->GetUrl(); |
[email protected] | df0846a5 | 2011-02-23 03:29:58 | [diff] [blame] | 228 | if (mgr) { |
| 229 | // If the original URL contains an anchor, then the URL queried |
| 230 | // from the protocol sink wrapper does not contain the anchor. To |
| 231 | // workaround this we retrieve the anchor from the navigation manager |
| 232 | // and append it to the url retrieved from the protocol sink wrapper. |
| 233 | GURL url_for_anchor(mgr->url()); |
| 234 | if (url_for_anchor.has_ref()) { |
| 235 | url += L"#"; |
| 236 | url += UTF8ToWide(url_for_anchor.ref()); |
| 237 | } |
| 238 | } |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 239 | } else { |
| 240 | // If the original URL contains an anchor, then the URL queried |
| 241 | // from the moniker does not contain the anchor. To workaround |
| 242 | // this we retrieve the URL from our BHO. |
| 243 | url = GetActualUrlFromMoniker(moniker_name, bind_context, |
| 244 | mgr ? mgr->url(): std::wstring()); |
| 245 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 246 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 247 | ChromeFrameUrl cf_url; |
| 248 | if (!cf_url.Parse(url)) { |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 249 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 250 | return E_INVALIDARG; |
| 251 | } |
| 252 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 253 | std::string referrer(mgr ? mgr->referrer() : EmptyString()); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 254 | RendererType renderer_type = cf_url.is_chrome_protocol() ? |
| 255 | RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 256 | |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 257 | // With CTransaction patch we have more robust way to grab the referrer for |
| 258 | // each top-level-switch-to-CF request by peeking at our sniffing data |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 259 | // object that lives inside the bind context. We also remember the reason |
| 260 | // we're rendering the document in Chrome. |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 261 | if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) { |
| 262 | scoped_refptr<ProtData> prot_data = info->get_prot_data(); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 263 | if (prot_data) { |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 264 | referrer = prot_data->referrer(); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 265 | renderer_type = prot_data->renderer_type(); |
| 266 | } |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 267 | } |
| 268 | |
[email protected] | 62ce0973 | 2010-09-03 18:32:04 | [diff] [blame] | 269 | // For gcf: URLs allow only about and view-source schemes to pass through for |
| 270 | // further inspection. |
| 271 | bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) || |
| 272 | cf_url.gurl().SchemeIs(chrome::kViewSourceScheme); |
| 273 | if (cf_url.is_chrome_protocol() && !is_safe_scheme && |
| 274 | !GetConfigBool(false, kAllowUnsafeURLs)) { |
| 275 | DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url; |
| 276 | return E_INVALIDARG; |
| 277 | } |
| 278 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 279 | if (!LaunchUrl(cf_url, referrer)) { |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 280 | DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 281 | return E_INVALIDARG; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 284 | if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab()) |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 285 | url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 286 | |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 287 | // Log a metric indicating why GCF is rendering in Chrome. |
| 288 | // (Note: we only track the renderer type when using the CTransaction patch. |
| 289 | // When the code for the browser service patch and for the moniker patch is |
| 290 | // removed, this conditional can also go away.) |
| 291 | if (RENDERER_TYPE_UNDETERMINED != renderer_type) { |
[email protected] | 92c79d3 | 2011-04-06 18:41:15 | [diff] [blame] | 292 | UMA_LAUNCH_TYPE_COUNT(renderer_type); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 295 | return S_OK; |
| 296 | } |
| 297 | |
| 298 | STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name, |
| 299 | LPBC bind_context, |
| 300 | BOOL remember) { |
| 301 | return E_NOTIMPL; |
| 302 | } |
| 303 | |
| 304 | STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name, |
| 305 | LPBC bind_context) { |
| 306 | return E_NOTIMPL; |
| 307 | } |
| 308 | |
| 309 | STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) { |
| 310 | return E_NOTIMPL; |
| 311 | } |
| 312 | |
| 313 | STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 314 | if (NULL == class_id) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 315 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 316 | *class_id = GetObjectCLSID(); |
| 317 | return S_OK; |
| 318 | } |
| 319 | |
| 320 | STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid, |
| 321 | ULONG number_of_commands, |
| 322 | OLECMD commands[], |
| 323 | OLECMDTEXT* command_text) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 324 | DVLOG(1) << __FUNCTION__; |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 325 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 326 | CommandStatusMap* command_map = NULL; |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 327 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 328 | if (cmd_group_guid) { |
| 329 | if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) { |
| 330 | command_map = &null_group_commands_map_; |
| 331 | } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) { |
| 332 | command_map = &mshtml_group_commands_map_; |
| 333 | } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) { |
| 334 | command_map = &explorer_group_commands_map_; |
| 335 | } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) { |
| 336 | command_map = &shdoc_view_group_commands_map_; |
| 337 | } |
| 338 | } else { |
| 339 | command_map = &null_group_commands_map_; |
| 340 | } |
| 341 | |
| 342 | if (!command_map) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 343 | DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid); |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 344 | return OLECMDERR_E_NOTSUPPORTED; |
| 345 | } |
| 346 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 347 | for (ULONG command_index = 0; command_index < number_of_commands; |
| 348 | command_index++) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 349 | DVLOG(1) << "Command id = " << commands[command_index].cmdID; |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 350 | CommandStatusMap::iterator index = |
| 351 | command_map->find(commands[command_index].cmdID); |
| 352 | if (index != command_map->end()) |
| 353 | commands[command_index].cmdf = index->second; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 354 | } |
| 355 | return S_OK; |
| 356 | } |
| 357 | |
| 358 | STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid, |
| 359 | DWORD command_id, |
| 360 | DWORD cmd_exec_opt, |
| 361 | VARIANT* in_args, |
| 362 | VARIANT* out_args) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 363 | DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 364 | // Bail out if we have been uninitialized. |
| 365 | if (automation_client_.get() && automation_client_->tab()) { |
| 366 | return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt, |
| 367 | in_args, out_args); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 368 | } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) { |
| 369 | // If the automation server has crashed and the user is refreshing the |
| 370 | // page, let OnRefreshPage attempt to recover. |
| 371 | OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 372 | } |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 373 | |
[email protected] | e320093 | 2009-10-09 21:33:03 | [diff] [blame] | 374 | return OLECMDERR_E_NOTSUPPORTED; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 377 | STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream, |
| 378 | IBindCtx* bind_context) { |
| 379 | // Read notes in ChromeActiveDocument::SaveHistory |
| 380 | DCHECK(stream); |
| 381 | LARGE_INTEGER offset = {0}; |
| 382 | ULARGE_INTEGER cur_pos = {0}; |
| 383 | STATSTG statstg = {0}; |
| 384 | |
| 385 | stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos); |
| 386 | stream->Stat(&statstg, STATFLAG_NONAME); |
| 387 | |
| 388 | DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart; |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 389 | base::win::ScopedBstr url_bstr; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 390 | DWORD bytes_read = 0; |
| 391 | stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read); |
| 392 | std::wstring url(url_bstr); |
| 393 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 394 | ChromeFrameUrl cf_url; |
| 395 | if (!cf_url.Parse(url)) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 396 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
| 397 | return E_INVALIDARG; |
| 398 | } |
| 399 | |
[email protected] | c5cbf4e | 2010-07-15 21:48:25 | [diff] [blame] | 400 | const std::string& referrer = EmptyString(); |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 401 | if (!LaunchUrl(cf_url, referrer)) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 402 | NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url; |
| 403 | return E_INVALIDARG; |
| 404 | } |
| 405 | return S_OK; |
| 406 | } |
| 407 | |
| 408 | STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) { |
| 409 | // TODO(sanjeevr): We need to fetch the entire list of navigation entries |
| 410 | // from Chrome and persist it in the stream. And in LoadHistory we need to |
| 411 | // pass this list back to Chrome which will recreate the list. This will allow |
| 412 | // Back-Forward navigation to anchors to work correctly when we navigate to a |
| 413 | // page outside of ChromeFrame and then come back. |
| 414 | if (!stream) { |
| 415 | NOTREACHED(); |
| 416 | return E_INVALIDARG; |
| 417 | } |
| 418 | |
| 419 | LARGE_INTEGER offset = {0}; |
| 420 | ULARGE_INTEGER new_pos = {0}; |
| 421 | DWORD written = 0; |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 422 | std::wstring url = UTF8ToWide(navigation_info_->url.spec()); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 423 | return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t), |
| 424 | &written); |
| 425 | } |
| 426 | |
| 427 | STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 428 | if (automation_client_.get()) { |
| 429 | int index = static_cast<int>(position_cookie); |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 430 | navigation_info_->navigation_index = index; |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 431 | automation_client_->NavigateToIndex(index); |
| 432 | } else { |
| 433 | DLOG(WARNING) << "Invalid automation client instance"; |
| 434 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 435 | return S_OK; |
| 436 | } |
| 437 | |
| 438 | STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) { |
| 439 | if (!position_cookie) |
| 440 | return E_INVALIDARG; |
| 441 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 442 | *position_cookie = navigation_info_->navigation_index; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 443 | return S_OK; |
| 444 | } |
| 445 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 446 | STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 447 | if (NULL == url) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 448 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 449 | *url = ::SysAllocString(url_); |
| 450 | return S_OK; |
| 451 | } |
| 452 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 453 | STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) { |
| 454 | return GetUrlForEvents(url); |
| 455 | } |
| 456 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 457 | STDMETHODIMP ChromeActiveDocument::Reset() { |
| 458 | next_privacy_record_ = privacy_info_.privacy_records.begin(); |
| 459 | return S_OK; |
| 460 | } |
| 461 | |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 462 | STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 463 | if (!size) |
| 464 | return E_POINTER; |
| 465 | |
| 466 | *size = privacy_info_.privacy_records.size(); |
| 467 | return S_OK; |
| 468 | } |
| 469 | |
| 470 | STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) { |
| 471 | if (!privacy_impacted) |
| 472 | return E_POINTER; |
| 473 | |
| 474 | *privacy_impacted = privacy_info_.privacy_impacted; |
| 475 | return S_OK; |
| 476 | } |
| 477 | |
| 478 | STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy, |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 479 | LONG* reserved, DWORD* flags) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 480 | if (!url || !policy || !flags) |
| 481 | return E_POINTER; |
| 482 | |
| 483 | if (next_privacy_record_ == privacy_info_.privacy_records.end()) |
| 484 | return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS); |
| 485 | |
| 486 | *url = SysAllocString(next_privacy_record_->first.c_str()); |
| 487 | *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str()); |
| 488 | *flags = next_privacy_record_->second.flags; |
| 489 | |
| 490 | next_privacy_record_++; |
| 491 | return S_OK; |
| 492 | } |
| 493 | |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 494 | bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) { |
| 495 | bool allowed = BaseActiveX::IsSchemeAllowed(url); |
| 496 | if (allowed) |
| 497 | return true; |
| 498 | |
| 499 | if (url.SchemeIs(chrome::kAboutScheme)) { |
| 500 | if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL)) |
| 501 | return true; |
| 502 | } |
| 503 | return false; |
| 504 | } |
| 505 | |
[email protected] | 3eafbfb9 | 2010-08-02 16:54:22 | [diff] [blame] | 506 | HRESULT ChromeActiveDocument::GetInPlaceFrame( |
| 507 | IOleInPlaceFrame** in_place_frame) { |
| 508 | DCHECK(in_place_frame); |
| 509 | if (in_place_frame_) { |
| 510 | *in_place_frame = in_place_frame_.get(); |
| 511 | (*in_place_frame)->AddRef(); |
| 512 | return S_OK; |
| 513 | } else { |
| 514 | return S_FALSE; |
| 515 | } |
| 516 | } |
| 517 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 518 | HRESULT ChromeActiveDocument::IOleObject_SetClientSite( |
| 519 | IOleClientSite* client_site) { |
| 520 | if (client_site == NULL) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 521 | base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 522 | if (doc_site_) |
[email protected] | 77059f7 | 2010-02-28 06:16:00 | [diff] [blame] | 523 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 524 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 525 | if (doc_host_handler.get()) |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 526 | doc_host_handler->HideUI(); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 527 | |
| 528 | doc_site_.Release(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 529 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 530 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 531 | if (client_site != m_spClientSite) |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 532 | return BaseActiveX::IOleObject_SetClientSite(client_site); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 533 | |
| 534 | return S_OK; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 535 | } |
| 536 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 537 | HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) { |
| 538 | HRESULT hr = S_OK; |
| 539 | m_bNegotiatedWnd = TRUE; |
| 540 | if (!m_bInPlaceActive) { |
| 541 | hr = m_spInPlaceSite->CanInPlaceActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 542 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 543 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 544 | m_spInPlaceSite->OnInPlaceActivate(); |
| 545 | } |
| 546 | m_bInPlaceActive = TRUE; |
| 547 | // get location in the parent window, |
| 548 | // as well as some information about the parent |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 549 | base::win::ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 550 | frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO); |
| 551 | HWND parent_window = NULL; |
| 552 | if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) { |
| 553 | in_place_frame_.Release(); |
| 554 | RECT position_rect = {0}; |
| 555 | RECT clip_rect = {0}; |
| 556 | m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(), |
| 557 | in_place_ui_window.Receive(), |
| 558 | &position_rect, |
| 559 | &clip_rect, |
| 560 | &frame_info_); |
| 561 | if (!m_bWndLess) { |
| 562 | if (IsWindow()) { |
| 563 | ::ShowWindow(m_hWnd, SW_SHOW); |
| 564 | SetFocus(); |
| 565 | } else { |
[email protected] | fca446b9 | 2011-02-18 20:44:06 | [diff] [blame] | 566 | m_hWnd = Create(parent_window, position_rect); |
[email protected] | dd4beb52 | 2010-07-13 18:18:14 | [diff] [blame] | 567 | if (!IsWindow()) { |
| 568 | // This might happen if the automation server couldn't be |
| 569 | // instantiated. If so, a NOTREACHED() will have already been hit. |
| 570 | DLOG(ERROR) << "Failed to create Ax window"; |
| 571 | return AtlHresultFromLastError(); |
| 572 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | SetObjectRects(&position_rect, &clip_rect); |
| 576 | } |
| 577 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 578 | base::win::ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 579 | |
| 580 | // Gone active by now, take care of UIACTIVATE |
| 581 | if (DoesVerbUIActivate(verb)) { |
| 582 | if (!m_bUIActive) { |
| 583 | m_bUIActive = TRUE; |
| 584 | hr = m_spInPlaceSite->OnUIActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 585 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 586 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 587 | // set ourselves up in the host |
| 588 | if (in_place_active_object) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 589 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 590 | in_place_frame_->SetActiveObject(in_place_active_object, NULL); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 591 | if (in_place_ui_window) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 592 | in_place_ui_window->SetActiveObject(in_place_active_object, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | m_spClientSite->ShowObject(); |
| 597 | return S_OK; |
| 598 | } |
| 599 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 600 | void ChromeActiveDocument::OnNavigationStateChanged( |
| 601 | int flags, const NavigationInfo& nav_info) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 602 | // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc. |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 603 | DVLOG(1) << __FUNCTION__ |
| 604 | << "\n Flags: " << flags |
| 605 | << ", Url: " << nav_info.url |
| 606 | << ", Title: " << nav_info.title |
| 607 | << ", Type: " << nav_info.navigation_type |
| 608 | << ", Relative Offset: " << nav_info.relative_offset |
| 609 | << ", Index: " << nav_info.navigation_index; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 610 | |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 611 | UpdateNavigationState(nav_info, flags); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 612 | } |
| 613 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 614 | void ChromeActiveDocument::OnUpdateTargetUrl( |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 615 | const std::wstring& new_target_url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 616 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 617 | in_place_frame_->SetStatusText(new_target_url.c_str()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | bool IsFindAccelerator(const MSG& msg) { |
| 621 | // TODO(robertshield): This may not stand up to localization. Fix if this |
| 622 | // is the case. |
| 623 | return msg.message == WM_KEYDOWN && msg.wParam == 'F' && |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 624 | base::win::IsCtrlPressed() && |
| 625 | !(base::win::IsAltPressed() || base::win::IsShiftPressed()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 626 | } |
| 627 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 628 | void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) { |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 629 | if (::TranslateAccelerator(m_hWnd, accelerator_table_, |
| 630 | const_cast<MSG*>(&accel_message))) |
| 631 | return; |
| 632 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 633 | bool handled_accel = false; |
| 634 | if (in_place_frame_ != NULL) { |
| 635 | handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW( |
| 636 | const_cast<MSG*>(&accel_message), 0)); |
| 637 | } |
| 638 | |
| 639 | if (!handled_accel) { |
| 640 | if (IsFindAccelerator(accel_message)) { |
| 641 | // Handle the showing of the find dialog explicitly. |
| 642 | OnFindInPage(); |
[email protected] | 2b8fd32 | 2009-10-02 00:00:59 | [diff] [blame] | 643 | } else { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 644 | BaseActiveX::OnAcceleratorPressed(accel_message); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 645 | } |
| 646 | } else { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 647 | DVLOG(1) << "IE handled accel key " << accel_message.wParam; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 651 | void ChromeActiveDocument::OnTabbedOut(bool reverse) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 652 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 653 | if (in_place_frame_) { |
| 654 | MSG msg = { NULL, WM_KEYDOWN, VK_TAB }; |
| 655 | in_place_frame_->TranslateAcceleratorW(&msg, 0); |
| 656 | } |
| 657 | } |
| 658 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 659 | void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 660 | DVLOG(1) << __FUNCTION__ << std::endl |
| 661 | << "Url: " << nav_info.url |
| 662 | << ", Title: " << nav_info.title |
| 663 | << ", Type: " << nav_info.navigation_type |
| 664 | << ", Relative Offset: " << nav_info.relative_offset |
| 665 | << ", Index: " << nav_info.navigation_index; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 666 | |
[email protected] | 897b2627 | 2010-06-11 02:23:44 | [diff] [blame] | 667 | CrashMetricsReporter::GetInstance()->IncrementMetric( |
| 668 | CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT); |
| 669 | |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 670 | UpdateNavigationState(nav_info, 0); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 671 | } |
| 672 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 673 | void ChromeActiveDocument::OnCloseTab() { |
[email protected] | 2f1793ea | 2010-10-27 17:32:51 | [diff] [blame] | 674 | // Base class will fire DIChromeFrameEvents::onclose. |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 675 | BaseActiveX::OnCloseTab(); |
[email protected] | 2f1793ea | 2010-10-27 17:32:51 | [diff] [blame] | 676 | |
| 677 | // Close the container window. |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 678 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | e16dd167 | 2010-06-07 21:40:29 | [diff] [blame] | 679 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 680 | if (web_browser2) |
| 681 | web_browser2->Quit(); |
| 682 | } |
| 683 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 684 | void ChromeActiveDocument::UpdateNavigationState( |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 685 | const NavigationInfo& new_navigation_info, int flags) { |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 686 | // This could be NULL if the active document instance is being destroyed. |
| 687 | if (!m_spInPlaceSite) { |
| 688 | DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning"; |
| 689 | return; |
| 690 | } |
| 691 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 692 | HRESULT hr = S_OK; |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 693 | bool is_title_changed = |
| 694 | (navigation_info_->title != new_navigation_info.title); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 695 | bool is_ssl_state_changed = |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 696 | (navigation_info_->security_style != |
| 697 | new_navigation_info.security_style) || |
| 698 | (navigation_info_->displayed_insecure_content != |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 699 | new_navigation_info.displayed_insecure_content) || |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 700 | (navigation_info_->ran_insecure_content != |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 701 | new_navigation_info.ran_insecure_content); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 702 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 703 | if (is_ssl_state_changed) { |
| 704 | int lock_status = SECURELOCK_SET_UNSECURE; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 705 | switch (new_navigation_info.security_style) { |
[email protected] | cfa79d76 | 2011-10-21 00:15:04 | [diff] [blame^] | 706 | case content::SECURITY_STYLE_AUTHENTICATED: |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 707 | lock_status = new_navigation_info.displayed_insecure_content ? |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 708 | SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT; |
| 709 | break; |
| 710 | default: |
| 711 | break; |
| 712 | } |
| 713 | |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 714 | base::win::ScopedVariant secure_lock_status(lock_status); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 715 | IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK, |
| 716 | OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL); |
| 717 | } |
| 718 | |
[email protected] | a17930d8 | 2011-02-11 23:12:35 | [diff] [blame] | 719 | // A number of poorly written bho's crash in their event sink callbacks if |
| 720 | // chrome frame is the currently loaded document. This is because they expect |
| 721 | // chrome frame to implement interfaces like IHTMLDocument, etc. We patch the |
| 722 | // event sink's of these bho's and don't invoke the event sink if chrome |
| 723 | // frame is the currently loaded document. |
| 724 | if (GetConfigBool(true, kEnableBuggyBhoIntercept)) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 725 | base::win::ScopedComPtr<IWebBrowser2> wb2; |
[email protected] | a17930d8 | 2011-02-11 23:12:35 | [diff] [blame] | 726 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive()); |
| 727 | if (wb2 && buggy_bho::BuggyBhoTls::GetInstance()) { |
| 728 | buggy_bho::BuggyBhoTls::GetInstance()->PatchBuggyBHOs(wb2); |
| 729 | } |
| 730 | } |
| 731 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 732 | // Ideally all navigations should come to Chrome Frame so that we can call |
| 733 | // BeforeNavigate2 on installed BHOs and give them a chance to cancel the |
| 734 | // navigation. However, in practice what happens is as below: |
| 735 | // The very first navigation that happens in CF happens via a Load or a |
| 736 | // LoadHistory call. In this case, IE already has the correct information for |
| 737 | // its travel log as well address bar. For other internal navigations (navs |
| 738 | // that only happen within Chrome such as anchor navigations) we need to |
| 739 | // update IE's internal state after the fact. In the case of internal |
| 740 | // navigations, we notify the BHOs but ignore the should_cancel flag. |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 741 | |
| 742 | // Another case where we need to issue BeforeNavigate2 calls is as below:- |
| 743 | // We get notified after the fact, when navigations are initiated within |
| 744 | // Chrome via window.open calls. These navigations are handled by creating |
| 745 | // an external tab container within chrome and then connecting to it from IE. |
| 746 | // We still want to update the address bar/history, etc, to ensure that |
| 747 | // the special URL used by Chrome to indicate this is updated correctly. |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 748 | ChromeFrameUrl cf_url; |
| 749 | bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) && |
| 750 | cf_url.attach_to_external_tab(); |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 751 | |
| 752 | bool is_internal_navigation = |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 753 | IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 754 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 755 | if (new_navigation_info.url.is_valid()) |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 756 | url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str()); |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 757 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 758 | if (is_internal_navigation) { |
[email protected] | 74b1eaf54 | 2011-10-05 19:34:27 | [diff] [blame] | 759 | // IE6 does not support tabs. If Chrome sent us a window open request |
| 760 | // indicating that the navigation needs to occur in a foreground tab or |
| 761 | // a popup window, then we need to ensure that the new window in IE6 is |
| 762 | // brought to the foreground. |
| 763 | if (GetIEVersion() == IE_6 && |
| 764 | is_attach_external_tab_url && |
| 765 | (cf_url.disposition() == NEW_FOREGROUND_TAB || |
| 766 | cf_url.disposition() == NEW_POPUP)) { |
| 767 | base::win::ScopedComPtr<IWebBrowser2> wb2; |
| 768 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive()); |
| 769 | if (wb2) |
| 770 | BaseActiveX::BringWebBrowserWindowToTop(wb2); |
| 771 | } |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 772 | base::win::ScopedComPtr<IDocObjectService> doc_object_svc; |
| 773 | base::win::ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc; |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 774 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 775 | DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite, |
| 776 | web_browser_events_svc.Receive()); |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 777 | |
| 778 | if (!web_browser_events_svc.get()) { |
| 779 | DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 780 | doc_object_svc.Receive()); |
| 781 | } |
| 782 | |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 783 | // web_browser_events_svc can be NULL on IE6. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 784 | if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 785 | VARIANT_BOOL should_cancel = VARIANT_FALSE; |
| 786 | web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel); |
[email protected] | 33bd26d | 2010-08-31 05:05:03 | [diff] [blame] | 787 | } else if (doc_object_svc) { |
| 788 | BOOL should_cancel = FALSE; |
| 789 | doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0, |
| 790 | NULL, FALSE, &should_cancel); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // We need to tell IE that we support navigation so that IE will query us |
| 794 | // for IPersistHistory and call GetPositionCookie to save our navigation |
| 795 | // index. |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 796 | base::win::ScopedVariant html_window(static_cast<IUnknown*>( |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 797 | static_cast<IHTMLWindow2*>(this))); |
| 798 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, |
| 799 | html_window.AsInput(), NULL); |
| 800 | |
| 801 | // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG |
| 802 | // since we want to make IE treat all internal navigations within this page |
| 803 | // (including anchor navigations and subframe navigations) as anchor |
| 804 | // navigations. This will ensure that IE calls GetPositionCookie |
| 805 | // to save the current position cookie in the travel log and then call |
| 806 | // SetPositionCookie when the user hits Back/Forward to come back here. |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 807 | base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 808 | IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0, |
| 809 | internal_navigation.AsInput(), NULL); |
| 810 | |
| 811 | // We no longer need to lie to IE. If we lie persistently to IE, then |
| 812 | // IE reuses us for new navigations. |
| 813 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL); |
| 814 | |
| 815 | if (doc_object_svc) { |
| 816 | // Now call the FireNavigateCompleteEvent which makes IE update the text |
| 817 | // in the address-bar. |
| 818 | doc_object_svc->FireNavigateComplete2(this, 0); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 819 | doc_object_svc->FireDocumentComplete(this, 0); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 820 | } else if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 821 | web_browser_events_svc->FireNavigateComplete2Event(); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 822 | web_browser_events_svc->FireDocumentCompleteEvent(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 823 | } |
| 824 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 825 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 826 | if (is_title_changed) { |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 827 | base::win::ScopedVariant title(new_navigation_info.title.c_str()); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 828 | IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER, |
| 829 | title.AsInput(), NULL); |
| 830 | } |
| 831 | |
| 832 | // It is important that we only update the navigation_info_ after we have |
| 833 | // finalized the travel log. This is because IE will ask for information |
| 834 | // such as navigation index when the travel log is finalized and we need |
| 835 | // supply the old index and not the new one. |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 836 | *navigation_info_ = new_navigation_info; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 837 | // Update the IE zone here. Ideally we would like to do it when the active |
| 838 | // document is activated. However that does not work at times as the frame we |
| 839 | // get there is not the actual frame which handles the command. |
| 840 | IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | void ChromeActiveDocument::OnFindInPage() { |
| 844 | TabProxy* tab = GetTabProxy(); |
| 845 | if (tab) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 846 | if (!find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 847 | find_dialog_.Create(m_hWnd); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 848 | |
| 849 | find_dialog_.ShowWindow(SW_SHOW); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | void ChromeActiveDocument::OnViewSource() { |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 854 | DCHECK(navigation_info_->url.is_valid()); |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 855 | HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") + |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 856 | navigation_info_->url.spec()), GURL(), NEW_WINDOW); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 857 | } |
| 858 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 859 | void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid, |
| 860 | DWORD command_id, |
| 861 | DWORD cmd_exec_opt, |
| 862 | VARIANT* in_args, |
| 863 | VARIANT* out_args) { |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 864 | // Always return URLZONE_INTERNET since that is the Chrome's behaviour. |
| 865 | // Correct step is to use MapUrlToZone(). |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 866 | if (out_args != NULL) { |
| 867 | out_args->vt = VT_UI4; |
| 868 | out_args->ulVal = URLZONE_INTERNET; |
| 869 | } |
| 870 | } |
| 871 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 872 | void ChromeActiveDocument::OnDisplayPrivacyInfo() { |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 873 | privacy_info_ = url_fetcher_->privacy_info(); |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 874 | Reset(); |
| 875 | DoPrivacyDlg(m_hWnd, url_, this, TRUE); |
| 876 | } |
| 877 | |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 878 | void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid, |
| 879 | DWORD command_id, |
| 880 | DWORD cmd_exec_opt, |
| 881 | VARIANT* in_args, |
| 882 | VARIANT* out_args) { |
| 883 | if (out_args != NULL) { |
| 884 | out_args->vt = VT_I4; |
| 885 | out_args->lVal = 0; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid, |
| 890 | DWORD command_id, |
| 891 | DWORD cmd_exec_opt, |
| 892 | VARIANT* in_args, |
| 893 | VARIANT* out_args) { |
| 894 | const int kZoomIn = 125; |
| 895 | const int kZoomOut = 75; |
| 896 | |
| 897 | if (in_args && V_VT(in_args) == VT_I4 && IsValid()) { |
| 898 | if (in_args->lVal == kZoomIn) { |
| 899 | automation_client_->SetZoomLevel(PageZoom::ZOOM_IN); |
| 900 | } else if (in_args->lVal == kZoomOut) { |
| 901 | automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT); |
| 902 | } else { |
| 903 | DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal; |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 908 | void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid, |
| 909 | DWORD command_id, |
| 910 | DWORD cmd_exec_opt, |
| 911 | VARIANT* in_args, |
| 912 | VARIANT* out_args) { |
| 913 | if (IsValid() && out_args) { |
[email protected] | 9ae7b91 | 2011-06-30 21:41:25 | [diff] [blame] | 914 | // If the navigation is attempted to the url loaded in CF, with the only |
| 915 | // difference being the addition of an anchor, IE will attempt to unload |
| 916 | // the currently loaded document which basically would end up running |
| 917 | // unload handlers on the currently loaded document thus rendering it non |
| 918 | // functional. We handle this as below:- |
| 919 | // The BHO receives the new url in the BeforeNavigate event. |
| 920 | // We compare the non anchor portions of the url in the BHO with the loaded |
| 921 | // url and if they match, we initiate a Chrome navigation to the url with |
| 922 | // the anchor which works nicely. |
| 923 | // We don't want to continue processing the unload in this case. |
| 924 | // Note:- |
| 925 | // IE handles these navigations by querying the loaded document for |
| 926 | // IHTMLDocument which then handles the new navigation. That won't work for |
| 927 | // us as we don't implement IHTMLDocument. |
| 928 | NavigationManager* mgr = NavigationManager::GetThreadInstance(); |
| 929 | DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager"; |
| 930 | if (mgr) { |
| 931 | ChromeFrameUrl url; |
| 932 | url.Parse(mgr->url()); |
| 933 | if (url.gurl().has_ref()) { |
| 934 | url_canon::Replacements<char> replacements; |
| 935 | replacements.ClearRef(); |
| 936 | |
| 937 | if (url.gurl().ReplaceComponents(replacements) == |
| 938 | GURL(static_cast<BSTR>(url_))) { |
| 939 | // We want to reuse the existing automation client and channel for |
| 940 | // initiating the new navigation. Setting the |
| 941 | // is_automation_client_reused_ flag to true before calling the |
| 942 | // LaunchUrl function achieves that. |
| 943 | is_automation_client_reused_ = true; |
| 944 | LaunchUrl(url, mgr->referrer()); |
| 945 | out_args->vt = VT_BOOL; |
| 946 | out_args->boolVal = VARIANT_FALSE; |
| 947 | return; |
| 948 | } |
| 949 | } |
| 950 | } |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 951 | bool should_unload = true; |
| 952 | automation_client_->OnUnload(&should_unload); |
| 953 | out_args->vt = VT_BOOL; |
| 954 | out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE; |
| 955 | } |
| 956 | } |
| 957 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 958 | void ChromeActiveDocument::OnAttachExternalTab( |
| 959 | const AttachExternalTabParams& params) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 960 | if (!automation_client_.get()) { |
| 961 | DLOG(WARNING) << "Invalid automation client instance"; |
| 962 | return; |
| 963 | } |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 964 | DWORD flags = 0; |
| 965 | if (params.user_gesture) |
| 966 | flags = NWMF_USERREQUESTED; |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 967 | else if (popup_allowed_) |
| 968 | flags = NWMF_USERALLOWED; |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 969 | |
| 970 | HRESULT hr = S_OK; |
| 971 | if (popup_manager_) { |
[email protected] | e4456ae | 2010-09-22 23:35:11 | [diff] [blame] | 972 | const std::wstring& url_wide = UTF8ToWide(params.url.spec()); |
| 973 | hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_, |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 974 | NULL, FALSE, flags, 0); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 975 | } |
| 976 | // Allow popup |
| 977 | if (hr == S_OK) { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 978 | BaseActiveX::OnAttachExternalTab(params); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 979 | return; |
| 980 | } |
| 981 | |
| 982 | automation_client_->BlockExternalTab(params.cookie); |
| 983 | } |
| 984 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 985 | bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 986 | base::win::ScopedComPtr<IBrowserService> browser_service; |
| 987 | base::win::ScopedComPtr<ITravelLog> travel_log; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 988 | GetBrowserServiceAndTravelLog(browser_service.Receive(), |
| 989 | travel_log.Receive()); |
| 990 | if (!browser_service || !travel_log) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 991 | return true; |
| 992 | |
[email protected] | d118f54 | 2010-11-05 18:50:31 | [diff] [blame] | 993 | EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND | |
| 994 | (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK, |
| 995 | NULL)) ? |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 996 | MF_ENABLED : MF_DISABLED)); |
[email protected] | d118f54 | 2010-11-05 18:50:31 | [diff] [blame] | 997 | EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND | |
| 998 | (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE, |
| 999 | NULL)) ? |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1000 | MF_ENABLED : MF_DISABLED)); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1001 | // Call base class (adds 'About' item) |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 1002 | return BaseActiveX::PreProcessContextMenu(menu); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 1005 | bool ChromeActiveDocument::HandleContextMenuCommand( |
| 1006 | UINT cmd, const MiniContextMenuParams& params) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1007 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1008 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1009 | |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 1010 | if (cmd == IDC_BACK) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 1011 | web_browser2->GoBack(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 1012 | else if (cmd == IDC_FORWARD) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 1013 | web_browser2->GoForward(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 1014 | else if (cmd == IDC_RELOAD) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 1015 | web_browser2->Refresh(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 1016 | else |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 1017 | return BaseActiveX::HandleContextMenuCommand(cmd, params); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1018 | |
| 1019 | return true; |
| 1020 | } |
| 1021 | |
| 1022 | HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid, |
| 1023 | DWORD command_id, DWORD cmd_exec_opt, |
| 1024 | VARIANT* in_args, VARIANT* out_args) { |
| 1025 | HRESULT hr = E_FAIL; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1026 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1027 | base::win::ScopedComPtr<IOleCommandTarget> frame_cmd_target; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1028 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1029 | base::win::ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1030 | if (!in_place_site.get() && m_spClientSite != NULL) |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1031 | in_place_site.QueryFrom(m_spClientSite); |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1032 | |
| 1033 | if (in_place_site) |
| 1034 | hr = frame_cmd_target.QueryFrom(in_place_site); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1035 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1036 | if (frame_cmd_target) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1037 | hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt, |
| 1038 | in_args, out_args); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1039 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1040 | |
| 1041 | return hr; |
| 1042 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1043 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 1044 | bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url, |
| 1045 | const std::string& referrer) { |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 1046 | DCHECK(!cf_url.gurl().is_empty()); |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 1047 | |
[email protected] | 242ceb03 | 2010-08-26 17:06:36 | [diff] [blame] | 1048 | if (!automation_client_.get()) { |
| 1049 | // http://code.google.com/p/chromium/issues/detail?id=52894 |
| 1050 | // Still not sure how this happens. |
| 1051 | DLOG(ERROR) << "No automation client!"; |
| 1052 | if (!Initialize()) { |
| 1053 | NOTREACHED() << "...and failed to start a new one >:("; |
| 1054 | return false; |
| 1055 | } |
| 1056 | } |
| 1057 | |
[email protected] | 93b79279 | 2011-06-07 23:00:01 | [diff] [blame] | 1058 | document_url_ = cf_url.gurl().spec(); |
| 1059 | |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 1060 | url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str()); |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 1061 | if (cf_url.attach_to_external_tab()) { |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 1062 | automation_client_->AttachExternalTab(cf_url.cookie()); |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 1063 | OnMoveWindow(cf_url.dimensions()); |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 1064 | } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(), |
[email protected] | 6f8f31d | 2010-07-30 08:17:15 | [diff] [blame] | 1065 | referrer, |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 1066 | this)) { |
[email protected] | 6f8f31d | 2010-07-30 08:17:15 | [diff] [blame] | 1067 | DLOG(ERROR) << "Invalid URL: " << url_; |
| 1068 | Error(L"Invalid URL"); |
| 1069 | url_.Reset(); |
| 1070 | return false; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1071 | } |
| 1072 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 1073 | if (is_automation_client_reused_) |
| 1074 | return true; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1075 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1076 | automation_client_->SetUrlFetcher(url_fetcher_.get()); |
[email protected] | 701142a | 2010-08-31 20:57:07 | [diff] [blame] | 1077 | if (launch_params_) { |
| 1078 | return automation_client_->Initialize(this, launch_params_); |
| 1079 | } else { |
[email protected] | 8103c7f | 2010-09-08 22:36:09 | [diff] [blame] | 1080 | std::wstring profile = UTF8ToWide(cf_url.profile_name()); |
| 1081 | // If no profile was given, then make use of the host process's name. |
| 1082 | if (profile.empty()) |
| 1083 | profile = GetHostProcessName(false); |
| 1084 | return InitializeAutomation(profile, L"", IsIEInPrivate(), |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1085 | false, cf_url.gurl(), GURL(referrer), |
| 1086 | false); |
[email protected] | 701142a | 2010-08-31 20:57:07 | [diff] [blame] | 1087 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1088 | } |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1089 | |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1090 | HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid, |
| 1091 | DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 1092 | DVLOG(1) << __FUNCTION__; |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1093 | popup_allowed_ = false; |
| 1094 | if (in_args->vt == VT_I4 && |
| 1095 | in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) { |
| 1096 | popup_allowed_ = true; |
| 1097 | |
| 1098 | // Ask the yellow security band to change the text and icon and to remain |
| 1099 | // visible. |
| 1100 | IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED, |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1101 | 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL); |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1102 | } |
| 1103 | |
[email protected] | 3eb8a7049 | 2010-12-03 21:32:19 | [diff] [blame] | 1104 | NavigationManager* mgr = NavigationManager::GetThreadInstance(); |
| 1105 | DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager"; |
| 1106 | |
| 1107 | // If ChromeFrame was activated on this page as a result of a document |
| 1108 | // received in response to a top level post, then we ask the user for |
| 1109 | // permission to repost and issue a navigation with the saved post data |
| 1110 | // which reinitates the whole sequence, i.e. the server receives the top |
| 1111 | // level post and chrome frame will be reactivated in response. |
| 1112 | if (mgr && mgr->post_data().type() != VT_EMPTY) { |
| 1113 | if (MessageBox( |
| 1114 | SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING).c_str(), |
| 1115 | SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING_TITLE).c_str(), |
| 1116 | MB_YESNO | MB_ICONEXCLAMATION) == IDYES) { |
| 1117 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
| 1118 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1119 | web_browser2.Receive()); |
| 1120 | DCHECK(web_browser2); |
| 1121 | VARIANT empty = base::win::ScopedVariant::kEmptyVariant; |
| 1122 | VARIANT flags = { VT_I4 }; |
| 1123 | V_I4(&flags) = navNoHistory; |
| 1124 | |
| 1125 | return web_browser2->Navigate2(base::win::ScopedVariant(url_).AsInput(), |
| 1126 | &flags, |
| 1127 | &empty, |
| 1128 | const_cast<VARIANT*>(&mgr->post_data()), |
| 1129 | const_cast<VARIANT*>(&mgr->headers())); |
| 1130 | } else { |
| 1131 | return S_OK; |
| 1132 | } |
| 1133 | } |
| 1134 | |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1135 | TabProxy* tab_proxy = GetTabProxy(); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1136 | if (tab_proxy) { |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1137 | tab_proxy->ReloadAsync(); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1138 | } else { |
| 1139 | DLOG(ERROR) << "No automation proxy"; |
[email protected] | 242ceb03 | 2010-08-26 17:06:36 | [diff] [blame] | 1140 | DCHECK(automation_client_.get() != NULL) << "how did it get freed?"; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1141 | // The current url request manager (url_fetcher_) has been switched to |
| 1142 | // a stopping state so we need to reset it and get a new one for the new |
| 1143 | // automation server. |
| 1144 | ResetUrlRequestManager(); |
| 1145 | url_fetcher_->set_frame_busting(false); |
| 1146 | // And now launch the current URL again. This starts a new server process. |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1147 | DCHECK(navigation_info_->url.is_valid()); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1148 | ChromeFrameUrl cf_url; |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1149 | cf_url.Parse(UTF8ToWide(navigation_info_->url.spec())); |
| 1150 | LaunchUrl(cf_url, navigation_info_->referrer.spec()); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1151 | } |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1152 | |
| 1153 | return S_OK; |
| 1154 | } |
| 1155 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1156 | HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid, |
| 1157 | DWORD command_id, |
| 1158 | DWORD cmd_exec_opt, |
| 1159 | VARIANT* in_args, |
| 1160 | VARIANT* out_args) { |
| 1161 | if (!automation_client_.get()) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 1162 | NOTREACHED() << "Invalid automation client"; |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1163 | return E_FAIL; |
| 1164 | } |
| 1165 | |
| 1166 | switch (command_id) { |
| 1167 | case IDM_BASELINEFONT1: |
| 1168 | automation_client_->SetPageFontSize(SMALLEST_FONT); |
| 1169 | break; |
| 1170 | |
| 1171 | case IDM_BASELINEFONT2: |
| 1172 | automation_client_->SetPageFontSize(SMALL_FONT); |
| 1173 | break; |
| 1174 | |
| 1175 | case IDM_BASELINEFONT3: |
| 1176 | automation_client_->SetPageFontSize(MEDIUM_FONT); |
| 1177 | break; |
| 1178 | |
| 1179 | case IDM_BASELINEFONT4: |
| 1180 | automation_client_->SetPageFontSize(LARGE_FONT); |
| 1181 | break; |
| 1182 | |
| 1183 | case IDM_BASELINEFONT5: |
| 1184 | automation_client_->SetPageFontSize(LARGEST_FONT); |
| 1185 | break; |
| 1186 | |
| 1187 | default: |
| 1188 | NOTREACHED() << "Invalid font size command: " |
| 1189 | << command_id; |
| 1190 | return E_FAIL; |
| 1191 | } |
| 1192 | |
| 1193 | // Forward the command back to IEFrame with group set to |
| 1194 | // CGID_ExplorerBarDoc. This is probably needed to update the menu state to |
| 1195 | // indicate that the font size was set. This currently fails with error |
| 1196 | // 0x80040104. |
| 1197 | // TODO(iyengar) |
| 1198 | // Do some investigation into why this Exec call fails. |
| 1199 | IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL); |
| 1200 | return S_OK; |
| 1201 | } |
| 1202 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 1203 | HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid, |
| 1204 | DWORD command_id, |
| 1205 | DWORD cmd_exec_opt, |
| 1206 | VARIANT* in_args, |
| 1207 | VARIANT* out_args) { |
| 1208 | const struct EncodingMapData { |
| 1209 | DWORD ie_encoding_id; |
| 1210 | const char* chrome_encoding_name; |
| 1211 | } kEncodingTestDatas[] = { |
| 1212 | #define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \ |
| 1213 | { encoding_name, chrome_name }, |
| 1214 | INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP) |
| 1215 | #undef DEFINE_ENCODING_MAP |
| 1216 | }; |
| 1217 | |
| 1218 | if (!automation_client_.get()) { |
| 1219 | NOTREACHED() << "Invalid automtion client"; |
| 1220 | return E_FAIL; |
| 1221 | } |
| 1222 | |
[email protected] | e9b3528 | 2010-06-02 16:43:19 | [diff] [blame] | 1223 | // Using ARRAYSIZE_UNSAFE in here is because we define the struct |
| 1224 | // EncodingMapData inside function. |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 1225 | const char* chrome_encoding_name = NULL; |
| 1226 | for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { |
| 1227 | const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i]; |
| 1228 | if (command_id == encoding_data->ie_encoding_id) { |
| 1229 | chrome_encoding_name = encoding_data->chrome_encoding_name; |
| 1230 | break; |
| 1231 | } |
| 1232 | } |
| 1233 | // Return E_FAIL when encountering invalid encoding id. |
| 1234 | if (!chrome_encoding_name) |
| 1235 | return E_FAIL; |
| 1236 | |
| 1237 | TabProxy* tab = GetTabProxy(); |
| 1238 | if (!tab) { |
| 1239 | NOTREACHED() << "Can not get TabProxy"; |
| 1240 | return E_FAIL; |
| 1241 | } |
| 1242 | |
| 1243 | if (chrome_encoding_name) |
| 1244 | tab->OverrideEncoding(chrome_encoding_name); |
| 1245 | |
| 1246 | // Like we did on SetPageFontSize, we may forward the command back to IEFrame |
| 1247 | // to update the menu state to indicate that which encoding was set. |
| 1248 | // TODO(iyengar) |
| 1249 | // Do some investigation into why this Exec call fails. |
| 1250 | IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL); |
| 1251 | return S_OK; |
| 1252 | } |
| 1253 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 1254 | void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 1255 | DVLOG(1) << __FUNCTION__ << " - offset:" << offset; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1256 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1257 | base::win::ScopedComPtr<IBrowserService> browser_service; |
| 1258 | base::win::ScopedComPtr<ITravelLog> travel_log; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1259 | GetBrowserServiceAndTravelLog(browser_service.Receive(), |
| 1260 | travel_log.Receive()); |
| 1261 | |
| 1262 | if (browser_service && travel_log) |
| 1263 | travel_log->Travel(browser_service, offset); |
| 1264 | } |
| 1265 | |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 1266 | void ChromeActiveDocument::OnMoveWindow(const gfx::Rect& dimensions) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1267 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 1268 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1269 | web_browser2.Receive()); |
| 1270 | if (!web_browser2) |
| 1271 | return; |
| 1272 | DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions.width() |
| 1273 | << " height:" << dimensions.height(); |
| 1274 | if (!dimensions.IsEmpty()) { |
| 1275 | web_browser2->put_MenuBar(VARIANT_FALSE); |
| 1276 | web_browser2->put_ToolBar(VARIANT_FALSE); |
| 1277 | |
| 1278 | int width = dimensions.width(); |
| 1279 | int height = dimensions.height(); |
| 1280 | // Compute the size of the browser window given the desired size of the |
| 1281 | // content area. As per MSDN, the WebBrowser object returns an error from |
| 1282 | // this method. As a result the code below is best effort. |
| 1283 | web_browser2->ClientToWindow(&width, &height); |
| 1284 | |
| 1285 | web_browser2->put_Width(width); |
| 1286 | web_browser2->put_Height(height); |
| 1287 | web_browser2->put_Left(dimensions.x()); |
| 1288 | web_browser2->put_Top(dimensions.y()); |
| 1289 | } |
| 1290 | } |
| 1291 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1292 | HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog( |
| 1293 | IBrowserService** browser_service, ITravelLog** travel_log) { |
| 1294 | DCHECK(browser_service || travel_log); |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1295 | base::win::ScopedComPtr<IBrowserService> browser_service_local; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1296 | HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 1297 | browser_service_local.Receive()); |
| 1298 | if (!browser_service_local) { |
| 1299 | NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr; |
| 1300 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1301 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1302 | |
| 1303 | if (travel_log) { |
| 1304 | hr = browser_service_local->GetTravelLog(travel_log); |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 1305 | DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | if (browser_service) |
| 1309 | *browser_service = browser_service_local.Detach(); |
| 1310 | |
| 1311 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1312 | } |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1313 | |
| 1314 | LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id, |
| 1315 | HWND control_window, |
| 1316 | BOOL& bHandled) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1317 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1318 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1319 | DCHECK(web_browser2); |
| 1320 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1321 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1322 | web_browser2->GoForward(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id, |
| 1327 | HWND control_window, |
| 1328 | BOOL& bHandled) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1329 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1330 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1331 | DCHECK(web_browser2); |
| 1332 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1333 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1334 | web_browser2->GoBack(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1335 | return 0; |
| 1336 | } |
| 1337 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1338 | LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam, |
| 1339 | LPARAM lparam, |
| 1340 | BOOL& handled) { |
| 1341 | if (!m_spClientSite) |
| 1342 | return 0; |
| 1343 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1344 | base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1345 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1346 | web_browser2.Receive()); |
| 1347 | if (!web_browser2) { |
| 1348 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1352 | base::win::ScopedComPtr<IShellBrowser> shell_browser; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1353 | DoQueryService(SID_STopLevelBrowser, web_browser2, |
| 1354 | shell_browser.Receive()); |
| 1355 | DCHECK(shell_browser.get() != NULL); |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1356 | base::win::ScopedComPtr<ITridentService2> trident_services; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1357 | trident_services.QueryFrom(shell_browser); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1358 | if (trident_services) |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1359 | trident_services->FirePrivacyImpactedStateChange(wparam); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1360 | else |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1361 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1362 | return 0; |
| 1363 | } |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 1364 | |
[email protected] | 723e544 | 2010-07-21 17:36:05 | [diff] [blame] | 1365 | LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam, |
| 1366 | LPARAM lparam, |
| 1367 | BOOL& handled) { // NO_LINT |
| 1368 | if (wparam) |
| 1369 | SetFocus(); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
| 1373 | LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam, |
| 1374 | LPARAM lparam, |
| 1375 | BOOL& handled) { // NO_LINT |
[email protected] | e7ad932 | 2010-08-02 20:41:29 | [diff] [blame] | 1376 | if (!ignore_setfocus_) |
| 1377 | GiveFocusToChrome(false); |
[email protected] | 723e544 | 2010-07-21 17:36:05 | [diff] [blame] | 1378 | return 0; |
| 1379 | } |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1380 | |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1381 | bool ChromeActiveDocument::IsNewNavigation( |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1382 | const NavigationInfo& new_navigation_info, int flags) const { |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1383 | // A new navigation is typically an internal navigation which is initiated by |
| 1384 | // the renderer(WebKit). Condition 1 below has to be true along with the |
| 1385 | // any of the other conditions below. |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1386 | // 1. The navigation notification flags passed in as the flags parameter |
| 1387 | // is not INVALIDATE_LOAD which indicates that the loading state of the |
| 1388 | // tab changed. |
| 1389 | // 2. The navigation index is greater than 0 which means that a top level |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1390 | // navigation was initiated on the current external tab. |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1391 | // 3. The navigation type has changed. |
| 1392 | // 4. The url or the referrer are different. |
| 1393 | if (flags == TabContents::INVALIDATE_LOAD) |
| 1394 | return false; |
| 1395 | |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1396 | if (new_navigation_info.navigation_index <= 0) |
| 1397 | return false; |
| 1398 | |
| 1399 | if (new_navigation_info.navigation_index == |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1400 | navigation_info_->navigation_index) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1401 | return false; |
| 1402 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1403 | if (new_navigation_info.navigation_type != navigation_info_->navigation_type) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1404 | return true; |
| 1405 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1406 | if (new_navigation_info.url != navigation_info_->url) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1407 | return true; |
| 1408 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1409 | if (new_navigation_info.referrer != navigation_info_->referrer) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1410 | return true; |
| 1411 | |
| 1412 | return false; |
| 1413 | } |