blob: 7ee002667c929093ccd605c0b521ea75b4a251a2 [file] [log] [blame]
[email protected]92c79d32011-04-06 18:41:151// Copyright (c) 2011 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/logging.h"
[email protected]f7817822009-09-24 05:11:5823#include "base/string_util.h"
[email protected]252cad62010-08-18 18:33:5724#include "base/utf_string_conversions.h"
[email protected]965722ff2010-10-20 15:50:3025#include "base/win/scoped_variant.h"
[email protected]1a3aba82010-11-08 23:52:5426#include "chrome/app/chrome_command_ids.h"
[email protected]cccd3762010-11-12 18:40:0127#include "chrome/app/chrome_dll_resource.h"
[email protected]a22f7e02011-02-09 07:15:3528#include "chrome/common/automation_messages.h"
[email protected]f7817822009-09-24 05:11:5829#include "chrome/common/chrome_constants.h"
[email protected]f7817822009-09-24 05:11:5830#include "chrome/test/automation/browser_proxy.h"
31#include "chrome/test/automation/tab_proxy.h"
[email protected]b36a9f92009-10-19 17:34:5732#include "chrome_frame/bho.h"
[email protected]29c32f902010-04-20 23:27:2933#include "chrome_frame/bind_context_info.h"
[email protected]5ae94d22010-07-21 19:55:3634#include "chrome_frame/buggy_bho_handling.h"
[email protected]9607f6a82010-06-12 17:24:4135#include "chrome_frame/crash_reporting/crash_metrics.h"
[email protected]f7817822009-09-24 05:11:5836#include "chrome_frame/utils.h"
[email protected]d9083482012-01-06 00:38:4637#include "content/public/browser/invalidate_type.h"
[email protected]dd6f5582012-02-13 22:10:0738#include "content/public/browser/web_contents.h"
[email protected]54087fe2011-10-28 22:02:4839#include "content/public/common/page_zoom.h"
[email protected]8ee65ba2011-04-12 20:53:2340#include "grit/generated_resources.h"
[email protected]f7817822009-09-24 05:11:5841
[email protected]a1800e82009-11-19 00:53:2342DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
43 0x46);
44
[email protected]f7817822009-09-24 05:11:5845bool g_first_launch_by_process_ = true;
46
[email protected]2f2afba2010-04-01 01:53:1947const DWORD kIEEncodingIdArray[] = {
48#define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name,
49 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY)
50#undef DEFINE_ENCODING_ID_ARRAY
51 0 // The Last data must be 0 to indicate the end of the encoding id array.
52};
53
[email protected]f7817822009-09-24 05:11:5854ChromeActiveDocument::ChromeActiveDocument()
[email protected]a22f7e02011-02-09 07:15:3555 : navigation_info_(new NavigationInfo()),
56 first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3557 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3458 popup_allowed_(false),
[email protected]c4e45b32010-07-28 21:15:1559 accelerator_table_(NULL) {
[email protected]366ae242011-05-10 02:23:5860 TRACE_EVENT_BEGIN_ETW("chromeframe.createactivedocument", this, "");
[email protected]04e3f352010-05-10 13:48:2461
[email protected]bbfa9a12010-08-10 14:09:3762 url_fetcher_->set_frame_busting(false);
[email protected]a22f7e02011-02-09 07:15:3563 memset(navigation_info_.get(), 0, sizeof(NavigationInfo));
[email protected]f7817822009-09-24 05:11:5864}
65
66HRESULT ChromeActiveDocument::FinalConstruct() {
[email protected]e67d08172011-08-17 19:22:2167 // The FinalConstruct implementation in the ChromeFrameActivexBase class
68 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
69 // and initializes it, which would spawn a new Chrome process, etc.
70 // We don't want to be doing this if we have a cached document, whose
71 // automation client instance can be reused.
72 HRESULT hr = BaseActiveX::FinalConstruct();
73 if (FAILED(hr))
74 return hr;
[email protected]f7817822009-09-24 05:11:5875
[email protected]e1081d92010-09-10 20:29:1176 InitializeAutomationSettings();
[email protected]8f56e612010-09-09 17:03:1477
[email protected]f7817822009-09-24 05:11:5878 find_dialog_.Init(automation_client_.get());
79
[email protected]6fd1a7a2010-07-26 22:09:4680 OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED);
81
82 null_group_commands_map_[OLECMDID_PRINT] = flags;
83 null_group_commands_map_[OLECMDID_FIND] = flags;
84 null_group_commands_map_[OLECMDID_CUT] = flags;
85 null_group_commands_map_[OLECMDID_COPY] = flags;
86 null_group_commands_map_[OLECMDID_PASTE] = flags;
87 null_group_commands_map_[OLECMDID_SELECTALL] = flags;
88 null_group_commands_map_[OLECMDID_SAVEAS] = flags;
89
90 mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags;
91 mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags;
92 mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags;
93 mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags;
94 mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags;
[email protected]b2529722010-12-01 02:49:0795 mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags;
[email protected]a15d4a42010-02-17 08:21:3596
[email protected]3c6f8e12010-03-24 21:58:2197 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
[email protected]a15d4a42010-02-17 08:21:3598 accelerator_table_ =
[email protected]3c6f8e12010-03-24 21:58:2199 LoadAccelerators(this_module,
[email protected]a15d4a42010-02-17 08:21:35100 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
101 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58102 return S_OK;
103}
104
105ChromeActiveDocument::~ChromeActiveDocument() {
[email protected]2b9a9f162010-10-19 20:30:45106 DVLOG(1) << __FUNCTION__;
[email protected]bc2ff5192010-06-01 22:05:45107 if (find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58108 find_dialog_.DestroyWindow();
[email protected]3eb07da2010-02-01 19:48:36109 // ChromeFramePlugin
[email protected]97965e12010-04-09 00:51:10110 BaseActiveX::Uninitialize();
[email protected]04e3f352010-05-10 13:48:24111
[email protected]366ae242011-05-10 02:23:58112 TRACE_EVENT_END_ETW("chromeframe.createactivedocument", this, "");
[email protected]f7817822009-09-24 05:11:58113}
114
115// Override DoVerb
116STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
117 LPMSG msg,
118 IOleClientSite* active_site,
119 LONG index,
120 HWND parent_window,
121 LPCRECT pos) {
122 // IE will try and in-place activate us in some cases. This happens when
123 // the user opens a new IE window with a URL that has us as the DocObject.
124 // Here we refuse to be activated in-place and we will force IE to UIActivate
125 // us.
[email protected]bc2ff5192010-06-01 22:05:45126 if (OLEIVERB_INPLACEACTIVATE == verb)
[email protected]23b33612010-11-09 23:47:01127 return OLEOBJ_E_INVALIDVERB;
[email protected]f7817822009-09-24 05:11:58128 // Check if we should activate as a docobject or not
129 // (client supports IOleDocumentSite)
130 if (doc_site_) {
131 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57132 case OLEIVERB_SHOW: {
[email protected]8ee65ba2011-04-12 20:53:23133 base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]1bb5f892009-10-06 01:44:57134 doc_host_handler.QueryFrom(doc_site_);
[email protected]bc2ff5192010-06-01 22:05:45135 if (doc_host_handler.get())
[email protected]1bb5f892009-10-06 01:44:57136 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
[email protected]1bb5f892009-10-06 01:44:57137 }
[email protected]f7817822009-09-24 05:11:58138 case OLEIVERB_OPEN:
139 case OLEIVERB_UIACTIVATE:
[email protected]bc2ff5192010-06-01 22:05:45140 if (!m_bUIActive)
[email protected]f7817822009-09-24 05:11:58141 return doc_site_->ActivateMe(NULL);
[email protected]f7817822009-09-24 05:11:58142 break;
143 }
144 }
145 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
146 msg,
147 active_site,
148 index,
149 parent_window,
150 pos);
151}
152
[email protected]f7817822009-09-24 05:11:58153// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
154STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
[email protected]2b9a9f162010-10-19 20:30:45155 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58156 return S_OK;
157}
158
159STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
[email protected]2b9a9f162010-10-19 20:30:45160 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58161 if (msg == NULL)
162 return E_POINTER;
163
164 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
165 HWND focus = ::GetFocus();
166 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
167 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
168 // set focus to the correct element in Chrome.
169 ::SetFocus(m_hWnd);
170 return S_OK;
171 }
172 }
173
174 return S_FALSE;
175}
176// Override IPersistStorageImpl::IsDirty
177STDMETHODIMP ChromeActiveDocument::IsDirty() {
[email protected]2b9a9f162010-10-19 20:30:45178 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58179 return S_FALSE;
180}
181
[email protected]b95f550f2009-11-19 05:35:22182void ChromeActiveDocument::OnAutomationServerReady() {
[email protected]97965e12010-04-09 00:51:10183 BaseActiveX::OnAutomationServerReady();
[email protected]1fd45692010-04-19 21:01:18184 BaseActiveX::GiveFocusToChrome(true);
[email protected]b95f550f2009-11-19 05:35:22185}
186
[email protected]f7817822009-09-24 05:11:58187STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
188 IMoniker* moniker_name,
189 LPBC bind_context,
190 DWORD mode) {
[email protected]bc2ff5192010-06-01 22:05:45191 if (NULL == moniker_name)
[email protected]f7817822009-09-24 05:11:58192 return E_INVALIDARG;
[email protected]a1800e82009-11-19 00:53:23193
[email protected]8ee65ba2011-04-12 20:53:23194 base::win::ScopedComPtr<IOleClientSite> client_site;
[email protected]a1800e82009-11-19 00:53:23195 if (bind_context) {
[email protected]8ee65ba2011-04-12 20:53:23196 base::win::ScopedComPtr<IUnknown> site;
[email protected]a1800e82009-11-19 00:53:23197 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
198 site.Receive());
199 if (site)
200 client_site.QueryFrom(site);
201 }
202
203 if (client_site) {
204 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11205 DoQueryService(IID_INewWindowManager, client_site,
206 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14207
208 // See if mshtml parsed the html header for us. If so, we need to
209 // clear the browser service flag that we use to indicate that this
210 // browser instance is navigating to a CF document.
[email protected]8ee65ba2011-04-12 20:53:23211 base::win::ScopedComPtr<IBrowserService> browser_service;
[email protected]051236f2010-03-12 22:06:14212 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
213 if (browser_service) {
214 bool flagged = CheckForCFNavigation(browser_service, true);
[email protected]5044da82010-10-27 01:09:16215 DVLOG_IF(1, flagged) << "Cleared flagged browser service";
[email protected]051236f2010-03-12 22:06:14216 }
[email protected]a1800e82009-11-19 00:53:23217 }
218
[email protected]051236f2010-03-12 22:06:14219 NavigationManager* mgr = NavigationManager::GetThreadInstance();
[email protected]21b4e6d2010-07-14 18:19:59220 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
[email protected]7e3544b2010-01-22 00:02:34221
[email protected]29c32f902010-04-20 23:27:29222 std::wstring url;
223
[email protected]8ee65ba2011-04-12 20:53:23224 base::win::ScopedComPtr<BindContextInfo> info;
[email protected]77d7aee2010-05-14 20:31:55225 BindContextInfo::FromBindContext(bind_context, info.Receive());
[email protected]29c32f902010-04-20 23:27:29226 DCHECK(info);
[email protected]4f45d4582011-02-22 23:27:27227 if (info && !info->GetUrl().empty()) {
228 url = info->GetUrl();
[email protected]df0846a52011-02-23 03:29:58229 if (mgr) {
230 // If the original URL contains an anchor, then the URL queried
231 // from the protocol sink wrapper does not contain the anchor. To
232 // workaround this we retrieve the anchor from the navigation manager
233 // and append it to the url retrieved from the protocol sink wrapper.
234 GURL url_for_anchor(mgr->url());
235 if (url_for_anchor.has_ref()) {
236 url += L"#";
237 url += UTF8ToWide(url_for_anchor.ref());
238 }
239 }
[email protected]29c32f902010-04-20 23:27:29240 } else {
241 // If the original URL contains an anchor, then the URL queried
242 // from the moniker does not contain the anchor. To workaround
243 // this we retrieve the URL from our BHO.
244 url = GetActualUrlFromMoniker(moniker_name, bind_context,
245 mgr ? mgr->url(): std::wstring());
246 }
[email protected]051236f2010-03-12 22:06:14247
[email protected]c4e45b32010-07-28 21:15:15248 ChromeFrameUrl cf_url;
249 if (!cf_url.Parse(url)) {
[email protected]37346bc2009-09-25 22:54:33250 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58251 return E_INVALIDARG;
252 }
253
[email protected]bbfa9a12010-08-10 14:09:37254 std::string referrer(mgr ? mgr->referrer() : EmptyString());
[email protected]d8e13512010-09-22 17:02:58255 RendererType renderer_type = cf_url.is_chrome_protocol() ?
256 RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED;
[email protected]bbfa9a12010-08-10 14:09:37257
[email protected]aaf124502010-07-17 04:02:58258 // With CTransaction patch we have more robust way to grab the referrer for
259 // each top-level-switch-to-CF request by peeking at our sniffing data
[email protected]d8e13512010-09-22 17:02:58260 // object that lives inside the bind context. We also remember the reason
261 // we're rendering the document in Chrome.
[email protected]aaf124502010-07-17 04:02:58262 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
263 scoped_refptr<ProtData> prot_data = info->get_prot_data();
[email protected]d8e13512010-09-22 17:02:58264 if (prot_data) {
[email protected]aaf124502010-07-17 04:02:58265 referrer = prot_data->referrer();
[email protected]d8e13512010-09-22 17:02:58266 renderer_type = prot_data->renderer_type();
267 }
[email protected]aaf124502010-07-17 04:02:58268 }
269
[email protected]62ce09732010-09-03 18:32:04270 // For gcf: URLs allow only about and view-source schemes to pass through for
271 // further inspection.
272 bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) ||
273 cf_url.gurl().SchemeIs(chrome::kViewSourceScheme);
274 if (cf_url.is_chrome_protocol() && !is_safe_scheme &&
275 !GetConfigBool(false, kAllowUnsafeURLs)) {
276 DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url;
277 return E_INVALIDARG;
278 }
279
[email protected]c4e45b32010-07-28 21:15:15280 if (!LaunchUrl(cf_url, referrer)) {
[email protected]d266ce82010-08-13 21:33:40281 DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url;
[email protected]37346bc2009-09-25 22:54:33282 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58283 }
284
[email protected]c4e45b32010-07-28 21:15:15285 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
[email protected]d266ce82010-08-13 21:33:40286 url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context);
[email protected]f7817822009-09-24 05:11:58287
[email protected]d8e13512010-09-22 17:02:58288 // Log a metric indicating why GCF is rendering in Chrome.
289 // (Note: we only track the renderer type when using the CTransaction patch.
290 // When the code for the browser service patch and for the moniker patch is
291 // removed, this conditional can also go away.)
292 if (RENDERER_TYPE_UNDETERMINED != renderer_type) {
[email protected]92c79d32011-04-06 18:41:15293 UMA_LAUNCH_TYPE_COUNT(renderer_type);
[email protected]d8e13512010-09-22 17:02:58294 }
295
[email protected]f7817822009-09-24 05:11:58296 return S_OK;
297}
298
299STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
300 LPBC bind_context,
301 BOOL remember) {
302 return E_NOTIMPL;
303}
304
305STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
306 LPBC bind_context) {
307 return E_NOTIMPL;
308}
309
310STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
311 return E_NOTIMPL;
312}
313
314STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
[email protected]bc2ff5192010-06-01 22:05:45315 if (NULL == class_id)
[email protected]f7817822009-09-24 05:11:58316 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58317 *class_id = GetObjectCLSID();
318 return S_OK;
319}
320
321STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
322 ULONG number_of_commands,
323 OLECMD commands[],
324 OLECMDTEXT* command_text) {
[email protected]2b9a9f162010-10-19 20:30:45325 DVLOG(1) << __FUNCTION__;
[email protected]b509ec82010-04-13 16:53:06326
[email protected]6fd1a7a2010-07-26 22:09:46327 CommandStatusMap* command_map = NULL;
[email protected]b509ec82010-04-13 16:53:06328
[email protected]6fd1a7a2010-07-26 22:09:46329 if (cmd_group_guid) {
330 if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) {
331 command_map = &null_group_commands_map_;
332 } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) {
333 command_map = &mshtml_group_commands_map_;
334 } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) {
335 command_map = &explorer_group_commands_map_;
336 } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) {
337 command_map = &shdoc_view_group_commands_map_;
338 }
339 } else {
340 command_map = &null_group_commands_map_;
341 }
342
343 if (!command_map) {
[email protected]2b9a9f162010-10-19 20:30:45344 DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid);
[email protected]b509ec82010-04-13 16:53:06345 return OLECMDERR_E_NOTSUPPORTED;
346 }
347
[email protected]f7817822009-09-24 05:11:58348 for (ULONG command_index = 0; command_index < number_of_commands;
349 command_index++) {
[email protected]2b9a9f162010-10-19 20:30:45350 DVLOG(1) << "Command id = " << commands[command_index].cmdID;
[email protected]6fd1a7a2010-07-26 22:09:46351 CommandStatusMap::iterator index =
352 command_map->find(commands[command_index].cmdID);
353 if (index != command_map->end())
354 commands[command_index].cmdf = index->second;
[email protected]f7817822009-09-24 05:11:58355 }
356 return S_OK;
357}
358
359STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
360 DWORD command_id,
361 DWORD cmd_exec_opt,
362 VARIANT* in_args,
363 VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:45364 DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id;
[email protected]f7817822009-09-24 05:11:58365 // Bail out if we have been uninitialized.
366 if (automation_client_.get() && automation_client_->tab()) {
367 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
368 in_args, out_args);
[email protected]bbfa9a12010-08-10 14:09:37369 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
370 // If the automation server has crashed and the user is refreshing the
371 // page, let OnRefreshPage attempt to recover.
372 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
[email protected]f7817822009-09-24 05:11:58373 }
[email protected]bbfa9a12010-08-10 14:09:37374
[email protected]e3200932009-10-09 21:33:03375 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58376}
377
[email protected]a1800e82009-11-19 00:53:23378STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
379 IBindCtx* bind_context) {
380 // Read notes in ChromeActiveDocument::SaveHistory
381 DCHECK(stream);
382 LARGE_INTEGER offset = {0};
383 ULARGE_INTEGER cur_pos = {0};
384 STATSTG statstg = {0};
385
386 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
387 stream->Stat(&statstg, STATFLAG_NONAME);
388
389 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
[email protected]965722ff2010-10-20 15:50:30390 base::win::ScopedBstr url_bstr;
[email protected]a1800e82009-11-19 00:53:23391 DWORD bytes_read = 0;
392 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
393 std::wstring url(url_bstr);
394
[email protected]c4e45b32010-07-28 21:15:15395 ChromeFrameUrl cf_url;
396 if (!cf_url.Parse(url)) {
[email protected]a1800e82009-11-19 00:53:23397 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
398 return E_INVALIDARG;
399 }
400
[email protected]c5cbf4e2010-07-15 21:48:25401 const std::string& referrer = EmptyString();
[email protected]c4e45b32010-07-28 21:15:15402 if (!LaunchUrl(cf_url, referrer)) {
[email protected]a1800e82009-11-19 00:53:23403 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
404 return E_INVALIDARG;
405 }
406 return S_OK;
407}
408
409STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
410 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
411 // from Chrome and persist it in the stream. And in LoadHistory we need to
412 // pass this list back to Chrome which will recreate the list. This will allow
413 // Back-Forward navigation to anchors to work correctly when we navigate to a
414 // page outside of ChromeFrame and then come back.
415 if (!stream) {
416 NOTREACHED();
417 return E_INVALIDARG;
418 }
419
420 LARGE_INTEGER offset = {0};
421 ULARGE_INTEGER new_pos = {0};
422 DWORD written = 0;
[email protected]a22f7e02011-02-09 07:15:35423 std::wstring url = UTF8ToWide(navigation_info_->url.spec());
[email protected]a1800e82009-11-19 00:53:23424 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
425 &written);
426}
427
428STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
[email protected]77700832010-04-27 00:06:03429 if (automation_client_.get()) {
430 int index = static_cast<int>(position_cookie);
[email protected]a22f7e02011-02-09 07:15:35431 navigation_info_->navigation_index = index;
[email protected]77700832010-04-27 00:06:03432 automation_client_->NavigateToIndex(index);
433 } else {
434 DLOG(WARNING) << "Invalid automation client instance";
435 }
[email protected]a1800e82009-11-19 00:53:23436 return S_OK;
437}
438
439STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
440 if (!position_cookie)
441 return E_INVALIDARG;
442
[email protected]a22f7e02011-02-09 07:15:35443 *position_cookie = navigation_info_->navigation_index;
[email protected]a1800e82009-11-19 00:53:23444 return S_OK;
445}
446
[email protected]f7817822009-09-24 05:11:58447STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
[email protected]bc2ff5192010-06-01 22:05:45448 if (NULL == url)
[email protected]f7817822009-09-24 05:11:58449 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58450 *url = ::SysAllocString(url_);
451 return S_OK;
452}
453
[email protected]a1800e82009-11-19 00:53:23454STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
455 return GetUrlForEvents(url);
456}
457
[email protected]80b5a8d2010-03-19 16:50:43458STDMETHODIMP ChromeActiveDocument::Reset() {
459 next_privacy_record_ = privacy_info_.privacy_records.begin();
460 return S_OK;
461}
462
[email protected]00aebd72010-07-16 14:44:32463STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) {
[email protected]80b5a8d2010-03-19 16:50:43464 if (!size)
465 return E_POINTER;
466
467 *size = privacy_info_.privacy_records.size();
468 return S_OK;
469}
470
471STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
472 if (!privacy_impacted)
473 return E_POINTER;
474
475 *privacy_impacted = privacy_info_.privacy_impacted;
476 return S_OK;
477}
478
479STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
[email protected]00aebd72010-07-16 14:44:32480 LONG* reserved, DWORD* flags) {
[email protected]80b5a8d2010-03-19 16:50:43481 if (!url || !policy || !flags)
482 return E_POINTER;
483
484 if (next_privacy_record_ == privacy_info_.privacy_records.end())
485 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
486
487 *url = SysAllocString(next_privacy_record_->first.c_str());
488 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
489 *flags = next_privacy_record_->second.flags;
490
491 next_privacy_record_++;
492 return S_OK;
493}
494
[email protected]354bcba2010-12-14 04:34:43495bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) {
496 bool allowed = BaseActiveX::IsSchemeAllowed(url);
497 if (allowed)
498 return true;
499
500 if (url.SchemeIs(chrome::kAboutScheme)) {
501 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL))
502 return true;
503 }
504 return false;
505}
506
[email protected]3eafbfb92010-08-02 16:54:22507HRESULT ChromeActiveDocument::GetInPlaceFrame(
508 IOleInPlaceFrame** in_place_frame) {
509 DCHECK(in_place_frame);
510 if (in_place_frame_) {
511 *in_place_frame = in_place_frame_.get();
512 (*in_place_frame)->AddRef();
513 return S_OK;
514 } else {
515 return S_FALSE;
516 }
517}
518
[email protected]f7817822009-09-24 05:11:58519HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
520 IOleClientSite* client_site) {
521 if (client_site == NULL) {
[email protected]8ee65ba2011-04-12 20:53:23522 base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]bc2ff5192010-06-01 22:05:45523 if (doc_site_)
[email protected]77059f72010-02-28 06:16:00524 doc_host_handler.QueryFrom(doc_site_);
[email protected]dda7d9c2009-11-11 23:01:47525
[email protected]bc2ff5192010-06-01 22:05:45526 if (doc_host_handler.get())
[email protected]dda7d9c2009-11-11 23:01:47527 doc_host_handler->HideUI();
[email protected]dda7d9c2009-11-11 23:01:47528
529 doc_site_.Release();
[email protected]f7817822009-09-24 05:11:58530 }
[email protected]a1800e82009-11-19 00:53:23531
[email protected]bc2ff5192010-06-01 22:05:45532 if (client_site != m_spClientSite)
[email protected]97965e12010-04-09 00:51:10533 return BaseActiveX::IOleObject_SetClientSite(client_site);
[email protected]a1800e82009-11-19 00:53:23534
535 return S_OK;
[email protected]f7817822009-09-24 05:11:58536}
537
[email protected]f7817822009-09-24 05:11:58538HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
539 HRESULT hr = S_OK;
540 m_bNegotiatedWnd = TRUE;
541 if (!m_bInPlaceActive) {
542 hr = m_spInPlaceSite->CanInPlaceActivate();
[email protected]bc2ff5192010-06-01 22:05:45543 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58544 return hr;
[email protected]f7817822009-09-24 05:11:58545 m_spInPlaceSite->OnInPlaceActivate();
546 }
547 m_bInPlaceActive = TRUE;
548 // get location in the parent window,
549 // as well as some information about the parent
[email protected]8ee65ba2011-04-12 20:53:23550 base::win::ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
[email protected]f7817822009-09-24 05:11:58551 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
552 HWND parent_window = NULL;
553 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
554 in_place_frame_.Release();
555 RECT position_rect = {0};
556 RECT clip_rect = {0};
557 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
558 in_place_ui_window.Receive(),
559 &position_rect,
560 &clip_rect,
561 &frame_info_);
562 if (!m_bWndLess) {
563 if (IsWindow()) {
564 ::ShowWindow(m_hWnd, SW_SHOW);
565 SetFocus();
566 } else {
[email protected]fca446b92011-02-18 20:44:06567 m_hWnd = Create(parent_window, position_rect);
[email protected]dd4beb522010-07-13 18:18:14568 if (!IsWindow()) {
569 // This might happen if the automation server couldn't be
570 // instantiated. If so, a NOTREACHED() will have already been hit.
571 DLOG(ERROR) << "Failed to create Ax window";
572 return AtlHresultFromLastError();
573 }
[email protected]f7817822009-09-24 05:11:58574 }
575 }
576 SetObjectRects(&position_rect, &clip_rect);
577 }
578
[email protected]8ee65ba2011-04-12 20:53:23579 base::win::ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
[email protected]f7817822009-09-24 05:11:58580
581 // Gone active by now, take care of UIACTIVATE
582 if (DoesVerbUIActivate(verb)) {
583 if (!m_bUIActive) {
584 m_bUIActive = TRUE;
585 hr = m_spInPlaceSite->OnUIActivate();
[email protected]bc2ff5192010-06-01 22:05:45586 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58587 return hr;
[email protected]f7817822009-09-24 05:11:58588 // set ourselves up in the host
589 if (in_place_active_object) {
[email protected]bc2ff5192010-06-01 22:05:45590 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58591 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
[email protected]bc2ff5192010-06-01 22:05:45592 if (in_place_ui_window)
[email protected]f7817822009-09-24 05:11:58593 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
[email protected]f7817822009-09-24 05:11:58594 }
595 }
596 }
597 m_spClientSite->ShowObject();
598 return S_OK;
599}
600
[email protected]f5494d42010-12-23 22:15:34601void ChromeActiveDocument::OnNavigationStateChanged(
602 int flags, const NavigationInfo& nav_info) {
[email protected]d9083482012-01-06 00:38:46603 // TODO(joshia): handle INVALIDATE_TYPE_TAB,INVALIDATE_TYPE_LOAD etc.
[email protected]2b9a9f162010-10-19 20:30:45604 DVLOG(1) << __FUNCTION__
605 << "\n Flags: " << flags
606 << ", Url: " << nav_info.url
607 << ", Title: " << nav_info.title
608 << ", Type: " << nav_info.navigation_type
609 << ", Relative Offset: " << nav_info.relative_offset
610 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58611
[email protected]747bca12011-01-15 00:28:45612 UpdateNavigationState(nav_info, flags);
[email protected]f7817822009-09-24 05:11:58613}
614
[email protected]f5494d42010-12-23 22:15:34615void ChromeActiveDocument::OnUpdateTargetUrl(
[email protected]f7817822009-09-24 05:11:58616 const std::wstring& new_target_url) {
[email protected]bc2ff5192010-06-01 22:05:45617 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58618 in_place_frame_->SetStatusText(new_target_url.c_str());
[email protected]f7817822009-09-24 05:11:58619}
620
621bool IsFindAccelerator(const MSG& msg) {
622 // TODO(robertshield): This may not stand up to localization. Fix if this
623 // is the case.
624 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
[email protected]a8e20582010-12-31 17:18:50625 base::win::IsCtrlPressed() &&
626 !(base::win::IsAltPressed() || base::win::IsShiftPressed());
[email protected]f7817822009-09-24 05:11:58627}
628
[email protected]f5494d42010-12-23 22:15:34629void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35630 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
631 const_cast<MSG*>(&accel_message)))
632 return;
633
[email protected]f7817822009-09-24 05:11:58634 bool handled_accel = false;
635 if (in_place_frame_ != NULL) {
636 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
637 const_cast<MSG*>(&accel_message), 0));
638 }
639
640 if (!handled_accel) {
641 if (IsFindAccelerator(accel_message)) {
642 // Handle the showing of the find dialog explicitly.
643 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59644 } else {
[email protected]f5494d42010-12-23 22:15:34645 BaseActiveX::OnAcceleratorPressed(accel_message);
[email protected]f7817822009-09-24 05:11:58646 }
647 } else {
[email protected]2b9a9f162010-10-19 20:30:45648 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
[email protected]f7817822009-09-24 05:11:58649 }
650}
651
[email protected]f5494d42010-12-23 22:15:34652void ChromeActiveDocument::OnTabbedOut(bool reverse) {
[email protected]2b9a9f162010-10-19 20:30:45653 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58654 if (in_place_frame_) {
655 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
656 in_place_frame_->TranslateAcceleratorW(&msg, 0);
657 }
658}
659
[email protected]f5494d42010-12-23 22:15:34660void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
[email protected]2b9a9f162010-10-19 20:30:45661 DVLOG(1) << __FUNCTION__ << std::endl
662 << "Url: " << nav_info.url
663 << ", Title: " << nav_info.title
664 << ", Type: " << nav_info.navigation_type
665 << ", Relative Offset: " << nav_info.relative_offset
666 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58667
[email protected]897b26272010-06-11 02:23:44668 CrashMetricsReporter::GetInstance()->IncrementMetric(
669 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
670
[email protected]747bca12011-01-15 00:28:45671 UpdateNavigationState(nav_info, 0);
[email protected]f7817822009-09-24 05:11:58672}
673
[email protected]f5494d42010-12-23 22:15:34674void ChromeActiveDocument::OnCloseTab() {
[email protected]2f1793ea2010-10-27 17:32:51675 // Base class will fire DIChromeFrameEvents::onclose.
[email protected]f5494d42010-12-23 22:15:34676 BaseActiveX::OnCloseTab();
[email protected]2f1793ea2010-10-27 17:32:51677
678 // Close the container window.
[email protected]8ee65ba2011-04-12 20:53:23679 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]e16dd1672010-06-07 21:40:29680 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
681 if (web_browser2)
682 web_browser2->Quit();
683}
684
[email protected]f7817822009-09-24 05:11:58685void ChromeActiveDocument::UpdateNavigationState(
[email protected]747bca12011-01-15 00:28:45686 const NavigationInfo& new_navigation_info, int flags) {
[email protected]326d3b72011-03-29 20:38:24687 // This could be NULL if the active document instance is being destroyed.
688 if (!m_spInPlaceSite) {
689 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
690 return;
691 }
692
[email protected]a1800e82009-11-19 00:53:23693 HRESULT hr = S_OK;
[email protected]a22f7e02011-02-09 07:15:35694 bool is_title_changed =
695 (navigation_info_->title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58696 bool is_ssl_state_changed =
[email protected]a22f7e02011-02-09 07:15:35697 (navigation_info_->security_style !=
698 new_navigation_info.security_style) ||
699 (navigation_info_->displayed_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48700 new_navigation_info.displayed_insecure_content) ||
[email protected]a22f7e02011-02-09 07:15:35701 (navigation_info_->ran_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48702 new_navigation_info.ran_insecure_content);
[email protected]f7817822009-09-24 05:11:58703
[email protected]f7817822009-09-24 05:11:58704 if (is_ssl_state_changed) {
705 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23706 switch (new_navigation_info.security_style) {
[email protected]cfa79d762011-10-21 00:15:04707 case content::SECURITY_STYLE_AUTHENTICATED:
[email protected]b4e75c12010-05-18 18:28:48708 lock_status = new_navigation_info.displayed_insecure_content ?
[email protected]f7817822009-09-24 05:11:58709 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
710 break;
711 default:
712 break;
713 }
714
[email protected]965722ff2010-10-20 15:50:30715 base::win::ScopedVariant secure_lock_status(lock_status);
[email protected]f7817822009-09-24 05:11:58716 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
717 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
718 }
719
[email protected]a17930d82011-02-11 23:12:35720 // A number of poorly written bho's crash in their event sink callbacks if
721 // chrome frame is the currently loaded document. This is because they expect
722 // chrome frame to implement interfaces like IHTMLDocument, etc. We patch the
723 // event sink's of these bho's and don't invoke the event sink if chrome
724 // frame is the currently loaded document.
725 if (GetConfigBool(true, kEnableBuggyBhoIntercept)) {
[email protected]8ee65ba2011-04-12 20:53:23726 base::win::ScopedComPtr<IWebBrowser2> wb2;
[email protected]a17930d82011-02-11 23:12:35727 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
728 if (wb2 && buggy_bho::BuggyBhoTls::GetInstance()) {
729 buggy_bho::BuggyBhoTls::GetInstance()->PatchBuggyBHOs(wb2);
730 }
731 }
732
[email protected]a1800e82009-11-19 00:53:23733 // Ideally all navigations should come to Chrome Frame so that we can call
734 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
735 // navigation. However, in practice what happens is as below:
736 // The very first navigation that happens in CF happens via a Load or a
737 // LoadHistory call. In this case, IE already has the correct information for
738 // its travel log as well address bar. For other internal navigations (navs
739 // that only happen within Chrome such as anchor navigations) we need to
740 // update IE's internal state after the fact. In the case of internal
741 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58742
743 // Another case where we need to issue BeforeNavigate2 calls is as below:-
744 // We get notified after the fact, when navigations are initiated within
745 // Chrome via window.open calls. These navigations are handled by creating
746 // an external tab container within chrome and then connecting to it from IE.
747 // We still want to update the address bar/history, etc, to ensure that
748 // the special URL used by Chrome to indicate this is updated correctly.
[email protected]d266ce82010-08-13 21:33:40749 ChromeFrameUrl cf_url;
750 bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) &&
751 cf_url.attach_to_external_tab();
[email protected]342de552010-10-21 20:46:14752
753 bool is_internal_navigation =
[email protected]747bca12011-01-15 00:28:45754 IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url;
[email protected]f7817822009-09-24 05:11:58755
[email protected]bc2ff5192010-06-01 22:05:45756 if (new_navigation_info.url.is_valid())
[email protected]38939de2010-05-13 02:32:06757 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]38939de2010-05-13 02:32:06758
[email protected]a1800e82009-11-19 00:53:23759 if (is_internal_navigation) {
[email protected]74b1eaf542011-10-05 19:34:27760 // IE6 does not support tabs. If Chrome sent us a window open request
761 // indicating that the navigation needs to occur in a foreground tab or
762 // a popup window, then we need to ensure that the new window in IE6 is
763 // brought to the foreground.
764 if (GetIEVersion() == IE_6 &&
765 is_attach_external_tab_url &&
766 (cf_url.disposition() == NEW_FOREGROUND_TAB ||
767 cf_url.disposition() == NEW_POPUP)) {
768 base::win::ScopedComPtr<IWebBrowser2> wb2;
769 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
770 if (wb2)
771 BaseActiveX::BringWebBrowserWindowToTop(wb2);
772 }
[email protected]8ee65ba2011-04-12 20:53:23773 base::win::ScopedComPtr<IDocObjectService> doc_object_svc;
774 base::win::ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06775
[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.
[email protected]a22f7e02011-02-09 07:15:35837 *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() {
[email protected]a22f7e02011-02-09 07:15:35855 DCHECK(navigation_info_->url.is_valid());
[email protected]76e7da22010-06-18 22:44:49856 HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") +
[email protected]a22f7e02011-02-09 07:15:35857 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) {
[email protected]54087fe2011-10-28 22:02:48900 automation_client_->SetZoomLevel(content::PAGE_ZOOM_IN);
[email protected]7f860dd82010-08-09 23:18:05901 } else if (in_args->lVal == kZoomOut) {
[email protected]54087fe2011-10-28 22:02:48902 automation_client_->SetZoomLevel(content::PAGE_ZOOM_OUT);
[email protected]7f860dd82010-08-09 23:18:05903 } 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) {
[email protected]9ae7b912011-06-30 21:41:25915 // If the navigation is attempted to the url loaded in CF, with the only
916 // difference being the addition of an anchor, IE will attempt to unload
917 // the currently loaded document which basically would end up running
918 // unload handlers on the currently loaded document thus rendering it non
919 // functional. We handle this as below:-
920 // The BHO receives the new url in the BeforeNavigate event.
921 // We compare the non anchor portions of the url in the BHO with the loaded
922 // url and if they match, we initiate a Chrome navigation to the url with
923 // the anchor which works nicely.
924 // We don't want to continue processing the unload in this case.
925 // Note:-
926 // IE handles these navigations by querying the loaded document for
927 // IHTMLDocument which then handles the new navigation. That won't work for
928 // us as we don't implement IHTMLDocument.
929 NavigationManager* mgr = NavigationManager::GetThreadInstance();
930 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
931 if (mgr) {
932 ChromeFrameUrl url;
933 url.Parse(mgr->url());
934 if (url.gurl().has_ref()) {
935 url_canon::Replacements<char> replacements;
936 replacements.ClearRef();
937
938 if (url.gurl().ReplaceComponents(replacements) ==
939 GURL(static_cast<BSTR>(url_))) {
940 // We want to reuse the existing automation client and channel for
941 // initiating the new navigation. Setting the
942 // is_automation_client_reused_ flag to true before calling the
943 // LaunchUrl function achieves that.
944 is_automation_client_reused_ = true;
945 LaunchUrl(url, mgr->referrer());
946 out_args->vt = VT_BOOL;
947 out_args->boolVal = VARIANT_FALSE;
948 return;
949 }
950 }
951 }
[email protected]d9d8f0c2010-09-17 21:47:16952 bool should_unload = true;
953 automation_client_->OnUnload(&should_unload);
954 out_args->vt = VT_BOOL;
955 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
956 }
957}
958
[email protected]f5494d42010-12-23 22:15:34959void ChromeActiveDocument::OnAttachExternalTab(
960 const AttachExternalTabParams& params) {
[email protected]77700832010-04-27 00:06:03961 if (!automation_client_.get()) {
962 DLOG(WARNING) << "Invalid automation client instance";
963 return;
964 }
[email protected]b1c55638612010-03-08 16:26:11965 DWORD flags = 0;
966 if (params.user_gesture)
967 flags = NWMF_USERREQUESTED;
[email protected]355309e2010-03-15 17:01:34968 else if (popup_allowed_)
969 flags = NWMF_USERALLOWED;
[email protected]b1c55638612010-03-08 16:26:11970
971 HRESULT hr = S_OK;
972 if (popup_manager_) {
[email protected]e4456ae2010-09-22 23:35:11973 const std::wstring& url_wide = UTF8ToWide(params.url.spec());
974 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_,
[email protected]355309e2010-03-15 17:01:34975 NULL, FALSE, flags, 0);
[email protected]b1c55638612010-03-08 16:26:11976 }
977 // Allow popup
978 if (hr == S_OK) {
[email protected]f5494d42010-12-23 22:15:34979 BaseActiveX::OnAttachExternalTab(params);
[email protected]b1c55638612010-03-08 16:26:11980 return;
981 }
982
983 automation_client_->BlockExternalTab(params.cookie);
984}
985
[email protected]f7817822009-09-24 05:11:58986bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
[email protected]8ee65ba2011-04-12 20:53:23987 base::win::ScopedComPtr<IBrowserService> browser_service;
988 base::win::ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:23989 GetBrowserServiceAndTravelLog(browser_service.Receive(),
990 travel_log.Receive());
991 if (!browser_service || !travel_log)
[email protected]f7817822009-09-24 05:11:58992 return true;
993
[email protected]d118f542010-11-05 18:50:31994 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND |
995 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK,
996 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45997 MF_ENABLED : MF_DISABLED));
[email protected]d118f542010-11-05 18:50:31998 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND |
999 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE,
1000 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:451001 MF_ENABLED : MF_DISABLED));
[email protected]f7817822009-09-24 05:11:581002 // Call base class (adds 'About' item)
[email protected]97965e12010-04-09 00:51:101003 return BaseActiveX::PreProcessContextMenu(menu);
[email protected]f7817822009-09-24 05:11:581004}
1005
[email protected]f5494d42010-12-23 22:15:341006bool ChromeActiveDocument::HandleContextMenuCommand(
1007 UINT cmd, const MiniContextMenuParams& params) {
[email protected]8ee65ba2011-04-12 20:53:231008 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]f7817822009-09-24 05:11:581009 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1010
[email protected]074283a2010-05-28 23:47:591011 if (cmd == IDC_BACK)
[email protected]b731a142010-05-14 00:03:031012 web_browser2->GoBack();
[email protected]074283a2010-05-28 23:47:591013 else if (cmd == IDC_FORWARD)
[email protected]b731a142010-05-14 00:03:031014 web_browser2->GoForward();
[email protected]074283a2010-05-28 23:47:591015 else if (cmd == IDC_RELOAD)
[email protected]b731a142010-05-14 00:03:031016 web_browser2->Refresh();
[email protected]074283a2010-05-28 23:47:591017 else
[email protected]b731a142010-05-14 00:03:031018 return BaseActiveX::HandleContextMenuCommand(cmd, params);
[email protected]f7817822009-09-24 05:11:581019
1020 return true;
1021}
1022
1023HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid,
1024 DWORD command_id, DWORD cmd_exec_opt,
1025 VARIANT* in_args, VARIANT* out_args) {
1026 HRESULT hr = E_FAIL;
[email protected]37346bc2009-09-25 22:54:331027
[email protected]8ee65ba2011-04-12 20:53:231028 base::win::ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:331029
[email protected]8ee65ba2011-04-12 20:53:231030 base::win::ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite);
[email protected]bc2ff5192010-06-01 22:05:451031 if (!in_place_site.get() && m_spClientSite != NULL)
[email protected]37346bc2009-09-25 22:54:331032 in_place_site.QueryFrom(m_spClientSite);
[email protected]37346bc2009-09-25 22:54:331033
1034 if (in_place_site)
1035 hr = frame_cmd_target.QueryFrom(in_place_site);
[email protected]f7817822009-09-24 05:11:581036
[email protected]bc2ff5192010-06-01 22:05:451037 if (frame_cmd_target) {
[email protected]f7817822009-09-24 05:11:581038 hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt,
1039 in_args, out_args);
[email protected]bc2ff5192010-06-01 22:05:451040 }
[email protected]f7817822009-09-24 05:11:581041
1042 return hr;
1043}
[email protected]37346bc2009-09-25 22:54:331044
[email protected]c4e45b32010-07-28 21:15:151045bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url,
1046 const std::string& referrer) {
[email protected]d266ce82010-08-13 21:33:401047 DCHECK(!cf_url.gurl().is_empty());
[email protected]77700832010-04-27 00:06:031048
[email protected]242ceb032010-08-26 17:06:361049 if (!automation_client_.get()) {
1050 // http://code.google.com/p/chromium/issues/detail?id=52894
1051 // Still not sure how this happens.
1052 DLOG(ERROR) << "No automation client!";
1053 if (!Initialize()) {
1054 NOTREACHED() << "...and failed to start a new one >:(";
1055 return false;
1056 }
1057 }
1058
[email protected]93b792792011-06-07 23:00:011059 document_url_ = cf_url.gurl().spec();
1060
[email protected]d266ce82010-08-13 21:33:401061 url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str());
[email protected]c4e45b32010-07-28 21:15:151062 if (cf_url.attach_to_external_tab()) {
[email protected]c4e45b32010-07-28 21:15:151063 automation_client_->AttachExternalTab(cf_url.cookie());
[email protected]326d3b72011-03-29 20:38:241064 OnMoveWindow(cf_url.dimensions());
[email protected]d266ce82010-08-13 21:33:401065 } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(),
[email protected]6f8f31d2010-07-30 08:17:151066 referrer,
[email protected]354bcba2010-12-14 04:34:431067 this)) {
[email protected]6f8f31d2010-07-30 08:17:151068 DLOG(ERROR) << "Invalid URL: " << url_;
1069 Error(L"Invalid URL");
1070 url_.Reset();
1071 return false;
[email protected]37346bc2009-09-25 22:54:331072 }
1073
[email protected]3eb07da2010-02-01 19:48:361074 if (is_automation_client_reused_)
1075 return true;
[email protected]37346bc2009-09-25 22:54:331076
[email protected]bbfa9a12010-08-10 14:09:371077 automation_client_->SetUrlFetcher(url_fetcher_.get());
[email protected]701142a2010-08-31 20:57:071078 if (launch_params_) {
1079 return automation_client_->Initialize(this, launch_params_);
1080 } else {
[email protected]8103c7f2010-09-08 22:36:091081 std::wstring profile = UTF8ToWide(cf_url.profile_name());
1082 // If no profile was given, then make use of the host process's name.
1083 if (profile.empty())
1084 profile = GetHostProcessName(false);
[email protected]c70e5582011-12-20 21:22:451085 return InitializeAutomation(profile, IsIEInPrivate(),
[email protected]9eeb35e2010-09-30 21:38:501086 false, cf_url.gurl(), GURL(referrer),
1087 false);
[email protected]701142a2010-08-31 20:57:071088 }
[email protected]37346bc2009-09-25 22:54:331089}
[email protected]1bb5f892009-10-06 01:44:571090
[email protected]355309e2010-03-15 17:01:341091HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1092 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:451093 DVLOG(1) << __FUNCTION__;
[email protected]355309e2010-03-15 17:01:341094 popup_allowed_ = false;
1095 if (in_args->vt == VT_I4 &&
1096 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1097 popup_allowed_ = true;
1098
1099 // Ask the yellow security band to change the text and icon and to remain
1100 // visible.
1101 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
[email protected]bbfa9a12010-08-10 14:09:371102 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
[email protected]355309e2010-03-15 17:01:341103 }
1104
[email protected]3eb8a70492010-12-03 21:32:191105 NavigationManager* mgr = NavigationManager::GetThreadInstance();
1106 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
1107
1108 // If ChromeFrame was activated on this page as a result of a document
1109 // received in response to a top level post, then we ask the user for
1110 // permission to repost and issue a navigation with the saved post data
1111 // which reinitates the whole sequence, i.e. the server receives the top
1112 // level post and chrome frame will be reactivated in response.
1113 if (mgr && mgr->post_data().type() != VT_EMPTY) {
1114 if (MessageBox(
1115 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING).c_str(),
1116 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING_TITLE).c_str(),
1117 MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
1118 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
1119 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1120 web_browser2.Receive());
1121 DCHECK(web_browser2);
1122 VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
1123 VARIANT flags = { VT_I4 };
1124 V_I4(&flags) = navNoHistory;
1125
1126 return web_browser2->Navigate2(base::win::ScopedVariant(url_).AsInput(),
1127 &flags,
1128 &empty,
1129 const_cast<VARIANT*>(&mgr->post_data()),
1130 const_cast<VARIANT*>(&mgr->headers()));
1131 } else {
1132 return S_OK;
1133 }
1134 }
1135
[email protected]355309e2010-03-15 17:01:341136 TabProxy* tab_proxy = GetTabProxy();
[email protected]bbfa9a12010-08-10 14:09:371137 if (tab_proxy) {
[email protected]355309e2010-03-15 17:01:341138 tab_proxy->ReloadAsync();
[email protected]bbfa9a12010-08-10 14:09:371139 } else {
1140 DLOG(ERROR) << "No automation proxy";
[email protected]242ceb032010-08-26 17:06:361141 DCHECK(automation_client_.get() != NULL) << "how did it get freed?";
[email protected]bbfa9a12010-08-10 14:09:371142 // The current url request manager (url_fetcher_) has been switched to
1143 // a stopping state so we need to reset it and get a new one for the new
1144 // automation server.
1145 ResetUrlRequestManager();
1146 url_fetcher_->set_frame_busting(false);
1147 // And now launch the current URL again. This starts a new server process.
[email protected]a22f7e02011-02-09 07:15:351148 DCHECK(navigation_info_->url.is_valid());
[email protected]bbfa9a12010-08-10 14:09:371149 ChromeFrameUrl cf_url;
[email protected]a22f7e02011-02-09 07:15:351150 cf_url.Parse(UTF8ToWide(navigation_info_->url.spec()));
1151 LaunchUrl(cf_url, navigation_info_->referrer.spec());
[email protected]bbfa9a12010-08-10 14:09:371152 }
[email protected]355309e2010-03-15 17:01:341153
1154 return S_OK;
1155}
1156
[email protected]1bb5f892009-10-06 01:44:571157HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1158 DWORD command_id,
1159 DWORD cmd_exec_opt,
1160 VARIANT* in_args,
1161 VARIANT* out_args) {
1162 if (!automation_client_.get()) {
[email protected]77700832010-04-27 00:06:031163 NOTREACHED() << "Invalid automation client";
[email protected]1bb5f892009-10-06 01:44:571164 return E_FAIL;
1165 }
1166
1167 switch (command_id) {
1168 case IDM_BASELINEFONT1:
1169 automation_client_->SetPageFontSize(SMALLEST_FONT);
1170 break;
1171
1172 case IDM_BASELINEFONT2:
1173 automation_client_->SetPageFontSize(SMALL_FONT);
1174 break;
1175
1176 case IDM_BASELINEFONT3:
1177 automation_client_->SetPageFontSize(MEDIUM_FONT);
1178 break;
1179
1180 case IDM_BASELINEFONT4:
1181 automation_client_->SetPageFontSize(LARGE_FONT);
1182 break;
1183
1184 case IDM_BASELINEFONT5:
1185 automation_client_->SetPageFontSize(LARGEST_FONT);
1186 break;
1187
1188 default:
1189 NOTREACHED() << "Invalid font size command: "
1190 << command_id;
1191 return E_FAIL;
1192 }
1193
1194 // Forward the command back to IEFrame with group set to
1195 // CGID_ExplorerBarDoc. This is probably needed to update the menu state to
1196 // indicate that the font size was set. This currently fails with error
1197 // 0x80040104.
1198 // TODO(iyengar)
1199 // Do some investigation into why this Exec call fails.
1200 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1201 return S_OK;
1202}
1203
[email protected]2f2afba2010-04-01 01:53:191204HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid,
1205 DWORD command_id,
1206 DWORD cmd_exec_opt,
1207 VARIANT* in_args,
1208 VARIANT* out_args) {
1209 const struct EncodingMapData {
1210 DWORD ie_encoding_id;
1211 const char* chrome_encoding_name;
1212 } kEncodingTestDatas[] = {
1213#define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \
1214 { encoding_name, chrome_name },
1215 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP)
1216#undef DEFINE_ENCODING_MAP
1217 };
1218
1219 if (!automation_client_.get()) {
1220 NOTREACHED() << "Invalid automtion client";
1221 return E_FAIL;
1222 }
1223
[email protected]e9b35282010-06-02 16:43:191224 // Using ARRAYSIZE_UNSAFE in here is because we define the struct
1225 // EncodingMapData inside function.
[email protected]2f2afba2010-04-01 01:53:191226 const char* chrome_encoding_name = NULL;
1227 for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
1228 const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i];
1229 if (command_id == encoding_data->ie_encoding_id) {
1230 chrome_encoding_name = encoding_data->chrome_encoding_name;
1231 break;
1232 }
1233 }
1234 // Return E_FAIL when encountering invalid encoding id.
1235 if (!chrome_encoding_name)
1236 return E_FAIL;
1237
1238 TabProxy* tab = GetTabProxy();
1239 if (!tab) {
1240 NOTREACHED() << "Can not get TabProxy";
1241 return E_FAIL;
1242 }
1243
1244 if (chrome_encoding_name)
1245 tab->OverrideEncoding(chrome_encoding_name);
1246
1247 // Like we did on SetPageFontSize, we may forward the command back to IEFrame
1248 // to update the menu state to indicate that which encoding was set.
1249 // TODO(iyengar)
1250 // Do some investigation into why this Exec call fails.
1251 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1252 return S_OK;
1253}
1254
[email protected]f5494d42010-12-23 22:15:341255void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) {
[email protected]2b9a9f162010-10-19 20:30:451256 DVLOG(1) << __FUNCTION__ << " - offset:" << offset;
[email protected]a1800e82009-11-19 00:53:231257
[email protected]8ee65ba2011-04-12 20:53:231258 base::win::ScopedComPtr<IBrowserService> browser_service;
1259 base::win::ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:231260 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1261 travel_log.Receive());
1262
1263 if (browser_service && travel_log)
1264 travel_log->Travel(browser_service, offset);
1265}
1266
[email protected]326d3b72011-03-29 20:38:241267void ChromeActiveDocument::OnMoveWindow(const gfx::Rect& dimensions) {
[email protected]8ee65ba2011-04-12 20:53:231268 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]326d3b72011-03-29 20:38:241269 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1270 web_browser2.Receive());
1271 if (!web_browser2)
1272 return;
1273 DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions.width()
1274 << " height:" << dimensions.height();
1275 if (!dimensions.IsEmpty()) {
1276 web_browser2->put_MenuBar(VARIANT_FALSE);
1277 web_browser2->put_ToolBar(VARIANT_FALSE);
1278
1279 int width = dimensions.width();
1280 int height = dimensions.height();
1281 // Compute the size of the browser window given the desired size of the
1282 // content area. As per MSDN, the WebBrowser object returns an error from
1283 // this method. As a result the code below is best effort.
1284 web_browser2->ClientToWindow(&width, &height);
1285
1286 web_browser2->put_Width(width);
1287 web_browser2->put_Height(height);
1288 web_browser2->put_Left(dimensions.x());
1289 web_browser2->put_Top(dimensions.y());
1290 }
1291}
1292
[email protected]a1800e82009-11-19 00:53:231293HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1294 IBrowserService** browser_service, ITravelLog** travel_log) {
1295 DCHECK(browser_service || travel_log);
[email protected]8ee65ba2011-04-12 20:53:231296 base::win::ScopedComPtr<IBrowserService> browser_service_local;
[email protected]a1800e82009-11-19 00:53:231297 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1298 browser_service_local.Receive());
1299 if (!browser_service_local) {
1300 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1301 return hr;
[email protected]f9cc4c452009-10-13 14:56:381302 }
[email protected]a1800e82009-11-19 00:53:231303
1304 if (travel_log) {
1305 hr = browser_service_local->GetTravelLog(travel_log);
[email protected]5044da82010-10-27 01:09:161306 DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr;
[email protected]a1800e82009-11-19 00:53:231307 }
1308
1309 if (browser_service)
1310 *browser_service = browser_service_local.Detach();
1311
1312 return hr;
[email protected]f9cc4c452009-10-13 14:56:381313}
[email protected]a15d4a42010-02-17 08:21:351314
1315LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1316 HWND control_window,
1317 BOOL& bHandled) {
[email protected]8ee65ba2011-04-12 20:53:231318 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]a15d4a42010-02-17 08:21:351319 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1320 DCHECK(web_browser2);
1321
[email protected]bc2ff5192010-06-01 22:05:451322 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351323 web_browser2->GoForward();
[email protected]a15d4a42010-02-17 08:21:351324 return 0;
1325}
1326
1327LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1328 HWND control_window,
1329 BOOL& bHandled) {
[email protected]8ee65ba2011-04-12 20:53:231330 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]a15d4a42010-02-17 08:21:351331 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1332 DCHECK(web_browser2);
1333
[email protected]bc2ff5192010-06-01 22:05:451334 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351335 web_browser2->GoBack();
[email protected]a15d4a42010-02-17 08:21:351336 return 0;
1337}
1338
[email protected]80b5a8d2010-03-19 16:50:431339LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1340 LPARAM lparam,
1341 BOOL& handled) {
1342 if (!m_spClientSite)
1343 return 0;
1344
[email protected]8ee65ba2011-04-12 20:53:231345 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]80b5a8d2010-03-19 16:50:431346 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1347 web_browser2.Receive());
1348 if (!web_browser2) {
1349 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1350 return 0;
1351 }
1352
[email protected]8ee65ba2011-04-12 20:53:231353 base::win::ScopedComPtr<IShellBrowser> shell_browser;
[email protected]80b5a8d2010-03-19 16:50:431354 DoQueryService(SID_STopLevelBrowser, web_browser2,
1355 shell_browser.Receive());
1356 DCHECK(shell_browser.get() != NULL);
[email protected]8ee65ba2011-04-12 20:53:231357 base::win::ScopedComPtr<ITridentService2> trident_services;
[email protected]80b5a8d2010-03-19 16:50:431358 trident_services.QueryFrom(shell_browser);
[email protected]bc2ff5192010-06-01 22:05:451359 if (trident_services)
[email protected]80b5a8d2010-03-19 16:50:431360 trident_services->FirePrivacyImpactedStateChange(wparam);
[email protected]bc2ff5192010-06-01 22:05:451361 else
[email protected]80b5a8d2010-03-19 16:50:431362 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
[email protected]80b5a8d2010-03-19 16:50:431363 return 0;
1364}
[email protected]00aebd72010-07-16 14:44:321365
[email protected]723e5442010-07-21 17:36:051366LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam,
1367 LPARAM lparam,
1368 BOOL& handled) { // NO_LINT
1369 if (wparam)
1370 SetFocus();
1371 return 0;
1372}
1373
1374LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam,
1375 LPARAM lparam,
1376 BOOL& handled) { // NO_LINT
[email protected]e7ad9322010-08-02 20:41:291377 if (!ignore_setfocus_)
1378 GiveFocusToChrome(false);
[email protected]723e5442010-07-21 17:36:051379 return 0;
1380}
[email protected]7f860dd82010-08-09 23:18:051381
[email protected]342de552010-10-21 20:46:141382bool ChromeActiveDocument::IsNewNavigation(
[email protected]747bca12011-01-15 00:28:451383 const NavigationInfo& new_navigation_info, int flags) const {
[email protected]342de552010-10-21 20:46:141384 // A new navigation is typically an internal navigation which is initiated by
1385 // the renderer(WebKit). Condition 1 below has to be true along with the
1386 // any of the other conditions below.
[email protected]747bca12011-01-15 00:28:451387 // 1. The navigation notification flags passed in as the flags parameter
[email protected]d9083482012-01-06 00:38:461388 // is not INVALIDATE_TYPE_LOAD which indicates that the loading state of
1389 // the tab changed.
[email protected]747bca12011-01-15 00:28:451390 // 2. The navigation index is greater than 0 which means that a top level
[email protected]342de552010-10-21 20:46:141391 // navigation was initiated on the current external tab.
[email protected]747bca12011-01-15 00:28:451392 // 3. The navigation type has changed.
1393 // 4. The url or the referrer are different.
[email protected]d9083482012-01-06 00:38:461394 if (flags == content::INVALIDATE_TYPE_LOAD)
[email protected]747bca12011-01-15 00:28:451395 return false;
1396
[email protected]342de552010-10-21 20:46:141397 if (new_navigation_info.navigation_index <= 0)
1398 return false;
1399
1400 if (new_navigation_info.navigation_index ==
[email protected]a22f7e02011-02-09 07:15:351401 navigation_info_->navigation_index)
[email protected]342de552010-10-21 20:46:141402 return false;
1403
[email protected]a22f7e02011-02-09 07:15:351404 if (new_navigation_info.navigation_type != navigation_info_->navigation_type)
[email protected]342de552010-10-21 20:46:141405 return true;
1406
[email protected]a22f7e02011-02-09 07:15:351407 if (new_navigation_info.url != navigation_info_->url)
[email protected]342de552010-10-21 20:46:141408 return true;
1409
[email protected]a22f7e02011-02-09 07:15:351410 if (new_navigation_info.referrer != navigation_info_->referrer)
[email protected]342de552010-10-21 20:46:141411 return true;
1412
1413 return false;
1414}