[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 1 | // Copyright (c) 2010 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/file_util.h" |
| 23 | #include "base/logging.h" |
| 24 | #include "base/path_service.h" |
| 25 | #include "base/process_util.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 26 | #include "base/string_tokenizer.h" |
| 27 | #include "base/string_util.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 28 | #include "base/threading/thread.h" |
[email protected] | 1357c32 | 2010-12-30 22:18:56 | [diff] [blame] | 29 | #include "base/threading/thread_local.h" |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 30 | #include "base/utf_string_conversions.h" |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 31 | #include "base/win/scoped_variant.h" |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 32 | #include "base/win/win_util.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 33 | #include "grit/generated_resources.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 34 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | cccd376 | 2010-11-12 18:40:01 | [diff] [blame] | 35 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 36 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 37 | #include "chrome/common/automation_messages.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 38 | #include "chrome/common/chrome_constants.h" |
| 39 | #include "chrome/common/navigation_types.h" |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 40 | #include "chrome/common/page_zoom.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 41 | #include "chrome/test/automation/browser_proxy.h" |
| 42 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 43 | #include "chrome_frame/bho.h" |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 44 | #include "chrome_frame/bind_context_info.h" |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 45 | #include "chrome_frame/buggy_bho_handling.h" |
[email protected] | 9607f6a8 | 2010-06-12 17:24:41 | [diff] [blame] | 46 | #include "chrome_frame/crash_reporting/crash_metrics.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 47 | #include "chrome_frame/utils.h" |
| 48 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 49 | DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, |
| 50 | 0x46); |
| 51 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 52 | base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache; |
| 53 | |
| 54 | bool g_first_launch_by_process_ = true; |
| 55 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 56 | const DWORD kIEEncodingIdArray[] = { |
| 57 | #define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name, |
| 58 | INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY) |
| 59 | #undef DEFINE_ENCODING_ID_ARRAY |
| 60 | 0 // The Last data must be 0 to indicate the end of the encoding id array. |
| 61 | }; |
| 62 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 63 | ChromeActiveDocument::ChromeActiveDocument() |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 64 | : navigation_info_(new NavigationInfo()), |
| 65 | first_navigation_(true), |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 66 | is_automation_client_reused_(false), |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 67 | popup_allowed_(false), |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 68 | accelerator_table_(NULL) { |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 69 | TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, ""); |
| 70 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 71 | url_fetcher_->set_frame_busting(false); |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 72 | memset(navigation_info_.get(), 0, sizeof(NavigationInfo)); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | HRESULT ChromeActiveDocument::FinalConstruct() { |
| 76 | // If we have a cached ChromeActiveDocument instance in TLS, then grab |
| 77 | // ownership of the cached document's automation client. This is an |
| 78 | // optimization to get Chrome active documents to load faster. |
| 79 | ChromeActiveDocument* cached_document = g_active_doc_cache.Get(); |
[email protected] | 58174a7 | 2010-05-05 21:30:30 | [diff] [blame] | 80 | if (cached_document && cached_document->IsValid()) { |
[email protected] | 3eb8a7049 | 2010-12-03 21:32:19 | [diff] [blame] | 81 | SetResourceModule(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 82 | DCHECK(automation_client_.get() == NULL); |
[email protected] | 3148c0ae | 2010-03-11 18:06:00 | [diff] [blame] | 83 | automation_client_.swap(cached_document->automation_client_); |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 84 | DVLOG(1) << "Reusing automation client instance from " << cached_document; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 85 | DCHECK(automation_client_.get() != NULL); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 86 | automation_client_->Reinitialize(this, url_fetcher_.get()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 87 | is_automation_client_reused_ = true; |
[email protected] | b581105 | 2010-08-21 01:37:29 | [diff] [blame] | 88 | OnAutomationServerReady(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 89 | } else { |
| 90 | // The FinalConstruct implementation in the ChromeFrameActivexBase class |
| 91 | // i.e. Base creates an instance of the ChromeFrameAutomationClient class |
| 92 | // and initializes it, which would spawn a new Chrome process, etc. |
| 93 | // We don't want to be doing this if we have a cached document, whose |
| 94 | // automation client instance can be reused. |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 95 | HRESULT hr = BaseActiveX::FinalConstruct(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 96 | if (FAILED(hr)) |
| 97 | return hr; |
| 98 | } |
| 99 | |
[email protected] | e1081d9 | 2010-09-10 20:29:11 | [diff] [blame] | 100 | InitializeAutomationSettings(); |
[email protected] | 8f56e61 | 2010-09-09 17:03:14 | [diff] [blame] | 101 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 102 | find_dialog_.Init(automation_client_.get()); |
| 103 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 104 | OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED); |
| 105 | |
| 106 | null_group_commands_map_[OLECMDID_PRINT] = flags; |
| 107 | null_group_commands_map_[OLECMDID_FIND] = flags; |
| 108 | null_group_commands_map_[OLECMDID_CUT] = flags; |
| 109 | null_group_commands_map_[OLECMDID_COPY] = flags; |
| 110 | null_group_commands_map_[OLECMDID_PASTE] = flags; |
| 111 | null_group_commands_map_[OLECMDID_SELECTALL] = flags; |
| 112 | null_group_commands_map_[OLECMDID_SAVEAS] = flags; |
| 113 | |
| 114 | mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags; |
| 115 | mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags; |
| 116 | mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags; |
| 117 | mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags; |
| 118 | mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags; |
[email protected] | b252972 | 2010-12-01 02:49:07 | [diff] [blame] | 119 | mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags; |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 120 | |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 121 | HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 122 | accelerator_table_ = |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 123 | LoadAccelerators(this_module, |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 124 | MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB)); |
| 125 | DCHECK(accelerator_table_ != NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 126 | return S_OK; |
| 127 | } |
| 128 | |
| 129 | ChromeActiveDocument::~ChromeActiveDocument() { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 130 | DVLOG(1) << __FUNCTION__; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 131 | if (find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 132 | find_dialog_.DestroyWindow(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 133 | // ChromeFramePlugin |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 134 | BaseActiveX::Uninitialize(); |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 135 | |
| 136 | TRACE_EVENT_END("chromeframe.createactivedocument", this, ""); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | // Override DoVerb |
| 140 | STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb, |
| 141 | LPMSG msg, |
| 142 | IOleClientSite* active_site, |
| 143 | LONG index, |
| 144 | HWND parent_window, |
| 145 | LPCRECT pos) { |
| 146 | // IE will try and in-place activate us in some cases. This happens when |
| 147 | // the user opens a new IE window with a URL that has us as the DocObject. |
| 148 | // Here we refuse to be activated in-place and we will force IE to UIActivate |
| 149 | // us. |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 150 | if (OLEIVERB_INPLACEACTIVATE == verb) |
[email protected] | 23b3361 | 2010-11-09 23:47:01 | [diff] [blame] | 151 | return OLEOBJ_E_INVALIDVERB; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 152 | // Check if we should activate as a docobject or not |
| 153 | // (client supports IOleDocumentSite) |
| 154 | if (doc_site_) { |
| 155 | switch (verb) { |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 156 | case OLEIVERB_SHOW: { |
| 157 | ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
| 158 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 159 | if (doc_host_handler.get()) |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 160 | doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL); |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 161 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 162 | case OLEIVERB_OPEN: |
| 163 | case OLEIVERB_UIACTIVATE: |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 164 | if (!m_bUIActive) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 165 | return doc_site_->ActivateMe(NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 166 | break; |
| 167 | } |
| 168 | } |
| 169 | return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb, |
| 170 | msg, |
| 171 | active_site, |
| 172 | index, |
| 173 | parent_window, |
| 174 | pos); |
| 175 | } |
| 176 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 177 | // Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate |
| 178 | STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 179 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 180 | return S_OK; |
| 181 | } |
| 182 | |
| 183 | STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 184 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 185 | if (msg == NULL) |
| 186 | return E_POINTER; |
| 187 | |
| 188 | if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) { |
| 189 | HWND focus = ::GetFocus(); |
| 190 | if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) { |
| 191 | // The call to SetFocus triggers a WM_SETFOCUS that makes the base class |
| 192 | // set focus to the correct element in Chrome. |
| 193 | ::SetFocus(m_hWnd); |
| 194 | return S_OK; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return S_FALSE; |
| 199 | } |
| 200 | // Override IPersistStorageImpl::IsDirty |
| 201 | STDMETHODIMP ChromeActiveDocument::IsDirty() { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 202 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 203 | return S_FALSE; |
| 204 | } |
| 205 | |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 206 | void ChromeActiveDocument::OnAutomationServerReady() { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 207 | BaseActiveX::OnAutomationServerReady(); |
[email protected] | 1fd4569 | 2010-04-19 21:01:18 | [diff] [blame] | 208 | BaseActiveX::GiveFocusToChrome(true); |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 211 | STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable, |
| 212 | IMoniker* moniker_name, |
| 213 | LPBC bind_context, |
| 214 | DWORD mode) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 215 | if (NULL == moniker_name) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 216 | return E_INVALIDARG; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 217 | |
| 218 | ScopedComPtr<IOleClientSite> client_site; |
| 219 | if (bind_context) { |
| 220 | ScopedComPtr<IUnknown> site; |
| 221 | bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM, |
| 222 | site.Receive()); |
| 223 | if (site) |
| 224 | client_site.QueryFrom(site); |
| 225 | } |
| 226 | |
| 227 | if (client_site) { |
| 228 | SetClientSite(client_site); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 229 | DoQueryService(IID_INewWindowManager, client_site, |
| 230 | popup_manager_.Receive()); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 231 | |
| 232 | // See if mshtml parsed the html header for us. If so, we need to |
| 233 | // clear the browser service flag that we use to indicate that this |
| 234 | // browser instance is navigating to a CF document. |
| 235 | ScopedComPtr<IBrowserService> browser_service; |
| 236 | DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive()); |
| 237 | if (browser_service) { |
| 238 | bool flagged = CheckForCFNavigation(browser_service, true); |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 239 | DVLOG_IF(1, flagged) << "Cleared flagged browser service"; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 240 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 243 | NavigationManager* mgr = NavigationManager::GetThreadInstance(); |
[email protected] | 21b4e6d | 2010-07-14 18:19:59 | [diff] [blame] | 244 | DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager"; |
[email protected] | 7e3544b | 2010-01-22 00:02:34 | [diff] [blame] | 245 | |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 246 | std::wstring url; |
| 247 | |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 248 | ScopedComPtr<BindContextInfo> info; |
| 249 | BindContextInfo::FromBindContext(bind_context, info.Receive()); |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 250 | DCHECK(info); |
[email protected] | 4f45d458 | 2011-02-22 23:27:27 | [diff] [blame] | 251 | if (info && !info->GetUrl().empty()) { |
| 252 | url = info->GetUrl(); |
[email protected] | df0846a5 | 2011-02-23 03:29:58 | [diff] [blame^] | 253 | if (mgr) { |
| 254 | // If the original URL contains an anchor, then the URL queried |
| 255 | // from the protocol sink wrapper does not contain the anchor. To |
| 256 | // workaround this we retrieve the anchor from the navigation manager |
| 257 | // and append it to the url retrieved from the protocol sink wrapper. |
| 258 | GURL url_for_anchor(mgr->url()); |
| 259 | if (url_for_anchor.has_ref()) { |
| 260 | url += L"#"; |
| 261 | url += UTF8ToWide(url_for_anchor.ref()); |
| 262 | } |
| 263 | } |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 264 | } else { |
| 265 | // If the original URL contains an anchor, then the URL queried |
| 266 | // from the moniker does not contain the anchor. To workaround |
| 267 | // this we retrieve the URL from our BHO. |
| 268 | url = GetActualUrlFromMoniker(moniker_name, bind_context, |
| 269 | mgr ? mgr->url(): std::wstring()); |
| 270 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 271 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 272 | ChromeFrameUrl cf_url; |
| 273 | if (!cf_url.Parse(url)) { |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 274 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 275 | return E_INVALIDARG; |
| 276 | } |
| 277 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 278 | std::string referrer(mgr ? mgr->referrer() : EmptyString()); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 279 | RendererType renderer_type = cf_url.is_chrome_protocol() ? |
| 280 | RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 281 | |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 282 | // With CTransaction patch we have more robust way to grab the referrer for |
| 283 | // each top-level-switch-to-CF request by peeking at our sniffing data |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 284 | // object that lives inside the bind context. We also remember the reason |
| 285 | // we're rendering the document in Chrome. |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 286 | if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) { |
| 287 | scoped_refptr<ProtData> prot_data = info->get_prot_data(); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 288 | if (prot_data) { |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 289 | referrer = prot_data->referrer(); |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 290 | renderer_type = prot_data->renderer_type(); |
| 291 | } |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 62ce0973 | 2010-09-03 18:32:04 | [diff] [blame] | 294 | // For gcf: URLs allow only about and view-source schemes to pass through for |
| 295 | // further inspection. |
| 296 | bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) || |
| 297 | cf_url.gurl().SchemeIs(chrome::kViewSourceScheme); |
| 298 | if (cf_url.is_chrome_protocol() && !is_safe_scheme && |
| 299 | !GetConfigBool(false, kAllowUnsafeURLs)) { |
| 300 | DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url; |
| 301 | return E_INVALIDARG; |
| 302 | } |
| 303 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 304 | if (!LaunchUrl(cf_url, referrer)) { |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 305 | DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 306 | return E_INVALIDARG; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 309 | if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab()) |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 310 | url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 311 | |
[email protected] | d8e1351 | 2010-09-22 17:02:58 | [diff] [blame] | 312 | // Log a metric indicating why GCF is rendering in Chrome. |
| 313 | // (Note: we only track the renderer type when using the CTransaction patch. |
| 314 | // When the code for the browser service patch and for the moniker patch is |
| 315 | // removed, this conditional can also go away.) |
| 316 | if (RENDERER_TYPE_UNDETERMINED != renderer_type) { |
| 317 | THREAD_SAFE_UMA_LAUNCH_TYPE_COUNT(renderer_type); |
| 318 | } |
| 319 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 320 | return S_OK; |
| 321 | } |
| 322 | |
| 323 | STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name, |
| 324 | LPBC bind_context, |
| 325 | BOOL remember) { |
| 326 | return E_NOTIMPL; |
| 327 | } |
| 328 | |
| 329 | STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name, |
| 330 | LPBC bind_context) { |
| 331 | return E_NOTIMPL; |
| 332 | } |
| 333 | |
| 334 | STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) { |
| 335 | return E_NOTIMPL; |
| 336 | } |
| 337 | |
| 338 | STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 339 | if (NULL == class_id) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 340 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 341 | *class_id = GetObjectCLSID(); |
| 342 | return S_OK; |
| 343 | } |
| 344 | |
| 345 | STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid, |
| 346 | ULONG number_of_commands, |
| 347 | OLECMD commands[], |
| 348 | OLECMDTEXT* command_text) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 349 | DVLOG(1) << __FUNCTION__; |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 350 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 351 | CommandStatusMap* command_map = NULL; |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 352 | |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 353 | if (cmd_group_guid) { |
| 354 | if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) { |
| 355 | command_map = &null_group_commands_map_; |
| 356 | } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) { |
| 357 | command_map = &mshtml_group_commands_map_; |
| 358 | } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) { |
| 359 | command_map = &explorer_group_commands_map_; |
| 360 | } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) { |
| 361 | command_map = &shdoc_view_group_commands_map_; |
| 362 | } |
| 363 | } else { |
| 364 | command_map = &null_group_commands_map_; |
| 365 | } |
| 366 | |
| 367 | if (!command_map) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 368 | DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid); |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 369 | return OLECMDERR_E_NOTSUPPORTED; |
| 370 | } |
| 371 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 372 | for (ULONG command_index = 0; command_index < number_of_commands; |
| 373 | command_index++) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 374 | DVLOG(1) << "Command id = " << commands[command_index].cmdID; |
[email protected] | 6fd1a7a | 2010-07-26 22:09:46 | [diff] [blame] | 375 | CommandStatusMap::iterator index = |
| 376 | command_map->find(commands[command_index].cmdID); |
| 377 | if (index != command_map->end()) |
| 378 | commands[command_index].cmdf = index->second; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 379 | } |
| 380 | return S_OK; |
| 381 | } |
| 382 | |
| 383 | STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid, |
| 384 | DWORD command_id, |
| 385 | DWORD cmd_exec_opt, |
| 386 | VARIANT* in_args, |
| 387 | VARIANT* out_args) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 388 | DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 389 | // Bail out if we have been uninitialized. |
| 390 | if (automation_client_.get() && automation_client_->tab()) { |
| 391 | return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt, |
| 392 | in_args, out_args); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 393 | } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) { |
| 394 | // If the automation server has crashed and the user is refreshing the |
| 395 | // page, let OnRefreshPage attempt to recover. |
| 396 | OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 397 | } |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 398 | |
[email protected] | e320093 | 2009-10-09 21:33:03 | [diff] [blame] | 399 | return OLECMDERR_E_NOTSUPPORTED; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 400 | } |
| 401 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 402 | STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream, |
| 403 | IBindCtx* bind_context) { |
| 404 | // Read notes in ChromeActiveDocument::SaveHistory |
| 405 | DCHECK(stream); |
| 406 | LARGE_INTEGER offset = {0}; |
| 407 | ULARGE_INTEGER cur_pos = {0}; |
| 408 | STATSTG statstg = {0}; |
| 409 | |
| 410 | stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos); |
| 411 | stream->Stat(&statstg, STATFLAG_NONAME); |
| 412 | |
| 413 | DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart; |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 414 | base::win::ScopedBstr url_bstr; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 415 | DWORD bytes_read = 0; |
| 416 | stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read); |
| 417 | std::wstring url(url_bstr); |
| 418 | |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 419 | ChromeFrameUrl cf_url; |
| 420 | if (!cf_url.Parse(url)) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 421 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
| 422 | return E_INVALIDARG; |
| 423 | } |
| 424 | |
[email protected] | c5cbf4e | 2010-07-15 21:48:25 | [diff] [blame] | 425 | const std::string& referrer = EmptyString(); |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 426 | if (!LaunchUrl(cf_url, referrer)) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 427 | NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url; |
| 428 | return E_INVALIDARG; |
| 429 | } |
| 430 | return S_OK; |
| 431 | } |
| 432 | |
| 433 | STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) { |
| 434 | // TODO(sanjeevr): We need to fetch the entire list of navigation entries |
| 435 | // from Chrome and persist it in the stream. And in LoadHistory we need to |
| 436 | // pass this list back to Chrome which will recreate the list. This will allow |
| 437 | // Back-Forward navigation to anchors to work correctly when we navigate to a |
| 438 | // page outside of ChromeFrame and then come back. |
| 439 | if (!stream) { |
| 440 | NOTREACHED(); |
| 441 | return E_INVALIDARG; |
| 442 | } |
| 443 | |
| 444 | LARGE_INTEGER offset = {0}; |
| 445 | ULARGE_INTEGER new_pos = {0}; |
| 446 | DWORD written = 0; |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 447 | std::wstring url = UTF8ToWide(navigation_info_->url.spec()); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 448 | return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t), |
| 449 | &written); |
| 450 | } |
| 451 | |
| 452 | STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 453 | if (automation_client_.get()) { |
| 454 | int index = static_cast<int>(position_cookie); |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 455 | navigation_info_->navigation_index = index; |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 456 | automation_client_->NavigateToIndex(index); |
| 457 | } else { |
| 458 | DLOG(WARNING) << "Invalid automation client instance"; |
| 459 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 460 | return S_OK; |
| 461 | } |
| 462 | |
| 463 | STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) { |
| 464 | if (!position_cookie) |
| 465 | return E_INVALIDARG; |
| 466 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 467 | *position_cookie = navigation_info_->navigation_index; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 468 | return S_OK; |
| 469 | } |
| 470 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 471 | STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 472 | if (NULL == url) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 473 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 474 | *url = ::SysAllocString(url_); |
| 475 | return S_OK; |
| 476 | } |
| 477 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 478 | STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) { |
| 479 | return GetUrlForEvents(url); |
| 480 | } |
| 481 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 482 | STDMETHODIMP ChromeActiveDocument::Reset() { |
| 483 | next_privacy_record_ = privacy_info_.privacy_records.begin(); |
| 484 | return S_OK; |
| 485 | } |
| 486 | |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 487 | STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 488 | if (!size) |
| 489 | return E_POINTER; |
| 490 | |
| 491 | *size = privacy_info_.privacy_records.size(); |
| 492 | return S_OK; |
| 493 | } |
| 494 | |
| 495 | STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) { |
| 496 | if (!privacy_impacted) |
| 497 | return E_POINTER; |
| 498 | |
| 499 | *privacy_impacted = privacy_info_.privacy_impacted; |
| 500 | return S_OK; |
| 501 | } |
| 502 | |
| 503 | STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy, |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 504 | LONG* reserved, DWORD* flags) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 505 | if (!url || !policy || !flags) |
| 506 | return E_POINTER; |
| 507 | |
| 508 | if (next_privacy_record_ == privacy_info_.privacy_records.end()) |
| 509 | return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS); |
| 510 | |
| 511 | *url = SysAllocString(next_privacy_record_->first.c_str()); |
| 512 | *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str()); |
| 513 | *flags = next_privacy_record_->second.flags; |
| 514 | |
| 515 | next_privacy_record_++; |
| 516 | return S_OK; |
| 517 | } |
| 518 | |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 519 | bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) { |
| 520 | bool allowed = BaseActiveX::IsSchemeAllowed(url); |
| 521 | if (allowed) |
| 522 | return true; |
| 523 | |
| 524 | if (url.SchemeIs(chrome::kAboutScheme)) { |
| 525 | if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL)) |
| 526 | return true; |
| 527 | } |
| 528 | return false; |
| 529 | } |
| 530 | |
[email protected] | 3eafbfb9 | 2010-08-02 16:54:22 | [diff] [blame] | 531 | HRESULT ChromeActiveDocument::GetInPlaceFrame( |
| 532 | IOleInPlaceFrame** in_place_frame) { |
| 533 | DCHECK(in_place_frame); |
| 534 | if (in_place_frame_) { |
| 535 | *in_place_frame = in_place_frame_.get(); |
| 536 | (*in_place_frame)->AddRef(); |
| 537 | return S_OK; |
| 538 | } else { |
| 539 | return S_FALSE; |
| 540 | } |
| 541 | } |
| 542 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 543 | HRESULT ChromeActiveDocument::IOleObject_SetClientSite( |
| 544 | IOleClientSite* client_site) { |
| 545 | if (client_site == NULL) { |
| 546 | ChromeActiveDocument* cached_document = g_active_doc_cache.Get(); |
| 547 | if (cached_document) { |
| 548 | DCHECK(this == cached_document); |
| 549 | g_active_doc_cache.Set(NULL); |
| 550 | cached_document->Release(); |
| 551 | } |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 552 | |
| 553 | ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 554 | if (doc_site_) |
[email protected] | 77059f7 | 2010-02-28 06:16:00 | [diff] [blame] | 555 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 556 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 557 | if (doc_host_handler.get()) |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 558 | doc_host_handler->HideUI(); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 559 | |
| 560 | doc_site_.Release(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 561 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 562 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 563 | if (client_site != m_spClientSite) |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 564 | return BaseActiveX::IOleObject_SetClientSite(client_site); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 565 | |
| 566 | return S_OK; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 567 | } |
| 568 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 569 | HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) { |
| 570 | HRESULT hr = S_OK; |
| 571 | m_bNegotiatedWnd = TRUE; |
| 572 | if (!m_bInPlaceActive) { |
| 573 | hr = m_spInPlaceSite->CanInPlaceActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 574 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 575 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 576 | m_spInPlaceSite->OnInPlaceActivate(); |
| 577 | } |
| 578 | m_bInPlaceActive = TRUE; |
| 579 | // get location in the parent window, |
| 580 | // as well as some information about the parent |
| 581 | ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window; |
| 582 | frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO); |
| 583 | HWND parent_window = NULL; |
| 584 | if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) { |
| 585 | in_place_frame_.Release(); |
| 586 | RECT position_rect = {0}; |
| 587 | RECT clip_rect = {0}; |
| 588 | m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(), |
| 589 | in_place_ui_window.Receive(), |
| 590 | &position_rect, |
| 591 | &clip_rect, |
| 592 | &frame_info_); |
| 593 | if (!m_bWndLess) { |
| 594 | if (IsWindow()) { |
| 595 | ::ShowWindow(m_hWnd, SW_SHOW); |
| 596 | SetFocus(); |
| 597 | } else { |
[email protected] | fca446b9 | 2011-02-18 20:44:06 | [diff] [blame] | 598 | m_hWnd = Create(parent_window, position_rect); |
[email protected] | dd4beb52 | 2010-07-13 18:18:14 | [diff] [blame] | 599 | if (!IsWindow()) { |
| 600 | // This might happen if the automation server couldn't be |
| 601 | // instantiated. If so, a NOTREACHED() will have already been hit. |
| 602 | DLOG(ERROR) << "Failed to create Ax window"; |
| 603 | return AtlHresultFromLastError(); |
| 604 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 605 | } |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 606 | SetWindowDimensions(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 607 | } |
| 608 | SetObjectRects(&position_rect, &clip_rect); |
| 609 | } |
| 610 | |
| 611 | ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this); |
| 612 | |
| 613 | // Gone active by now, take care of UIACTIVATE |
| 614 | if (DoesVerbUIActivate(verb)) { |
| 615 | if (!m_bUIActive) { |
| 616 | m_bUIActive = TRUE; |
| 617 | hr = m_spInPlaceSite->OnUIActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 618 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 619 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 620 | // set ourselves up in the host |
| 621 | if (in_place_active_object) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 622 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 623 | in_place_frame_->SetActiveObject(in_place_active_object, NULL); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 624 | if (in_place_ui_window) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 625 | in_place_ui_window->SetActiveObject(in_place_active_object, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | } |
| 629 | m_spClientSite->ShowObject(); |
| 630 | return S_OK; |
| 631 | } |
| 632 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 633 | void ChromeActiveDocument::OnNavigationStateChanged( |
| 634 | int flags, const NavigationInfo& nav_info) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 635 | // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc. |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 636 | DVLOG(1) << __FUNCTION__ |
| 637 | << "\n Flags: " << flags |
| 638 | << ", Url: " << nav_info.url |
| 639 | << ", Title: " << nav_info.title |
| 640 | << ", Type: " << nav_info.navigation_type |
| 641 | << ", Relative Offset: " << nav_info.relative_offset |
| 642 | << ", Index: " << nav_info.navigation_index; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 643 | |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 644 | UpdateNavigationState(nav_info, flags); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 645 | } |
| 646 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 647 | void ChromeActiveDocument::OnUpdateTargetUrl( |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 648 | const std::wstring& new_target_url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 649 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 650 | in_place_frame_->SetStatusText(new_target_url.c_str()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | bool IsFindAccelerator(const MSG& msg) { |
| 654 | // TODO(robertshield): This may not stand up to localization. Fix if this |
| 655 | // is the case. |
| 656 | return msg.message == WM_KEYDOWN && msg.wParam == 'F' && |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 657 | base::win::IsCtrlPressed() && |
| 658 | !(base::win::IsAltPressed() || base::win::IsShiftPressed()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 659 | } |
| 660 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 661 | void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) { |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 662 | if (::TranslateAccelerator(m_hWnd, accelerator_table_, |
| 663 | const_cast<MSG*>(&accel_message))) |
| 664 | return; |
| 665 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 666 | bool handled_accel = false; |
| 667 | if (in_place_frame_ != NULL) { |
| 668 | handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW( |
| 669 | const_cast<MSG*>(&accel_message), 0)); |
| 670 | } |
| 671 | |
| 672 | if (!handled_accel) { |
| 673 | if (IsFindAccelerator(accel_message)) { |
| 674 | // Handle the showing of the find dialog explicitly. |
| 675 | OnFindInPage(); |
[email protected] | 2b8fd32 | 2009-10-02 00:00:59 | [diff] [blame] | 676 | } else { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 677 | BaseActiveX::OnAcceleratorPressed(accel_message); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 678 | } |
| 679 | } else { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 680 | DVLOG(1) << "IE handled accel key " << accel_message.wParam; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 684 | void ChromeActiveDocument::OnTabbedOut(bool reverse) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 685 | DVLOG(1) << __FUNCTION__; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 686 | if (in_place_frame_) { |
| 687 | MSG msg = { NULL, WM_KEYDOWN, VK_TAB }; |
| 688 | in_place_frame_->TranslateAcceleratorW(&msg, 0); |
| 689 | } |
| 690 | } |
| 691 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 692 | void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 693 | DVLOG(1) << __FUNCTION__ << std::endl |
| 694 | << "Url: " << nav_info.url |
| 695 | << ", Title: " << nav_info.title |
| 696 | << ", Type: " << nav_info.navigation_type |
| 697 | << ", Relative Offset: " << nav_info.relative_offset |
| 698 | << ", Index: " << nav_info.navigation_index; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 699 | |
[email protected] | 897b2627 | 2010-06-11 02:23:44 | [diff] [blame] | 700 | CrashMetricsReporter::GetInstance()->IncrementMetric( |
| 701 | CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT); |
| 702 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 703 | // This could be NULL if the active document instance is being destroyed. |
| 704 | if (!m_spInPlaceSite) { |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 705 | DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning"; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 709 | UpdateNavigationState(nav_info, 0); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 710 | } |
| 711 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 712 | void ChromeActiveDocument::OnCloseTab() { |
[email protected] | 2f1793ea | 2010-10-27 17:32:51 | [diff] [blame] | 713 | // Base class will fire DIChromeFrameEvents::onclose. |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 714 | BaseActiveX::OnCloseTab(); |
[email protected] | 2f1793ea | 2010-10-27 17:32:51 | [diff] [blame] | 715 | |
| 716 | // Close the container window. |
[email protected] | e16dd167 | 2010-06-07 21:40:29 | [diff] [blame] | 717 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 718 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 719 | if (web_browser2) |
| 720 | web_browser2->Quit(); |
| 721 | } |
| 722 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 723 | void ChromeActiveDocument::UpdateNavigationState( |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 724 | const NavigationInfo& new_navigation_info, int flags) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 725 | HRESULT hr = S_OK; |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 726 | bool is_title_changed = |
| 727 | (navigation_info_->title != new_navigation_info.title); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 728 | bool is_ssl_state_changed = |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 729 | (navigation_info_->security_style != |
| 730 | new_navigation_info.security_style) || |
| 731 | (navigation_info_->displayed_insecure_content != |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 732 | new_navigation_info.displayed_insecure_content) || |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 733 | (navigation_info_->ran_insecure_content != |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 734 | new_navigation_info.ran_insecure_content); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 735 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 736 | if (is_ssl_state_changed) { |
| 737 | int lock_status = SECURELOCK_SET_UNSECURE; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 738 | switch (new_navigation_info.security_style) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 739 | case SECURITY_STYLE_AUTHENTICATED: |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 740 | lock_status = new_navigation_info.displayed_insecure_content ? |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 741 | SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT; |
| 742 | break; |
| 743 | default: |
| 744 | break; |
| 745 | } |
| 746 | |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 747 | base::win::ScopedVariant secure_lock_status(lock_status); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 748 | IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK, |
| 749 | OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL); |
| 750 | } |
| 751 | |
[email protected] | a17930d8 | 2011-02-11 23:12:35 | [diff] [blame] | 752 | // A number of poorly written bho's crash in their event sink callbacks if |
| 753 | // chrome frame is the currently loaded document. This is because they expect |
| 754 | // chrome frame to implement interfaces like IHTMLDocument, etc. We patch the |
| 755 | // event sink's of these bho's and don't invoke the event sink if chrome |
| 756 | // frame is the currently loaded document. |
| 757 | if (GetConfigBool(true, kEnableBuggyBhoIntercept)) { |
| 758 | ScopedComPtr<IWebBrowser2> wb2; |
| 759 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive()); |
| 760 | if (wb2 && buggy_bho::BuggyBhoTls::GetInstance()) { |
| 761 | buggy_bho::BuggyBhoTls::GetInstance()->PatchBuggyBHOs(wb2); |
| 762 | } |
| 763 | } |
| 764 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 765 | // Ideally all navigations should come to Chrome Frame so that we can call |
| 766 | // BeforeNavigate2 on installed BHOs and give them a chance to cancel the |
| 767 | // navigation. However, in practice what happens is as below: |
| 768 | // The very first navigation that happens in CF happens via a Load or a |
| 769 | // LoadHistory call. In this case, IE already has the correct information for |
| 770 | // its travel log as well address bar. For other internal navigations (navs |
| 771 | // that only happen within Chrome such as anchor navigations) we need to |
| 772 | // update IE's internal state after the fact. In the case of internal |
| 773 | // navigations, we notify the BHOs but ignore the should_cancel flag. |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 774 | |
| 775 | // Another case where we need to issue BeforeNavigate2 calls is as below:- |
| 776 | // We get notified after the fact, when navigations are initiated within |
| 777 | // Chrome via window.open calls. These navigations are handled by creating |
| 778 | // an external tab container within chrome and then connecting to it from IE. |
| 779 | // We still want to update the address bar/history, etc, to ensure that |
| 780 | // the special URL used by Chrome to indicate this is updated correctly. |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 781 | ChromeFrameUrl cf_url; |
| 782 | bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) && |
| 783 | cf_url.attach_to_external_tab(); |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 784 | |
| 785 | bool is_internal_navigation = |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 786 | IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 787 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 788 | if (new_navigation_info.url.is_valid()) |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 789 | url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str()); |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 790 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 791 | if (is_internal_navigation) { |
| 792 | ScopedComPtr<IDocObjectService> doc_object_svc; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 793 | ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc; |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 794 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 795 | DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite, |
| 796 | web_browser_events_svc.Receive()); |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 797 | |
| 798 | if (!web_browser_events_svc.get()) { |
| 799 | DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 800 | doc_object_svc.Receive()); |
| 801 | } |
| 802 | |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 803 | // web_browser_events_svc can be NULL on IE6. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 804 | if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 805 | VARIANT_BOOL should_cancel = VARIANT_FALSE; |
| 806 | web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel); |
[email protected] | 33bd26d | 2010-08-31 05:05:03 | [diff] [blame] | 807 | } else if (doc_object_svc) { |
| 808 | BOOL should_cancel = FALSE; |
| 809 | doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0, |
| 810 | NULL, FALSE, &should_cancel); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | // We need to tell IE that we support navigation so that IE will query us |
| 814 | // for IPersistHistory and call GetPositionCookie to save our navigation |
| 815 | // index. |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 816 | base::win::ScopedVariant html_window(static_cast<IUnknown*>( |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 817 | static_cast<IHTMLWindow2*>(this))); |
| 818 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, |
| 819 | html_window.AsInput(), NULL); |
| 820 | |
| 821 | // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG |
| 822 | // since we want to make IE treat all internal navigations within this page |
| 823 | // (including anchor navigations and subframe navigations) as anchor |
| 824 | // navigations. This will ensure that IE calls GetPositionCookie |
| 825 | // to save the current position cookie in the travel log and then call |
| 826 | // SetPositionCookie when the user hits Back/Forward to come back here. |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 827 | base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 828 | IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0, |
| 829 | internal_navigation.AsInput(), NULL); |
| 830 | |
| 831 | // We no longer need to lie to IE. If we lie persistently to IE, then |
| 832 | // IE reuses us for new navigations. |
| 833 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL); |
| 834 | |
| 835 | if (doc_object_svc) { |
| 836 | // Now call the FireNavigateCompleteEvent which makes IE update the text |
| 837 | // in the address-bar. |
| 838 | doc_object_svc->FireNavigateComplete2(this, 0); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 839 | doc_object_svc->FireDocumentComplete(this, 0); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 840 | } else if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 841 | web_browser_events_svc->FireNavigateComplete2Event(); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 842 | web_browser_events_svc->FireDocumentCompleteEvent(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 843 | } |
| 844 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 845 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 846 | if (is_title_changed) { |
[email protected] | 965722ff | 2010-10-20 15:50:30 | [diff] [blame] | 847 | base::win::ScopedVariant title(new_navigation_info.title.c_str()); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 848 | IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER, |
| 849 | title.AsInput(), NULL); |
| 850 | } |
| 851 | |
| 852 | // It is important that we only update the navigation_info_ after we have |
| 853 | // finalized the travel log. This is because IE will ask for information |
| 854 | // such as navigation index when the travel log is finalized and we need |
| 855 | // supply the old index and not the new one. |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 856 | *navigation_info_ = new_navigation_info; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 857 | // Update the IE zone here. Ideally we would like to do it when the active |
| 858 | // document is activated. However that does not work at times as the frame we |
| 859 | // get there is not the actual frame which handles the command. |
| 860 | IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | void ChromeActiveDocument::OnFindInPage() { |
| 864 | TabProxy* tab = GetTabProxy(); |
| 865 | if (tab) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 866 | if (!find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 867 | find_dialog_.Create(m_hWnd); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 868 | |
| 869 | find_dialog_.ShowWindow(SW_SHOW); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | void ChromeActiveDocument::OnViewSource() { |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 874 | DCHECK(navigation_info_->url.is_valid()); |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 875 | HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") + |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 876 | navigation_info_->url.spec()), GURL(), NEW_WINDOW); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 877 | } |
| 878 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 879 | void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid, |
| 880 | DWORD command_id, |
| 881 | DWORD cmd_exec_opt, |
| 882 | VARIANT* in_args, |
| 883 | VARIANT* out_args) { |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 884 | // Always return URLZONE_INTERNET since that is the Chrome's behaviour. |
| 885 | // Correct step is to use MapUrlToZone(). |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 886 | if (out_args != NULL) { |
| 887 | out_args->vt = VT_UI4; |
| 888 | out_args->ulVal = URLZONE_INTERNET; |
| 889 | } |
| 890 | } |
| 891 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 892 | void ChromeActiveDocument::OnDisplayPrivacyInfo() { |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 893 | privacy_info_ = url_fetcher_->privacy_info(); |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 894 | Reset(); |
| 895 | DoPrivacyDlg(m_hWnd, url_, this, TRUE); |
| 896 | } |
| 897 | |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 898 | void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid, |
| 899 | DWORD command_id, |
| 900 | DWORD cmd_exec_opt, |
| 901 | VARIANT* in_args, |
| 902 | VARIANT* out_args) { |
| 903 | if (out_args != NULL) { |
| 904 | out_args->vt = VT_I4; |
| 905 | out_args->lVal = 0; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid, |
| 910 | DWORD command_id, |
| 911 | DWORD cmd_exec_opt, |
| 912 | VARIANT* in_args, |
| 913 | VARIANT* out_args) { |
| 914 | const int kZoomIn = 125; |
| 915 | const int kZoomOut = 75; |
| 916 | |
| 917 | if (in_args && V_VT(in_args) == VT_I4 && IsValid()) { |
| 918 | if (in_args->lVal == kZoomIn) { |
| 919 | automation_client_->SetZoomLevel(PageZoom::ZOOM_IN); |
| 920 | } else if (in_args->lVal == kZoomOut) { |
| 921 | automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT); |
| 922 | } else { |
| 923 | DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 928 | void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid, |
| 929 | DWORD command_id, |
| 930 | DWORD cmd_exec_opt, |
| 931 | VARIANT* in_args, |
| 932 | VARIANT* out_args) { |
| 933 | if (IsValid() && out_args) { |
| 934 | bool should_unload = true; |
| 935 | automation_client_->OnUnload(&should_unload); |
| 936 | out_args->vt = VT_BOOL; |
| 937 | out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE; |
| 938 | } |
| 939 | } |
| 940 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 941 | void ChromeActiveDocument::OnOpenURL(const GURL& url_to_open, |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 942 | const GURL& referrer, |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 943 | int open_disposition) { |
| 944 | // If the disposition indicates that we should be opening the URL in the |
| 945 | // current tab, then we can reuse the ChromeFrameAutomationClient instance |
| 946 | // maintained by the current ChromeActiveDocument instance. We cache this |
| 947 | // instance so that it can be used by the new ChromeActiveDocument instance |
| 948 | // which may be instantiated for handling the new URL. |
| 949 | if (open_disposition == CURRENT_TAB) { |
| 950 | // Grab a reference to ensure that the document remains valid. |
| 951 | AddRef(); |
| 952 | g_active_doc_cache.Set(this); |
| 953 | } |
| 954 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 955 | BaseActiveX::OnOpenURL(url_to_open, referrer, open_disposition); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 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) { |
| 986 | ScopedComPtr<IBrowserService> browser_service; |
| 987 | 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] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1007 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 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] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1027 | ScopedComPtr<IOleCommandTarget> frame_cmd_target; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1028 | |
| 1029 | 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] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 1058 | url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str()); |
[email protected] | c4e45b3 | 2010-07-28 21:15:15 | [diff] [blame] | 1059 | if (cf_url.attach_to_external_tab()) { |
| 1060 | dimensions_ = cf_url.dimensions(); |
| 1061 | automation_client_->AttachExternalTab(cf_url.cookie()); |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1062 | SetWindowDimensions(); |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 1063 | } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(), |
[email protected] | 6f8f31d | 2010-07-30 08:17:15 | [diff] [blame] | 1064 | referrer, |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 1065 | this)) { |
[email protected] | 6f8f31d | 2010-07-30 08:17:15 | [diff] [blame] | 1066 | DLOG(ERROR) << "Invalid URL: " << url_; |
| 1067 | Error(L"Invalid URL"); |
| 1068 | url_.Reset(); |
| 1069 | return false; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1070 | } |
| 1071 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 1072 | if (is_automation_client_reused_) |
| 1073 | return true; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1074 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 1075 | automation_client_->SetUrlFetcher(url_fetcher_.get()); |
[email protected] | 701142a | 2010-08-31 20:57:07 | [diff] [blame] | 1076 | if (launch_params_) { |
| 1077 | return automation_client_->Initialize(this, launch_params_); |
| 1078 | } else { |
[email protected] | 8103c7f | 2010-09-08 22:36:09 | [diff] [blame] | 1079 | std::wstring profile = UTF8ToWide(cf_url.profile_name()); |
| 1080 | // If no profile was given, then make use of the host process's name. |
| 1081 | if (profile.empty()) |
| 1082 | profile = GetHostProcessName(false); |
| 1083 | return InitializeAutomation(profile, L"", IsIEInPrivate(), |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1084 | false, cf_url.gurl(), GURL(referrer), |
| 1085 | false); |
[email protected] | 701142a | 2010-08-31 20:57:07 | [diff] [blame] | 1086 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1087 | } |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1088 | |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1089 | |
| 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] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1257 | ScopedComPtr<IBrowserService> browser_service; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1258 | ScopedComPtr<ITravelLog> travel_log; |
| 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 | |
| 1266 | HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog( |
| 1267 | IBrowserService** browser_service, ITravelLog** travel_log) { |
| 1268 | DCHECK(browser_service || travel_log); |
| 1269 | ScopedComPtr<IBrowserService> browser_service_local; |
| 1270 | HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 1271 | browser_service_local.Receive()); |
| 1272 | if (!browser_service_local) { |
| 1273 | NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr; |
| 1274 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1275 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1276 | |
| 1277 | if (travel_log) { |
| 1278 | hr = browser_service_local->GetTravelLog(travel_log); |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 1279 | DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | if (browser_service) |
| 1283 | *browser_service = browser_service_local.Detach(); |
| 1284 | |
| 1285 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1286 | } |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1287 | |
| 1288 | LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id, |
| 1289 | HWND control_window, |
| 1290 | BOOL& bHandled) { |
| 1291 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1292 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1293 | DCHECK(web_browser2); |
| 1294 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1295 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1296 | web_browser2->GoForward(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id, |
| 1301 | HWND control_window, |
| 1302 | BOOL& bHandled) { |
| 1303 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1304 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1305 | DCHECK(web_browser2); |
| 1306 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1307 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1308 | web_browser2->GoBack(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
| 1311 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1312 | LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam, |
| 1313 | LPARAM lparam, |
| 1314 | BOOL& handled) { |
| 1315 | if (!m_spClientSite) |
| 1316 | return 0; |
| 1317 | |
| 1318 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1319 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1320 | web_browser2.Receive()); |
| 1321 | if (!web_browser2) { |
| 1322 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | ScopedComPtr<IShellBrowser> shell_browser; |
| 1327 | DoQueryService(SID_STopLevelBrowser, web_browser2, |
| 1328 | shell_browser.Receive()); |
| 1329 | DCHECK(shell_browser.get() != NULL); |
| 1330 | ScopedComPtr<ITridentService2> trident_services; |
| 1331 | trident_services.QueryFrom(shell_browser); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1332 | if (trident_services) |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1333 | trident_services->FirePrivacyImpactedStateChange(wparam); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1334 | else |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1335 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1336 | return 0; |
| 1337 | } |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 1338 | |
[email protected] | 723e544 | 2010-07-21 17:36:05 | [diff] [blame] | 1339 | LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam, |
| 1340 | LPARAM lparam, |
| 1341 | BOOL& handled) { // NO_LINT |
| 1342 | if (wparam) |
| 1343 | SetFocus(); |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam, |
| 1348 | LPARAM lparam, |
| 1349 | BOOL& handled) { // NO_LINT |
[email protected] | e7ad932 | 2010-08-02 20:41:29 | [diff] [blame] | 1350 | if (!ignore_setfocus_) |
| 1351 | GiveFocusToChrome(false); |
[email protected] | 723e544 | 2010-07-21 17:36:05 | [diff] [blame] | 1352 | return 0; |
| 1353 | } |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1354 | |
| 1355 | void ChromeActiveDocument::SetWindowDimensions() { |
| 1356 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1357 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1358 | web_browser2.Receive()); |
| 1359 | if (!web_browser2) |
| 1360 | return; |
[email protected] | 2b9a9f16 | 2010-10-19 20:30:45 | [diff] [blame] | 1361 | DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions_.width() |
| 1362 | << " height:" << dimensions_.height(); |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1363 | if (!dimensions_.IsEmpty()) { |
[email protected] | 73b1897 | 2010-11-18 01:35:46 | [diff] [blame] | 1364 | web_browser2->put_MenuBar(VARIANT_FALSE); |
| 1365 | web_browser2->put_ToolBar(VARIANT_FALSE); |
| 1366 | |
| 1367 | int width = dimensions_.width(); |
| 1368 | int height = dimensions_.height(); |
| 1369 | // Compute the size of the browser window given the desired size of the |
| 1370 | // content area. As per MSDN, the WebBrowser object returns an error from |
| 1371 | // this method. As a result the code below is best effort. |
| 1372 | if (SUCCEEDED(web_browser2->ClientToWindow(&width, &height))) { |
| 1373 | dimensions_.set_width(width); |
| 1374 | dimensions_.set_height(height); |
| 1375 | } |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1376 | web_browser2->put_Width(dimensions_.width()); |
| 1377 | web_browser2->put_Height(dimensions_.height()); |
| 1378 | web_browser2->put_Left(dimensions_.x()); |
| 1379 | web_browser2->put_Top(dimensions_.y()); |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 1380 | |
| 1381 | dimensions_.set_height(0); |
| 1382 | dimensions_.set_width(0); |
| 1383 | } |
| 1384 | } |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1385 | |
| 1386 | bool ChromeActiveDocument::IsNewNavigation( |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1387 | const NavigationInfo& new_navigation_info, int flags) const { |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1388 | // A new navigation is typically an internal navigation which is initiated by |
| 1389 | // the renderer(WebKit). Condition 1 below has to be true along with the |
| 1390 | // any of the other conditions below. |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1391 | // 1. The navigation notification flags passed in as the flags parameter |
| 1392 | // is not INVALIDATE_LOAD which indicates that the loading state of the |
| 1393 | // tab changed. |
| 1394 | // 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] | 1395 | // navigation was initiated on the current external tab. |
[email protected] | 747bca1 | 2011-01-15 00:28:45 | [diff] [blame] | 1396 | // 3. The navigation type has changed. |
| 1397 | // 4. The url or the referrer are different. |
| 1398 | if (flags == TabContents::INVALIDATE_LOAD) |
| 1399 | return false; |
| 1400 | |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1401 | if (new_navigation_info.navigation_index <= 0) |
| 1402 | return false; |
| 1403 | |
| 1404 | if (new_navigation_info.navigation_index == |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1405 | navigation_info_->navigation_index) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1406 | return false; |
| 1407 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1408 | if (new_navigation_info.navigation_type != navigation_info_->navigation_type) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1409 | return true; |
| 1410 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1411 | if (new_navigation_info.url != navigation_info_->url) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1412 | return true; |
| 1413 | |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 1414 | if (new_navigation_info.referrer != navigation_info_->referrer) |
[email protected] | 342de55 | 2010-10-21 20:46:14 | [diff] [blame] | 1415 | return true; |
| 1416 | |
| 1417 | return false; |
| 1418 | } |