blob: b7267977b46b0bcc5e26fa038f2bf0bbfcea937c [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"
28#include "base/thread.h"
29#include "base/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]f7817822009-09-24 05:11:5832#include "grit/generated_resources.h"
[email protected]1a3aba82010-11-08 23:52:5433#include "chrome/app/chrome_command_ids.h"
[email protected]cccd3762010-11-12 18:40:0134#include "chrome/app/chrome_dll_resource.h"
[email protected]f7817822009-09-24 05:11:5835#include "chrome/common/chrome_constants.h"
36#include "chrome/common/navigation_types.h"
[email protected]7f860dd82010-08-09 23:18:0537#include "chrome/common/page_zoom.h"
[email protected]f7817822009-09-24 05:11:5838#include "chrome/test/automation/browser_proxy.h"
39#include "chrome/test/automation/tab_proxy.h"
[email protected]b36a9f92009-10-19 17:34:5740#include "chrome_frame/bho.h"
[email protected]29c32f902010-04-20 23:27:2941#include "chrome_frame/bind_context_info.h"
[email protected]5ae94d22010-07-21 19:55:3642#include "chrome_frame/buggy_bho_handling.h"
[email protected]9607f6a82010-06-12 17:24:4143#include "chrome_frame/crash_reporting/crash_metrics.h"
[email protected]f7817822009-09-24 05:11:5844#include "chrome_frame/utils.h"
45
[email protected]a1800e82009-11-19 00:53:2346DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
47 0x46);
48
[email protected]f7817822009-09-24 05:11:5849base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache;
50
51bool g_first_launch_by_process_ = true;
52
[email protected]2f2afba2010-04-01 01:53:1953const DWORD kIEEncodingIdArray[] = {
54#define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name,
55 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY)
56#undef DEFINE_ENCODING_ID_ARRAY
57 0 // The Last data must be 0 to indicate the end of the encoding id array.
58};
59
[email protected]f7817822009-09-24 05:11:5860ChromeActiveDocument::ChromeActiveDocument()
61 : first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3562 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3463 popup_allowed_(false),
[email protected]c4e45b32010-07-28 21:15:1564 accelerator_table_(NULL) {
[email protected]04e3f352010-05-10 13:48:2465 TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, "");
66
[email protected]bbfa9a12010-08-10 14:09:3767 url_fetcher_->set_frame_busting(false);
[email protected]a1800e82009-11-19 00:53:2368 memset(&navigation_info_, 0, sizeof(navigation_info_));
[email protected]f7817822009-09-24 05:11:5869}
70
71HRESULT ChromeActiveDocument::FinalConstruct() {
72 // If we have a cached ChromeActiveDocument instance in TLS, then grab
73 // ownership of the cached document's automation client. This is an
74 // optimization to get Chrome active documents to load faster.
75 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
[email protected]58174a72010-05-05 21:30:3076 if (cached_document && cached_document->IsValid()) {
[email protected]3eb8a70492010-12-03 21:32:1977 SetResourceModule();
[email protected]f7817822009-09-24 05:11:5878 DCHECK(automation_client_.get() == NULL);
[email protected]3148c0ae2010-03-11 18:06:0079 automation_client_.swap(cached_document->automation_client_);
[email protected]2b9a9f162010-10-19 20:30:4580 DVLOG(1) << "Reusing automation client instance from " << cached_document;
[email protected]f7817822009-09-24 05:11:5881 DCHECK(automation_client_.get() != NULL);
[email protected]bbfa9a12010-08-10 14:09:3782 automation_client_->Reinitialize(this, url_fetcher_.get());
[email protected]f7817822009-09-24 05:11:5883 is_automation_client_reused_ = true;
[email protected]b5811052010-08-21 01:37:2984 OnAutomationServerReady();
[email protected]f7817822009-09-24 05:11:5885 } else {
86 // The FinalConstruct implementation in the ChromeFrameActivexBase class
87 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
88 // and initializes it, which would spawn a new Chrome process, etc.
89 // We don't want to be doing this if we have a cached document, whose
90 // automation client instance can be reused.
[email protected]97965e12010-04-09 00:51:1091 HRESULT hr = BaseActiveX::FinalConstruct();
[email protected]f7817822009-09-24 05:11:5892 if (FAILED(hr))
93 return hr;
94 }
95
[email protected]e1081d92010-09-10 20:29:1196 InitializeAutomationSettings();
[email protected]8f56e612010-09-09 17:03:1497
[email protected]f7817822009-09-24 05:11:5898 find_dialog_.Init(automation_client_.get());
99
[email protected]6fd1a7a2010-07-26 22:09:46100 OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED);
101
102 null_group_commands_map_[OLECMDID_PRINT] = flags;
103 null_group_commands_map_[OLECMDID_FIND] = flags;
104 null_group_commands_map_[OLECMDID_CUT] = flags;
105 null_group_commands_map_[OLECMDID_COPY] = flags;
106 null_group_commands_map_[OLECMDID_PASTE] = flags;
107 null_group_commands_map_[OLECMDID_SELECTALL] = flags;
108 null_group_commands_map_[OLECMDID_SAVEAS] = flags;
109
110 mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags;
111 mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags;
112 mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags;
113 mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags;
114 mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags;
[email protected]b2529722010-12-01 02:49:07115 mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags;
[email protected]a15d4a42010-02-17 08:21:35116
[email protected]3c6f8e12010-03-24 21:58:21117 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
[email protected]a15d4a42010-02-17 08:21:35118 accelerator_table_ =
[email protected]3c6f8e12010-03-24 21:58:21119 LoadAccelerators(this_module,
[email protected]a15d4a42010-02-17 08:21:35120 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
121 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58122 return S_OK;
123}
124
125ChromeActiveDocument::~ChromeActiveDocument() {
[email protected]2b9a9f162010-10-19 20:30:45126 DVLOG(1) << __FUNCTION__;
[email protected]bc2ff5192010-06-01 22:05:45127 if (find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58128 find_dialog_.DestroyWindow();
[email protected]3eb07da2010-02-01 19:48:36129 // ChromeFramePlugin
[email protected]97965e12010-04-09 00:51:10130 BaseActiveX::Uninitialize();
[email protected]04e3f352010-05-10 13:48:24131
132 TRACE_EVENT_END("chromeframe.createactivedocument", this, "");
[email protected]f7817822009-09-24 05:11:58133}
134
135// Override DoVerb
136STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
137 LPMSG msg,
138 IOleClientSite* active_site,
139 LONG index,
140 HWND parent_window,
141 LPCRECT pos) {
142 // IE will try and in-place activate us in some cases. This happens when
143 // the user opens a new IE window with a URL that has us as the DocObject.
144 // Here we refuse to be activated in-place and we will force IE to UIActivate
145 // us.
[email protected]bc2ff5192010-06-01 22:05:45146 if (OLEIVERB_INPLACEACTIVATE == verb)
[email protected]23b33612010-11-09 23:47:01147 return OLEOBJ_E_INVALIDVERB;
[email protected]f7817822009-09-24 05:11:58148 // Check if we should activate as a docobject or not
149 // (client supports IOleDocumentSite)
150 if (doc_site_) {
151 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57152 case OLEIVERB_SHOW: {
153 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
154 doc_host_handler.QueryFrom(doc_site_);
[email protected]bc2ff5192010-06-01 22:05:45155 if (doc_host_handler.get())
[email protected]1bb5f892009-10-06 01:44:57156 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
[email protected]1bb5f892009-10-06 01:44:57157 }
[email protected]f7817822009-09-24 05:11:58158 case OLEIVERB_OPEN:
159 case OLEIVERB_UIACTIVATE:
[email protected]bc2ff5192010-06-01 22:05:45160 if (!m_bUIActive)
[email protected]f7817822009-09-24 05:11:58161 return doc_site_->ActivateMe(NULL);
[email protected]f7817822009-09-24 05:11:58162 break;
163 }
164 }
165 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
166 msg,
167 active_site,
168 index,
169 parent_window,
170 pos);
171}
172
[email protected]f7817822009-09-24 05:11:58173// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
174STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
[email protected]2b9a9f162010-10-19 20:30:45175 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58176 return S_OK;
177}
178
179STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
[email protected]2b9a9f162010-10-19 20:30:45180 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58181 if (msg == NULL)
182 return E_POINTER;
183
184 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
185 HWND focus = ::GetFocus();
186 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
187 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
188 // set focus to the correct element in Chrome.
189 ::SetFocus(m_hWnd);
190 return S_OK;
191 }
192 }
193
194 return S_FALSE;
195}
196// Override IPersistStorageImpl::IsDirty
197STDMETHODIMP ChromeActiveDocument::IsDirty() {
[email protected]2b9a9f162010-10-19 20:30:45198 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58199 return S_FALSE;
200}
201
[email protected]b95f550f2009-11-19 05:35:22202void ChromeActiveDocument::OnAutomationServerReady() {
[email protected]97965e12010-04-09 00:51:10203 BaseActiveX::OnAutomationServerReady();
[email protected]1fd45692010-04-19 21:01:18204 BaseActiveX::GiveFocusToChrome(true);
[email protected]b95f550f2009-11-19 05:35:22205}
206
[email protected]f7817822009-09-24 05:11:58207STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
208 IMoniker* moniker_name,
209 LPBC bind_context,
210 DWORD mode) {
[email protected]bc2ff5192010-06-01 22:05:45211 if (NULL == moniker_name)
[email protected]f7817822009-09-24 05:11:58212 return E_INVALIDARG;
[email protected]a1800e82009-11-19 00:53:23213
214 ScopedComPtr<IOleClientSite> client_site;
215 if (bind_context) {
216 ScopedComPtr<IUnknown> site;
217 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
218 site.Receive());
219 if (site)
220 client_site.QueryFrom(site);
221 }
222
223 if (client_site) {
224 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11225 DoQueryService(IID_INewWindowManager, client_site,
226 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14227
228 // See if mshtml parsed the html header for us. If so, we need to
229 // clear the browser service flag that we use to indicate that this
230 // browser instance is navigating to a CF document.
231 ScopedComPtr<IBrowserService> browser_service;
232 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
233 if (browser_service) {
234 bool flagged = CheckForCFNavigation(browser_service, true);
[email protected]5044da82010-10-27 01:09:16235 DVLOG_IF(1, flagged) << "Cleared flagged browser service";
[email protected]051236f2010-03-12 22:06:14236 }
[email protected]a1800e82009-11-19 00:53:23237 }
238
[email protected]051236f2010-03-12 22:06:14239 NavigationManager* mgr = NavigationManager::GetThreadInstance();
[email protected]21b4e6d2010-07-14 18:19:59240 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
[email protected]7e3544b2010-01-22 00:02:34241
[email protected]29c32f902010-04-20 23:27:29242 std::wstring url;
243
[email protected]77d7aee2010-05-14 20:31:55244 ScopedComPtr<BindContextInfo> info;
245 BindContextInfo::FromBindContext(bind_context, info.Receive());
[email protected]29c32f902010-04-20 23:27:29246 DCHECK(info);
247 if (info && !info->url().empty()) {
248 url = info->url();
249 } else {
250 // If the original URL contains an anchor, then the URL queried
251 // from the moniker does not contain the anchor. To workaround
252 // this we retrieve the URL from our BHO.
253 url = GetActualUrlFromMoniker(moniker_name, bind_context,
254 mgr ? mgr->url(): std::wstring());
255 }
[email protected]051236f2010-03-12 22:06:14256
[email protected]c4e45b32010-07-28 21:15:15257 ChromeFrameUrl cf_url;
258 if (!cf_url.Parse(url)) {
[email protected]37346bc2009-09-25 22:54:33259 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58260 return E_INVALIDARG;
261 }
262
[email protected]bbfa9a12010-08-10 14:09:37263 std::string referrer(mgr ? mgr->referrer() : EmptyString());
[email protected]d8e13512010-09-22 17:02:58264 RendererType renderer_type = cf_url.is_chrome_protocol() ?
265 RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED;
[email protected]bbfa9a12010-08-10 14:09:37266
[email protected]aaf124502010-07-17 04:02:58267 // With CTransaction patch we have more robust way to grab the referrer for
268 // each top-level-switch-to-CF request by peeking at our sniffing data
[email protected]d8e13512010-09-22 17:02:58269 // object that lives inside the bind context. We also remember the reason
270 // we're rendering the document in Chrome.
[email protected]aaf124502010-07-17 04:02:58271 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
272 scoped_refptr<ProtData> prot_data = info->get_prot_data();
[email protected]d8e13512010-09-22 17:02:58273 if (prot_data) {
[email protected]aaf124502010-07-17 04:02:58274 referrer = prot_data->referrer();
[email protected]d8e13512010-09-22 17:02:58275 renderer_type = prot_data->renderer_type();
276 }
[email protected]aaf124502010-07-17 04:02:58277 }
278
[email protected]62ce09732010-09-03 18:32:04279 // For gcf: URLs allow only about and view-source schemes to pass through for
280 // further inspection.
281 bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) ||
282 cf_url.gurl().SchemeIs(chrome::kViewSourceScheme);
283 if (cf_url.is_chrome_protocol() && !is_safe_scheme &&
284 !GetConfigBool(false, kAllowUnsafeURLs)) {
285 DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url;
286 return E_INVALIDARG;
287 }
288
[email protected]c4e45b32010-07-28 21:15:15289 if (!LaunchUrl(cf_url, referrer)) {
[email protected]d266ce82010-08-13 21:33:40290 DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url;
[email protected]37346bc2009-09-25 22:54:33291 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58292 }
293
[email protected]c4e45b32010-07-28 21:15:15294 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
[email protected]d266ce82010-08-13 21:33:40295 url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context);
[email protected]f7817822009-09-24 05:11:58296
[email protected]d8e13512010-09-22 17:02:58297 // Log a metric indicating why GCF is rendering in Chrome.
298 // (Note: we only track the renderer type when using the CTransaction patch.
299 // When the code for the browser service patch and for the moniker patch is
300 // removed, this conditional can also go away.)
301 if (RENDERER_TYPE_UNDETERMINED != renderer_type) {
302 THREAD_SAFE_UMA_LAUNCH_TYPE_COUNT(renderer_type);
303 }
304
[email protected]f7817822009-09-24 05:11:58305 return S_OK;
306}
307
308STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
309 LPBC bind_context,
310 BOOL remember) {
311 return E_NOTIMPL;
312}
313
314STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
315 LPBC bind_context) {
316 return E_NOTIMPL;
317}
318
319STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
320 return E_NOTIMPL;
321}
322
323STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
[email protected]bc2ff5192010-06-01 22:05:45324 if (NULL == class_id)
[email protected]f7817822009-09-24 05:11:58325 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58326 *class_id = GetObjectCLSID();
327 return S_OK;
328}
329
330STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
331 ULONG number_of_commands,
332 OLECMD commands[],
333 OLECMDTEXT* command_text) {
[email protected]2b9a9f162010-10-19 20:30:45334 DVLOG(1) << __FUNCTION__;
[email protected]b509ec82010-04-13 16:53:06335
[email protected]6fd1a7a2010-07-26 22:09:46336 CommandStatusMap* command_map = NULL;
[email protected]b509ec82010-04-13 16:53:06337
[email protected]6fd1a7a2010-07-26 22:09:46338 if (cmd_group_guid) {
339 if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) {
340 command_map = &null_group_commands_map_;
341 } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) {
342 command_map = &mshtml_group_commands_map_;
343 } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) {
344 command_map = &explorer_group_commands_map_;
345 } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) {
346 command_map = &shdoc_view_group_commands_map_;
347 }
348 } else {
349 command_map = &null_group_commands_map_;
350 }
351
352 if (!command_map) {
[email protected]2b9a9f162010-10-19 20:30:45353 DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid);
[email protected]b509ec82010-04-13 16:53:06354 return OLECMDERR_E_NOTSUPPORTED;
355 }
356
[email protected]f7817822009-09-24 05:11:58357 for (ULONG command_index = 0; command_index < number_of_commands;
358 command_index++) {
[email protected]2b9a9f162010-10-19 20:30:45359 DVLOG(1) << "Command id = " << commands[command_index].cmdID;
[email protected]6fd1a7a2010-07-26 22:09:46360 CommandStatusMap::iterator index =
361 command_map->find(commands[command_index].cmdID);
362 if (index != command_map->end())
363 commands[command_index].cmdf = index->second;
[email protected]f7817822009-09-24 05:11:58364 }
365 return S_OK;
366}
367
368STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
369 DWORD command_id,
370 DWORD cmd_exec_opt,
371 VARIANT* in_args,
372 VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:45373 DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id;
[email protected]f7817822009-09-24 05:11:58374 // Bail out if we have been uninitialized.
375 if (automation_client_.get() && automation_client_->tab()) {
376 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
377 in_args, out_args);
[email protected]bbfa9a12010-08-10 14:09:37378 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
379 // If the automation server has crashed and the user is refreshing the
380 // page, let OnRefreshPage attempt to recover.
381 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
[email protected]f7817822009-09-24 05:11:58382 }
[email protected]bbfa9a12010-08-10 14:09:37383
[email protected]e3200932009-10-09 21:33:03384 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58385}
386
[email protected]a1800e82009-11-19 00:53:23387STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
388 IBindCtx* bind_context) {
389 // Read notes in ChromeActiveDocument::SaveHistory
390 DCHECK(stream);
391 LARGE_INTEGER offset = {0};
392 ULARGE_INTEGER cur_pos = {0};
393 STATSTG statstg = {0};
394
395 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
396 stream->Stat(&statstg, STATFLAG_NONAME);
397
398 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
[email protected]965722ff2010-10-20 15:50:30399 base::win::ScopedBstr url_bstr;
[email protected]a1800e82009-11-19 00:53:23400 DWORD bytes_read = 0;
401 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
402 std::wstring url(url_bstr);
403
[email protected]c4e45b32010-07-28 21:15:15404 ChromeFrameUrl cf_url;
405 if (!cf_url.Parse(url)) {
[email protected]a1800e82009-11-19 00:53:23406 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
407 return E_INVALIDARG;
408 }
409
[email protected]c5cbf4e2010-07-15 21:48:25410 const std::string& referrer = EmptyString();
[email protected]c4e45b32010-07-28 21:15:15411 if (!LaunchUrl(cf_url, referrer)) {
[email protected]a1800e82009-11-19 00:53:23412 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
413 return E_INVALIDARG;
414 }
415 return S_OK;
416}
417
418STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
419 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
420 // from Chrome and persist it in the stream. And in LoadHistory we need to
421 // pass this list back to Chrome which will recreate the list. This will allow
422 // Back-Forward navigation to anchors to work correctly when we navigate to a
423 // page outside of ChromeFrame and then come back.
424 if (!stream) {
425 NOTREACHED();
426 return E_INVALIDARG;
427 }
428
429 LARGE_INTEGER offset = {0};
430 ULARGE_INTEGER new_pos = {0};
431 DWORD written = 0;
432 std::wstring url = UTF8ToWide(navigation_info_.url.spec());
433 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
434 &written);
435}
436
437STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
[email protected]77700832010-04-27 00:06:03438 if (automation_client_.get()) {
439 int index = static_cast<int>(position_cookie);
440 navigation_info_.navigation_index = index;
441 automation_client_->NavigateToIndex(index);
442 } else {
443 DLOG(WARNING) << "Invalid automation client instance";
444 }
[email protected]a1800e82009-11-19 00:53:23445 return S_OK;
446}
447
448STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
449 if (!position_cookie)
450 return E_INVALIDARG;
451
452 *position_cookie = navigation_info_.navigation_index;
453 return S_OK;
454}
455
[email protected]f7817822009-09-24 05:11:58456STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
[email protected]bc2ff5192010-06-01 22:05:45457 if (NULL == url)
[email protected]f7817822009-09-24 05:11:58458 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58459 *url = ::SysAllocString(url_);
460 return S_OK;
461}
462
[email protected]a1800e82009-11-19 00:53:23463STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
464 return GetUrlForEvents(url);
465}
466
[email protected]80b5a8d2010-03-19 16:50:43467STDMETHODIMP ChromeActiveDocument::Reset() {
468 next_privacy_record_ = privacy_info_.privacy_records.begin();
469 return S_OK;
470}
471
[email protected]00aebd72010-07-16 14:44:32472STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) {
[email protected]80b5a8d2010-03-19 16:50:43473 if (!size)
474 return E_POINTER;
475
476 *size = privacy_info_.privacy_records.size();
477 return S_OK;
478}
479
480STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
481 if (!privacy_impacted)
482 return E_POINTER;
483
484 *privacy_impacted = privacy_info_.privacy_impacted;
485 return S_OK;
486}
487
488STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
[email protected]00aebd72010-07-16 14:44:32489 LONG* reserved, DWORD* flags) {
[email protected]80b5a8d2010-03-19 16:50:43490 if (!url || !policy || !flags)
491 return E_POINTER;
492
493 if (next_privacy_record_ == privacy_info_.privacy_records.end())
494 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
495
496 *url = SysAllocString(next_privacy_record_->first.c_str());
497 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
498 *flags = next_privacy_record_->second.flags;
499
500 next_privacy_record_++;
501 return S_OK;
502}
503
[email protected]354bcba2010-12-14 04:34:43504bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) {
505 bool allowed = BaseActiveX::IsSchemeAllowed(url);
506 if (allowed)
507 return true;
508
509 if (url.SchemeIs(chrome::kAboutScheme)) {
510 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL))
511 return true;
512 }
513 return false;
514}
515
[email protected]3eafbfb92010-08-02 16:54:22516HRESULT ChromeActiveDocument::GetInPlaceFrame(
517 IOleInPlaceFrame** in_place_frame) {
518 DCHECK(in_place_frame);
519 if (in_place_frame_) {
520 *in_place_frame = in_place_frame_.get();
521 (*in_place_frame)->AddRef();
522 return S_OK;
523 } else {
524 return S_FALSE;
525 }
526}
527
[email protected]f7817822009-09-24 05:11:58528HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
529 IOleClientSite* client_site) {
530 if (client_site == NULL) {
531 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
532 if (cached_document) {
533 DCHECK(this == cached_document);
534 g_active_doc_cache.Set(NULL);
535 cached_document->Release();
536 }
[email protected]dda7d9c2009-11-11 23:01:47537
538 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]bc2ff5192010-06-01 22:05:45539 if (doc_site_)
[email protected]77059f72010-02-28 06:16:00540 doc_host_handler.QueryFrom(doc_site_);
[email protected]dda7d9c2009-11-11 23:01:47541
[email protected]bc2ff5192010-06-01 22:05:45542 if (doc_host_handler.get())
[email protected]dda7d9c2009-11-11 23:01:47543 doc_host_handler->HideUI();
[email protected]dda7d9c2009-11-11 23:01:47544
545 doc_site_.Release();
[email protected]f7817822009-09-24 05:11:58546 }
[email protected]a1800e82009-11-19 00:53:23547
[email protected]bc2ff5192010-06-01 22:05:45548 if (client_site != m_spClientSite)
[email protected]97965e12010-04-09 00:51:10549 return BaseActiveX::IOleObject_SetClientSite(client_site);
[email protected]a1800e82009-11-19 00:53:23550
551 return S_OK;
[email protected]f7817822009-09-24 05:11:58552}
553
[email protected]f7817822009-09-24 05:11:58554HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
555 HRESULT hr = S_OK;
556 m_bNegotiatedWnd = TRUE;
557 if (!m_bInPlaceActive) {
558 hr = m_spInPlaceSite->CanInPlaceActivate();
[email protected]bc2ff5192010-06-01 22:05:45559 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58560 return hr;
[email protected]f7817822009-09-24 05:11:58561 m_spInPlaceSite->OnInPlaceActivate();
562 }
563 m_bInPlaceActive = TRUE;
564 // get location in the parent window,
565 // as well as some information about the parent
566 ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
567 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
568 HWND parent_window = NULL;
569 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
570 in_place_frame_.Release();
571 RECT position_rect = {0};
572 RECT clip_rect = {0};
573 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
574 in_place_ui_window.Receive(),
575 &position_rect,
576 &clip_rect,
577 &frame_info_);
578 if (!m_bWndLess) {
579 if (IsWindow()) {
580 ::ShowWindow(m_hWnd, SW_SHOW);
581 SetFocus();
582 } else {
[email protected]c1d19582010-03-03 01:57:13583 m_hWnd = Create(parent_window, position_rect, 0, 0, WS_EX_CLIENTEDGE);
[email protected]dd4beb522010-07-13 18:18:14584 if (!IsWindow()) {
585 // This might happen if the automation server couldn't be
586 // instantiated. If so, a NOTREACHED() will have already been hit.
587 DLOG(ERROR) << "Failed to create Ax window";
588 return AtlHresultFromLastError();
589 }
[email protected]f7817822009-09-24 05:11:58590 }
[email protected]7f860dd82010-08-09 23:18:05591 SetWindowDimensions();
[email protected]f7817822009-09-24 05:11:58592 }
593 SetObjectRects(&position_rect, &clip_rect);
594 }
595
596 ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
597
598 // Gone active by now, take care of UIACTIVATE
599 if (DoesVerbUIActivate(verb)) {
600 if (!m_bUIActive) {
601 m_bUIActive = TRUE;
602 hr = m_spInPlaceSite->OnUIActivate();
[email protected]bc2ff5192010-06-01 22:05:45603 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58604 return hr;
[email protected]f7817822009-09-24 05:11:58605 // set ourselves up in the host
606 if (in_place_active_object) {
[email protected]bc2ff5192010-06-01 22:05:45607 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58608 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
[email protected]bc2ff5192010-06-01 22:05:45609 if (in_place_ui_window)
[email protected]f7817822009-09-24 05:11:58610 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
[email protected]f7817822009-09-24 05:11:58611 }
612 }
613 }
614 m_spClientSite->ShowObject();
615 return S_OK;
616}
617
[email protected]f5494d42010-12-23 22:15:34618void ChromeActiveDocument::OnNavigationStateChanged(
619 int flags, const NavigationInfo& nav_info) {
[email protected]f7817822009-09-24 05:11:58620 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
[email protected]2b9a9f162010-10-19 20:30:45621 DVLOG(1) << __FUNCTION__
622 << "\n Flags: " << flags
623 << ", Url: " << nav_info.url
624 << ", Title: " << nav_info.title
625 << ", Type: " << nav_info.navigation_type
626 << ", Relative Offset: " << nav_info.relative_offset
627 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58628
629 UpdateNavigationState(nav_info);
630}
631
[email protected]f5494d42010-12-23 22:15:34632void ChromeActiveDocument::OnUpdateTargetUrl(
[email protected]f7817822009-09-24 05:11:58633 const std::wstring& new_target_url) {
[email protected]bc2ff5192010-06-01 22:05:45634 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58635 in_place_frame_->SetStatusText(new_target_url.c_str());
[email protected]f7817822009-09-24 05:11:58636}
637
638bool IsFindAccelerator(const MSG& msg) {
639 // TODO(robertshield): This may not stand up to localization. Fix if this
640 // is the case.
641 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
642 win_util::IsCtrlPressed() &&
643 !(win_util::IsAltPressed() || win_util::IsShiftPressed());
644}
645
[email protected]f5494d42010-12-23 22:15:34646void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35647 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
648 const_cast<MSG*>(&accel_message)))
649 return;
650
[email protected]f7817822009-09-24 05:11:58651 bool handled_accel = false;
652 if (in_place_frame_ != NULL) {
653 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
654 const_cast<MSG*>(&accel_message), 0));
655 }
656
657 if (!handled_accel) {
658 if (IsFindAccelerator(accel_message)) {
659 // Handle the showing of the find dialog explicitly.
660 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59661 } else {
[email protected]f5494d42010-12-23 22:15:34662 BaseActiveX::OnAcceleratorPressed(accel_message);
[email protected]f7817822009-09-24 05:11:58663 }
664 } else {
[email protected]2b9a9f162010-10-19 20:30:45665 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
[email protected]f7817822009-09-24 05:11:58666 }
667}
668
[email protected]f5494d42010-12-23 22:15:34669void ChromeActiveDocument::OnTabbedOut(bool reverse) {
[email protected]2b9a9f162010-10-19 20:30:45670 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58671 if (in_place_frame_) {
672 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
673 in_place_frame_->TranslateAcceleratorW(&msg, 0);
674 }
675}
676
[email protected]f5494d42010-12-23 22:15:34677void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
[email protected]2b9a9f162010-10-19 20:30:45678 DVLOG(1) << __FUNCTION__ << std::endl
679 << "Url: " << nav_info.url
680 << ", Title: " << nav_info.title
681 << ", Type: " << nav_info.navigation_type
682 << ", Relative Offset: " << nav_info.relative_offset
683 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58684
[email protected]897b26272010-06-11 02:23:44685 CrashMetricsReporter::GetInstance()->IncrementMetric(
686 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
687
[email protected]f7817822009-09-24 05:11:58688 // This could be NULL if the active document instance is being destroyed.
689 if (!m_spInPlaceSite) {
[email protected]2b9a9f162010-10-19 20:30:45690 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
[email protected]f7817822009-09-24 05:11:58691 return;
692 }
693
694 UpdateNavigationState(nav_info);
695}
696
[email protected]f5494d42010-12-23 22:15:34697void ChromeActiveDocument::OnCloseTab() {
[email protected]2f1793ea2010-10-27 17:32:51698 // Base class will fire DIChromeFrameEvents::onclose.
[email protected]f5494d42010-12-23 22:15:34699 BaseActiveX::OnCloseTab();
[email protected]2f1793ea2010-10-27 17:32:51700
701 // Close the container window.
[email protected]e16dd1672010-06-07 21:40:29702 ScopedComPtr<IWebBrowser2> web_browser2;
703 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
704 if (web_browser2)
705 web_browser2->Quit();
706}
707
[email protected]f7817822009-09-24 05:11:58708void ChromeActiveDocument::UpdateNavigationState(
[email protected]f5494d42010-12-23 22:15:34709 const NavigationInfo& new_navigation_info) {
[email protected]a1800e82009-11-19 00:53:23710 HRESULT hr = S_OK;
[email protected]f7817822009-09-24 05:11:58711 bool is_title_changed = (navigation_info_.title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58712 bool is_ssl_state_changed =
713 (navigation_info_.security_style != new_navigation_info.security_style) ||
[email protected]b4e75c12010-05-18 18:28:48714 (navigation_info_.displayed_insecure_content !=
715 new_navigation_info.displayed_insecure_content) ||
716 (navigation_info_.ran_insecure_content !=
717 new_navigation_info.ran_insecure_content);
[email protected]f7817822009-09-24 05:11:58718
[email protected]f7817822009-09-24 05:11:58719 if (is_ssl_state_changed) {
720 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23721 switch (new_navigation_info.security_style) {
[email protected]f7817822009-09-24 05:11:58722 case SECURITY_STYLE_AUTHENTICATED:
[email protected]b4e75c12010-05-18 18:28:48723 lock_status = new_navigation_info.displayed_insecure_content ?
[email protected]f7817822009-09-24 05:11:58724 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
725 break;
726 default:
727 break;
728 }
729
[email protected]965722ff2010-10-20 15:50:30730 base::win::ScopedVariant secure_lock_status(lock_status);
[email protected]f7817822009-09-24 05:11:58731 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
732 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
733 }
734
[email protected]a1800e82009-11-19 00:53:23735 // Ideally all navigations should come to Chrome Frame so that we can call
736 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
737 // navigation. However, in practice what happens is as below:
738 // The very first navigation that happens in CF happens via a Load or a
739 // LoadHistory call. In this case, IE already has the correct information for
740 // its travel log as well address bar. For other internal navigations (navs
741 // that only happen within Chrome such as anchor navigations) we need to
742 // update IE's internal state after the fact. In the case of internal
743 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58744
745 // Another case where we need to issue BeforeNavigate2 calls is as below:-
746 // We get notified after the fact, when navigations are initiated within
747 // Chrome via window.open calls. These navigations are handled by creating
748 // an external tab container within chrome and then connecting to it from IE.
749 // We still want to update the address bar/history, etc, to ensure that
750 // the special URL used by Chrome to indicate this is updated correctly.
[email protected]d266ce82010-08-13 21:33:40751 ChromeFrameUrl cf_url;
752 bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) &&
753 cf_url.attach_to_external_tab();
[email protected]342de552010-10-21 20:46:14754
755 bool is_internal_navigation =
756 IsNewNavigation(new_navigation_info) || is_attach_external_tab_url;
[email protected]f7817822009-09-24 05:11:58757
[email protected]bc2ff5192010-06-01 22:05:45758 if (new_navigation_info.url.is_valid())
[email protected]38939de2010-05-13 02:32:06759 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]38939de2010-05-13 02:32:06760
[email protected]a1800e82009-11-19 00:53:23761 if (is_internal_navigation) {
762 ScopedComPtr<IDocObjectService> doc_object_svc;
[email protected]f7817822009-09-24 05:11:58763 ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06764
[email protected]5ae94d22010-07-21 19:55:36765 buggy_bho::BuggyBhoTls bad_bho_tls;
766 if (GetConfigBool(true, kEnableBuggyBhoIntercept)) {
767 ScopedComPtr<IWebBrowser2> wb2;
768 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
769 if (wb2) {
770 buggy_bho::BuggyBhoTls::PatchBuggyBHOs(wb2);
771 }
772 }
773
[email protected]f7817822009-09-24 05:11:58774 DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite,
775 web_browser_events_svc.Receive());
[email protected]ae33d672010-03-04 21:58:06776
777 if (!web_browser_events_svc.get()) {
778 DoQueryService(SID_SShellBrowser, m_spClientSite,
779 doc_object_svc.Receive());
780 }
781
[email protected]62bb18dc12009-11-25 01:34:08782 // web_browser_events_svc can be NULL on IE6.
[email protected]f7817822009-09-24 05:11:58783 if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58784 VARIANT_BOOL should_cancel = VARIANT_FALSE;
785 web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel);
[email protected]33bd26d2010-08-31 05:05:03786 } else if (doc_object_svc) {
787 BOOL should_cancel = FALSE;
788 doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0,
789 NULL, FALSE, &should_cancel);
[email protected]a1800e82009-11-19 00:53:23790 }
791
792 // We need to tell IE that we support navigation so that IE will query us
793 // for IPersistHistory and call GetPositionCookie to save our navigation
794 // index.
[email protected]965722ff2010-10-20 15:50:30795 base::win::ScopedVariant html_window(static_cast<IUnknown*>(
[email protected]a1800e82009-11-19 00:53:23796 static_cast<IHTMLWindow2*>(this)));
797 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
798 html_window.AsInput(), NULL);
799
800 // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG
801 // since we want to make IE treat all internal navigations within this page
802 // (including anchor navigations and subframe navigations) as anchor
803 // navigations. This will ensure that IE calls GetPositionCookie
804 // to save the current position cookie in the travel log and then call
805 // SetPositionCookie when the user hits Back/Forward to come back here.
[email protected]965722ff2010-10-20 15:50:30806 base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP);
[email protected]a1800e82009-11-19 00:53:23807 IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0,
808 internal_navigation.AsInput(), NULL);
809
810 // We no longer need to lie to IE. If we lie persistently to IE, then
811 // IE reuses us for new navigations.
812 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL);
813
814 if (doc_object_svc) {
815 // Now call the FireNavigateCompleteEvent which makes IE update the text
816 // in the address-bar.
817 doc_object_svc->FireNavigateComplete2(this, 0);
[email protected]5ae94d22010-07-21 19:55:36818 doc_object_svc->FireDocumentComplete(this, 0);
[email protected]a1800e82009-11-19 00:53:23819 } else if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58820 web_browser_events_svc->FireNavigateComplete2Event();
[email protected]5ae94d22010-07-21 19:55:36821 web_browser_events_svc->FireDocumentCompleteEvent();
[email protected]f7817822009-09-24 05:11:58822 }
823 }
[email protected]37346bc2009-09-25 22:54:33824
[email protected]a1800e82009-11-19 00:53:23825 if (is_title_changed) {
[email protected]965722ff2010-10-20 15:50:30826 base::win::ScopedVariant title(new_navigation_info.title.c_str());
[email protected]a1800e82009-11-19 00:53:23827 IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
828 title.AsInput(), NULL);
829 }
830
831 // It is important that we only update the navigation_info_ after we have
832 // finalized the travel log. This is because IE will ask for information
833 // such as navigation index when the travel log is finalized and we need
834 // supply the old index and not the new one.
835 navigation_info_ = new_navigation_info;
[email protected]37346bc2009-09-25 22:54:33836 // Update the IE zone here. Ideally we would like to do it when the active
837 // document is activated. However that does not work at times as the frame we
838 // get there is not the actual frame which handles the command.
839 IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL);
[email protected]f7817822009-09-24 05:11:58840}
841
842void ChromeActiveDocument::OnFindInPage() {
843 TabProxy* tab = GetTabProxy();
844 if (tab) {
[email protected]bc2ff5192010-06-01 22:05:45845 if (!find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58846 find_dialog_.Create(m_hWnd);
[email protected]f7817822009-09-24 05:11:58847
848 find_dialog_.ShowWindow(SW_SHOW);
849 }
850}
851
852void ChromeActiveDocument::OnViewSource() {
853 DCHECK(navigation_info_.url.is_valid());
[email protected]76e7da22010-06-18 22:44:49854 HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") +
855 navigation_info_.url.spec()), GURL(), NEW_WINDOW);
[email protected]f7817822009-09-24 05:11:58856}
857
[email protected]37346bc2009-09-25 22:54:33858void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid,
859 DWORD command_id,
860 DWORD cmd_exec_opt,
861 VARIANT* in_args,
862 VARIANT* out_args) {
[email protected]7c712c92010-03-24 17:29:22863 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
864 // Correct step is to use MapUrlToZone().
[email protected]37346bc2009-09-25 22:54:33865 if (out_args != NULL) {
866 out_args->vt = VT_UI4;
867 out_args->ulVal = URLZONE_INTERNET;
868 }
869}
870
[email protected]80b5a8d2010-03-19 16:50:43871void ChromeActiveDocument::OnDisplayPrivacyInfo() {
[email protected]bbfa9a12010-08-10 14:09:37872 privacy_info_ = url_fetcher_->privacy_info();
[email protected]80b5a8d2010-03-19 16:50:43873 Reset();
874 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
875}
876
[email protected]7f860dd82010-08-09 23:18:05877void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid,
878 DWORD command_id,
879 DWORD cmd_exec_opt,
880 VARIANT* in_args,
881 VARIANT* out_args) {
882 if (out_args != NULL) {
883 out_args->vt = VT_I4;
884 out_args->lVal = 0;
885 }
886}
887
888void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid,
889 DWORD command_id,
890 DWORD cmd_exec_opt,
891 VARIANT* in_args,
892 VARIANT* out_args) {
893 const int kZoomIn = 125;
894 const int kZoomOut = 75;
895
896 if (in_args && V_VT(in_args) == VT_I4 && IsValid()) {
897 if (in_args->lVal == kZoomIn) {
898 automation_client_->SetZoomLevel(PageZoom::ZOOM_IN);
899 } else if (in_args->lVal == kZoomOut) {
900 automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT);
901 } else {
902 DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal;
903 }
904 }
905}
906
[email protected]d9d8f0c2010-09-17 21:47:16907void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid,
908 DWORD command_id,
909 DWORD cmd_exec_opt,
910 VARIANT* in_args,
911 VARIANT* out_args) {
912 if (IsValid() && out_args) {
913 bool should_unload = true;
914 automation_client_->OnUnload(&should_unload);
915 out_args->vt = VT_BOOL;
916 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
917 }
918}
919
[email protected]f5494d42010-12-23 22:15:34920void ChromeActiveDocument::OnOpenURL(const GURL& url_to_open,
[email protected]b36a9f92009-10-19 17:34:57921 const GURL& referrer,
[email protected]f7817822009-09-24 05:11:58922 int open_disposition) {
923 // If the disposition indicates that we should be opening the URL in the
924 // current tab, then we can reuse the ChromeFrameAutomationClient instance
925 // maintained by the current ChromeActiveDocument instance. We cache this
926 // instance so that it can be used by the new ChromeActiveDocument instance
927 // which may be instantiated for handling the new URL.
928 if (open_disposition == CURRENT_TAB) {
929 // Grab a reference to ensure that the document remains valid.
930 AddRef();
931 g_active_doc_cache.Set(this);
932 }
933
[email protected]f5494d42010-12-23 22:15:34934 BaseActiveX::OnOpenURL(url_to_open, referrer, open_disposition);
[email protected]f7817822009-09-24 05:11:58935}
936
[email protected]f5494d42010-12-23 22:15:34937void ChromeActiveDocument::OnAttachExternalTab(
938 const AttachExternalTabParams& params) {
[email protected]77700832010-04-27 00:06:03939 if (!automation_client_.get()) {
940 DLOG(WARNING) << "Invalid automation client instance";
941 return;
942 }
[email protected]b1c55638612010-03-08 16:26:11943 DWORD flags = 0;
944 if (params.user_gesture)
945 flags = NWMF_USERREQUESTED;
[email protected]355309e2010-03-15 17:01:34946 else if (popup_allowed_)
947 flags = NWMF_USERALLOWED;
[email protected]b1c55638612010-03-08 16:26:11948
949 HRESULT hr = S_OK;
950 if (popup_manager_) {
[email protected]e4456ae2010-09-22 23:35:11951 const std::wstring& url_wide = UTF8ToWide(params.url.spec());
952 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_,
[email protected]355309e2010-03-15 17:01:34953 NULL, FALSE, flags, 0);
[email protected]b1c55638612010-03-08 16:26:11954 }
955 // Allow popup
956 if (hr == S_OK) {
[email protected]f5494d42010-12-23 22:15:34957 BaseActiveX::OnAttachExternalTab(params);
[email protected]b1c55638612010-03-08 16:26:11958 return;
959 }
960
961 automation_client_->BlockExternalTab(params.cookie);
962}
963
[email protected]f7817822009-09-24 05:11:58964bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
965 ScopedComPtr<IBrowserService> browser_service;
966 ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:23967 GetBrowserServiceAndTravelLog(browser_service.Receive(),
968 travel_log.Receive());
969 if (!browser_service || !travel_log)
[email protected]f7817822009-09-24 05:11:58970 return true;
971
[email protected]d118f542010-11-05 18:50:31972 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND |
973 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK,
974 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45975 MF_ENABLED : MF_DISABLED));
[email protected]d118f542010-11-05 18:50:31976 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND |
977 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE,
978 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45979 MF_ENABLED : MF_DISABLED));
[email protected]f7817822009-09-24 05:11:58980 // Call base class (adds 'About' item)
[email protected]97965e12010-04-09 00:51:10981 return BaseActiveX::PreProcessContextMenu(menu);
[email protected]f7817822009-09-24 05:11:58982}
983
[email protected]f5494d42010-12-23 22:15:34984bool ChromeActiveDocument::HandleContextMenuCommand(
985 UINT cmd, const MiniContextMenuParams& params) {
[email protected]f7817822009-09-24 05:11:58986 ScopedComPtr<IWebBrowser2> web_browser2;
987 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
988
[email protected]074283a2010-05-28 23:47:59989 if (cmd == IDC_BACK)
[email protected]b731a142010-05-14 00:03:03990 web_browser2->GoBack();
[email protected]074283a2010-05-28 23:47:59991 else if (cmd == IDC_FORWARD)
[email protected]b731a142010-05-14 00:03:03992 web_browser2->GoForward();
[email protected]074283a2010-05-28 23:47:59993 else if (cmd == IDC_RELOAD)
[email protected]b731a142010-05-14 00:03:03994 web_browser2->Refresh();
[email protected]074283a2010-05-28 23:47:59995 else
[email protected]b731a142010-05-14 00:03:03996 return BaseActiveX::HandleContextMenuCommand(cmd, params);
[email protected]f7817822009-09-24 05:11:58997
998 return true;
999}
1000
1001HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid,
1002 DWORD command_id, DWORD cmd_exec_opt,
1003 VARIANT* in_args, VARIANT* out_args) {
1004 HRESULT hr = E_FAIL;
[email protected]37346bc2009-09-25 22:54:331005
[email protected]f7817822009-09-24 05:11:581006 ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:331007
1008 ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite);
[email protected]bc2ff5192010-06-01 22:05:451009 if (!in_place_site.get() && m_spClientSite != NULL)
[email protected]37346bc2009-09-25 22:54:331010 in_place_site.QueryFrom(m_spClientSite);
[email protected]37346bc2009-09-25 22:54:331011
1012 if (in_place_site)
1013 hr = frame_cmd_target.QueryFrom(in_place_site);
[email protected]f7817822009-09-24 05:11:581014
[email protected]bc2ff5192010-06-01 22:05:451015 if (frame_cmd_target) {
[email protected]f7817822009-09-24 05:11:581016 hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt,
1017 in_args, out_args);
[email protected]bc2ff5192010-06-01 22:05:451018 }
[email protected]f7817822009-09-24 05:11:581019
1020 return hr;
1021}
[email protected]37346bc2009-09-25 22:54:331022
[email protected]c4e45b32010-07-28 21:15:151023bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url,
1024 const std::string& referrer) {
[email protected]d266ce82010-08-13 21:33:401025 DCHECK(!cf_url.gurl().is_empty());
[email protected]77700832010-04-27 00:06:031026
[email protected]242ceb032010-08-26 17:06:361027 if (!automation_client_.get()) {
1028 // http://code.google.com/p/chromium/issues/detail?id=52894
1029 // Still not sure how this happens.
1030 DLOG(ERROR) << "No automation client!";
1031 if (!Initialize()) {
1032 NOTREACHED() << "...and failed to start a new one >:(";
1033 return false;
1034 }
1035 }
1036
[email protected]d266ce82010-08-13 21:33:401037 url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str());
[email protected]c4e45b32010-07-28 21:15:151038 if (cf_url.attach_to_external_tab()) {
1039 dimensions_ = cf_url.dimensions();
1040 automation_client_->AttachExternalTab(cf_url.cookie());
[email protected]7f860dd82010-08-09 23:18:051041 SetWindowDimensions();
[email protected]d266ce82010-08-13 21:33:401042 } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(),
[email protected]6f8f31d2010-07-30 08:17:151043 referrer,
[email protected]354bcba2010-12-14 04:34:431044 this)) {
[email protected]6f8f31d2010-07-30 08:17:151045 DLOG(ERROR) << "Invalid URL: " << url_;
1046 Error(L"Invalid URL");
1047 url_.Reset();
1048 return false;
[email protected]37346bc2009-09-25 22:54:331049 }
1050
[email protected]3eb07da2010-02-01 19:48:361051 if (is_automation_client_reused_)
1052 return true;
[email protected]37346bc2009-09-25 22:54:331053
[email protected]bbfa9a12010-08-10 14:09:371054 automation_client_->SetUrlFetcher(url_fetcher_.get());
[email protected]701142a2010-08-31 20:57:071055 if (launch_params_) {
1056 return automation_client_->Initialize(this, launch_params_);
1057 } else {
[email protected]8103c7f2010-09-08 22:36:091058 std::wstring profile = UTF8ToWide(cf_url.profile_name());
1059 // If no profile was given, then make use of the host process's name.
1060 if (profile.empty())
1061 profile = GetHostProcessName(false);
1062 return InitializeAutomation(profile, L"", IsIEInPrivate(),
[email protected]9eeb35e2010-09-30 21:38:501063 false, cf_url.gurl(), GURL(referrer),
1064 false);
[email protected]701142a2010-08-31 20:57:071065 }
[email protected]37346bc2009-09-25 22:54:331066}
[email protected]1bb5f892009-10-06 01:44:571067
[email protected]355309e2010-03-15 17:01:341068
1069HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1070 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:451071 DVLOG(1) << __FUNCTION__;
[email protected]355309e2010-03-15 17:01:341072 popup_allowed_ = false;
1073 if (in_args->vt == VT_I4 &&
1074 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1075 popup_allowed_ = true;
1076
1077 // Ask the yellow security band to change the text and icon and to remain
1078 // visible.
1079 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
[email protected]bbfa9a12010-08-10 14:09:371080 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
[email protected]355309e2010-03-15 17:01:341081 }
1082
[email protected]3eb8a70492010-12-03 21:32:191083 NavigationManager* mgr = NavigationManager::GetThreadInstance();
1084 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
1085
1086 // If ChromeFrame was activated on this page as a result of a document
1087 // received in response to a top level post, then we ask the user for
1088 // permission to repost and issue a navigation with the saved post data
1089 // which reinitates the whole sequence, i.e. the server receives the top
1090 // level post and chrome frame will be reactivated in response.
1091 if (mgr && mgr->post_data().type() != VT_EMPTY) {
1092 if (MessageBox(
1093 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING).c_str(),
1094 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING_TITLE).c_str(),
1095 MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
1096 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
1097 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1098 web_browser2.Receive());
1099 DCHECK(web_browser2);
1100 VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
1101 VARIANT flags = { VT_I4 };
1102 V_I4(&flags) = navNoHistory;
1103
1104 return web_browser2->Navigate2(base::win::ScopedVariant(url_).AsInput(),
1105 &flags,
1106 &empty,
1107 const_cast<VARIANT*>(&mgr->post_data()),
1108 const_cast<VARIANT*>(&mgr->headers()));
1109 } else {
1110 return S_OK;
1111 }
1112 }
1113
[email protected]355309e2010-03-15 17:01:341114 TabProxy* tab_proxy = GetTabProxy();
[email protected]bbfa9a12010-08-10 14:09:371115 if (tab_proxy) {
[email protected]355309e2010-03-15 17:01:341116 tab_proxy->ReloadAsync();
[email protected]bbfa9a12010-08-10 14:09:371117 } else {
1118 DLOG(ERROR) << "No automation proxy";
[email protected]242ceb032010-08-26 17:06:361119 DCHECK(automation_client_.get() != NULL) << "how did it get freed?";
[email protected]bbfa9a12010-08-10 14:09:371120 // The current url request manager (url_fetcher_) has been switched to
1121 // a stopping state so we need to reset it and get a new one for the new
1122 // automation server.
1123 ResetUrlRequestManager();
1124 url_fetcher_->set_frame_busting(false);
1125 // And now launch the current URL again. This starts a new server process.
1126 DCHECK(navigation_info_.url.is_valid());
1127 ChromeFrameUrl cf_url;
1128 cf_url.Parse(UTF8ToWide(navigation_info_.url.spec()));
1129 LaunchUrl(cf_url, navigation_info_.referrer.spec());
1130 }
[email protected]355309e2010-03-15 17:01:341131
1132 return S_OK;
1133}
1134
[email protected]1bb5f892009-10-06 01:44:571135HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1136 DWORD command_id,
1137 DWORD cmd_exec_opt,
1138 VARIANT* in_args,
1139 VARIANT* out_args) {
1140 if (!automation_client_.get()) {
[email protected]77700832010-04-27 00:06:031141 NOTREACHED() << "Invalid automation client";
[email protected]1bb5f892009-10-06 01:44:571142 return E_FAIL;
1143 }
1144
1145 switch (command_id) {
1146 case IDM_BASELINEFONT1:
1147 automation_client_->SetPageFontSize(SMALLEST_FONT);
1148 break;
1149
1150 case IDM_BASELINEFONT2:
1151 automation_client_->SetPageFontSize(SMALL_FONT);
1152 break;
1153
1154 case IDM_BASELINEFONT3:
1155 automation_client_->SetPageFontSize(MEDIUM_FONT);
1156 break;
1157
1158 case IDM_BASELINEFONT4:
1159 automation_client_->SetPageFontSize(LARGE_FONT);
1160 break;
1161
1162 case IDM_BASELINEFONT5:
1163 automation_client_->SetPageFontSize(LARGEST_FONT);
1164 break;
1165
1166 default:
1167 NOTREACHED() << "Invalid font size command: "
1168 << command_id;
1169 return E_FAIL;
1170 }
1171
1172 // Forward the command back to IEFrame with group set to
1173 // CGID_ExplorerBarDoc. This is probably needed to update the menu state to
1174 // indicate that the font size was set. This currently fails with error
1175 // 0x80040104.
1176 // TODO(iyengar)
1177 // Do some investigation into why this Exec call fails.
1178 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1179 return S_OK;
1180}
1181
[email protected]2f2afba2010-04-01 01:53:191182HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid,
1183 DWORD command_id,
1184 DWORD cmd_exec_opt,
1185 VARIANT* in_args,
1186 VARIANT* out_args) {
1187 const struct EncodingMapData {
1188 DWORD ie_encoding_id;
1189 const char* chrome_encoding_name;
1190 } kEncodingTestDatas[] = {
1191#define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \
1192 { encoding_name, chrome_name },
1193 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP)
1194#undef DEFINE_ENCODING_MAP
1195 };
1196
1197 if (!automation_client_.get()) {
1198 NOTREACHED() << "Invalid automtion client";
1199 return E_FAIL;
1200 }
1201
[email protected]e9b35282010-06-02 16:43:191202 // Using ARRAYSIZE_UNSAFE in here is because we define the struct
1203 // EncodingMapData inside function.
[email protected]2f2afba2010-04-01 01:53:191204 const char* chrome_encoding_name = NULL;
1205 for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
1206 const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i];
1207 if (command_id == encoding_data->ie_encoding_id) {
1208 chrome_encoding_name = encoding_data->chrome_encoding_name;
1209 break;
1210 }
1211 }
1212 // Return E_FAIL when encountering invalid encoding id.
1213 if (!chrome_encoding_name)
1214 return E_FAIL;
1215
1216 TabProxy* tab = GetTabProxy();
1217 if (!tab) {
1218 NOTREACHED() << "Can not get TabProxy";
1219 return E_FAIL;
1220 }
1221
1222 if (chrome_encoding_name)
1223 tab->OverrideEncoding(chrome_encoding_name);
1224
1225 // Like we did on SetPageFontSize, we may forward the command back to IEFrame
1226 // to update the menu state to indicate that which encoding was set.
1227 // TODO(iyengar)
1228 // Do some investigation into why this Exec call fails.
1229 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1230 return S_OK;
1231}
1232
[email protected]f5494d42010-12-23 22:15:341233void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) {
[email protected]2b9a9f162010-10-19 20:30:451234 DVLOG(1) << __FUNCTION__ << " - offset:" << offset;
[email protected]a1800e82009-11-19 00:53:231235
[email protected]f9cc4c452009-10-13 14:56:381236 ScopedComPtr<IBrowserService> browser_service;
[email protected]a1800e82009-11-19 00:53:231237 ScopedComPtr<ITravelLog> travel_log;
1238 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1239 travel_log.Receive());
1240
1241 if (browser_service && travel_log)
1242 travel_log->Travel(browser_service, offset);
1243}
1244
1245HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1246 IBrowserService** browser_service, ITravelLog** travel_log) {
1247 DCHECK(browser_service || travel_log);
1248 ScopedComPtr<IBrowserService> browser_service_local;
1249 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1250 browser_service_local.Receive());
1251 if (!browser_service_local) {
1252 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1253 return hr;
[email protected]f9cc4c452009-10-13 14:56:381254 }
[email protected]a1800e82009-11-19 00:53:231255
1256 if (travel_log) {
1257 hr = browser_service_local->GetTravelLog(travel_log);
[email protected]5044da82010-10-27 01:09:161258 DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr;
[email protected]a1800e82009-11-19 00:53:231259 }
1260
1261 if (browser_service)
1262 *browser_service = browser_service_local.Detach();
1263
1264 return hr;
[email protected]f9cc4c452009-10-13 14:56:381265}
[email protected]a15d4a42010-02-17 08:21:351266
1267LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1268 HWND control_window,
1269 BOOL& bHandled) {
1270 ScopedComPtr<IWebBrowser2> web_browser2;
1271 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1272 DCHECK(web_browser2);
1273
[email protected]bc2ff5192010-06-01 22:05:451274 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351275 web_browser2->GoForward();
[email protected]a15d4a42010-02-17 08:21:351276 return 0;
1277}
1278
1279LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1280 HWND control_window,
1281 BOOL& bHandled) {
1282 ScopedComPtr<IWebBrowser2> web_browser2;
1283 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1284 DCHECK(web_browser2);
1285
[email protected]bc2ff5192010-06-01 22:05:451286 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351287 web_browser2->GoBack();
[email protected]a15d4a42010-02-17 08:21:351288 return 0;
1289}
1290
[email protected]80b5a8d2010-03-19 16:50:431291LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1292 LPARAM lparam,
1293 BOOL& handled) {
1294 if (!m_spClientSite)
1295 return 0;
1296
1297 ScopedComPtr<IWebBrowser2> web_browser2;
1298 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1299 web_browser2.Receive());
1300 if (!web_browser2) {
1301 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1302 return 0;
1303 }
1304
1305 ScopedComPtr<IShellBrowser> shell_browser;
1306 DoQueryService(SID_STopLevelBrowser, web_browser2,
1307 shell_browser.Receive());
1308 DCHECK(shell_browser.get() != NULL);
1309 ScopedComPtr<ITridentService2> trident_services;
1310 trident_services.QueryFrom(shell_browser);
[email protected]bc2ff5192010-06-01 22:05:451311 if (trident_services)
[email protected]80b5a8d2010-03-19 16:50:431312 trident_services->FirePrivacyImpactedStateChange(wparam);
[email protected]bc2ff5192010-06-01 22:05:451313 else
[email protected]80b5a8d2010-03-19 16:50:431314 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
[email protected]80b5a8d2010-03-19 16:50:431315 return 0;
1316}
[email protected]00aebd72010-07-16 14:44:321317
[email protected]723e5442010-07-21 17:36:051318LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam,
1319 LPARAM lparam,
1320 BOOL& handled) { // NO_LINT
1321 if (wparam)
1322 SetFocus();
1323 return 0;
1324}
1325
1326LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam,
1327 LPARAM lparam,
1328 BOOL& handled) { // NO_LINT
[email protected]e7ad9322010-08-02 20:41:291329 if (!ignore_setfocus_)
1330 GiveFocusToChrome(false);
[email protected]723e5442010-07-21 17:36:051331 return 0;
1332}
[email protected]7f860dd82010-08-09 23:18:051333
1334void ChromeActiveDocument::SetWindowDimensions() {
1335 ScopedComPtr<IWebBrowser2> web_browser2;
1336 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1337 web_browser2.Receive());
1338 if (!web_browser2)
1339 return;
[email protected]2b9a9f162010-10-19 20:30:451340 DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions_.width()
1341 << " height:" << dimensions_.height();
[email protected]7f860dd82010-08-09 23:18:051342 if (!dimensions_.IsEmpty()) {
[email protected]73b18972010-11-18 01:35:461343 web_browser2->put_MenuBar(VARIANT_FALSE);
1344 web_browser2->put_ToolBar(VARIANT_FALSE);
1345
1346 int width = dimensions_.width();
1347 int height = dimensions_.height();
1348 // Compute the size of the browser window given the desired size of the
1349 // content area. As per MSDN, the WebBrowser object returns an error from
1350 // this method. As a result the code below is best effort.
1351 if (SUCCEEDED(web_browser2->ClientToWindow(&width, &height))) {
1352 dimensions_.set_width(width);
1353 dimensions_.set_height(height);
1354 }
[email protected]7f860dd82010-08-09 23:18:051355 web_browser2->put_Width(dimensions_.width());
1356 web_browser2->put_Height(dimensions_.height());
1357 web_browser2->put_Left(dimensions_.x());
1358 web_browser2->put_Top(dimensions_.y());
[email protected]7f860dd82010-08-09 23:18:051359
1360 dimensions_.set_height(0);
1361 dimensions_.set_width(0);
1362 }
1363}
[email protected]342de552010-10-21 20:46:141364
1365bool ChromeActiveDocument::IsNewNavigation(
[email protected]f5494d42010-12-23 22:15:341366 const NavigationInfo& new_navigation_info) const {
[email protected]342de552010-10-21 20:46:141367 // A new navigation is typically an internal navigation which is initiated by
1368 // the renderer(WebKit). Condition 1 below has to be true along with the
1369 // any of the other conditions below.
1370 // 1. The navigation index is greater than 0 which means that a top level
1371 // navigation was initiated on the current external tab.
1372 // 2. The navigation type has changed.
1373 // 3. The url or the referrer are different.
1374 if (new_navigation_info.navigation_index <= 0)
1375 return false;
1376
1377 if (new_navigation_info.navigation_index ==
1378 navigation_info_.navigation_index)
1379 return false;
1380
1381 if (new_navigation_info.navigation_type != navigation_info_.navigation_type)
1382 return true;
1383
1384 if (new_navigation_info.url != navigation_info_.url)
1385 return true;
1386
1387 if (new_navigation_info.referrer != navigation_info_.referrer)
1388 return true;
1389
1390 return false;
1391}