[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> |
| 14 | #include <shobjidl.h> |
| 15 | #include <tlogstg.h> |
| 16 | #include <urlmon.h> |
| 17 | #include <wininet.h> |
| 18 | |
| 19 | #include "base/command_line.h" |
| 20 | #include "base/file_util.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 21 | #include "base/logging.h" |
| 22 | #include "base/path_service.h" |
| 23 | #include "base/process_util.h" |
| 24 | #include "base/registry.h" |
| 25 | #include "base/scoped_variant_win.h" |
| 26 | #include "base/string_tokenizer.h" |
| 27 | #include "base/string_util.h" |
| 28 | #include "base/thread.h" |
| 29 | #include "base/thread_local.h" |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 30 | #include "base/trace_event.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 31 | |
| 32 | #include "grit/generated_resources.h" |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 33 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 34 | #include "chrome/browser/tab_contents/tab_contents.h" |
| 35 | #include "chrome/common/chrome_constants.h" |
| 36 | #include "chrome/common/navigation_types.h" |
| 37 | #include "chrome/test/automation/browser_proxy.h" |
| 38 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 39 | #include "chrome_frame/bho.h" |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 40 | #include "chrome_frame/bind_context_info.h" |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame^] | 41 | #include "chrome_frame/buggy_bho_handling.h" |
[email protected] | 9607f6a8 | 2010-06-12 17:24:41 | [diff] [blame] | 42 | #include "chrome_frame/crash_reporting/crash_metrics.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 43 | #include "chrome_frame/utils.h" |
| 44 | |
| 45 | const wchar_t kChromeAttachExternalTabPrefix[] = L"attach_external_tab"; |
| 46 | |
| 47 | static const wchar_t kUseChromeNetworking[] = L"UseChromeNetworking"; |
[email protected] | 552fb601 | 2010-02-03 17:24:29 | [diff] [blame] | 48 | static const wchar_t kHandleTopLevelRequests[] = L"HandleTopLevelRequests"; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 49 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 50 | DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, |
| 51 | 0x46); |
| 52 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 53 | base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache; |
| 54 | |
| 55 | bool g_first_launch_by_process_ = true; |
| 56 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 57 | const DWORD kIEEncodingIdArray[] = { |
| 58 | #define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name, |
| 59 | INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY) |
| 60 | #undef DEFINE_ENCODING_ID_ARRAY |
| 61 | 0 // The Last data must be 0 to indicate the end of the encoding id array. |
| 62 | }; |
| 63 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 64 | ChromeActiveDocument::ChromeActiveDocument() |
| 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] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 68 | accelerator_table_(NULL), |
| 69 | is_new_navigation_(false) { |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 70 | TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, ""); |
| 71 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 72 | url_fetcher_.set_frame_busting(false); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 73 | memset(&navigation_info_, 0, sizeof(navigation_info_)); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | HRESULT ChromeActiveDocument::FinalConstruct() { |
| 77 | // If we have a cached ChromeActiveDocument instance in TLS, then grab |
| 78 | // ownership of the cached document's automation client. This is an |
| 79 | // optimization to get Chrome active documents to load faster. |
| 80 | ChromeActiveDocument* cached_document = g_active_doc_cache.Get(); |
[email protected] | 58174a7 | 2010-05-05 21:30:30 | [diff] [blame] | 81 | if (cached_document && cached_document->IsValid()) { |
[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] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 84 | DLOG(INFO) << "Reusing automation client instance from " |
| 85 | << cached_document; |
| 86 | DCHECK(automation_client_.get() != NULL); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 87 | automation_client_->Reinitialize(this, &url_fetcher_); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 88 | is_automation_client_reused_ = true; |
| 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 | |
| 100 | bool chrome_network = GetConfigBool(false, kUseChromeNetworking); |
| 101 | bool top_level_requests = GetConfigBool(true, kHandleTopLevelRequests); |
| 102 | automation_client_->set_use_chrome_network(chrome_network); |
| 103 | automation_client_->set_handle_top_level_requests(top_level_requests); |
| 104 | |
| 105 | find_dialog_.Init(automation_client_.get()); |
| 106 | |
| 107 | enabled_commands_map_[OLECMDID_PRINT] = true; |
| 108 | enabled_commands_map_[OLECMDID_FIND] = true; |
| 109 | enabled_commands_map_[OLECMDID_CUT] = true; |
| 110 | enabled_commands_map_[OLECMDID_COPY] = true; |
| 111 | enabled_commands_map_[OLECMDID_PASTE] = true; |
| 112 | enabled_commands_map_[OLECMDID_SELECTALL] = true; |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 113 | enabled_commands_map_[OLECMDID_SAVEAS] = true; |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 114 | |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 115 | HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 116 | accelerator_table_ = |
[email protected] | 3c6f8e1 | 2010-03-24 21:58:21 | [diff] [blame] | 117 | LoadAccelerators(this_module, |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 118 | MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB)); |
| 119 | DCHECK(accelerator_table_ != NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 120 | return S_OK; |
| 121 | } |
| 122 | |
| 123 | ChromeActiveDocument::~ChromeActiveDocument() { |
| 124 | DLOG(INFO) << __FUNCTION__; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 125 | if (find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 126 | find_dialog_.DestroyWindow(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 127 | // ChromeFramePlugin |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 128 | BaseActiveX::Uninitialize(); |
[email protected] | 04e3f35 | 2010-05-10 13:48:24 | [diff] [blame] | 129 | |
| 130 | TRACE_EVENT_END("chromeframe.createactivedocument", this, ""); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Override DoVerb |
| 134 | STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb, |
| 135 | LPMSG msg, |
| 136 | IOleClientSite* active_site, |
| 137 | LONG index, |
| 138 | HWND parent_window, |
| 139 | LPCRECT pos) { |
| 140 | // IE will try and in-place activate us in some cases. This happens when |
| 141 | // the user opens a new IE window with a URL that has us as the DocObject. |
| 142 | // Here we refuse to be activated in-place and we will force IE to UIActivate |
| 143 | // us. |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 144 | if (OLEIVERB_INPLACEACTIVATE == verb) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 145 | return E_NOTIMPL; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 146 | // Check if we should activate as a docobject or not |
| 147 | // (client supports IOleDocumentSite) |
| 148 | if (doc_site_) { |
| 149 | switch (verb) { |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 150 | case OLEIVERB_SHOW: { |
| 151 | ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
| 152 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 153 | if (doc_host_handler.get()) |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 154 | doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL); |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 155 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 156 | case OLEIVERB_OPEN: |
| 157 | case OLEIVERB_UIACTIVATE: |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 158 | if (!m_bUIActive) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 159 | return doc_site_->ActivateMe(NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb, |
| 164 | msg, |
| 165 | active_site, |
| 166 | index, |
| 167 | parent_window, |
| 168 | pos); |
| 169 | } |
| 170 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 171 | // Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate |
| 172 | STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) { |
| 173 | DLOG(INFO) << __FUNCTION__; |
| 174 | return S_OK; |
| 175 | } |
| 176 | |
| 177 | STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) { |
| 178 | DLOG(INFO) << __FUNCTION__; |
| 179 | if (msg == NULL) |
| 180 | return E_POINTER; |
| 181 | |
| 182 | if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) { |
| 183 | HWND focus = ::GetFocus(); |
| 184 | if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) { |
| 185 | // The call to SetFocus triggers a WM_SETFOCUS that makes the base class |
| 186 | // set focus to the correct element in Chrome. |
| 187 | ::SetFocus(m_hWnd); |
| 188 | return S_OK; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return S_FALSE; |
| 193 | } |
| 194 | // Override IPersistStorageImpl::IsDirty |
| 195 | STDMETHODIMP ChromeActiveDocument::IsDirty() { |
| 196 | DLOG(INFO) << __FUNCTION__; |
| 197 | return S_FALSE; |
| 198 | } |
| 199 | |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 200 | void ChromeActiveDocument::OnAutomationServerReady() { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 201 | BaseActiveX::OnAutomationServerReady(); |
[email protected] | 1fd4569 | 2010-04-19 21:01:18 | [diff] [blame] | 202 | BaseActiveX::GiveFocusToChrome(true); |
[email protected] | b95f550f | 2009-11-19 05:35:22 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 205 | STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable, |
| 206 | IMoniker* moniker_name, |
| 207 | LPBC bind_context, |
| 208 | DWORD mode) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 209 | if (NULL == moniker_name) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 210 | return E_INVALIDARG; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 211 | |
| 212 | ScopedComPtr<IOleClientSite> client_site; |
| 213 | if (bind_context) { |
| 214 | ScopedComPtr<IUnknown> site; |
| 215 | bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM, |
| 216 | site.Receive()); |
| 217 | if (site) |
| 218 | client_site.QueryFrom(site); |
| 219 | } |
| 220 | |
| 221 | if (client_site) { |
| 222 | SetClientSite(client_site); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 223 | DoQueryService(IID_INewWindowManager, client_site, |
| 224 | popup_manager_.Receive()); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 225 | |
| 226 | // See if mshtml parsed the html header for us. If so, we need to |
| 227 | // clear the browser service flag that we use to indicate that this |
| 228 | // browser instance is navigating to a CF document. |
| 229 | ScopedComPtr<IBrowserService> browser_service; |
| 230 | DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive()); |
| 231 | if (browser_service) { |
| 232 | bool flagged = CheckForCFNavigation(browser_service, true); |
| 233 | DLOG_IF(INFO, flagged) << "Cleared flagged browser service"; |
| 234 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 237 | NavigationManager* mgr = NavigationManager::GetThreadInstance(); |
[email protected] | 21b4e6d | 2010-07-14 18:19:59 | [diff] [blame] | 238 | DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager"; |
[email protected] | 7e3544b | 2010-01-22 00:02:34 | [diff] [blame] | 239 | |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 240 | std::wstring url; |
| 241 | |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 242 | ScopedComPtr<BindContextInfo> info; |
| 243 | BindContextInfo::FromBindContext(bind_context, info.Receive()); |
[email protected] | 29c32f90 | 2010-04-20 23:27:29 | [diff] [blame] | 244 | DCHECK(info); |
| 245 | if (info && !info->url().empty()) { |
| 246 | url = info->url(); |
| 247 | } else { |
| 248 | // If the original URL contains an anchor, then the URL queried |
| 249 | // from the moniker does not contain the anchor. To workaround |
| 250 | // this we retrieve the URL from our BHO. |
| 251 | url = GetActualUrlFromMoniker(moniker_name, bind_context, |
| 252 | mgr ? mgr->url(): std::wstring()); |
| 253 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 254 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 255 | // The is_new_navigation variable indicates if this a navigation initiated |
| 256 | // by typing in a URL for e.g. in the IE address bar, or from Chrome by |
| 257 | // a window.open call from javascript, in which case the current IE tab |
| 258 | // will attach to an existing ExternalTabContainer instance. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 259 | bool is_new_navigation = true; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 260 | bool is_chrome_protocol = false; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 261 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 262 | if (!ParseUrl(url, &is_new_navigation, &is_chrome_protocol, &url)) { |
| 263 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 264 | return E_INVALIDARG; |
| 265 | } |
| 266 | |
[email protected] | aaf12450 | 2010-07-17 04:02:58 | [diff] [blame] | 267 | std::string referrer = mgr ? mgr->referrer() : EmptyString(); |
| 268 | // With CTransaction patch we have more robust way to grab the referrer for |
| 269 | // each top-level-switch-to-CF request by peeking at our sniffing data |
| 270 | // object that lives inside the bind context. |
| 271 | if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) { |
| 272 | scoped_refptr<ProtData> prot_data = info->get_prot_data(); |
| 273 | if (prot_data) |
| 274 | referrer = prot_data->referrer(); |
| 275 | } |
| 276 | |
[email protected] | c5cbf4e | 2010-07-15 21:48:25 | [diff] [blame] | 277 | if (!LaunchUrl(url, referrer, is_new_navigation)) { |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 278 | NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url; |
| 279 | return E_INVALIDARG; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 280 | } |
| 281 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 282 | if (!is_chrome_protocol) |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 283 | url_fetcher_.SetInfoForUrl(url, moniker_name, bind_context); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 284 | |
[email protected] | 33359000 | 2010-03-05 18:49:21 | [diff] [blame] | 285 | THREAD_SAFE_UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.FullTabLaunchType", |
| 286 | is_chrome_protocol, 0, 1, 2); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 287 | return S_OK; |
| 288 | } |
| 289 | |
| 290 | STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name, |
| 291 | LPBC bind_context, |
| 292 | BOOL remember) { |
| 293 | return E_NOTIMPL; |
| 294 | } |
| 295 | |
| 296 | STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name, |
| 297 | LPBC bind_context) { |
| 298 | return E_NOTIMPL; |
| 299 | } |
| 300 | |
| 301 | STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) { |
| 302 | return E_NOTIMPL; |
| 303 | } |
| 304 | |
| 305 | STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 306 | if (NULL == class_id) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 307 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 308 | *class_id = GetObjectCLSID(); |
| 309 | return S_OK; |
| 310 | } |
| 311 | |
| 312 | STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid, |
| 313 | ULONG number_of_commands, |
| 314 | OLECMD commands[], |
| 315 | OLECMDTEXT* command_text) { |
| 316 | DLOG(INFO) << __FUNCTION__; |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 317 | const GUID* supported_groups[] = { |
| 318 | &GUID_NULL, |
| 319 | &CGID_MSHTML, |
| 320 | &CGID_Explorer, |
| 321 | }; |
| 322 | |
| 323 | bool supported = (cmd_group_guid == NULL); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 324 | for (int i = 0; !supported && i < arraysize(supported_groups); ++i) |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 325 | supported = (IsEqualGUID(*cmd_group_guid, *supported_groups[i]) != FALSE); |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 326 | |
| 327 | if (!supported) { |
| 328 | DLOG(INFO) << "unsupported command group: " |
| 329 | << GuidToString(*cmd_group_guid); |
| 330 | return OLECMDERR_E_NOTSUPPORTED; |
| 331 | } |
| 332 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 333 | for (ULONG command_index = 0; command_index < number_of_commands; |
| 334 | command_index++) { |
| 335 | DLOG(INFO) << "Command id = " << commands[command_index].cmdID; |
| 336 | if (enabled_commands_map_.find(commands[command_index].cmdID) != |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 337 | enabled_commands_map_.end()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 338 | commands[command_index].cmdf = OLECMDF_ENABLED; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 339 | } |
| 340 | return S_OK; |
| 341 | } |
| 342 | |
| 343 | STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid, |
| 344 | DWORD command_id, |
| 345 | DWORD cmd_exec_opt, |
| 346 | VARIANT* in_args, |
| 347 | VARIANT* out_args) { |
| 348 | DLOG(INFO) << __FUNCTION__ << " Cmd id =" << command_id; |
| 349 | // Bail out if we have been uninitialized. |
| 350 | if (automation_client_.get() && automation_client_->tab()) { |
| 351 | return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt, |
| 352 | in_args, out_args); |
| 353 | } |
[email protected] | e320093 | 2009-10-09 21:33:03 | [diff] [blame] | 354 | return OLECMDERR_E_NOTSUPPORTED; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 357 | STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream, |
| 358 | IBindCtx* bind_context) { |
| 359 | // Read notes in ChromeActiveDocument::SaveHistory |
| 360 | DCHECK(stream); |
| 361 | LARGE_INTEGER offset = {0}; |
| 362 | ULARGE_INTEGER cur_pos = {0}; |
| 363 | STATSTG statstg = {0}; |
| 364 | |
| 365 | stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos); |
| 366 | stream->Stat(&statstg, STATFLAG_NONAME); |
| 367 | |
| 368 | DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart; |
| 369 | ScopedBstr url_bstr; |
| 370 | DWORD bytes_read = 0; |
| 371 | stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read); |
| 372 | std::wstring url(url_bstr); |
| 373 | |
| 374 | bool is_new_navigation = true; |
| 375 | bool is_chrome_protocol = false; |
| 376 | |
| 377 | if (!ParseUrl(url, &is_new_navigation, &is_chrome_protocol, &url)) { |
| 378 | DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; |
| 379 | return E_INVALIDARG; |
| 380 | } |
| 381 | |
[email protected] | c5cbf4e | 2010-07-15 21:48:25 | [diff] [blame] | 382 | const std::string& referrer = EmptyString(); |
| 383 | if (!LaunchUrl(url, referrer, is_new_navigation)) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 384 | NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url; |
| 385 | return E_INVALIDARG; |
| 386 | } |
| 387 | return S_OK; |
| 388 | } |
| 389 | |
| 390 | STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) { |
| 391 | // TODO(sanjeevr): We need to fetch the entire list of navigation entries |
| 392 | // from Chrome and persist it in the stream. And in LoadHistory we need to |
| 393 | // pass this list back to Chrome which will recreate the list. This will allow |
| 394 | // Back-Forward navigation to anchors to work correctly when we navigate to a |
| 395 | // page outside of ChromeFrame and then come back. |
| 396 | if (!stream) { |
| 397 | NOTREACHED(); |
| 398 | return E_INVALIDARG; |
| 399 | } |
| 400 | |
| 401 | LARGE_INTEGER offset = {0}; |
| 402 | ULARGE_INTEGER new_pos = {0}; |
| 403 | DWORD written = 0; |
| 404 | std::wstring url = UTF8ToWide(navigation_info_.url.spec()); |
| 405 | return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t), |
| 406 | &written); |
| 407 | } |
| 408 | |
| 409 | STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 410 | if (automation_client_.get()) { |
| 411 | int index = static_cast<int>(position_cookie); |
| 412 | navigation_info_.navigation_index = index; |
| 413 | automation_client_->NavigateToIndex(index); |
| 414 | } else { |
| 415 | DLOG(WARNING) << "Invalid automation client instance"; |
| 416 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 417 | return S_OK; |
| 418 | } |
| 419 | |
| 420 | STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) { |
| 421 | if (!position_cookie) |
| 422 | return E_INVALIDARG; |
| 423 | |
| 424 | *position_cookie = navigation_info_.navigation_index; |
| 425 | return S_OK; |
| 426 | } |
| 427 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 428 | STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 429 | if (NULL == url) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 430 | return E_POINTER; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 431 | *url = ::SysAllocString(url_); |
| 432 | return S_OK; |
| 433 | } |
| 434 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 435 | STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) { |
| 436 | return GetUrlForEvents(url); |
| 437 | } |
| 438 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 439 | STDMETHODIMP ChromeActiveDocument::Reset() { |
| 440 | next_privacy_record_ = privacy_info_.privacy_records.begin(); |
| 441 | return S_OK; |
| 442 | } |
| 443 | |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 444 | STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 445 | if (!size) |
| 446 | return E_POINTER; |
| 447 | |
| 448 | *size = privacy_info_.privacy_records.size(); |
| 449 | return S_OK; |
| 450 | } |
| 451 | |
| 452 | STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) { |
| 453 | if (!privacy_impacted) |
| 454 | return E_POINTER; |
| 455 | |
| 456 | *privacy_impacted = privacy_info_.privacy_impacted; |
| 457 | return S_OK; |
| 458 | } |
| 459 | |
| 460 | STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy, |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 461 | LONG* reserved, DWORD* flags) { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 462 | if (!url || !policy || !flags) |
| 463 | return E_POINTER; |
| 464 | |
| 465 | if (next_privacy_record_ == privacy_info_.privacy_records.end()) |
| 466 | return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS); |
| 467 | |
| 468 | *url = SysAllocString(next_privacy_record_->first.c_str()); |
| 469 | *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str()); |
| 470 | *flags = next_privacy_record_->second.flags; |
| 471 | |
| 472 | next_privacy_record_++; |
| 473 | return S_OK; |
| 474 | } |
| 475 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 476 | HRESULT ChromeActiveDocument::IOleObject_SetClientSite( |
| 477 | IOleClientSite* client_site) { |
| 478 | if (client_site == NULL) { |
| 479 | ChromeActiveDocument* cached_document = g_active_doc_cache.Get(); |
| 480 | if (cached_document) { |
| 481 | DCHECK(this == cached_document); |
| 482 | g_active_doc_cache.Set(NULL); |
| 483 | cached_document->Release(); |
| 484 | } |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 485 | |
| 486 | ScopedComPtr<IDocHostUIHandler> doc_host_handler; |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 487 | if (doc_site_) |
[email protected] | 77059f7 | 2010-02-28 06:16:00 | [diff] [blame] | 488 | doc_host_handler.QueryFrom(doc_site_); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 489 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 490 | if (doc_host_handler.get()) |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 491 | doc_host_handler->HideUI(); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 492 | |
| 493 | doc_site_.Release(); |
| 494 | in_place_frame_.Release(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 495 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 496 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 497 | if (client_site != m_spClientSite) |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 498 | return BaseActiveX::IOleObject_SetClientSite(client_site); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 499 | |
| 500 | return S_OK; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 501 | } |
| 502 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 503 | HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) { |
| 504 | HRESULT hr = S_OK; |
| 505 | m_bNegotiatedWnd = TRUE; |
| 506 | if (!m_bInPlaceActive) { |
| 507 | hr = m_spInPlaceSite->CanInPlaceActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 508 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 509 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 510 | m_spInPlaceSite->OnInPlaceActivate(); |
| 511 | } |
| 512 | m_bInPlaceActive = TRUE; |
| 513 | // get location in the parent window, |
| 514 | // as well as some information about the parent |
| 515 | ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window; |
| 516 | frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO); |
| 517 | HWND parent_window = NULL; |
| 518 | if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) { |
| 519 | in_place_frame_.Release(); |
| 520 | RECT position_rect = {0}; |
| 521 | RECT clip_rect = {0}; |
| 522 | m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(), |
| 523 | in_place_ui_window.Receive(), |
| 524 | &position_rect, |
| 525 | &clip_rect, |
| 526 | &frame_info_); |
| 527 | if (!m_bWndLess) { |
| 528 | if (IsWindow()) { |
| 529 | ::ShowWindow(m_hWnd, SW_SHOW); |
| 530 | SetFocus(); |
| 531 | } else { |
[email protected] | c1d1958 | 2010-03-03 01:57:13 | [diff] [blame] | 532 | m_hWnd = Create(parent_window, position_rect, 0, 0, WS_EX_CLIENTEDGE); |
[email protected] | dd4beb52 | 2010-07-13 18:18:14 | [diff] [blame] | 533 | if (!IsWindow()) { |
| 534 | // This might happen if the automation server couldn't be |
| 535 | // instantiated. If so, a NOTREACHED() will have already been hit. |
| 536 | DLOG(ERROR) << "Failed to create Ax window"; |
| 537 | return AtlHresultFromLastError(); |
| 538 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 539 | } |
[email protected] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 540 | |
| 541 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 542 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 543 | web_browser2.Receive()); |
| 544 | if (web_browser2) { |
| 545 | if (!dimensions_.IsEmpty()) { |
| 546 | web_browser2->put_Width(dimensions_.width()); |
| 547 | web_browser2->put_Height(dimensions_.height()); |
| 548 | web_browser2->put_Left(dimensions_.x()); |
| 549 | web_browser2->put_Top(dimensions_.y()); |
| 550 | web_browser2->put_MenuBar(VARIANT_FALSE); |
| 551 | web_browser2->put_ToolBar(VARIANT_FALSE); |
| 552 | |
| 553 | dimensions_.set_height(0); |
| 554 | dimensions_.set_width(0); |
| 555 | } |
| 556 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 557 | } |
| 558 | SetObjectRects(&position_rect, &clip_rect); |
| 559 | } |
| 560 | |
| 561 | ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this); |
| 562 | |
| 563 | // Gone active by now, take care of UIACTIVATE |
| 564 | if (DoesVerbUIActivate(verb)) { |
| 565 | if (!m_bUIActive) { |
| 566 | m_bUIActive = TRUE; |
| 567 | hr = m_spInPlaceSite->OnUIActivate(); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 568 | if (FAILED(hr)) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 569 | return hr; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 570 | // set ourselves up in the host |
| 571 | if (in_place_active_object) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 572 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 573 | in_place_frame_->SetActiveObject(in_place_active_object, NULL); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 574 | if (in_place_ui_window) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 575 | in_place_ui_window->SetActiveObject(in_place_active_object, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | } |
| 579 | m_spClientSite->ShowObject(); |
| 580 | return S_OK; |
| 581 | } |
| 582 | |
| 583 | void ChromeActiveDocument::OnNavigationStateChanged(int tab_handle, int flags, |
| 584 | const IPC::NavigationInfo& nav_info) { |
| 585 | // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc. |
| 586 | DLOG(INFO) << __FUNCTION__ << std::endl << " Flags: " << flags |
| 587 | << "Url: " << nav_info.url << |
| 588 | ", Title: " << nav_info.title << |
| 589 | ", Type: " << nav_info.navigation_type << ", Relative Offset: " << |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 590 | nav_info.relative_offset << ", Index: " << nav_info.navigation_index; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 591 | |
| 592 | UpdateNavigationState(nav_info); |
| 593 | } |
| 594 | |
| 595 | void ChromeActiveDocument::OnUpdateTargetUrl(int tab_handle, |
| 596 | const std::wstring& new_target_url) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 597 | if (in_place_frame_) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 598 | in_place_frame_->SetStatusText(new_target_url.c_str()); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | bool IsFindAccelerator(const MSG& msg) { |
| 602 | // TODO(robertshield): This may not stand up to localization. Fix if this |
| 603 | // is the case. |
| 604 | return msg.message == WM_KEYDOWN && msg.wParam == 'F' && |
| 605 | win_util::IsCtrlPressed() && |
| 606 | !(win_util::IsAltPressed() || win_util::IsShiftPressed()); |
| 607 | } |
| 608 | |
| 609 | void ChromeActiveDocument::OnAcceleratorPressed(int tab_handle, |
| 610 | const MSG& accel_message) { |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 611 | if (::TranslateAccelerator(m_hWnd, accelerator_table_, |
| 612 | const_cast<MSG*>(&accel_message))) |
| 613 | return; |
| 614 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 615 | bool handled_accel = false; |
| 616 | if (in_place_frame_ != NULL) { |
| 617 | handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW( |
| 618 | const_cast<MSG*>(&accel_message), 0)); |
| 619 | } |
| 620 | |
| 621 | if (!handled_accel) { |
| 622 | if (IsFindAccelerator(accel_message)) { |
| 623 | // Handle the showing of the find dialog explicitly. |
| 624 | OnFindInPage(); |
[email protected] | 2b8fd32 | 2009-10-02 00:00:59 | [diff] [blame] | 625 | } else { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 626 | BaseActiveX::OnAcceleratorPressed(tab_handle, accel_message); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 627 | } |
| 628 | } else { |
| 629 | DLOG(INFO) << "IE handled accel key " << accel_message.wParam; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | void ChromeActiveDocument::OnTabbedOut(int tab_handle, bool reverse) { |
| 634 | DLOG(INFO) << __FUNCTION__; |
| 635 | if (in_place_frame_) { |
| 636 | MSG msg = { NULL, WM_KEYDOWN, VK_TAB }; |
| 637 | in_place_frame_->TranslateAcceleratorW(&msg, 0); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | void ChromeActiveDocument::OnDidNavigate(int tab_handle, |
| 642 | const IPC::NavigationInfo& nav_info) { |
| 643 | DLOG(INFO) << __FUNCTION__ << std::endl << "Url: " << nav_info.url << |
| 644 | ", Title: " << nav_info.title << |
| 645 | ", Type: " << nav_info.navigation_type << ", Relative Offset: " << |
| 646 | nav_info.relative_offset << ", Index: " << nav_info.navigation_index; |
| 647 | |
[email protected] | 897b2627 | 2010-06-11 02:23:44 | [diff] [blame] | 648 | CrashMetricsReporter::GetInstance()->IncrementMetric( |
| 649 | CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT); |
| 650 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 651 | // This could be NULL if the active document instance is being destroyed. |
| 652 | if (!m_spInPlaceSite) { |
| 653 | DLOG(INFO) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning"; |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | UpdateNavigationState(nav_info); |
| 658 | } |
| 659 | |
[email protected] | e16dd167 | 2010-06-07 21:40:29 | [diff] [blame] | 660 | void ChromeActiveDocument::OnCloseTab(int tab_handle) { |
| 661 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 662 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 663 | if (web_browser2) |
| 664 | web_browser2->Quit(); |
| 665 | } |
| 666 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 667 | void ChromeActiveDocument::UpdateNavigationState( |
| 668 | const IPC::NavigationInfo& new_navigation_info) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 669 | HRESULT hr = S_OK; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 670 | bool is_title_changed = (navigation_info_.title != new_navigation_info.title); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 671 | bool is_ssl_state_changed = |
| 672 | (navigation_info_.security_style != new_navigation_info.security_style) || |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 673 | (navigation_info_.displayed_insecure_content != |
| 674 | new_navigation_info.displayed_insecure_content) || |
| 675 | (navigation_info_.ran_insecure_content != |
| 676 | new_navigation_info.ran_insecure_content); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 677 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 678 | if (is_ssl_state_changed) { |
| 679 | int lock_status = SECURELOCK_SET_UNSECURE; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 680 | switch (new_navigation_info.security_style) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 681 | case SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| 682 | lock_status = SECURELOCK_SET_SECUREUNKNOWNBIT; |
| 683 | break; |
| 684 | case SECURITY_STYLE_AUTHENTICATED: |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 685 | lock_status = new_navigation_info.displayed_insecure_content ? |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 686 | SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT; |
| 687 | break; |
| 688 | default: |
| 689 | break; |
| 690 | } |
| 691 | |
| 692 | ScopedVariant secure_lock_status(lock_status); |
| 693 | IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK, |
| 694 | OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL); |
| 695 | } |
| 696 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 697 | // Ideally all navigations should come to Chrome Frame so that we can call |
| 698 | // BeforeNavigate2 on installed BHOs and give them a chance to cancel the |
| 699 | // navigation. However, in practice what happens is as below: |
| 700 | // The very first navigation that happens in CF happens via a Load or a |
| 701 | // LoadHistory call. In this case, IE already has the correct information for |
| 702 | // its travel log as well address bar. For other internal navigations (navs |
| 703 | // that only happen within Chrome such as anchor navigations) we need to |
| 704 | // update IE's internal state after the fact. In the case of internal |
| 705 | // navigations, we notify the BHOs but ignore the should_cancel flag. |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 706 | |
| 707 | // Another case where we need to issue BeforeNavigate2 calls is as below:- |
| 708 | // We get notified after the fact, when navigations are initiated within |
| 709 | // Chrome via window.open calls. These navigations are handled by creating |
| 710 | // an external tab container within chrome and then connecting to it from IE. |
| 711 | // We still want to update the address bar/history, etc, to ensure that |
| 712 | // the special URL used by Chrome to indicate this is updated correctly. |
| 713 | bool is_internal_navigation = ((new_navigation_info.navigation_index > 0) && |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 714 | (new_navigation_info.navigation_index != |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 715 | navigation_info_.navigation_index)) || |
| 716 | StartsWith(static_cast<BSTR>(url_), kChromeAttachExternalTabPrefix, |
| 717 | false); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 718 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 719 | if (new_navigation_info.url.is_valid()) |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 720 | url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str()); |
[email protected] | 38939de | 2010-05-13 02:32:06 | [diff] [blame] | 721 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 722 | if (is_internal_navigation) { |
| 723 | ScopedComPtr<IDocObjectService> doc_object_svc; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 724 | ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc; |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 725 | |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame^] | 726 | buggy_bho::BuggyBhoTls bad_bho_tls; |
| 727 | if (GetConfigBool(true, kEnableBuggyBhoIntercept)) { |
| 728 | ScopedComPtr<IWebBrowser2> wb2; |
| 729 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive()); |
| 730 | if (wb2) { |
| 731 | buggy_bho::BuggyBhoTls::PatchBuggyBHOs(wb2); |
| 732 | } |
| 733 | } |
| 734 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 735 | DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite, |
| 736 | web_browser_events_svc.Receive()); |
[email protected] | ae33d67 | 2010-03-04 21:58:06 | [diff] [blame] | 737 | |
| 738 | if (!web_browser_events_svc.get()) { |
| 739 | DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 740 | doc_object_svc.Receive()); |
| 741 | } |
| 742 | |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 743 | // web_browser_events_svc can be NULL on IE6. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 744 | if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 745 | VARIANT_BOOL should_cancel = VARIANT_FALSE; |
| 746 | web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | // We need to tell IE that we support navigation so that IE will query us |
| 750 | // for IPersistHistory and call GetPositionCookie to save our navigation |
| 751 | // index. |
| 752 | ScopedVariant html_window(static_cast<IUnknown*>( |
| 753 | static_cast<IHTMLWindow2*>(this))); |
| 754 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, |
| 755 | html_window.AsInput(), NULL); |
| 756 | |
| 757 | // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG |
| 758 | // since we want to make IE treat all internal navigations within this page |
| 759 | // (including anchor navigations and subframe navigations) as anchor |
| 760 | // navigations. This will ensure that IE calls GetPositionCookie |
| 761 | // to save the current position cookie in the travel log and then call |
| 762 | // SetPositionCookie when the user hits Back/Forward to come back here. |
| 763 | ScopedVariant internal_navigation(HLNF_INTERNALJUMP); |
| 764 | IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0, |
| 765 | internal_navigation.AsInput(), NULL); |
| 766 | |
| 767 | // We no longer need to lie to IE. If we lie persistently to IE, then |
| 768 | // IE reuses us for new navigations. |
| 769 | IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL); |
| 770 | |
| 771 | if (doc_object_svc) { |
| 772 | // Now call the FireNavigateCompleteEvent which makes IE update the text |
| 773 | // in the address-bar. |
| 774 | doc_object_svc->FireNavigateComplete2(this, 0); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame^] | 775 | doc_object_svc->FireDocumentComplete(this, 0); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 776 | } else if (web_browser_events_svc) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 777 | web_browser_events_svc->FireNavigateComplete2Event(); |
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame^] | 778 | web_browser_events_svc->FireDocumentCompleteEvent(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 779 | } |
| 780 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 781 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 782 | if (is_title_changed) { |
| 783 | ScopedVariant title(new_navigation_info.title.c_str()); |
| 784 | IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER, |
| 785 | title.AsInput(), NULL); |
| 786 | } |
| 787 | |
| 788 | // It is important that we only update the navigation_info_ after we have |
| 789 | // finalized the travel log. This is because IE will ask for information |
| 790 | // such as navigation index when the travel log is finalized and we need |
| 791 | // supply the old index and not the new one. |
| 792 | navigation_info_ = new_navigation_info; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 793 | // Update the IE zone here. Ideally we would like to do it when the active |
| 794 | // document is activated. However that does not work at times as the frame we |
| 795 | // get there is not the actual frame which handles the command. |
| 796 | IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | void ChromeActiveDocument::OnFindInPage() { |
| 800 | TabProxy* tab = GetTabProxy(); |
| 801 | if (tab) { |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 802 | if (!find_dialog_.IsWindow()) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 803 | find_dialog_.Create(m_hWnd); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 804 | |
| 805 | find_dialog_.ShowWindow(SW_SHOW); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | void ChromeActiveDocument::OnViewSource() { |
| 810 | DCHECK(navigation_info_.url.is_valid()); |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 811 | HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") + |
| 812 | navigation_info_.url.spec()), GURL(), NEW_WINDOW); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 815 | void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid, |
| 816 | DWORD command_id, |
| 817 | DWORD cmd_exec_opt, |
| 818 | VARIANT* in_args, |
| 819 | VARIANT* out_args) { |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 820 | // Always return URLZONE_INTERNET since that is the Chrome's behaviour. |
| 821 | // Correct step is to use MapUrlToZone(). |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 822 | if (out_args != NULL) { |
| 823 | out_args->vt = VT_UI4; |
| 824 | out_args->ulVal = URLZONE_INTERNET; |
| 825 | } |
| 826 | } |
| 827 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 828 | void ChromeActiveDocument::OnDisplayPrivacyInfo() { |
| 829 | privacy_info_ = url_fetcher_.privacy_info(); |
| 830 | Reset(); |
| 831 | DoPrivacyDlg(m_hWnd, url_, this, TRUE); |
| 832 | } |
| 833 | |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 834 | void ChromeActiveDocument::OnOpenURL(int tab_handle, |
| 835 | const GURL& url_to_open, |
| 836 | const GURL& referrer, |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 837 | int open_disposition) { |
| 838 | // If the disposition indicates that we should be opening the URL in the |
| 839 | // current tab, then we can reuse the ChromeFrameAutomationClient instance |
| 840 | // maintained by the current ChromeActiveDocument instance. We cache this |
| 841 | // instance so that it can be used by the new ChromeActiveDocument instance |
| 842 | // which may be instantiated for handling the new URL. |
| 843 | if (open_disposition == CURRENT_TAB) { |
| 844 | // Grab a reference to ensure that the document remains valid. |
| 845 | AddRef(); |
| 846 | g_active_doc_cache.Set(this); |
| 847 | } |
| 848 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 849 | BaseActiveX::OnOpenURL(tab_handle, url_to_open, referrer, open_disposition); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 850 | } |
| 851 | |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 852 | void ChromeActiveDocument::OnAttachExternalTab(int tab_handle, |
| 853 | const IPC::AttachExternalTabParams& params) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 854 | if (!automation_client_.get()) { |
| 855 | DLOG(WARNING) << "Invalid automation client instance"; |
| 856 | return; |
| 857 | } |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 858 | DWORD flags = 0; |
| 859 | if (params.user_gesture) |
| 860 | flags = NWMF_USERREQUESTED; |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 861 | else if (popup_allowed_) |
| 862 | flags = NWMF_USERALLOWED; |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 863 | |
| 864 | HRESULT hr = S_OK; |
| 865 | if (popup_manager_) { |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 866 | LPCWSTR popup_wnd_url = UTF8ToWide(params.url.spec()).c_str(); |
| 867 | hr = popup_manager_->EvaluateNewWindow(popup_wnd_url, NULL, url_, |
| 868 | NULL, FALSE, flags, 0); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 869 | } |
| 870 | // Allow popup |
| 871 | if (hr == S_OK) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 872 | BaseActiveX::OnAttachExternalTab(tab_handle, params); |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 873 | return; |
| 874 | } |
| 875 | |
| 876 | automation_client_->BlockExternalTab(params.cookie); |
| 877 | } |
| 878 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 879 | bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) { |
| 880 | ScopedComPtr<IBrowserService> browser_service; |
| 881 | ScopedComPtr<ITravelLog> travel_log; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 882 | GetBrowserServiceAndTravelLog(browser_service.Receive(), |
| 883 | travel_log.Receive()); |
| 884 | if (!browser_service || !travel_log) |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 885 | return true; |
| 886 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 887 | EnableMenuItem(menu, IDS_CONTENT_CONTEXT_BACK, MF_BYCOMMAND | |
| 888 | (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK, NULL)) ? |
| 889 | MF_ENABLED : MF_DISABLED)); |
| 890 | EnableMenuItem(menu, IDS_CONTENT_CONTEXT_FORWARD, MF_BYCOMMAND | |
| 891 | (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE, NULL)) ? |
| 892 | MF_ENABLED : MF_DISABLED)); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 893 | |
| 894 | // Call base class (adds 'About' item) |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 895 | return BaseActiveX::PreProcessContextMenu(menu); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | 35f13ab | 2009-12-16 23:59:17 | [diff] [blame] | 898 | bool ChromeActiveDocument::HandleContextMenuCommand(UINT cmd, |
| 899 | const IPC::ContextMenuParams& params) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 900 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 901 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 902 | |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 903 | if (cmd == IDC_BACK) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 904 | web_browser2->GoBack(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 905 | else if (cmd == IDC_FORWARD) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 906 | web_browser2->GoForward(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 907 | else if (cmd == IDC_RELOAD) |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 908 | web_browser2->Refresh(); |
[email protected] | 074283a | 2010-05-28 23:47:59 | [diff] [blame] | 909 | else |
[email protected] | b731a14 | 2010-05-14 00:03:03 | [diff] [blame] | 910 | return BaseActiveX::HandleContextMenuCommand(cmd, params); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 911 | |
| 912 | return true; |
| 913 | } |
| 914 | |
| 915 | HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid, |
| 916 | DWORD command_id, DWORD cmd_exec_opt, |
| 917 | VARIANT* in_args, VARIANT* out_args) { |
| 918 | HRESULT hr = E_FAIL; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 919 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 920 | ScopedComPtr<IOleCommandTarget> frame_cmd_target; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 921 | |
| 922 | ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 923 | if (!in_place_site.get() && m_spClientSite != NULL) |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 924 | in_place_site.QueryFrom(m_spClientSite); |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 925 | |
| 926 | if (in_place_site) |
| 927 | hr = frame_cmd_target.QueryFrom(in_place_site); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 928 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 929 | if (frame_cmd_target) { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 930 | hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt, |
| 931 | in_args, out_args); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 932 | } |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 933 | |
| 934 | return hr; |
| 935 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 936 | |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 937 | DWORD ChromeActiveDocument::MapUrlToZone(const wchar_t* url) { |
| 938 | DWORD zone = URLZONE_INVALID; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 939 | if (security_manager_.get() == NULL) { |
| 940 | HRESULT hr = CoCreateInstance( |
| 941 | CLSID_InternetSecurityManager, |
| 942 | NULL, |
| 943 | CLSCTX_ALL, |
| 944 | IID_IInternetSecurityManager, |
| 945 | reinterpret_cast<void**>(security_manager_.Receive())); |
| 946 | |
| 947 | if (FAILED(hr)) { |
| 948 | NOTREACHED() << __FUNCTION__ |
| 949 | << " Failed to create InternetSecurityManager. Error: 0x%x" |
| 950 | << hr; |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 951 | return zone; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 955 | security_manager_->MapUrlToZone(url, &zone, 0); |
| 956 | return zone; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | bool ChromeActiveDocument::ParseUrl(const std::wstring& url, |
| 960 | bool* is_new_navigation, |
| 961 | bool* is_chrome_protocol, |
| 962 | std::wstring* parsed_url) { |
| 963 | if (!is_new_navigation || !is_chrome_protocol|| !parsed_url) { |
| 964 | NOTREACHED() << __FUNCTION__ << " Invalid arguments"; |
| 965 | return false; |
| 966 | } |
| 967 | |
| 968 | std::wstring initial_url = url; |
| 969 | |
| 970 | *is_chrome_protocol = StartsWith(initial_url, kChromeProtocolPrefix, |
| 971 | false); |
| 972 | |
| 973 | *is_new_navigation = true; |
| 974 | |
| 975 | if (*is_chrome_protocol) { |
| 976 | initial_url.erase(0, lstrlen(kChromeProtocolPrefix)); |
| 977 | *is_new_navigation = |
| 978 | !StartsWith(initial_url, kChromeAttachExternalTabPrefix, false); |
| 979 | } |
| 980 | |
[email protected] | 10bf1a7 | 2009-10-01 16:00:21 | [diff] [blame] | 981 | if (!IsValidUrlScheme(initial_url, is_privileged_)) { |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 982 | DLOG(WARNING) << __FUNCTION__ << " Disallowing navigation to url: " |
| 983 | << url; |
| 984 | return false; |
| 985 | } |
| 986 | |
[email protected] | 7c712c9 | 2010-03-24 17:29:22 | [diff] [blame] | 987 | if (URLZONE_UNTRUSTED == MapUrlToZone(initial_url.c_str())) { |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 988 | DLOG(WARNING) << __FUNCTION__ |
| 989 | << " Disallowing navigation to restricted url: " |
| 990 | << initial_url; |
| 991 | return false; |
| 992 | } |
| 993 | |
[email protected] | 552fb601 | 2010-02-03 17:24:29 | [diff] [blame] | 994 | if (*is_chrome_protocol) { |
| 995 | // Allow chrome protocol (gcf:) if - |
| 996 | // - explicitly enabled using registry |
| 997 | // - for gcf:attach_external_tab |
| 998 | // - for gcf:about and gcf:view-source |
| 999 | GURL crack_url(initial_url); |
| 1000 | bool allow_gcf_protocol = !*is_new_navigation || |
| 1001 | GetConfigBool(false, kEnableGCFProtocol) || |
| 1002 | crack_url.SchemeIs(chrome::kAboutScheme) || |
| 1003 | crack_url.SchemeIs(chrome::kViewSourceScheme); |
| 1004 | if (!allow_gcf_protocol) |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1008 | *parsed_url = initial_url; |
| 1009 | return true; |
| 1010 | } |
| 1011 | |
| 1012 | bool ChromeActiveDocument::LaunchUrl(const std::wstring& url, |
[email protected] | c5cbf4e | 2010-07-15 21:48:25 | [diff] [blame] | 1013 | const std::string& referrer, |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1014 | bool is_new_navigation) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 1015 | DCHECK(automation_client_.get() != NULL); |
| 1016 | |
[email protected] | b509ec8 | 2010-04-13 16:53:06 | [diff] [blame] | 1017 | url_.Allocate(url.c_str()); |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 1018 | |
[email protected] | e150e82 | 2010-06-03 23:10:55 | [diff] [blame] | 1019 | std::string utf8_url; |
| 1020 | |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1021 | if (!is_new_navigation) { |
[email protected] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 1022 | int disposition = 0; |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 1023 | uint64 external_tab_cookie = 0; |
[email protected] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 1024 | |
| 1025 | if (!ParseAttachExternalTabUrl(url, &external_tab_cookie, &dimensions_, |
| 1026 | &disposition)) { |
| 1027 | NOTREACHED() << "Failed to parse attach tab url:" << url; |
| 1028 | return false; |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 1029 | } |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1030 | |
| 1031 | if (external_tab_cookie == 0) { |
| 1032 | NOTREACHED() << "invalid url for attach tab: " << url; |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
[email protected] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 1036 | is_new_navigation_ = false; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1037 | automation_client_->AttachExternalTab(external_tab_cookie); |
| 1038 | } else { |
[email protected] | e3a91e7 | 2010-06-17 01:19:04 | [diff] [blame] | 1039 | is_new_navigation_ = true; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1040 | // Initiate navigation before launching chrome so that the url will be |
| 1041 | // cached and sent with launch settings. |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 1042 | if (url_.Length()) { |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 1043 | WideToUTF8(url_, url_.Length(), &utf8_url); |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 1044 | if (!automation_client_->InitiateNavigation(utf8_url, |
| 1045 | referrer, |
| 1046 | is_privileged_)) { |
| 1047 | DLOG(ERROR) << "Invalid URL: " << url; |
| 1048 | Error(L"Invalid URL"); |
| 1049 | url_.Reset(); |
| 1050 | return false; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1051 | } |
[email protected] | 62bb18dc1 | 2009-11-25 01:34:08 | [diff] [blame] | 1052 | |
| 1053 | DLOG(INFO) << "Url is " << url_; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 1057 | if (is_automation_client_reused_) |
| 1058 | return true; |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1059 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 1060 | automation_client_->SetUrlFetcher(&url_fetcher_); |
| 1061 | |
[email protected] | e150e82 | 2010-06-03 23:10:55 | [diff] [blame] | 1062 | return InitializeAutomation(GetHostProcessName(false), L"", IsIEInPrivate(), |
| 1063 | false, GURL(utf8_url), GURL(referrer)); |
[email protected] | 37346bc | 2009-09-25 22:54:33 | [diff] [blame] | 1064 | } |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1065 | |
[email protected] | 355309e | 2010-03-15 17:01:34 | [diff] [blame] | 1066 | |
| 1067 | HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid, |
| 1068 | DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) { |
| 1069 | popup_allowed_ = false; |
| 1070 | if (in_args->vt == VT_I4 && |
| 1071 | in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) { |
| 1072 | popup_allowed_ = true; |
| 1073 | |
| 1074 | // Ask the yellow security band to change the text and icon and to remain |
| 1075 | // visible. |
| 1076 | IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED, |
| 1077 | 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL); |
| 1078 | } |
| 1079 | |
| 1080 | TabProxy* tab_proxy = GetTabProxy(); |
| 1081 | if (tab_proxy) |
| 1082 | tab_proxy->ReloadAsync(); |
| 1083 | |
| 1084 | return S_OK; |
| 1085 | } |
| 1086 | |
| 1087 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1088 | HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid, |
| 1089 | DWORD command_id, |
| 1090 | DWORD cmd_exec_opt, |
| 1091 | VARIANT* in_args, |
| 1092 | VARIANT* out_args) { |
| 1093 | if (!automation_client_.get()) { |
[email protected] | 7770083 | 2010-04-27 00:06:03 | [diff] [blame] | 1094 | NOTREACHED() << "Invalid automation client"; |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 1095 | return E_FAIL; |
| 1096 | } |
| 1097 | |
| 1098 | switch (command_id) { |
| 1099 | case IDM_BASELINEFONT1: |
| 1100 | automation_client_->SetPageFontSize(SMALLEST_FONT); |
| 1101 | break; |
| 1102 | |
| 1103 | case IDM_BASELINEFONT2: |
| 1104 | automation_client_->SetPageFontSize(SMALL_FONT); |
| 1105 | break; |
| 1106 | |
| 1107 | case IDM_BASELINEFONT3: |
| 1108 | automation_client_->SetPageFontSize(MEDIUM_FONT); |
| 1109 | break; |
| 1110 | |
| 1111 | case IDM_BASELINEFONT4: |
| 1112 | automation_client_->SetPageFontSize(LARGE_FONT); |
| 1113 | break; |
| 1114 | |
| 1115 | case IDM_BASELINEFONT5: |
| 1116 | automation_client_->SetPageFontSize(LARGEST_FONT); |
| 1117 | break; |
| 1118 | |
| 1119 | default: |
| 1120 | NOTREACHED() << "Invalid font size command: " |
| 1121 | << command_id; |
| 1122 | return E_FAIL; |
| 1123 | } |
| 1124 | |
| 1125 | // Forward the command back to IEFrame with group set to |
| 1126 | // CGID_ExplorerBarDoc. This is probably needed to update the menu state to |
| 1127 | // indicate that the font size was set. This currently fails with error |
| 1128 | // 0x80040104. |
| 1129 | // TODO(iyengar) |
| 1130 | // Do some investigation into why this Exec call fails. |
| 1131 | IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL); |
| 1132 | return S_OK; |
| 1133 | } |
| 1134 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 1135 | HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid, |
| 1136 | DWORD command_id, |
| 1137 | DWORD cmd_exec_opt, |
| 1138 | VARIANT* in_args, |
| 1139 | VARIANT* out_args) { |
| 1140 | const struct EncodingMapData { |
| 1141 | DWORD ie_encoding_id; |
| 1142 | const char* chrome_encoding_name; |
| 1143 | } kEncodingTestDatas[] = { |
| 1144 | #define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \ |
| 1145 | { encoding_name, chrome_name }, |
| 1146 | INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP) |
| 1147 | #undef DEFINE_ENCODING_MAP |
| 1148 | }; |
| 1149 | |
| 1150 | if (!automation_client_.get()) { |
| 1151 | NOTREACHED() << "Invalid automtion client"; |
| 1152 | return E_FAIL; |
| 1153 | } |
| 1154 | |
[email protected] | e9b3528 | 2010-06-02 16:43:19 | [diff] [blame] | 1155 | // Using ARRAYSIZE_UNSAFE in here is because we define the struct |
| 1156 | // EncodingMapData inside function. |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 1157 | const char* chrome_encoding_name = NULL; |
| 1158 | for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { |
| 1159 | const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i]; |
| 1160 | if (command_id == encoding_data->ie_encoding_id) { |
| 1161 | chrome_encoding_name = encoding_data->chrome_encoding_name; |
| 1162 | break; |
| 1163 | } |
| 1164 | } |
| 1165 | // Return E_FAIL when encountering invalid encoding id. |
| 1166 | if (!chrome_encoding_name) |
| 1167 | return E_FAIL; |
| 1168 | |
| 1169 | TabProxy* tab = GetTabProxy(); |
| 1170 | if (!tab) { |
| 1171 | NOTREACHED() << "Can not get TabProxy"; |
| 1172 | return E_FAIL; |
| 1173 | } |
| 1174 | |
| 1175 | if (chrome_encoding_name) |
| 1176 | tab->OverrideEncoding(chrome_encoding_name); |
| 1177 | |
| 1178 | // Like we did on SetPageFontSize, we may forward the command back to IEFrame |
| 1179 | // to update the menu state to indicate that which encoding was set. |
| 1180 | // TODO(iyengar) |
| 1181 | // Do some investigation into why this Exec call fails. |
| 1182 | IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL); |
| 1183 | return S_OK; |
| 1184 | } |
| 1185 | |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1186 | void ChromeActiveDocument::OnGoToHistoryEntryOffset(int tab_handle, |
| 1187 | int offset) { |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1188 | DLOG(INFO) << __FUNCTION__ << " - offset:" << offset; |
| 1189 | |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1190 | ScopedComPtr<IBrowserService> browser_service; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1191 | ScopedComPtr<ITravelLog> travel_log; |
| 1192 | GetBrowserServiceAndTravelLog(browser_service.Receive(), |
| 1193 | travel_log.Receive()); |
| 1194 | |
| 1195 | if (browser_service && travel_log) |
| 1196 | travel_log->Travel(browser_service, offset); |
| 1197 | } |
| 1198 | |
| 1199 | HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog( |
| 1200 | IBrowserService** browser_service, ITravelLog** travel_log) { |
| 1201 | DCHECK(browser_service || travel_log); |
| 1202 | ScopedComPtr<IBrowserService> browser_service_local; |
| 1203 | HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite, |
| 1204 | browser_service_local.Receive()); |
| 1205 | if (!browser_service_local) { |
| 1206 | NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr; |
| 1207 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1208 | } |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1209 | |
| 1210 | if (travel_log) { |
| 1211 | hr = browser_service_local->GetTravelLog(travel_log); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1212 | DLOG_IF(INFO, !travel_log) << "browser_service->GetTravelLog failed: " << |
| 1213 | hr; |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (browser_service) |
| 1217 | *browser_service = browser_service_local.Detach(); |
| 1218 | |
| 1219 | return hr; |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1220 | } |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1221 | |
| 1222 | LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id, |
| 1223 | HWND control_window, |
| 1224 | BOOL& bHandled) { |
| 1225 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1226 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1227 | DCHECK(web_browser2); |
| 1228 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1229 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1230 | web_browser2->GoForward(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id, |
| 1235 | HWND control_window, |
| 1236 | BOOL& bHandled) { |
| 1237 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1238 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); |
| 1239 | DCHECK(web_browser2); |
| 1240 | |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1241 | if (web_browser2) |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1242 | web_browser2->GoBack(); |
[email protected] | a15d4a4 | 2010-02-17 08:21:35 | [diff] [blame] | 1243 | return 0; |
| 1244 | } |
| 1245 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1246 | LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam, |
| 1247 | LPARAM lparam, |
| 1248 | BOOL& handled) { |
| 1249 | if (!m_spClientSite) |
| 1250 | return 0; |
| 1251 | |
| 1252 | ScopedComPtr<IWebBrowser2> web_browser2; |
| 1253 | DoQueryService(SID_SWebBrowserApp, m_spClientSite, |
| 1254 | web_browser2.Receive()); |
| 1255 | if (!web_browser2) { |
| 1256 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | ScopedComPtr<IShellBrowser> shell_browser; |
| 1261 | DoQueryService(SID_STopLevelBrowser, web_browser2, |
| 1262 | shell_browser.Receive()); |
| 1263 | DCHECK(shell_browser.get() != NULL); |
| 1264 | ScopedComPtr<ITridentService2> trident_services; |
| 1265 | trident_services.QueryFrom(shell_browser); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1266 | if (trident_services) |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1267 | trident_services->FirePrivacyImpactedStateChange(wparam); |
[email protected] | bc2ff519 | 2010-06-01 22:05:45 | [diff] [blame] | 1268 | else |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1269 | NOTREACHED() << "Failed to retrieve IWebBrowser2 interface."; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
[email protected] | 00aebd7 | 2010-07-16 14:44:32 | [diff] [blame] | 1272 | |
[email protected] | 723e544 | 2010-07-21 17:36:05 | [diff] [blame] | 1273 | LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam, |
| 1274 | LPARAM lparam, |
| 1275 | BOOL& handled) { // NO_LINT |
| 1276 | if (wparam) |
| 1277 | SetFocus(); |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam, |
| 1282 | LPARAM lparam, |
| 1283 | BOOL& handled) { // NO_LINT |
| 1284 | GiveFocusToChrome(false); |
| 1285 | return 0; |
| 1286 | } |