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