blob: 01ce8b6f7c3a13b9957ca7504a50f23d11a9303c [file] [log] [blame]
[email protected]f17a0ee2010-05-17 17:38:471// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// 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]a1800e82009-11-19 00:53:2310#include <initguid.h>
[email protected]f7817822009-09-24 05:11:5811#include <mshtmcid.h>
12#include <shdeprecated.h>
13#include <shlguid.h>
[email protected]48dc9e12010-08-26 19:49:5714#include <shlobj.h>
[email protected]f7817822009-09-24 05:11:5815#include <shobjidl.h>
16#include <tlogstg.h>
17#include <urlmon.h>
18#include <wininet.h>
19
20#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5021#include "base/debug/trace_event.h"
[email protected]f7817822009-09-24 05:11:5822#include "base/file_util.h"
23#include "base/logging.h"
24#include "base/path_service.h"
25#include "base/process_util.h"
[email protected]f7817822009-09-24 05:11:5826#include "base/string_tokenizer.h"
27#include "base/string_util.h"
[email protected]34b99632011-01-01 01:01:0628#include "base/threading/thread.h"
[email protected]1357c322010-12-30 22:18:5629#include "base/threading/thread_local.h"
[email protected]252cad62010-08-18 18:33:5730#include "base/utf_string_conversions.h"
[email protected]965722ff2010-10-20 15:50:3031#include "base/win/scoped_variant.h"
[email protected]a8e20582010-12-31 17:18:5032#include "base/win/win_util.h"
[email protected]f7817822009-09-24 05:11:5833#include "grit/generated_resources.h"
[email protected]1a3aba82010-11-08 23:52:5434#include "chrome/app/chrome_command_ids.h"
[email protected]cccd3762010-11-12 18:40:0135#include "chrome/app/chrome_dll_resource.h"
[email protected]747bca12011-01-15 00:28:4536#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]f7817822009-09-24 05:11:5837#include "chrome/common/chrome_constants.h"
38#include "chrome/common/navigation_types.h"
[email protected]7f860dd82010-08-09 23:18:0539#include "chrome/common/page_zoom.h"
[email protected]f7817822009-09-24 05:11:5840#include "chrome/test/automation/browser_proxy.h"
41#include "chrome/test/automation/tab_proxy.h"
[email protected]b36a9f92009-10-19 17:34:5742#include "chrome_frame/bho.h"
[email protected]29c32f902010-04-20 23:27:2943#include "chrome_frame/bind_context_info.h"
[email protected]5ae94d22010-07-21 19:55:3644#include "chrome_frame/buggy_bho_handling.h"
[email protected]9607f6a82010-06-12 17:24:4145#include "chrome_frame/crash_reporting/crash_metrics.h"
[email protected]f7817822009-09-24 05:11:5846#include "chrome_frame/utils.h"
47
[email protected]a1800e82009-11-19 00:53:2348DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
49 0x46);
50
[email protected]f7817822009-09-24 05:11:5851base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache;
52
53bool g_first_launch_by_process_ = true;
54
[email protected]2f2afba2010-04-01 01:53:1955const DWORD kIEEncodingIdArray[] = {
56#define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name,
57 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY)
58#undef DEFINE_ENCODING_ID_ARRAY
59 0 // The Last data must be 0 to indicate the end of the encoding id array.
60};
61
[email protected]f7817822009-09-24 05:11:5862ChromeActiveDocument::ChromeActiveDocument()
63 : first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3564 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3465 popup_allowed_(false),
[email protected]c4e45b32010-07-28 21:15:1566 accelerator_table_(NULL) {
[email protected]04e3f352010-05-10 13:48:2467 TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, "");
68
[email protected]bbfa9a12010-08-10 14:09:3769 url_fetcher_->set_frame_busting(false);
[email protected]a1800e82009-11-19 00:53:2370 memset(&navigation_info_, 0, sizeof(navigation_info_));
[email protected]f7817822009-09-24 05:11:5871}
72
73HRESULT ChromeActiveDocument::FinalConstruct() {
74 // If we have a cached ChromeActiveDocument instance in TLS, then grab
75 // ownership of the cached document's automation client. This is an
76 // optimization to get Chrome active documents to load faster.
77 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
[email protected]58174a72010-05-05 21:30:3078 if (cached_document && cached_document->IsValid()) {
[email protected]3eb8a70492010-12-03 21:32:1979 SetResourceModule();
[email protected]f7817822009-09-24 05:11:5880 DCHECK(automation_client_.get() == NULL);
[email protected]3148c0ae2010-03-11 18:06:0081 automation_client_.swap(cached_document->automation_client_);
[email protected]2b9a9f162010-10-19 20:30:4582 DVLOG(1) << "Reusing automation client instance from " << cached_document;
[email protected]f7817822009-09-24 05:11:5883 DCHECK(automation_client_.get() != NULL);
[email protected]bbfa9a12010-08-10 14:09:3784 automation_client_->Reinitialize(this, url_fetcher_.get());
[email protected]f7817822009-09-24 05:11:5885 is_automation_client_reused_ = true;
[email protected]b5811052010-08-21 01:37:2986 OnAutomationServerReady();
[email protected]f7817822009-09-24 05:11:5887 } else {
88 // The FinalConstruct implementation in the ChromeFrameActivexBase class
89 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
90 // and initializes it, which would spawn a new Chrome process, etc.
91 // We don't want to be doing this if we have a cached document, whose
92 // automation client instance can be reused.
[email protected]97965e12010-04-09 00:51:1093 HRESULT hr = BaseActiveX::FinalConstruct();
[email protected]f7817822009-09-24 05:11:5894 if (FAILED(hr))
95 return hr;
96 }
97
[email protected]e1081d92010-09-10 20:29:1198 InitializeAutomationSettings();
[email protected]8f56e612010-09-09 17:03:1499
[email protected]f7817822009-09-24 05:11:58100 find_dialog_.Init(automation_client_.get());
101
[email protected]6fd1a7a2010-07-26 22:09:46102 OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED);
103
104 null_group_commands_map_[OLECMDID_PRINT] = flags;
105 null_group_commands_map_[OLECMDID_FIND] = flags;
106 null_group_commands_map_[OLECMDID_CUT] = flags;
107 null_group_commands_map_[OLECMDID_COPY] = flags;
108 null_group_commands_map_[OLECMDID_PASTE] = flags;
109 null_group_commands_map_[OLECMDID_SELECTALL] = flags;
110 null_group_commands_map_[OLECMDID_SAVEAS] = flags;
111
112 mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags;
113 mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags;
114 mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags;
115 mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags;
116 mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags;
[email protected]b2529722010-12-01 02:49:07117 mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags;
[email protected]a15d4a42010-02-17 08:21:35118
[email protected]3c6f8e12010-03-24 21:58:21119 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
[email protected]a15d4a42010-02-17 08:21:35120 accelerator_table_ =
[email protected]3c6f8e12010-03-24 21:58:21121 LoadAccelerators(this_module,
[email protected]a15d4a42010-02-17 08:21:35122 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
123 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58124 return S_OK;
125}
126
127ChromeActiveDocument::~ChromeActiveDocument() {
[email protected]2b9a9f162010-10-19 20:30:45128 DVLOG(1) << __FUNCTION__;
[email protected]bc2ff5192010-06-01 22:05:45129 if (find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58130 find_dialog_.DestroyWindow();
[email protected]3eb07da2010-02-01 19:48:36131 // ChromeFramePlugin
[email protected]97965e12010-04-09 00:51:10132 BaseActiveX::Uninitialize();
[email protected]04e3f352010-05-10 13:48:24133
134 TRACE_EVENT_END("chromeframe.createactivedocument", this, "");
[email protected]f7817822009-09-24 05:11:58135}
136
137// Override DoVerb
138STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
139 LPMSG msg,
140 IOleClientSite* active_site,
141 LONG index,
142 HWND parent_window,
143 LPCRECT pos) {
144 // IE will try and in-place activate us in some cases. This happens when
145 // the user opens a new IE window with a URL that has us as the DocObject.
146 // Here we refuse to be activated in-place and we will force IE to UIActivate
147 // us.
[email protected]bc2ff5192010-06-01 22:05:45148 if (OLEIVERB_INPLACEACTIVATE == verb)
[email protected]23b33612010-11-09 23:47:01149 return OLEOBJ_E_INVALIDVERB;
[email protected]f7817822009-09-24 05:11:58150 // Check if we should activate as a docobject or not
151 // (client supports IOleDocumentSite)
152 if (doc_site_) {
153 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57154 case OLEIVERB_SHOW: {
155 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
156 doc_host_handler.QueryFrom(doc_site_);
[email protected]bc2ff5192010-06-01 22:05:45157 if (doc_host_handler.get())
[email protected]1bb5f892009-10-06 01:44:57158 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
[email protected]1bb5f892009-10-06 01:44:57159 }
[email protected]f7817822009-09-24 05:11:58160 case OLEIVERB_OPEN:
161 case OLEIVERB_UIACTIVATE:
[email protected]bc2ff5192010-06-01 22:05:45162 if (!m_bUIActive)
[email protected]f7817822009-09-24 05:11:58163 return doc_site_->ActivateMe(NULL);
[email protected]f7817822009-09-24 05:11:58164 break;
165 }
166 }
167 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
168 msg,
169 active_site,
170 index,
171 parent_window,
172 pos);
173}
174
[email protected]f7817822009-09-24 05:11:58175// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
176STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
[email protected]2b9a9f162010-10-19 20:30:45177 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58178 return S_OK;
179}
180
181STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
[email protected]2b9a9f162010-10-19 20:30:45182 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58183 if (msg == NULL)
184 return E_POINTER;
185
186 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
187 HWND focus = ::GetFocus();
188 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
189 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
190 // set focus to the correct element in Chrome.
191 ::SetFocus(m_hWnd);
192 return S_OK;
193 }
194 }
195
196 return S_FALSE;
197}
198// Override IPersistStorageImpl::IsDirty
199STDMETHODIMP ChromeActiveDocument::IsDirty() {
[email protected]2b9a9f162010-10-19 20:30:45200 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58201 return S_FALSE;
202}
203
[email protected]b95f550f2009-11-19 05:35:22204void ChromeActiveDocument::OnAutomationServerReady() {
[email protected]97965e12010-04-09 00:51:10205 BaseActiveX::OnAutomationServerReady();
[email protected]1fd45692010-04-19 21:01:18206 BaseActiveX::GiveFocusToChrome(true);
[email protected]b95f550f2009-11-19 05:35:22207}
208
[email protected]f7817822009-09-24 05:11:58209STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
210 IMoniker* moniker_name,
211 LPBC bind_context,
212 DWORD mode) {
[email protected]bc2ff5192010-06-01 22:05:45213 if (NULL == moniker_name)
[email protected]f7817822009-09-24 05:11:58214 return E_INVALIDARG;
[email protected]a1800e82009-11-19 00:53:23215
216 ScopedComPtr<IOleClientSite> client_site;
217 if (bind_context) {
218 ScopedComPtr<IUnknown> site;
219 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
220 site.Receive());
221 if (site)
222 client_site.QueryFrom(site);
223 }
224
225 if (client_site) {
226 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11227 DoQueryService(IID_INewWindowManager, client_site,
228 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14229
230 // See if mshtml parsed the html header for us. If so, we need to
231 // clear the browser service flag that we use to indicate that this
232 // browser instance is navigating to a CF document.
233 ScopedComPtr<IBrowserService> browser_service;
234 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
235 if (browser_service) {
236 bool flagged = CheckForCFNavigation(browser_service, true);
[email protected]5044da82010-10-27 01:09:16237 DVLOG_IF(1, flagged) << "Cleared flagged browser service";
[email protected]051236f2010-03-12 22:06:14238 }
[email protected]a1800e82009-11-19 00:53:23239 }
240
[email protected]051236f2010-03-12 22:06:14241 NavigationManager* mgr = NavigationManager::GetThreadInstance();
[email protected]21b4e6d2010-07-14 18:19:59242 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
[email protected]7e3544b2010-01-22 00:02:34243
[email protected]29c32f902010-04-20 23:27:29244 std::wstring url;
245
[email protected]77d7aee2010-05-14 20:31:55246 ScopedComPtr<BindContextInfo> info;
247 BindContextInfo::FromBindContext(bind_context, info.Receive());
[email protected]29c32f902010-04-20 23:27:29248 DCHECK(info);
249 if (info && !info->url().empty()) {
250 url = info->url();
251 } else {
252 // If the original URL contains an anchor, then the URL queried
253 // from the moniker does not contain the anchor. To workaround
254 // this we retrieve the URL from our BHO.
255 url = GetActualUrlFromMoniker(moniker_name, bind_context,
256 mgr ? mgr->url(): std::wstring());
257 }
[email protected]051236f2010-03-12 22:06:14258
[email protected]c4e45b32010-07-28 21:15:15259 ChromeFrameUrl cf_url;
260 if (!cf_url.Parse(url)) {
[email protected]37346bc2009-09-25 22:54:33261 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58262 return E_INVALIDARG;
263 }
264
[email protected]bbfa9a12010-08-10 14:09:37265 std::string referrer(mgr ? mgr->referrer() : EmptyString());
[email protected]d8e13512010-09-22 17:02:58266 RendererType renderer_type = cf_url.is_chrome_protocol() ?
267 RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED;
[email protected]bbfa9a12010-08-10 14:09:37268
[email protected]aaf124502010-07-17 04:02:58269 // With CTransaction patch we have more robust way to grab the referrer for
270 // each top-level-switch-to-CF request by peeking at our sniffing data
[email protected]d8e13512010-09-22 17:02:58271 // object that lives inside the bind context. We also remember the reason
272 // we're rendering the document in Chrome.
[email protected]aaf124502010-07-17 04:02:58273 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
274 scoped_refptr<ProtData> prot_data = info->get_prot_data();
[email protected]d8e13512010-09-22 17:02:58275 if (prot_data) {
[email protected]aaf124502010-07-17 04:02:58276 referrer = prot_data->referrer();
[email protected]d8e13512010-09-22 17:02:58277 renderer_type = prot_data->renderer_type();
278 }
[email protected]aaf124502010-07-17 04:02:58279 }
280
[email protected]62ce09732010-09-03 18:32:04281 // For gcf: URLs allow only about and view-source schemes to pass through for
282 // further inspection.
283 bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) ||
284 cf_url.gurl().SchemeIs(chrome::kViewSourceScheme);
285 if (cf_url.is_chrome_protocol() && !is_safe_scheme &&
286 !GetConfigBool(false, kAllowUnsafeURLs)) {
287 DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url;
288 return E_INVALIDARG;
289 }
290
[email protected]c4e45b32010-07-28 21:15:15291 if (!LaunchUrl(cf_url, referrer)) {
[email protected]d266ce82010-08-13 21:33:40292 DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url;
[email protected]37346bc2009-09-25 22:54:33293 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58294 }
295
[email protected]c4e45b32010-07-28 21:15:15296 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
[email protected]d266ce82010-08-13 21:33:40297 url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context);
[email protected]f7817822009-09-24 05:11:58298
[email protected]d8e13512010-09-22 17:02:58299 // Log a metric indicating why GCF is rendering in Chrome.
300 // (Note: we only track the renderer type when using the CTransaction patch.
301 // When the code for the browser service patch and for the moniker patch is
302 // removed, this conditional can also go away.)
303 if (RENDERER_TYPE_UNDETERMINED != renderer_type) {
304 THREAD_SAFE_UMA_LAUNCH_TYPE_COUNT(renderer_type);
305 }
306
[email protected]f7817822009-09-24 05:11:58307 return S_OK;
308}
309
310STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
311 LPBC bind_context,
312 BOOL remember) {
313 return E_NOTIMPL;
314}
315
316STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
317 LPBC bind_context) {
318 return E_NOTIMPL;
319}
320
321STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
322 return E_NOTIMPL;
323}
324
325STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
[email protected]bc2ff5192010-06-01 22:05:45326 if (NULL == class_id)
[email protected]f7817822009-09-24 05:11:58327 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58328 *class_id = GetObjectCLSID();
329 return S_OK;
330}
331
332STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
333 ULONG number_of_commands,
334 OLECMD commands[],
335 OLECMDTEXT* command_text) {
[email protected]2b9a9f162010-10-19 20:30:45336 DVLOG(1) << __FUNCTION__;
[email protected]b509ec82010-04-13 16:53:06337
[email protected]6fd1a7a2010-07-26 22:09:46338 CommandStatusMap* command_map = NULL;
[email protected]b509ec82010-04-13 16:53:06339
[email protected]6fd1a7a2010-07-26 22:09:46340 if (cmd_group_guid) {
341 if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) {
342 command_map = &null_group_commands_map_;
343 } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) {
344 command_map = &mshtml_group_commands_map_;
345 } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) {
346 command_map = &explorer_group_commands_map_;
347 } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) {
348 command_map = &shdoc_view_group_commands_map_;
349 }
350 } else {
351 command_map = &null_group_commands_map_;
352 }
353
354 if (!command_map) {
[email protected]2b9a9f162010-10-19 20:30:45355 DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid);
[email protected]b509ec82010-04-13 16:53:06356 return OLECMDERR_E_NOTSUPPORTED;
357 }
358
[email protected]f7817822009-09-24 05:11:58359 for (ULONG command_index = 0; command_index < number_of_commands;
360 command_index++) {
[email protected]2b9a9f162010-10-19 20:30:45361 DVLOG(1) << "Command id = " << commands[command_index].cmdID;
[email protected]6fd1a7a2010-07-26 22:09:46362 CommandStatusMap::iterator index =
363 command_map->find(commands[command_index].cmdID);
364 if (index != command_map->end())
365 commands[command_index].cmdf = index->second;
[email protected]f7817822009-09-24 05:11:58366 }
367 return S_OK;
368}
369
370STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
371 DWORD command_id,
372 DWORD cmd_exec_opt,
373 VARIANT* in_args,
374 VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:45375 DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id;
[email protected]f7817822009-09-24 05:11:58376 // Bail out if we have been uninitialized.
377 if (automation_client_.get() && automation_client_->tab()) {
378 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
379 in_args, out_args);
[email protected]bbfa9a12010-08-10 14:09:37380 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
381 // If the automation server has crashed and the user is refreshing the
382 // page, let OnRefreshPage attempt to recover.
383 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
[email protected]f7817822009-09-24 05:11:58384 }
[email protected]bbfa9a12010-08-10 14:09:37385
[email protected]e3200932009-10-09 21:33:03386 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58387}
388
[email protected]a1800e82009-11-19 00:53:23389STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
390 IBindCtx* bind_context) {
391 // Read notes in ChromeActiveDocument::SaveHistory
392 DCHECK(stream);
393 LARGE_INTEGER offset = {0};
394 ULARGE_INTEGER cur_pos = {0};
395 STATSTG statstg = {0};
396
397 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
398 stream->Stat(&statstg, STATFLAG_NONAME);
399
400 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
[email protected]965722ff2010-10-20 15:50:30401 base::win::ScopedBstr url_bstr;
[email protected]a1800e82009-11-19 00:53:23402 DWORD bytes_read = 0;
403 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
404 std::wstring url(url_bstr);
405
[email protected]c4e45b32010-07-28 21:15:15406 ChromeFrameUrl cf_url;
407 if (!cf_url.Parse(url)) {
[email protected]a1800e82009-11-19 00:53:23408 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
409 return E_INVALIDARG;
410 }
411
[email protected]c5cbf4e2010-07-15 21:48:25412 const std::string& referrer = EmptyString();
[email protected]c4e45b32010-07-28 21:15:15413 if (!LaunchUrl(cf_url, referrer)) {
[email protected]a1800e82009-11-19 00:53:23414 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
415 return E_INVALIDARG;
416 }
417 return S_OK;
418}
419
420STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
421 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
422 // from Chrome and persist it in the stream. And in LoadHistory we need to
423 // pass this list back to Chrome which will recreate the list. This will allow
424 // Back-Forward navigation to anchors to work correctly when we navigate to a
425 // page outside of ChromeFrame and then come back.
426 if (!stream) {
427 NOTREACHED();
428 return E_INVALIDARG;
429 }
430
431 LARGE_INTEGER offset = {0};
432 ULARGE_INTEGER new_pos = {0};
433 DWORD written = 0;
434 std::wstring url = UTF8ToWide(navigation_info_.url.spec());
435 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
436 &written);
437}
438
439STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
[email protected]77700832010-04-27 00:06:03440 if (automation_client_.get()) {
441 int index = static_cast<int>(position_cookie);
442 navigation_info_.navigation_index = index;
443 automation_client_->NavigateToIndex(index);
444 } else {
445 DLOG(WARNING) << "Invalid automation client instance";
446 }
[email protected]a1800e82009-11-19 00:53:23447 return S_OK;
448}
449
450STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
451 if (!position_cookie)
452 return E_INVALIDARG;
453
454 *position_cookie = navigation_info_.navigation_index;
455 return S_OK;
456}
457
[email protected]f7817822009-09-24 05:11:58458STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
[email protected]bc2ff5192010-06-01 22:05:45459 if (NULL == url)
[email protected]f7817822009-09-24 05:11:58460 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58461 *url = ::SysAllocString(url_);
462 return S_OK;
463}
464
[email protected]a1800e82009-11-19 00:53:23465STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
466 return GetUrlForEvents(url);
467}
468
[email protected]80b5a8d2010-03-19 16:50:43469STDMETHODIMP ChromeActiveDocument::Reset() {
470 next_privacy_record_ = privacy_info_.privacy_records.begin();
471 return S_OK;
472}
473
[email protected]00aebd72010-07-16 14:44:32474STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) {
[email protected]80b5a8d2010-03-19 16:50:43475 if (!size)
476 return E_POINTER;
477
478 *size = privacy_info_.privacy_records.size();
479 return S_OK;
480}
481
482STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
483 if (!privacy_impacted)
484 return E_POINTER;
485
486 *privacy_impacted = privacy_info_.privacy_impacted;
487 return S_OK;
488}
489
490STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
[email protected]00aebd72010-07-16 14:44:32491 LONG* reserved, DWORD* flags) {
[email protected]80b5a8d2010-03-19 16:50:43492 if (!url || !policy || !flags)
493 return E_POINTER;
494
495 if (next_privacy_record_ == privacy_info_.privacy_records.end())
496 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
497
498 *url = SysAllocString(next_privacy_record_->first.c_str());
499 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
500 *flags = next_privacy_record_->second.flags;
501
502 next_privacy_record_++;
503 return S_OK;
504}
505
[email protected]354bcba2010-12-14 04:34:43506bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) {
507 bool allowed = BaseActiveX::IsSchemeAllowed(url);
508 if (allowed)
509 return true;
510
511 if (url.SchemeIs(chrome::kAboutScheme)) {
512 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL))
513 return true;
514 }
515 return false;
516}
517
[email protected]3eafbfb92010-08-02 16:54:22518HRESULT ChromeActiveDocument::GetInPlaceFrame(
519 IOleInPlaceFrame** in_place_frame) {
520 DCHECK(in_place_frame);
521 if (in_place_frame_) {
522 *in_place_frame = in_place_frame_.get();
523 (*in_place_frame)->AddRef();
524 return S_OK;
525 } else {
526 return S_FALSE;
527 }
528}
529
[email protected]f7817822009-09-24 05:11:58530HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
531 IOleClientSite* client_site) {
532 if (client_site == NULL) {
533 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
534 if (cached_document) {
535 DCHECK(this == cached_document);
536 g_active_doc_cache.Set(NULL);
537 cached_document->Release();
538 }
[email protected]dda7d9c2009-11-11 23:01:47539
540 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]bc2ff5192010-06-01 22:05:45541 if (doc_site_)
[email protected]77059f72010-02-28 06:16:00542 doc_host_handler.QueryFrom(doc_site_);
[email protected]dda7d9c2009-11-11 23:01:47543
[email protected]bc2ff5192010-06-01 22:05:45544 if (doc_host_handler.get())
[email protected]dda7d9c2009-11-11 23:01:47545 doc_host_handler->HideUI();
[email protected]dda7d9c2009-11-11 23:01:47546
547 doc_site_.Release();
[email protected]f7817822009-09-24 05:11:58548 }
[email protected]a1800e82009-11-19 00:53:23549
[email protected]bc2ff5192010-06-01 22:05:45550 if (client_site != m_spClientSite)
[email protected]97965e12010-04-09 00:51:10551 return BaseActiveX::IOleObject_SetClientSite(client_site);
[email protected]a1800e82009-11-19 00:53:23552
553 return S_OK;
[email protected]f7817822009-09-24 05:11:58554}
555
[email protected]f7817822009-09-24 05:11:58556HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
557 HRESULT hr = S_OK;
558 m_bNegotiatedWnd = TRUE;
559 if (!m_bInPlaceActive) {
560 hr = m_spInPlaceSite->CanInPlaceActivate();
[email protected]bc2ff5192010-06-01 22:05:45561 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58562 return hr;
[email protected]f7817822009-09-24 05:11:58563 m_spInPlaceSite->OnInPlaceActivate();
564 }
565 m_bInPlaceActive = TRUE;
566 // get location in the parent window,
567 // as well as some information about the parent
568 ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
569 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
570 HWND parent_window = NULL;
571 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
572 in_place_frame_.Release();
573 RECT position_rect = {0};
574 RECT clip_rect = {0};
575 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
576 in_place_ui_window.Receive(),
577 &position_rect,
578 &clip_rect,
579 &frame_info_);
580 if (!m_bWndLess) {
581 if (IsWindow()) {
582 ::ShowWindow(m_hWnd, SW_SHOW);
583 SetFocus();
584 } else {
[email protected]c1d19582010-03-03 01:57:13585 m_hWnd = Create(parent_window, position_rect, 0, 0, WS_EX_CLIENTEDGE);
[email protected]dd4beb522010-07-13 18:18:14586 if (!IsWindow()) {
587 // This might happen if the automation server couldn't be
588 // instantiated. If so, a NOTREACHED() will have already been hit.
589 DLOG(ERROR) << "Failed to create Ax window";
590 return AtlHresultFromLastError();
591 }
[email protected]f7817822009-09-24 05:11:58592 }
[email protected]7f860dd82010-08-09 23:18:05593 SetWindowDimensions();
[email protected]f7817822009-09-24 05:11:58594 }
595 SetObjectRects(&position_rect, &clip_rect);
596 }
597
598 ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
599
600 // Gone active by now, take care of UIACTIVATE
601 if (DoesVerbUIActivate(verb)) {
602 if (!m_bUIActive) {
603 m_bUIActive = TRUE;
604 hr = m_spInPlaceSite->OnUIActivate();
[email protected]bc2ff5192010-06-01 22:05:45605 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58606 return hr;
[email protected]f7817822009-09-24 05:11:58607 // set ourselves up in the host
608 if (in_place_active_object) {
[email protected]bc2ff5192010-06-01 22:05:45609 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58610 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
[email protected]bc2ff5192010-06-01 22:05:45611 if (in_place_ui_window)
[email protected]f7817822009-09-24 05:11:58612 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
[email protected]f7817822009-09-24 05:11:58613 }
614 }
615 }
616 m_spClientSite->ShowObject();
617 return S_OK;
618}
619
[email protected]f5494d42010-12-23 22:15:34620void ChromeActiveDocument::OnNavigationStateChanged(
621 int flags, const NavigationInfo& nav_info) {
[email protected]f7817822009-09-24 05:11:58622 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
[email protected]2b9a9f162010-10-19 20:30:45623 DVLOG(1) << __FUNCTION__
624 << "\n Flags: " << flags
625 << ", Url: " << nav_info.url
626 << ", Title: " << nav_info.title
627 << ", Type: " << nav_info.navigation_type
628 << ", Relative Offset: " << nav_info.relative_offset
629 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58630
[email protected]747bca12011-01-15 00:28:45631 UpdateNavigationState(nav_info, flags);
[email protected]f7817822009-09-24 05:11:58632}
633
[email protected]f5494d42010-12-23 22:15:34634void ChromeActiveDocument::OnUpdateTargetUrl(
[email protected]f7817822009-09-24 05:11:58635 const std::wstring& new_target_url) {
[email protected]bc2ff5192010-06-01 22:05:45636 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58637 in_place_frame_->SetStatusText(new_target_url.c_str());
[email protected]f7817822009-09-24 05:11:58638}
639
640bool IsFindAccelerator(const MSG& msg) {
641 // TODO(robertshield): This may not stand up to localization. Fix if this
642 // is the case.
643 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
[email protected]a8e20582010-12-31 17:18:50644 base::win::IsCtrlPressed() &&
645 !(base::win::IsAltPressed() || base::win::IsShiftPressed());
[email protected]f7817822009-09-24 05:11:58646}
647
[email protected]f5494d42010-12-23 22:15:34648void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35649 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
650 const_cast<MSG*>(&accel_message)))
651 return;
652
[email protected]f7817822009-09-24 05:11:58653 bool handled_accel = false;
654 if (in_place_frame_ != NULL) {
655 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
656 const_cast<MSG*>(&accel_message), 0));
657 }
658
659 if (!handled_accel) {
660 if (IsFindAccelerator(accel_message)) {
661 // Handle the showing of the find dialog explicitly.
662 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59663 } else {
[email protected]f5494d42010-12-23 22:15:34664 BaseActiveX::OnAcceleratorPressed(accel_message);
[email protected]f7817822009-09-24 05:11:58665 }
666 } else {
[email protected]2b9a9f162010-10-19 20:30:45667 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
[email protected]f7817822009-09-24 05:11:58668 }
669}
670
[email protected]f5494d42010-12-23 22:15:34671void ChromeActiveDocument::OnTabbedOut(bool reverse) {
[email protected]2b9a9f162010-10-19 20:30:45672 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58673 if (in_place_frame_) {
674 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
675 in_place_frame_->TranslateAcceleratorW(&msg, 0);
676 }
677}
678
[email protected]f5494d42010-12-23 22:15:34679void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
[email protected]2b9a9f162010-10-19 20:30:45680 DVLOG(1) << __FUNCTION__ << std::endl
681 << "Url: " << nav_info.url
682 << ", Title: " << nav_info.title
683 << ", Type: " << nav_info.navigation_type
684 << ", Relative Offset: " << nav_info.relative_offset
685 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58686
[email protected]897b26272010-06-11 02:23:44687 CrashMetricsReporter::GetInstance()->IncrementMetric(
688 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
689
[email protected]f7817822009-09-24 05:11:58690 // This could be NULL if the active document instance is being destroyed.
691 if (!m_spInPlaceSite) {
[email protected]2b9a9f162010-10-19 20:30:45692 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
[email protected]f7817822009-09-24 05:11:58693 return;
694 }
695
[email protected]747bca12011-01-15 00:28:45696 UpdateNavigationState(nav_info, 0);
[email protected]f7817822009-09-24 05:11:58697}
698
[email protected]f5494d42010-12-23 22:15:34699void ChromeActiveDocument::OnCloseTab() {
[email protected]2f1793ea2010-10-27 17:32:51700 // Base class will fire DIChromeFrameEvents::onclose.
[email protected]f5494d42010-12-23 22:15:34701 BaseActiveX::OnCloseTab();
[email protected]2f1793ea2010-10-27 17:32:51702
703 // Close the container window.
[email protected]e16dd1672010-06-07 21:40:29704 ScopedComPtr<IWebBrowser2> web_browser2;
705 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
706 if (web_browser2)
707 web_browser2->Quit();
708}
709
[email protected]f7817822009-09-24 05:11:58710void ChromeActiveDocument::UpdateNavigationState(
[email protected]747bca12011-01-15 00:28:45711 const NavigationInfo& new_navigation_info, int flags) {
[email protected]a1800e82009-11-19 00:53:23712 HRESULT hr = S_OK;
[email protected]f7817822009-09-24 05:11:58713 bool is_title_changed = (navigation_info_.title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58714 bool is_ssl_state_changed =
715 (navigation_info_.security_style != new_navigation_info.security_style) ||
[email protected]b4e75c12010-05-18 18:28:48716 (navigation_info_.displayed_insecure_content !=
717 new_navigation_info.displayed_insecure_content) ||
718 (navigation_info_.ran_insecure_content !=
719 new_navigation_info.ran_insecure_content);
[email protected]f7817822009-09-24 05:11:58720
[email protected]f7817822009-09-24 05:11:58721 if (is_ssl_state_changed) {
722 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23723 switch (new_navigation_info.security_style) {
[email protected]f7817822009-09-24 05:11:58724 case SECURITY_STYLE_AUTHENTICATED:
[email protected]b4e75c12010-05-18 18:28:48725 lock_status = new_navigation_info.displayed_insecure_content ?
[email protected]f7817822009-09-24 05:11:58726 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
727 break;
728 default:
729 break;
730 }
731
[email protected]965722ff2010-10-20 15:50:30732 base::win::ScopedVariant secure_lock_status(lock_status);
[email protected]f7817822009-09-24 05:11:58733 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
734 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
735 }
736
[email protected]a1800e82009-11-19 00:53:23737 // Ideally all navigations should come to Chrome Frame so that we can call
738 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
739 // navigation. However, in practice what happens is as below:
740 // The very first navigation that happens in CF happens via a Load or a
741 // LoadHistory call. In this case, IE already has the correct information for
742 // its travel log as well address bar. For other internal navigations (navs
743 // that only happen within Chrome such as anchor navigations) we need to
744 // update IE's internal state after the fact. In the case of internal
745 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58746
747 // Another case where we need to issue BeforeNavigate2 calls is as below:-
748 // We get notified after the fact, when navigations are initiated within
749 // Chrome via window.open calls. These navigations are handled by creating
750 // an external tab container within chrome and then connecting to it from IE.
751 // We still want to update the address bar/history, etc, to ensure that
752 // the special URL used by Chrome to indicate this is updated correctly.
[email protected]d266ce82010-08-13 21:33:40753 ChromeFrameUrl cf_url;
754 bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) &&
755 cf_url.attach_to_external_tab();
[email protected]342de552010-10-21 20:46:14756
757 bool is_internal_navigation =
[email protected]747bca12011-01-15 00:28:45758 IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url;
[email protected]f7817822009-09-24 05:11:58759
[email protected]bc2ff5192010-06-01 22:05:45760 if (new_navigation_info.url.is_valid())
[email protected]38939de2010-05-13 02:32:06761 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]38939de2010-05-13 02:32:06762
[email protected]a1800e82009-11-19 00:53:23763 if (is_internal_navigation) {
764 ScopedComPtr<IDocObjectService> doc_object_svc;
[email protected]f7817822009-09-24 05:11:58765 ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06766
[email protected]5ae94d22010-07-21 19:55:36767 buggy_bho::BuggyBhoTls bad_bho_tls;
768 if (GetConfigBool(true, kEnableBuggyBhoIntercept)) {
769 ScopedComPtr<IWebBrowser2> wb2;
770 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
771 if (wb2) {
772 buggy_bho::BuggyBhoTls::PatchBuggyBHOs(wb2);
773 }
774 }
775
[email protected]f7817822009-09-24 05:11:58776 DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite,
777 web_browser_events_svc.Receive());
[email protected]ae33d672010-03-04 21:58:06778
779 if (!web_browser_events_svc.get()) {
780 DoQueryService(SID_SShellBrowser, m_spClientSite,
781 doc_object_svc.Receive());
782 }
783
[email protected]62bb18dc12009-11-25 01:34:08784 // web_browser_events_svc can be NULL on IE6.
[email protected]f7817822009-09-24 05:11:58785 if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58786 VARIANT_BOOL should_cancel = VARIANT_FALSE;
787 web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel);
[email protected]33bd26d2010-08-31 05:05:03788 } else if (doc_object_svc) {
789 BOOL should_cancel = FALSE;
790 doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0,
791 NULL, FALSE, &should_cancel);
[email protected]a1800e82009-11-19 00:53:23792 }
793
794 // We need to tell IE that we support navigation so that IE will query us
795 // for IPersistHistory and call GetPositionCookie to save our navigation
796 // index.
[email protected]965722ff2010-10-20 15:50:30797 base::win::ScopedVariant html_window(static_cast<IUnknown*>(
[email protected]a1800e82009-11-19 00:53:23798 static_cast<IHTMLWindow2*>(this)));
799 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
800 html_window.AsInput(), NULL);
801
802 // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG
803 // since we want to make IE treat all internal navigations within this page
804 // (including anchor navigations and subframe navigations) as anchor
805 // navigations. This will ensure that IE calls GetPositionCookie
806 // to save the current position cookie in the travel log and then call
807 // SetPositionCookie when the user hits Back/Forward to come back here.
[email protected]965722ff2010-10-20 15:50:30808 base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP);
[email protected]a1800e82009-11-19 00:53:23809 IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0,
810 internal_navigation.AsInput(), NULL);
811
812 // We no longer need to lie to IE. If we lie persistently to IE, then
813 // IE reuses us for new navigations.
814 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL);
815
816 if (doc_object_svc) {
817 // Now call the FireNavigateCompleteEvent which makes IE update the text
818 // in the address-bar.
819 doc_object_svc->FireNavigateComplete2(this, 0);
[email protected]5ae94d22010-07-21 19:55:36820 doc_object_svc->FireDocumentComplete(this, 0);
[email protected]a1800e82009-11-19 00:53:23821 } else if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58822 web_browser_events_svc->FireNavigateComplete2Event();
[email protected]5ae94d22010-07-21 19:55:36823 web_browser_events_svc->FireDocumentCompleteEvent();
[email protected]f7817822009-09-24 05:11:58824 }
825 }
[email protected]37346bc2009-09-25 22:54:33826
[email protected]a1800e82009-11-19 00:53:23827 if (is_title_changed) {
[email protected]965722ff2010-10-20 15:50:30828 base::win::ScopedVariant title(new_navigation_info.title.c_str());
[email protected]a1800e82009-11-19 00:53:23829 IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
830 title.AsInput(), NULL);
831 }
832
833 // It is important that we only update the navigation_info_ after we have
834 // finalized the travel log. This is because IE will ask for information
835 // such as navigation index when the travel log is finalized and we need
836 // supply the old index and not the new one.
837 navigation_info_ = new_navigation_info;
[email protected]37346bc2009-09-25 22:54:33838 // Update the IE zone here. Ideally we would like to do it when the active
839 // document is activated. However that does not work at times as the frame we
840 // get there is not the actual frame which handles the command.
841 IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL);
[email protected]f7817822009-09-24 05:11:58842}
843
844void ChromeActiveDocument::OnFindInPage() {
845 TabProxy* tab = GetTabProxy();
846 if (tab) {
[email protected]bc2ff5192010-06-01 22:05:45847 if (!find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58848 find_dialog_.Create(m_hWnd);
[email protected]f7817822009-09-24 05:11:58849
850 find_dialog_.ShowWindow(SW_SHOW);
851 }
852}
853
854void ChromeActiveDocument::OnViewSource() {
855 DCHECK(navigation_info_.url.is_valid());
[email protected]76e7da22010-06-18 22:44:49856 HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") +
857 navigation_info_.url.spec()), GURL(), NEW_WINDOW);
[email protected]f7817822009-09-24 05:11:58858}
859
[email protected]37346bc2009-09-25 22:54:33860void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid,
861 DWORD command_id,
862 DWORD cmd_exec_opt,
863 VARIANT* in_args,
864 VARIANT* out_args) {
[email protected]7c712c92010-03-24 17:29:22865 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
866 // Correct step is to use MapUrlToZone().
[email protected]37346bc2009-09-25 22:54:33867 if (out_args != NULL) {
868 out_args->vt = VT_UI4;
869 out_args->ulVal = URLZONE_INTERNET;
870 }
871}
872
[email protected]80b5a8d2010-03-19 16:50:43873void ChromeActiveDocument::OnDisplayPrivacyInfo() {
[email protected]bbfa9a12010-08-10 14:09:37874 privacy_info_ = url_fetcher_->privacy_info();
[email protected]80b5a8d2010-03-19 16:50:43875 Reset();
876 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
877}
878
[email protected]7f860dd82010-08-09 23:18:05879void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid,
880 DWORD command_id,
881 DWORD cmd_exec_opt,
882 VARIANT* in_args,
883 VARIANT* out_args) {
884 if (out_args != NULL) {
885 out_args->vt = VT_I4;
886 out_args->lVal = 0;
887 }
888}
889
890void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid,
891 DWORD command_id,
892 DWORD cmd_exec_opt,
893 VARIANT* in_args,
894 VARIANT* out_args) {
895 const int kZoomIn = 125;
896 const int kZoomOut = 75;
897
898 if (in_args && V_VT(in_args) == VT_I4 && IsValid()) {
899 if (in_args->lVal == kZoomIn) {
900 automation_client_->SetZoomLevel(PageZoom::ZOOM_IN);
901 } else if (in_args->lVal == kZoomOut) {
902 automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT);
903 } else {
904 DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal;
905 }
906 }
907}
908
[email protected]d9d8f0c2010-09-17 21:47:16909void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid,
910 DWORD command_id,
911 DWORD cmd_exec_opt,
912 VARIANT* in_args,
913 VARIANT* out_args) {
914 if (IsValid() && out_args) {
915 bool should_unload = true;
916 automation_client_->OnUnload(&should_unload);
917 out_args->vt = VT_BOOL;
918 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
919 }
920}
921
[email protected]f5494d42010-12-23 22:15:34922void ChromeActiveDocument::OnOpenURL(const GURL& url_to_open,
[email protected]b36a9f92009-10-19 17:34:57923 const GURL& referrer,
[email protected]f7817822009-09-24 05:11:58924 int open_disposition) {
925 // If the disposition indicates that we should be opening the URL in the
926 // current tab, then we can reuse the ChromeFrameAutomationClient instance
927 // maintained by the current ChromeActiveDocument instance. We cache this
928 // instance so that it can be used by the new ChromeActiveDocument instance
929 // which may be instantiated for handling the new URL.
930 if (open_disposition == CURRENT_TAB) {
931 // Grab a reference to ensure that the document remains valid.
932 AddRef();
933 g_active_doc_cache.Set(this);
934 }
935
[email protected]f5494d42010-12-23 22:15:34936 BaseActiveX::OnOpenURL(url_to_open, referrer, open_disposition);
[email protected]f7817822009-09-24 05:11:58937}
938
[email protected]f5494d42010-12-23 22:15:34939void ChromeActiveDocument::OnAttachExternalTab(
940 const AttachExternalTabParams& params) {
[email protected]77700832010-04-27 00:06:03941 if (!automation_client_.get()) {
942 DLOG(WARNING) << "Invalid automation client instance";
943 return;
944 }
[email protected]b1c55638612010-03-08 16:26:11945 DWORD flags = 0;
946 if (params.user_gesture)
947 flags = NWMF_USERREQUESTED;
[email protected]355309e2010-03-15 17:01:34948 else if (popup_allowed_)
949 flags = NWMF_USERALLOWED;
[email protected]b1c55638612010-03-08 16:26:11950
951 HRESULT hr = S_OK;
952 if (popup_manager_) {
[email protected]e4456ae2010-09-22 23:35:11953 const std::wstring& url_wide = UTF8ToWide(params.url.spec());
954 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_,
[email protected]355309e2010-03-15 17:01:34955 NULL, FALSE, flags, 0);
[email protected]b1c55638612010-03-08 16:26:11956 }
957 // Allow popup
958 if (hr == S_OK) {
[email protected]f5494d42010-12-23 22:15:34959 BaseActiveX::OnAttachExternalTab(params);
[email protected]b1c55638612010-03-08 16:26:11960 return;
961 }
962
963 automation_client_->BlockExternalTab(params.cookie);
964}
965
[email protected]f7817822009-09-24 05:11:58966bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
967 ScopedComPtr<IBrowserService> browser_service;
968 ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:23969 GetBrowserServiceAndTravelLog(browser_service.Receive(),
970 travel_log.Receive());
971 if (!browser_service || !travel_log)
[email protected]f7817822009-09-24 05:11:58972 return true;
973
[email protected]d118f542010-11-05 18:50:31974 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND |
975 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK,
976 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45977 MF_ENABLED : MF_DISABLED));
[email protected]d118f542010-11-05 18:50:31978 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND |
979 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE,
980 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45981 MF_ENABLED : MF_DISABLED));
[email protected]f7817822009-09-24 05:11:58982 // Call base class (adds 'About' item)
[email protected]97965e12010-04-09 00:51:10983 return BaseActiveX::PreProcessContextMenu(menu);
[email protected]f7817822009-09-24 05:11:58984}
985
[email protected]f5494d42010-12-23 22:15:34986bool ChromeActiveDocument::HandleContextMenuCommand(
987 UINT cmd, const MiniContextMenuParams& params) {
[email protected]f7817822009-09-24 05:11:58988 ScopedComPtr<IWebBrowser2> web_browser2;
989 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
990
[email protected]074283a2010-05-28 23:47:59991 if (cmd == IDC_BACK)
[email protected]b731a142010-05-14 00:03:03992 web_browser2->GoBack();
[email protected]074283a2010-05-28 23:47:59993 else if (cmd == IDC_FORWARD)
[email protected]b731a142010-05-14 00:03:03994 web_browser2->GoForward();
[email protected]074283a2010-05-28 23:47:59995 else if (cmd == IDC_RELOAD)
[email protected]b731a142010-05-14 00:03:03996 web_browser2->Refresh();
[email protected]074283a2010-05-28 23:47:59997 else
[email protected]b731a142010-05-14 00:03:03998 return BaseActiveX::HandleContextMenuCommand(cmd, params);
[email protected]f7817822009-09-24 05:11:58999
1000 return true;
1001}
1002
1003HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid,
1004 DWORD command_id, DWORD cmd_exec_opt,
1005 VARIANT* in_args, VARIANT* out_args) {
1006 HRESULT hr = E_FAIL;
[email protected]37346bc2009-09-25 22:54:331007
[email protected]f7817822009-09-24 05:11:581008 ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:331009
1010 ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite);
[email protected]bc2ff5192010-06-01 22:05:451011 if (!in_place_site.get() && m_spClientSite != NULL)
[email protected]37346bc2009-09-25 22:54:331012 in_place_site.QueryFrom(m_spClientSite);
[email protected]37346bc2009-09-25 22:54:331013
1014 if (in_place_site)
1015 hr = frame_cmd_target.QueryFrom(in_place_site);
[email protected]f7817822009-09-24 05:11:581016
[email protected]bc2ff5192010-06-01 22:05:451017 if (frame_cmd_target) {
[email protected]f7817822009-09-24 05:11:581018 hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt,
1019 in_args, out_args);
[email protected]bc2ff5192010-06-01 22:05:451020 }
[email protected]f7817822009-09-24 05:11:581021
1022 return hr;
1023}
[email protected]37346bc2009-09-25 22:54:331024
[email protected]c4e45b32010-07-28 21:15:151025bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url,
1026 const std::string& referrer) {
[email protected]d266ce82010-08-13 21:33:401027 DCHECK(!cf_url.gurl().is_empty());
[email protected]77700832010-04-27 00:06:031028
[email protected]242ceb032010-08-26 17:06:361029 if (!automation_client_.get()) {
1030 // http://code.google.com/p/chromium/issues/detail?id=52894
1031 // Still not sure how this happens.
1032 DLOG(ERROR) << "No automation client!";
1033 if (!Initialize()) {
1034 NOTREACHED() << "...and failed to start a new one >:(";
1035 return false;
1036 }
1037 }
1038
[email protected]d266ce82010-08-13 21:33:401039 url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str());
[email protected]c4e45b32010-07-28 21:15:151040 if (cf_url.attach_to_external_tab()) {
1041 dimensions_ = cf_url.dimensions();
1042 automation_client_->AttachExternalTab(cf_url.cookie());
[email protected]7f860dd82010-08-09 23:18:051043 SetWindowDimensions();
[email protected]d266ce82010-08-13 21:33:401044 } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(),
[email protected]6f8f31d2010-07-30 08:17:151045 referrer,
[email protected]354bcba2010-12-14 04:34:431046 this)) {
[email protected]6f8f31d2010-07-30 08:17:151047 DLOG(ERROR) << "Invalid URL: " << url_;
1048 Error(L"Invalid URL");
1049 url_.Reset();
1050 return false;
[email protected]37346bc2009-09-25 22:54:331051 }
1052
[email protected]3eb07da2010-02-01 19:48:361053 if (is_automation_client_reused_)
1054 return true;
[email protected]37346bc2009-09-25 22:54:331055
[email protected]bbfa9a12010-08-10 14:09:371056 automation_client_->SetUrlFetcher(url_fetcher_.get());
[email protected]701142a2010-08-31 20:57:071057 if (launch_params_) {
1058 return automation_client_->Initialize(this, launch_params_);
1059 } else {
[email protected]8103c7f2010-09-08 22:36:091060 std::wstring profile = UTF8ToWide(cf_url.profile_name());
1061 // If no profile was given, then make use of the host process's name.
1062 if (profile.empty())
1063 profile = GetHostProcessName(false);
1064 return InitializeAutomation(profile, L"", IsIEInPrivate(),
[email protected]9eeb35e2010-09-30 21:38:501065 false, cf_url.gurl(), GURL(referrer),
1066 false);
[email protected]701142a2010-08-31 20:57:071067 }
[email protected]37346bc2009-09-25 22:54:331068}
[email protected]1bb5f892009-10-06 01:44:571069
[email protected]355309e2010-03-15 17:01:341070
1071HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1072 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:451073 DVLOG(1) << __FUNCTION__;
[email protected]355309e2010-03-15 17:01:341074 popup_allowed_ = false;
1075 if (in_args->vt == VT_I4 &&
1076 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1077 popup_allowed_ = true;
1078
1079 // Ask the yellow security band to change the text and icon and to remain
1080 // visible.
1081 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
[email protected]bbfa9a12010-08-10 14:09:371082 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
[email protected]355309e2010-03-15 17:01:341083 }
1084
[email protected]3eb8a70492010-12-03 21:32:191085 NavigationManager* mgr = NavigationManager::GetThreadInstance();
1086 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
1087
1088 // If ChromeFrame was activated on this page as a result of a document
1089 // received in response to a top level post, then we ask the user for
1090 // permission to repost and issue a navigation with the saved post data
1091 // which reinitates the whole sequence, i.e. the server receives the top
1092 // level post and chrome frame will be reactivated in response.
1093 if (mgr && mgr->post_data().type() != VT_EMPTY) {
1094 if (MessageBox(
1095 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING).c_str(),
1096 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING_TITLE).c_str(),
1097 MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
1098 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
1099 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1100 web_browser2.Receive());
1101 DCHECK(web_browser2);
1102 VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
1103 VARIANT flags = { VT_I4 };
1104 V_I4(&flags) = navNoHistory;
1105
1106 return web_browser2->Navigate2(base::win::ScopedVariant(url_).AsInput(),
1107 &flags,
1108 &empty,
1109 const_cast<VARIANT*>(&mgr->post_data()),
1110 const_cast<VARIANT*>(&mgr->headers()));
1111 } else {
1112 return S_OK;
1113 }
1114 }
1115
[email protected]355309e2010-03-15 17:01:341116 TabProxy* tab_proxy = GetTabProxy();
[email protected]bbfa9a12010-08-10 14:09:371117 if (tab_proxy) {
[email protected]355309e2010-03-15 17:01:341118 tab_proxy->ReloadAsync();
[email protected]bbfa9a12010-08-10 14:09:371119 } else {
1120 DLOG(ERROR) << "No automation proxy";
[email protected]242ceb032010-08-26 17:06:361121 DCHECK(automation_client_.get() != NULL) << "how did it get freed?";
[email protected]bbfa9a12010-08-10 14:09:371122 // The current url request manager (url_fetcher_) has been switched to
1123 // a stopping state so we need to reset it and get a new one for the new
1124 // automation server.
1125 ResetUrlRequestManager();
1126 url_fetcher_->set_frame_busting(false);
1127 // And now launch the current URL again. This starts a new server process.
1128 DCHECK(navigation_info_.url.is_valid());
1129 ChromeFrameUrl cf_url;
1130 cf_url.Parse(UTF8ToWide(navigation_info_.url.spec()));
1131 LaunchUrl(cf_url, navigation_info_.referrer.spec());
1132 }
[email protected]355309e2010-03-15 17:01:341133
1134 return S_OK;
1135}
1136
[email protected]1bb5f892009-10-06 01:44:571137HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1138 DWORD command_id,
1139 DWORD cmd_exec_opt,
1140 VARIANT* in_args,
1141 VARIANT* out_args) {
1142 if (!automation_client_.get()) {
[email protected]77700832010-04-27 00:06:031143 NOTREACHED() << "Invalid automation client";
[email protected]1bb5f892009-10-06 01:44:571144 return E_FAIL;
1145 }
1146
1147 switch (command_id) {
1148 case IDM_BASELINEFONT1:
1149 automation_client_->SetPageFontSize(SMALLEST_FONT);
1150 break;
1151
1152 case IDM_BASELINEFONT2:
1153 automation_client_->SetPageFontSize(SMALL_FONT);
1154 break;
1155
1156 case IDM_BASELINEFONT3:
1157 automation_client_->SetPageFontSize(MEDIUM_FONT);
1158 break;
1159
1160 case IDM_BASELINEFONT4:
1161 automation_client_->SetPageFontSize(LARGE_FONT);
1162 break;
1163
1164 case IDM_BASELINEFONT5:
1165 automation_client_->SetPageFontSize(LARGEST_FONT);
1166 break;
1167
1168 default:
1169 NOTREACHED() << "Invalid font size command: "
1170 << command_id;
1171 return E_FAIL;
1172 }
1173
1174 // Forward the command back to IEFrame with group set to
1175 // CGID_ExplorerBarDoc. This is probably needed to update the menu state to
1176 // indicate that the font size was set. This currently fails with error
1177 // 0x80040104.
1178 // TODO(iyengar)
1179 // Do some investigation into why this Exec call fails.
1180 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1181 return S_OK;
1182}
1183
[email protected]2f2afba2010-04-01 01:53:191184HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid,
1185 DWORD command_id,
1186 DWORD cmd_exec_opt,
1187 VARIANT* in_args,
1188 VARIANT* out_args) {
1189 const struct EncodingMapData {
1190 DWORD ie_encoding_id;
1191 const char* chrome_encoding_name;
1192 } kEncodingTestDatas[] = {
1193#define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \
1194 { encoding_name, chrome_name },
1195 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP)
1196#undef DEFINE_ENCODING_MAP
1197 };
1198
1199 if (!automation_client_.get()) {
1200 NOTREACHED() << "Invalid automtion client";
1201 return E_FAIL;
1202 }
1203
[email protected]e9b35282010-06-02 16:43:191204 // Using ARRAYSIZE_UNSAFE in here is because we define the struct
1205 // EncodingMapData inside function.
[email protected]2f2afba2010-04-01 01:53:191206 const char* chrome_encoding_name = NULL;
1207 for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
1208 const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i];
1209 if (command_id == encoding_data->ie_encoding_id) {
1210 chrome_encoding_name = encoding_data->chrome_encoding_name;
1211 break;
1212 }
1213 }
1214 // Return E_FAIL when encountering invalid encoding id.
1215 if (!chrome_encoding_name)
1216 return E_FAIL;
1217
1218 TabProxy* tab = GetTabProxy();
1219 if (!tab) {
1220 NOTREACHED() << "Can not get TabProxy";
1221 return E_FAIL;
1222 }
1223
1224 if (chrome_encoding_name)
1225 tab->OverrideEncoding(chrome_encoding_name);
1226
1227 // Like we did on SetPageFontSize, we may forward the command back to IEFrame
1228 // to update the menu state to indicate that which encoding was set.
1229 // TODO(iyengar)
1230 // Do some investigation into why this Exec call fails.
1231 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1232 return S_OK;
1233}
1234
[email protected]f5494d42010-12-23 22:15:341235void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) {
[email protected]2b9a9f162010-10-19 20:30:451236 DVLOG(1) << __FUNCTION__ << " - offset:" << offset;
[email protected]a1800e82009-11-19 00:53:231237
[email protected]f9cc4c452009-10-13 14:56:381238 ScopedComPtr<IBrowserService> browser_service;
[email protected]a1800e82009-11-19 00:53:231239 ScopedComPtr<ITravelLog> travel_log;
1240 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1241 travel_log.Receive());
1242
1243 if (browser_service && travel_log)
1244 travel_log->Travel(browser_service, offset);
1245}
1246
1247HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1248 IBrowserService** browser_service, ITravelLog** travel_log) {
1249 DCHECK(browser_service || travel_log);
1250 ScopedComPtr<IBrowserService> browser_service_local;
1251 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1252 browser_service_local.Receive());
1253 if (!browser_service_local) {
1254 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1255 return hr;
[email protected]f9cc4c452009-10-13 14:56:381256 }
[email protected]a1800e82009-11-19 00:53:231257
1258 if (travel_log) {
1259 hr = browser_service_local->GetTravelLog(travel_log);
[email protected]5044da82010-10-27 01:09:161260 DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr;
[email protected]a1800e82009-11-19 00:53:231261 }
1262
1263 if (browser_service)
1264 *browser_service = browser_service_local.Detach();
1265
1266 return hr;
[email protected]f9cc4c452009-10-13 14:56:381267}
[email protected]a15d4a42010-02-17 08:21:351268
1269LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1270 HWND control_window,
1271 BOOL& bHandled) {
1272 ScopedComPtr<IWebBrowser2> web_browser2;
1273 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1274 DCHECK(web_browser2);
1275
[email protected]bc2ff5192010-06-01 22:05:451276 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351277 web_browser2->GoForward();
[email protected]a15d4a42010-02-17 08:21:351278 return 0;
1279}
1280
1281LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1282 HWND control_window,
1283 BOOL& bHandled) {
1284 ScopedComPtr<IWebBrowser2> web_browser2;
1285 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1286 DCHECK(web_browser2);
1287
[email protected]bc2ff5192010-06-01 22:05:451288 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351289 web_browser2->GoBack();
[email protected]a15d4a42010-02-17 08:21:351290 return 0;
1291}
1292
[email protected]80b5a8d2010-03-19 16:50:431293LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1294 LPARAM lparam,
1295 BOOL& handled) {
1296 if (!m_spClientSite)
1297 return 0;
1298
1299 ScopedComPtr<IWebBrowser2> web_browser2;
1300 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1301 web_browser2.Receive());
1302 if (!web_browser2) {
1303 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1304 return 0;
1305 }
1306
1307 ScopedComPtr<IShellBrowser> shell_browser;
1308 DoQueryService(SID_STopLevelBrowser, web_browser2,
1309 shell_browser.Receive());
1310 DCHECK(shell_browser.get() != NULL);
1311 ScopedComPtr<ITridentService2> trident_services;
1312 trident_services.QueryFrom(shell_browser);
[email protected]bc2ff5192010-06-01 22:05:451313 if (trident_services)
[email protected]80b5a8d2010-03-19 16:50:431314 trident_services->FirePrivacyImpactedStateChange(wparam);
[email protected]bc2ff5192010-06-01 22:05:451315 else
[email protected]80b5a8d2010-03-19 16:50:431316 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
[email protected]80b5a8d2010-03-19 16:50:431317 return 0;
1318}
[email protected]00aebd72010-07-16 14:44:321319
[email protected]723e5442010-07-21 17:36:051320LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam,
1321 LPARAM lparam,
1322 BOOL& handled) { // NO_LINT
1323 if (wparam)
1324 SetFocus();
1325 return 0;
1326}
1327
1328LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam,
1329 LPARAM lparam,
1330 BOOL& handled) { // NO_LINT
[email protected]e7ad9322010-08-02 20:41:291331 if (!ignore_setfocus_)
1332 GiveFocusToChrome(false);
[email protected]723e5442010-07-21 17:36:051333 return 0;
1334}
[email protected]7f860dd82010-08-09 23:18:051335
1336void ChromeActiveDocument::SetWindowDimensions() {
1337 ScopedComPtr<IWebBrowser2> web_browser2;
1338 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1339 web_browser2.Receive());
1340 if (!web_browser2)
1341 return;
[email protected]2b9a9f162010-10-19 20:30:451342 DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions_.width()
1343 << " height:" << dimensions_.height();
[email protected]7f860dd82010-08-09 23:18:051344 if (!dimensions_.IsEmpty()) {
[email protected]73b18972010-11-18 01:35:461345 web_browser2->put_MenuBar(VARIANT_FALSE);
1346 web_browser2->put_ToolBar(VARIANT_FALSE);
1347
1348 int width = dimensions_.width();
1349 int height = dimensions_.height();
1350 // Compute the size of the browser window given the desired size of the
1351 // content area. As per MSDN, the WebBrowser object returns an error from
1352 // this method. As a result the code below is best effort.
1353 if (SUCCEEDED(web_browser2->ClientToWindow(&width, &height))) {
1354 dimensions_.set_width(width);
1355 dimensions_.set_height(height);
1356 }
[email protected]7f860dd82010-08-09 23:18:051357 web_browser2->put_Width(dimensions_.width());
1358 web_browser2->put_Height(dimensions_.height());
1359 web_browser2->put_Left(dimensions_.x());
1360 web_browser2->put_Top(dimensions_.y());
[email protected]7f860dd82010-08-09 23:18:051361
1362 dimensions_.set_height(0);
1363 dimensions_.set_width(0);
1364 }
1365}
[email protected]342de552010-10-21 20:46:141366
1367bool ChromeActiveDocument::IsNewNavigation(
[email protected]747bca12011-01-15 00:28:451368 const NavigationInfo& new_navigation_info, int flags) const {
[email protected]342de552010-10-21 20:46:141369 // A new navigation is typically an internal navigation which is initiated by
1370 // the renderer(WebKit). Condition 1 below has to be true along with the
1371 // any of the other conditions below.
[email protected]747bca12011-01-15 00:28:451372 // 1. The navigation notification flags passed in as the flags parameter
1373 // is not INVALIDATE_LOAD which indicates that the loading state of the
1374 // tab changed.
1375 // 2. The navigation index is greater than 0 which means that a top level
[email protected]342de552010-10-21 20:46:141376 // navigation was initiated on the current external tab.
[email protected]747bca12011-01-15 00:28:451377 // 3. The navigation type has changed.
1378 // 4. The url or the referrer are different.
1379 if (flags == TabContents::INVALIDATE_LOAD)
1380 return false;
1381
[email protected]342de552010-10-21 20:46:141382 if (new_navigation_info.navigation_index <= 0)
1383 return false;
1384
1385 if (new_navigation_info.navigation_index ==
1386 navigation_info_.navigation_index)
1387 return false;
1388
1389 if (new_navigation_info.navigation_type != navigation_info_.navigation_type)
1390 return true;
1391
1392 if (new_navigation_info.url != navigation_info_.url)
1393 return true;
1394
1395 if (new_navigation_info.referrer != navigation_info_.referrer)
1396 return true;
1397
1398 return false;
1399}