blob: cf903e9021263459e18c1957b1b74df626c68ff4 [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]21f11682011-03-02 16:45:4237#include "content/browser/tab_contents/tab_contents.h"
[email protected]4dd57932011-03-17 06:06:1238#include "content/common/page_zoom.h"
[email protected]8ee65ba2011-04-12 20:53:2339#include "grit/generated_resources.h"
[email protected]f7817822009-09-24 05:11:5840
[email protected]a1800e82009-11-19 00:53:2341DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
42 0x46);
43
[email protected]f7817822009-09-24 05:11:5844bool g_first_launch_by_process_ = true;
45
[email protected]2f2afba2010-04-01 01:53:1946const DWORD kIEEncodingIdArray[] = {
47#define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name,
48 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY)
49#undef DEFINE_ENCODING_ID_ARRAY
50 0 // The Last data must be 0 to indicate the end of the encoding id array.
51};
52
[email protected]f7817822009-09-24 05:11:5853ChromeActiveDocument::ChromeActiveDocument()
[email protected]a22f7e02011-02-09 07:15:3554 : navigation_info_(new NavigationInfo()),
55 first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3556 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3457 popup_allowed_(false),
[email protected]c4e45b32010-07-28 21:15:1558 accelerator_table_(NULL) {
[email protected]366ae242011-05-10 02:23:5859 TRACE_EVENT_BEGIN_ETW("chromeframe.createactivedocument", this, "");
[email protected]04e3f352010-05-10 13:48:2460
[email protected]bbfa9a12010-08-10 14:09:3761 url_fetcher_->set_frame_busting(false);
[email protected]a22f7e02011-02-09 07:15:3562 memset(navigation_info_.get(), 0, sizeof(NavigationInfo));
[email protected]f7817822009-09-24 05:11:5863}
64
65HRESULT ChromeActiveDocument::FinalConstruct() {
[email protected]e67d08172011-08-17 19:22:2166 // The FinalConstruct implementation in the ChromeFrameActivexBase class
67 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
68 // and initializes it, which would spawn a new Chrome process, etc.
69 // We don't want to be doing this if we have a cached document, whose
70 // automation client instance can be reused.
71 HRESULT hr = BaseActiveX::FinalConstruct();
72 if (FAILED(hr))
73 return hr;
[email protected]f7817822009-09-24 05:11:5874
[email protected]e1081d92010-09-10 20:29:1175 InitializeAutomationSettings();
[email protected]8f56e612010-09-09 17:03:1476
[email protected]f7817822009-09-24 05:11:5877 find_dialog_.Init(automation_client_.get());
78
[email protected]6fd1a7a2010-07-26 22:09:4679 OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED);
80
81 null_group_commands_map_[OLECMDID_PRINT] = flags;
82 null_group_commands_map_[OLECMDID_FIND] = flags;
83 null_group_commands_map_[OLECMDID_CUT] = flags;
84 null_group_commands_map_[OLECMDID_COPY] = flags;
85 null_group_commands_map_[OLECMDID_PASTE] = flags;
86 null_group_commands_map_[OLECMDID_SELECTALL] = flags;
87 null_group_commands_map_[OLECMDID_SAVEAS] = flags;
88
89 mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags;
90 mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags;
91 mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags;
92 mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags;
93 mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags;
[email protected]b2529722010-12-01 02:49:0794 mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags;
[email protected]a15d4a42010-02-17 08:21:3595
[email protected]3c6f8e12010-03-24 21:58:2196 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
[email protected]a15d4a42010-02-17 08:21:3597 accelerator_table_ =
[email protected]3c6f8e12010-03-24 21:58:2198 LoadAccelerators(this_module,
[email protected]a15d4a42010-02-17 08:21:3599 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
100 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58101 return S_OK;
102}
103
104ChromeActiveDocument::~ChromeActiveDocument() {
[email protected]2b9a9f162010-10-19 20:30:45105 DVLOG(1) << __FUNCTION__;
[email protected]bc2ff5192010-06-01 22:05:45106 if (find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58107 find_dialog_.DestroyWindow();
[email protected]3eb07da2010-02-01 19:48:36108 // ChromeFramePlugin
[email protected]97965e12010-04-09 00:51:10109 BaseActiveX::Uninitialize();
[email protected]04e3f352010-05-10 13:48:24110
[email protected]366ae242011-05-10 02:23:58111 TRACE_EVENT_END_ETW("chromeframe.createactivedocument", this, "");
[email protected]f7817822009-09-24 05:11:58112}
113
114// Override DoVerb
115STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
116 LPMSG msg,
117 IOleClientSite* active_site,
118 LONG index,
119 HWND parent_window,
120 LPCRECT pos) {
121 // IE will try and in-place activate us in some cases. This happens when
122 // the user opens a new IE window with a URL that has us as the DocObject.
123 // Here we refuse to be activated in-place and we will force IE to UIActivate
124 // us.
[email protected]bc2ff5192010-06-01 22:05:45125 if (OLEIVERB_INPLACEACTIVATE == verb)
[email protected]23b33612010-11-09 23:47:01126 return OLEOBJ_E_INVALIDVERB;
[email protected]f7817822009-09-24 05:11:58127 // Check if we should activate as a docobject or not
128 // (client supports IOleDocumentSite)
129 if (doc_site_) {
130 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57131 case OLEIVERB_SHOW: {
[email protected]8ee65ba2011-04-12 20:53:23132 base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]1bb5f892009-10-06 01:44:57133 doc_host_handler.QueryFrom(doc_site_);
[email protected]bc2ff5192010-06-01 22:05:45134 if (doc_host_handler.get())
[email protected]1bb5f892009-10-06 01:44:57135 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
[email protected]1bb5f892009-10-06 01:44:57136 }
[email protected]f7817822009-09-24 05:11:58137 case OLEIVERB_OPEN:
138 case OLEIVERB_UIACTIVATE:
[email protected]bc2ff5192010-06-01 22:05:45139 if (!m_bUIActive)
[email protected]f7817822009-09-24 05:11:58140 return doc_site_->ActivateMe(NULL);
[email protected]f7817822009-09-24 05:11:58141 break;
142 }
143 }
144 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
145 msg,
146 active_site,
147 index,
148 parent_window,
149 pos);
150}
151
[email protected]f7817822009-09-24 05:11:58152// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
153STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
[email protected]2b9a9f162010-10-19 20:30:45154 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58155 return S_OK;
156}
157
158STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
[email protected]2b9a9f162010-10-19 20:30:45159 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58160 if (msg == NULL)
161 return E_POINTER;
162
163 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
164 HWND focus = ::GetFocus();
165 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
166 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
167 // set focus to the correct element in Chrome.
168 ::SetFocus(m_hWnd);
169 return S_OK;
170 }
171 }
172
173 return S_FALSE;
174}
175// Override IPersistStorageImpl::IsDirty
176STDMETHODIMP ChromeActiveDocument::IsDirty() {
[email protected]2b9a9f162010-10-19 20:30:45177 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58178 return S_FALSE;
179}
180
[email protected]b95f550f2009-11-19 05:35:22181void ChromeActiveDocument::OnAutomationServerReady() {
[email protected]97965e12010-04-09 00:51:10182 BaseActiveX::OnAutomationServerReady();
[email protected]1fd45692010-04-19 21:01:18183 BaseActiveX::GiveFocusToChrome(true);
[email protected]b95f550f2009-11-19 05:35:22184}
185
[email protected]f7817822009-09-24 05:11:58186STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
187 IMoniker* moniker_name,
188 LPBC bind_context,
189 DWORD mode) {
[email protected]bc2ff5192010-06-01 22:05:45190 if (NULL == moniker_name)
[email protected]f7817822009-09-24 05:11:58191 return E_INVALIDARG;
[email protected]a1800e82009-11-19 00:53:23192
[email protected]8ee65ba2011-04-12 20:53:23193 base::win::ScopedComPtr<IOleClientSite> client_site;
[email protected]a1800e82009-11-19 00:53:23194 if (bind_context) {
[email protected]8ee65ba2011-04-12 20:53:23195 base::win::ScopedComPtr<IUnknown> site;
[email protected]a1800e82009-11-19 00:53:23196 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
197 site.Receive());
198 if (site)
199 client_site.QueryFrom(site);
200 }
201
202 if (client_site) {
203 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11204 DoQueryService(IID_INewWindowManager, client_site,
205 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14206
207 // See if mshtml parsed the html header for us. If so, we need to
208 // clear the browser service flag that we use to indicate that this
209 // browser instance is navigating to a CF document.
[email protected]8ee65ba2011-04-12 20:53:23210 base::win::ScopedComPtr<IBrowserService> browser_service;
[email protected]051236f2010-03-12 22:06:14211 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
212 if (browser_service) {
213 bool flagged = CheckForCFNavigation(browser_service, true);
[email protected]5044da82010-10-27 01:09:16214 DVLOG_IF(1, flagged) << "Cleared flagged browser service";
[email protected]051236f2010-03-12 22:06:14215 }
[email protected]a1800e82009-11-19 00:53:23216 }
217
[email protected]051236f2010-03-12 22:06:14218 NavigationManager* mgr = NavigationManager::GetThreadInstance();
[email protected]21b4e6d2010-07-14 18:19:59219 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
[email protected]7e3544b2010-01-22 00:02:34220
[email protected]29c32f902010-04-20 23:27:29221 std::wstring url;
222
[email protected]8ee65ba2011-04-12 20:53:23223 base::win::ScopedComPtr<BindContextInfo> info;
[email protected]77d7aee2010-05-14 20:31:55224 BindContextInfo::FromBindContext(bind_context, info.Receive());
[email protected]29c32f902010-04-20 23:27:29225 DCHECK(info);
[email protected]4f45d4582011-02-22 23:27:27226 if (info && !info->GetUrl().empty()) {
227 url = info->GetUrl();
[email protected]df0846a52011-02-23 03:29:58228 if (mgr) {
229 // If the original URL contains an anchor, then the URL queried
230 // from the protocol sink wrapper does not contain the anchor. To
231 // workaround this we retrieve the anchor from the navigation manager
232 // and append it to the url retrieved from the protocol sink wrapper.
233 GURL url_for_anchor(mgr->url());
234 if (url_for_anchor.has_ref()) {
235 url += L"#";
236 url += UTF8ToWide(url_for_anchor.ref());
237 }
238 }
[email protected]29c32f902010-04-20 23:27:29239 } else {
240 // If the original URL contains an anchor, then the URL queried
241 // from the moniker does not contain the anchor. To workaround
242 // this we retrieve the URL from our BHO.
243 url = GetActualUrlFromMoniker(moniker_name, bind_context,
244 mgr ? mgr->url(): std::wstring());
245 }
[email protected]051236f2010-03-12 22:06:14246
[email protected]c4e45b32010-07-28 21:15:15247 ChromeFrameUrl cf_url;
248 if (!cf_url.Parse(url)) {
[email protected]37346bc2009-09-25 22:54:33249 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58250 return E_INVALIDARG;
251 }
252
[email protected]bbfa9a12010-08-10 14:09:37253 std::string referrer(mgr ? mgr->referrer() : EmptyString());
[email protected]d8e13512010-09-22 17:02:58254 RendererType renderer_type = cf_url.is_chrome_protocol() ?
255 RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED;
[email protected]bbfa9a12010-08-10 14:09:37256
[email protected]aaf124502010-07-17 04:02:58257 // With CTransaction patch we have more robust way to grab the referrer for
258 // each top-level-switch-to-CF request by peeking at our sniffing data
[email protected]d8e13512010-09-22 17:02:58259 // object that lives inside the bind context. We also remember the reason
260 // we're rendering the document in Chrome.
[email protected]aaf124502010-07-17 04:02:58261 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
262 scoped_refptr<ProtData> prot_data = info->get_prot_data();
[email protected]d8e13512010-09-22 17:02:58263 if (prot_data) {
[email protected]aaf124502010-07-17 04:02:58264 referrer = prot_data->referrer();
[email protected]d8e13512010-09-22 17:02:58265 renderer_type = prot_data->renderer_type();
266 }
[email protected]aaf124502010-07-17 04:02:58267 }
268
[email protected]62ce09732010-09-03 18:32:04269 // For gcf: URLs allow only about and view-source schemes to pass through for
270 // further inspection.
271 bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) ||
272 cf_url.gurl().SchemeIs(chrome::kViewSourceScheme);
273 if (cf_url.is_chrome_protocol() && !is_safe_scheme &&
274 !GetConfigBool(false, kAllowUnsafeURLs)) {
275 DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url;
276 return E_INVALIDARG;
277 }
278
[email protected]c4e45b32010-07-28 21:15:15279 if (!LaunchUrl(cf_url, referrer)) {
[email protected]d266ce82010-08-13 21:33:40280 DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url;
[email protected]37346bc2009-09-25 22:54:33281 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58282 }
283
[email protected]c4e45b32010-07-28 21:15:15284 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
[email protected]d266ce82010-08-13 21:33:40285 url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context);
[email protected]f7817822009-09-24 05:11:58286
[email protected]d8e13512010-09-22 17:02:58287 // Log a metric indicating why GCF is rendering in Chrome.
288 // (Note: we only track the renderer type when using the CTransaction patch.
289 // When the code for the browser service patch and for the moniker patch is
290 // removed, this conditional can also go away.)
291 if (RENDERER_TYPE_UNDETERMINED != renderer_type) {
[email protected]92c79d32011-04-06 18:41:15292 UMA_LAUNCH_TYPE_COUNT(renderer_type);
[email protected]d8e13512010-09-22 17:02:58293 }
294
[email protected]f7817822009-09-24 05:11:58295 return S_OK;
296}
297
298STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
299 LPBC bind_context,
300 BOOL remember) {
301 return E_NOTIMPL;
302}
303
304STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
305 LPBC bind_context) {
306 return E_NOTIMPL;
307}
308
309STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
310 return E_NOTIMPL;
311}
312
313STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
[email protected]bc2ff5192010-06-01 22:05:45314 if (NULL == class_id)
[email protected]f7817822009-09-24 05:11:58315 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58316 *class_id = GetObjectCLSID();
317 return S_OK;
318}
319
320STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
321 ULONG number_of_commands,
322 OLECMD commands[],
323 OLECMDTEXT* command_text) {
[email protected]2b9a9f162010-10-19 20:30:45324 DVLOG(1) << __FUNCTION__;
[email protected]b509ec82010-04-13 16:53:06325
[email protected]6fd1a7a2010-07-26 22:09:46326 CommandStatusMap* command_map = NULL;
[email protected]b509ec82010-04-13 16:53:06327
[email protected]6fd1a7a2010-07-26 22:09:46328 if (cmd_group_guid) {
329 if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) {
330 command_map = &null_group_commands_map_;
331 } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) {
332 command_map = &mshtml_group_commands_map_;
333 } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) {
334 command_map = &explorer_group_commands_map_;
335 } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) {
336 command_map = &shdoc_view_group_commands_map_;
337 }
338 } else {
339 command_map = &null_group_commands_map_;
340 }
341
342 if (!command_map) {
[email protected]2b9a9f162010-10-19 20:30:45343 DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid);
[email protected]b509ec82010-04-13 16:53:06344 return OLECMDERR_E_NOTSUPPORTED;
345 }
346
[email protected]f7817822009-09-24 05:11:58347 for (ULONG command_index = 0; command_index < number_of_commands;
348 command_index++) {
[email protected]2b9a9f162010-10-19 20:30:45349 DVLOG(1) << "Command id = " << commands[command_index].cmdID;
[email protected]6fd1a7a2010-07-26 22:09:46350 CommandStatusMap::iterator index =
351 command_map->find(commands[command_index].cmdID);
352 if (index != command_map->end())
353 commands[command_index].cmdf = index->second;
[email protected]f7817822009-09-24 05:11:58354 }
355 return S_OK;
356}
357
358STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
359 DWORD command_id,
360 DWORD cmd_exec_opt,
361 VARIANT* in_args,
362 VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:45363 DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id;
[email protected]f7817822009-09-24 05:11:58364 // Bail out if we have been uninitialized.
365 if (automation_client_.get() && automation_client_->tab()) {
366 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
367 in_args, out_args);
[email protected]bbfa9a12010-08-10 14:09:37368 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
369 // If the automation server has crashed and the user is refreshing the
370 // page, let OnRefreshPage attempt to recover.
371 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
[email protected]f7817822009-09-24 05:11:58372 }
[email protected]bbfa9a12010-08-10 14:09:37373
[email protected]e3200932009-10-09 21:33:03374 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58375}
376
[email protected]a1800e82009-11-19 00:53:23377STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
378 IBindCtx* bind_context) {
379 // Read notes in ChromeActiveDocument::SaveHistory
380 DCHECK(stream);
381 LARGE_INTEGER offset = {0};
382 ULARGE_INTEGER cur_pos = {0};
383 STATSTG statstg = {0};
384
385 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
386 stream->Stat(&statstg, STATFLAG_NONAME);
387
388 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
[email protected]965722ff2010-10-20 15:50:30389 base::win::ScopedBstr url_bstr;
[email protected]a1800e82009-11-19 00:53:23390 DWORD bytes_read = 0;
391 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
392 std::wstring url(url_bstr);
393
[email protected]c4e45b32010-07-28 21:15:15394 ChromeFrameUrl cf_url;
395 if (!cf_url.Parse(url)) {
[email protected]a1800e82009-11-19 00:53:23396 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
397 return E_INVALIDARG;
398 }
399
[email protected]c5cbf4e2010-07-15 21:48:25400 const std::string& referrer = EmptyString();
[email protected]c4e45b32010-07-28 21:15:15401 if (!LaunchUrl(cf_url, referrer)) {
[email protected]a1800e82009-11-19 00:53:23402 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
403 return E_INVALIDARG;
404 }
405 return S_OK;
406}
407
408STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
409 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
410 // from Chrome and persist it in the stream. And in LoadHistory we need to
411 // pass this list back to Chrome which will recreate the list. This will allow
412 // Back-Forward navigation to anchors to work correctly when we navigate to a
413 // page outside of ChromeFrame and then come back.
414 if (!stream) {
415 NOTREACHED();
416 return E_INVALIDARG;
417 }
418
419 LARGE_INTEGER offset = {0};
420 ULARGE_INTEGER new_pos = {0};
421 DWORD written = 0;
[email protected]a22f7e02011-02-09 07:15:35422 std::wstring url = UTF8ToWide(navigation_info_->url.spec());
[email protected]a1800e82009-11-19 00:53:23423 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
424 &written);
425}
426
427STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
[email protected]77700832010-04-27 00:06:03428 if (automation_client_.get()) {
429 int index = static_cast<int>(position_cookie);
[email protected]a22f7e02011-02-09 07:15:35430 navigation_info_->navigation_index = index;
[email protected]77700832010-04-27 00:06:03431 automation_client_->NavigateToIndex(index);
432 } else {
433 DLOG(WARNING) << "Invalid automation client instance";
434 }
[email protected]a1800e82009-11-19 00:53:23435 return S_OK;
436}
437
438STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
439 if (!position_cookie)
440 return E_INVALIDARG;
441
[email protected]a22f7e02011-02-09 07:15:35442 *position_cookie = navigation_info_->navigation_index;
[email protected]a1800e82009-11-19 00:53:23443 return S_OK;
444}
445
[email protected]f7817822009-09-24 05:11:58446STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
[email protected]bc2ff5192010-06-01 22:05:45447 if (NULL == url)
[email protected]f7817822009-09-24 05:11:58448 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58449 *url = ::SysAllocString(url_);
450 return S_OK;
451}
452
[email protected]a1800e82009-11-19 00:53:23453STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
454 return GetUrlForEvents(url);
455}
456
[email protected]80b5a8d2010-03-19 16:50:43457STDMETHODIMP ChromeActiveDocument::Reset() {
458 next_privacy_record_ = privacy_info_.privacy_records.begin();
459 return S_OK;
460}
461
[email protected]00aebd72010-07-16 14:44:32462STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) {
[email protected]80b5a8d2010-03-19 16:50:43463 if (!size)
464 return E_POINTER;
465
466 *size = privacy_info_.privacy_records.size();
467 return S_OK;
468}
469
470STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
471 if (!privacy_impacted)
472 return E_POINTER;
473
474 *privacy_impacted = privacy_info_.privacy_impacted;
475 return S_OK;
476}
477
478STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
[email protected]00aebd72010-07-16 14:44:32479 LONG* reserved, DWORD* flags) {
[email protected]80b5a8d2010-03-19 16:50:43480 if (!url || !policy || !flags)
481 return E_POINTER;
482
483 if (next_privacy_record_ == privacy_info_.privacy_records.end())
484 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
485
486 *url = SysAllocString(next_privacy_record_->first.c_str());
487 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
488 *flags = next_privacy_record_->second.flags;
489
490 next_privacy_record_++;
491 return S_OK;
492}
493
[email protected]354bcba2010-12-14 04:34:43494bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) {
495 bool allowed = BaseActiveX::IsSchemeAllowed(url);
496 if (allowed)
497 return true;
498
499 if (url.SchemeIs(chrome::kAboutScheme)) {
500 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL))
501 return true;
502 }
503 return false;
504}
505
[email protected]3eafbfb92010-08-02 16:54:22506HRESULT ChromeActiveDocument::GetInPlaceFrame(
507 IOleInPlaceFrame** in_place_frame) {
508 DCHECK(in_place_frame);
509 if (in_place_frame_) {
510 *in_place_frame = in_place_frame_.get();
511 (*in_place_frame)->AddRef();
512 return S_OK;
513 } else {
514 return S_FALSE;
515 }
516}
517
[email protected]f7817822009-09-24 05:11:58518HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
519 IOleClientSite* client_site) {
520 if (client_site == NULL) {
[email protected]8ee65ba2011-04-12 20:53:23521 base::win::ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]bc2ff5192010-06-01 22:05:45522 if (doc_site_)
[email protected]77059f72010-02-28 06:16:00523 doc_host_handler.QueryFrom(doc_site_);
[email protected]dda7d9c2009-11-11 23:01:47524
[email protected]bc2ff5192010-06-01 22:05:45525 if (doc_host_handler.get())
[email protected]dda7d9c2009-11-11 23:01:47526 doc_host_handler->HideUI();
[email protected]dda7d9c2009-11-11 23:01:47527
528 doc_site_.Release();
[email protected]f7817822009-09-24 05:11:58529 }
[email protected]a1800e82009-11-19 00:53:23530
[email protected]bc2ff5192010-06-01 22:05:45531 if (client_site != m_spClientSite)
[email protected]97965e12010-04-09 00:51:10532 return BaseActiveX::IOleObject_SetClientSite(client_site);
[email protected]a1800e82009-11-19 00:53:23533
534 return S_OK;
[email protected]f7817822009-09-24 05:11:58535}
536
[email protected]f7817822009-09-24 05:11:58537HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
538 HRESULT hr = S_OK;
539 m_bNegotiatedWnd = TRUE;
540 if (!m_bInPlaceActive) {
541 hr = m_spInPlaceSite->CanInPlaceActivate();
[email protected]bc2ff5192010-06-01 22:05:45542 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58543 return hr;
[email protected]f7817822009-09-24 05:11:58544 m_spInPlaceSite->OnInPlaceActivate();
545 }
546 m_bInPlaceActive = TRUE;
547 // get location in the parent window,
548 // as well as some information about the parent
[email protected]8ee65ba2011-04-12 20:53:23549 base::win::ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
[email protected]f7817822009-09-24 05:11:58550 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
551 HWND parent_window = NULL;
552 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
553 in_place_frame_.Release();
554 RECT position_rect = {0};
555 RECT clip_rect = {0};
556 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
557 in_place_ui_window.Receive(),
558 &position_rect,
559 &clip_rect,
560 &frame_info_);
561 if (!m_bWndLess) {
562 if (IsWindow()) {
563 ::ShowWindow(m_hWnd, SW_SHOW);
564 SetFocus();
565 } else {
[email protected]fca446b92011-02-18 20:44:06566 m_hWnd = Create(parent_window, position_rect);
[email protected]dd4beb522010-07-13 18:18:14567 if (!IsWindow()) {
568 // This might happen if the automation server couldn't be
569 // instantiated. If so, a NOTREACHED() will have already been hit.
570 DLOG(ERROR) << "Failed to create Ax window";
571 return AtlHresultFromLastError();
572 }
[email protected]f7817822009-09-24 05:11:58573 }
574 }
575 SetObjectRects(&position_rect, &clip_rect);
576 }
577
[email protected]8ee65ba2011-04-12 20:53:23578 base::win::ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
[email protected]f7817822009-09-24 05:11:58579
580 // Gone active by now, take care of UIACTIVATE
581 if (DoesVerbUIActivate(verb)) {
582 if (!m_bUIActive) {
583 m_bUIActive = TRUE;
584 hr = m_spInPlaceSite->OnUIActivate();
[email protected]bc2ff5192010-06-01 22:05:45585 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58586 return hr;
[email protected]f7817822009-09-24 05:11:58587 // set ourselves up in the host
588 if (in_place_active_object) {
[email protected]bc2ff5192010-06-01 22:05:45589 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58590 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
[email protected]bc2ff5192010-06-01 22:05:45591 if (in_place_ui_window)
[email protected]f7817822009-09-24 05:11:58592 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
[email protected]f7817822009-09-24 05:11:58593 }
594 }
595 }
596 m_spClientSite->ShowObject();
597 return S_OK;
598}
599
[email protected]f5494d42010-12-23 22:15:34600void ChromeActiveDocument::OnNavigationStateChanged(
601 int flags, const NavigationInfo& nav_info) {
[email protected]f7817822009-09-24 05:11:58602 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
[email protected]2b9a9f162010-10-19 20:30:45603 DVLOG(1) << __FUNCTION__
604 << "\n Flags: " << flags
605 << ", Url: " << nav_info.url
606 << ", Title: " << nav_info.title
607 << ", Type: " << nav_info.navigation_type
608 << ", Relative Offset: " << nav_info.relative_offset
609 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58610
[email protected]747bca12011-01-15 00:28:45611 UpdateNavigationState(nav_info, flags);
[email protected]f7817822009-09-24 05:11:58612}
613
[email protected]f5494d42010-12-23 22:15:34614void ChromeActiveDocument::OnUpdateTargetUrl(
[email protected]f7817822009-09-24 05:11:58615 const std::wstring& new_target_url) {
[email protected]bc2ff5192010-06-01 22:05:45616 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58617 in_place_frame_->SetStatusText(new_target_url.c_str());
[email protected]f7817822009-09-24 05:11:58618}
619
620bool IsFindAccelerator(const MSG& msg) {
621 // TODO(robertshield): This may not stand up to localization. Fix if this
622 // is the case.
623 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
[email protected]a8e20582010-12-31 17:18:50624 base::win::IsCtrlPressed() &&
625 !(base::win::IsAltPressed() || base::win::IsShiftPressed());
[email protected]f7817822009-09-24 05:11:58626}
627
[email protected]f5494d42010-12-23 22:15:34628void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35629 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
630 const_cast<MSG*>(&accel_message)))
631 return;
632
[email protected]f7817822009-09-24 05:11:58633 bool handled_accel = false;
634 if (in_place_frame_ != NULL) {
635 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
636 const_cast<MSG*>(&accel_message), 0));
637 }
638
639 if (!handled_accel) {
640 if (IsFindAccelerator(accel_message)) {
641 // Handle the showing of the find dialog explicitly.
642 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59643 } else {
[email protected]f5494d42010-12-23 22:15:34644 BaseActiveX::OnAcceleratorPressed(accel_message);
[email protected]f7817822009-09-24 05:11:58645 }
646 } else {
[email protected]2b9a9f162010-10-19 20:30:45647 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
[email protected]f7817822009-09-24 05:11:58648 }
649}
650
[email protected]f5494d42010-12-23 22:15:34651void ChromeActiveDocument::OnTabbedOut(bool reverse) {
[email protected]2b9a9f162010-10-19 20:30:45652 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58653 if (in_place_frame_) {
654 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
655 in_place_frame_->TranslateAcceleratorW(&msg, 0);
656 }
657}
658
[email protected]f5494d42010-12-23 22:15:34659void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
[email protected]2b9a9f162010-10-19 20:30:45660 DVLOG(1) << __FUNCTION__ << std::endl
661 << "Url: " << nav_info.url
662 << ", Title: " << nav_info.title
663 << ", Type: " << nav_info.navigation_type
664 << ", Relative Offset: " << nav_info.relative_offset
665 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58666
[email protected]897b26272010-06-11 02:23:44667 CrashMetricsReporter::GetInstance()->IncrementMetric(
668 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
669
[email protected]747bca12011-01-15 00:28:45670 UpdateNavigationState(nav_info, 0);
[email protected]f7817822009-09-24 05:11:58671}
672
[email protected]f5494d42010-12-23 22:15:34673void ChromeActiveDocument::OnCloseTab() {
[email protected]2f1793ea2010-10-27 17:32:51674 // Base class will fire DIChromeFrameEvents::onclose.
[email protected]f5494d42010-12-23 22:15:34675 BaseActiveX::OnCloseTab();
[email protected]2f1793ea2010-10-27 17:32:51676
677 // Close the container window.
[email protected]8ee65ba2011-04-12 20:53:23678 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]e16dd1672010-06-07 21:40:29679 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
680 if (web_browser2)
681 web_browser2->Quit();
682}
683
[email protected]f7817822009-09-24 05:11:58684void ChromeActiveDocument::UpdateNavigationState(
[email protected]747bca12011-01-15 00:28:45685 const NavigationInfo& new_navigation_info, int flags) {
[email protected]326d3b72011-03-29 20:38:24686 // This could be NULL if the active document instance is being destroyed.
687 if (!m_spInPlaceSite) {
688 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
689 return;
690 }
691
[email protected]a1800e82009-11-19 00:53:23692 HRESULT hr = S_OK;
[email protected]a22f7e02011-02-09 07:15:35693 bool is_title_changed =
694 (navigation_info_->title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58695 bool is_ssl_state_changed =
[email protected]a22f7e02011-02-09 07:15:35696 (navigation_info_->security_style !=
697 new_navigation_info.security_style) ||
698 (navigation_info_->displayed_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48699 new_navigation_info.displayed_insecure_content) ||
[email protected]a22f7e02011-02-09 07:15:35700 (navigation_info_->ran_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48701 new_navigation_info.ran_insecure_content);
[email protected]f7817822009-09-24 05:11:58702
[email protected]f7817822009-09-24 05:11:58703 if (is_ssl_state_changed) {
704 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23705 switch (new_navigation_info.security_style) {
[email protected]cfa79d762011-10-21 00:15:04706 case content::SECURITY_STYLE_AUTHENTICATED:
[email protected]b4e75c12010-05-18 18:28:48707 lock_status = new_navigation_info.displayed_insecure_content ?
[email protected]f7817822009-09-24 05:11:58708 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
709 break;
710 default:
711 break;
712 }
713
[email protected]965722ff2010-10-20 15:50:30714 base::win::ScopedVariant secure_lock_status(lock_status);
[email protected]f7817822009-09-24 05:11:58715 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
716 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
717 }
718
[email protected]a17930d82011-02-11 23:12:35719 // A number of poorly written bho's crash in their event sink callbacks if
720 // chrome frame is the currently loaded document. This is because they expect
721 // chrome frame to implement interfaces like IHTMLDocument, etc. We patch the
722 // event sink's of these bho's and don't invoke the event sink if chrome
723 // frame is the currently loaded document.
724 if (GetConfigBool(true, kEnableBuggyBhoIntercept)) {
[email protected]8ee65ba2011-04-12 20:53:23725 base::win::ScopedComPtr<IWebBrowser2> wb2;
[email protected]a17930d82011-02-11 23:12:35726 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
727 if (wb2 && buggy_bho::BuggyBhoTls::GetInstance()) {
728 buggy_bho::BuggyBhoTls::GetInstance()->PatchBuggyBHOs(wb2);
729 }
730 }
731
[email protected]a1800e82009-11-19 00:53:23732 // Ideally all navigations should come to Chrome Frame so that we can call
733 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
734 // navigation. However, in practice what happens is as below:
735 // The very first navigation that happens in CF happens via a Load or a
736 // LoadHistory call. In this case, IE already has the correct information for
737 // its travel log as well address bar. For other internal navigations (navs
738 // that only happen within Chrome such as anchor navigations) we need to
739 // update IE's internal state after the fact. In the case of internal
740 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58741
742 // Another case where we need to issue BeforeNavigate2 calls is as below:-
743 // We get notified after the fact, when navigations are initiated within
744 // Chrome via window.open calls. These navigations are handled by creating
745 // an external tab container within chrome and then connecting to it from IE.
746 // We still want to update the address bar/history, etc, to ensure that
747 // the special URL used by Chrome to indicate this is updated correctly.
[email protected]d266ce82010-08-13 21:33:40748 ChromeFrameUrl cf_url;
749 bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) &&
750 cf_url.attach_to_external_tab();
[email protected]342de552010-10-21 20:46:14751
752 bool is_internal_navigation =
[email protected]747bca12011-01-15 00:28:45753 IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url;
[email protected]f7817822009-09-24 05:11:58754
[email protected]bc2ff5192010-06-01 22:05:45755 if (new_navigation_info.url.is_valid())
[email protected]38939de2010-05-13 02:32:06756 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]38939de2010-05-13 02:32:06757
[email protected]a1800e82009-11-19 00:53:23758 if (is_internal_navigation) {
[email protected]74b1eaf542011-10-05 19:34:27759 // IE6 does not support tabs. If Chrome sent us a window open request
760 // indicating that the navigation needs to occur in a foreground tab or
761 // a popup window, then we need to ensure that the new window in IE6 is
762 // brought to the foreground.
763 if (GetIEVersion() == IE_6 &&
764 is_attach_external_tab_url &&
765 (cf_url.disposition() == NEW_FOREGROUND_TAB ||
766 cf_url.disposition() == NEW_POPUP)) {
767 base::win::ScopedComPtr<IWebBrowser2> wb2;
768 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
769 if (wb2)
770 BaseActiveX::BringWebBrowserWindowToTop(wb2);
771 }
[email protected]8ee65ba2011-04-12 20:53:23772 base::win::ScopedComPtr<IDocObjectService> doc_object_svc;
773 base::win::ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06774
[email protected]f7817822009-09-24 05:11:58775 DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite,
776 web_browser_events_svc.Receive());
[email protected]ae33d672010-03-04 21:58:06777
778 if (!web_browser_events_svc.get()) {
779 DoQueryService(SID_SShellBrowser, m_spClientSite,
780 doc_object_svc.Receive());
781 }
782
[email protected]62bb18dc12009-11-25 01:34:08783 // web_browser_events_svc can be NULL on IE6.
[email protected]f7817822009-09-24 05:11:58784 if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58785 VARIANT_BOOL should_cancel = VARIANT_FALSE;
786 web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel);
[email protected]33bd26d2010-08-31 05:05:03787 } else if (doc_object_svc) {
788 BOOL should_cancel = FALSE;
789 doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0,
790 NULL, FALSE, &should_cancel);
[email protected]a1800e82009-11-19 00:53:23791 }
792
793 // We need to tell IE that we support navigation so that IE will query us
794 // for IPersistHistory and call GetPositionCookie to save our navigation
795 // index.
[email protected]965722ff2010-10-20 15:50:30796 base::win::ScopedVariant html_window(static_cast<IUnknown*>(
[email protected]a1800e82009-11-19 00:53:23797 static_cast<IHTMLWindow2*>(this)));
798 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
799 html_window.AsInput(), NULL);
800
801 // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG
802 // since we want to make IE treat all internal navigations within this page
803 // (including anchor navigations and subframe navigations) as anchor
804 // navigations. This will ensure that IE calls GetPositionCookie
805 // to save the current position cookie in the travel log and then call
806 // SetPositionCookie when the user hits Back/Forward to come back here.
[email protected]965722ff2010-10-20 15:50:30807 base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP);
[email protected]a1800e82009-11-19 00:53:23808 IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0,
809 internal_navigation.AsInput(), NULL);
810
811 // We no longer need to lie to IE. If we lie persistently to IE, then
812 // IE reuses us for new navigations.
813 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL);
814
815 if (doc_object_svc) {
816 // Now call the FireNavigateCompleteEvent which makes IE update the text
817 // in the address-bar.
818 doc_object_svc->FireNavigateComplete2(this, 0);
[email protected]5ae94d22010-07-21 19:55:36819 doc_object_svc->FireDocumentComplete(this, 0);
[email protected]a1800e82009-11-19 00:53:23820 } else if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58821 web_browser_events_svc->FireNavigateComplete2Event();
[email protected]5ae94d22010-07-21 19:55:36822 web_browser_events_svc->FireDocumentCompleteEvent();
[email protected]f7817822009-09-24 05:11:58823 }
824 }
[email protected]37346bc2009-09-25 22:54:33825
[email protected]a1800e82009-11-19 00:53:23826 if (is_title_changed) {
[email protected]965722ff2010-10-20 15:50:30827 base::win::ScopedVariant title(new_navigation_info.title.c_str());
[email protected]a1800e82009-11-19 00:53:23828 IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
829 title.AsInput(), NULL);
830 }
831
832 // It is important that we only update the navigation_info_ after we have
833 // finalized the travel log. This is because IE will ask for information
834 // such as navigation index when the travel log is finalized and we need
835 // supply the old index and not the new one.
[email protected]a22f7e02011-02-09 07:15:35836 *navigation_info_ = new_navigation_info;
[email protected]37346bc2009-09-25 22:54:33837 // Update the IE zone here. Ideally we would like to do it when the active
838 // document is activated. However that does not work at times as the frame we
839 // get there is not the actual frame which handles the command.
840 IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL);
[email protected]f7817822009-09-24 05:11:58841}
842
843void ChromeActiveDocument::OnFindInPage() {
844 TabProxy* tab = GetTabProxy();
845 if (tab) {
[email protected]bc2ff5192010-06-01 22:05:45846 if (!find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58847 find_dialog_.Create(m_hWnd);
[email protected]f7817822009-09-24 05:11:58848
849 find_dialog_.ShowWindow(SW_SHOW);
850 }
851}
852
853void ChromeActiveDocument::OnViewSource() {
[email protected]a22f7e02011-02-09 07:15:35854 DCHECK(navigation_info_->url.is_valid());
[email protected]76e7da22010-06-18 22:44:49855 HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") +
[email protected]a22f7e02011-02-09 07:15:35856 navigation_info_->url.spec()), GURL(), NEW_WINDOW);
[email protected]f7817822009-09-24 05:11:58857}
858
[email protected]37346bc2009-09-25 22:54:33859void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid,
860 DWORD command_id,
861 DWORD cmd_exec_opt,
862 VARIANT* in_args,
863 VARIANT* out_args) {
[email protected]7c712c92010-03-24 17:29:22864 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
865 // Correct step is to use MapUrlToZone().
[email protected]37346bc2009-09-25 22:54:33866 if (out_args != NULL) {
867 out_args->vt = VT_UI4;
868 out_args->ulVal = URLZONE_INTERNET;
869 }
870}
871
[email protected]80b5a8d2010-03-19 16:50:43872void ChromeActiveDocument::OnDisplayPrivacyInfo() {
[email protected]bbfa9a12010-08-10 14:09:37873 privacy_info_ = url_fetcher_->privacy_info();
[email protected]80b5a8d2010-03-19 16:50:43874 Reset();
875 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
876}
877
[email protected]7f860dd82010-08-09 23:18:05878void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid,
879 DWORD command_id,
880 DWORD cmd_exec_opt,
881 VARIANT* in_args,
882 VARIANT* out_args) {
883 if (out_args != NULL) {
884 out_args->vt = VT_I4;
885 out_args->lVal = 0;
886 }
887}
888
889void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid,
890 DWORD command_id,
891 DWORD cmd_exec_opt,
892 VARIANT* in_args,
893 VARIANT* out_args) {
894 const int kZoomIn = 125;
895 const int kZoomOut = 75;
896
897 if (in_args && V_VT(in_args) == VT_I4 && IsValid()) {
898 if (in_args->lVal == kZoomIn) {
899 automation_client_->SetZoomLevel(PageZoom::ZOOM_IN);
900 } else if (in_args->lVal == kZoomOut) {
901 automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT);
902 } else {
903 DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal;
904 }
905 }
906}
907
[email protected]d9d8f0c2010-09-17 21:47:16908void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid,
909 DWORD command_id,
910 DWORD cmd_exec_opt,
911 VARIANT* in_args,
912 VARIANT* out_args) {
913 if (IsValid() && out_args) {
[email protected]9ae7b912011-06-30 21:41:25914 // If the navigation is attempted to the url loaded in CF, with the only
915 // difference being the addition of an anchor, IE will attempt to unload
916 // the currently loaded document which basically would end up running
917 // unload handlers on the currently loaded document thus rendering it non
918 // functional. We handle this as below:-
919 // The BHO receives the new url in the BeforeNavigate event.
920 // We compare the non anchor portions of the url in the BHO with the loaded
921 // url and if they match, we initiate a Chrome navigation to the url with
922 // the anchor which works nicely.
923 // We don't want to continue processing the unload in this case.
924 // Note:-
925 // IE handles these navigations by querying the loaded document for
926 // IHTMLDocument which then handles the new navigation. That won't work for
927 // us as we don't implement IHTMLDocument.
928 NavigationManager* mgr = NavigationManager::GetThreadInstance();
929 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
930 if (mgr) {
931 ChromeFrameUrl url;
932 url.Parse(mgr->url());
933 if (url.gurl().has_ref()) {
934 url_canon::Replacements<char> replacements;
935 replacements.ClearRef();
936
937 if (url.gurl().ReplaceComponents(replacements) ==
938 GURL(static_cast<BSTR>(url_))) {
939 // We want to reuse the existing automation client and channel for
940 // initiating the new navigation. Setting the
941 // is_automation_client_reused_ flag to true before calling the
942 // LaunchUrl function achieves that.
943 is_automation_client_reused_ = true;
944 LaunchUrl(url, mgr->referrer());
945 out_args->vt = VT_BOOL;
946 out_args->boolVal = VARIANT_FALSE;
947 return;
948 }
949 }
950 }
[email protected]d9d8f0c2010-09-17 21:47:16951 bool should_unload = true;
952 automation_client_->OnUnload(&should_unload);
953 out_args->vt = VT_BOOL;
954 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
955 }
956}
957
[email protected]f5494d42010-12-23 22:15:34958void ChromeActiveDocument::OnAttachExternalTab(
959 const AttachExternalTabParams& params) {
[email protected]77700832010-04-27 00:06:03960 if (!automation_client_.get()) {
961 DLOG(WARNING) << "Invalid automation client instance";
962 return;
963 }
[email protected]b1c55638612010-03-08 16:26:11964 DWORD flags = 0;
965 if (params.user_gesture)
966 flags = NWMF_USERREQUESTED;
[email protected]355309e2010-03-15 17:01:34967 else if (popup_allowed_)
968 flags = NWMF_USERALLOWED;
[email protected]b1c55638612010-03-08 16:26:11969
970 HRESULT hr = S_OK;
971 if (popup_manager_) {
[email protected]e4456ae2010-09-22 23:35:11972 const std::wstring& url_wide = UTF8ToWide(params.url.spec());
973 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_,
[email protected]355309e2010-03-15 17:01:34974 NULL, FALSE, flags, 0);
[email protected]b1c55638612010-03-08 16:26:11975 }
976 // Allow popup
977 if (hr == S_OK) {
[email protected]f5494d42010-12-23 22:15:34978 BaseActiveX::OnAttachExternalTab(params);
[email protected]b1c55638612010-03-08 16:26:11979 return;
980 }
981
982 automation_client_->BlockExternalTab(params.cookie);
983}
984
[email protected]f7817822009-09-24 05:11:58985bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
[email protected]8ee65ba2011-04-12 20:53:23986 base::win::ScopedComPtr<IBrowserService> browser_service;
987 base::win::ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:23988 GetBrowserServiceAndTravelLog(browser_service.Receive(),
989 travel_log.Receive());
990 if (!browser_service || !travel_log)
[email protected]f7817822009-09-24 05:11:58991 return true;
992
[email protected]d118f542010-11-05 18:50:31993 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND |
994 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK,
995 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:45996 MF_ENABLED : MF_DISABLED));
[email protected]d118f542010-11-05 18:50:31997 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND |
998 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE,
999 NULL)) ?
[email protected]bc2ff5192010-06-01 22:05:451000 MF_ENABLED : MF_DISABLED));
[email protected]f7817822009-09-24 05:11:581001 // Call base class (adds 'About' item)
[email protected]97965e12010-04-09 00:51:101002 return BaseActiveX::PreProcessContextMenu(menu);
[email protected]f7817822009-09-24 05:11:581003}
1004
[email protected]f5494d42010-12-23 22:15:341005bool ChromeActiveDocument::HandleContextMenuCommand(
1006 UINT cmd, const MiniContextMenuParams& params) {
[email protected]8ee65ba2011-04-12 20:53:231007 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]f7817822009-09-24 05:11:581008 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1009
[email protected]074283a2010-05-28 23:47:591010 if (cmd == IDC_BACK)
[email protected]b731a142010-05-14 00:03:031011 web_browser2->GoBack();
[email protected]074283a2010-05-28 23:47:591012 else if (cmd == IDC_FORWARD)
[email protected]b731a142010-05-14 00:03:031013 web_browser2->GoForward();
[email protected]074283a2010-05-28 23:47:591014 else if (cmd == IDC_RELOAD)
[email protected]b731a142010-05-14 00:03:031015 web_browser2->Refresh();
[email protected]074283a2010-05-28 23:47:591016 else
[email protected]b731a142010-05-14 00:03:031017 return BaseActiveX::HandleContextMenuCommand(cmd, params);
[email protected]f7817822009-09-24 05:11:581018
1019 return true;
1020}
1021
1022HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid,
1023 DWORD command_id, DWORD cmd_exec_opt,
1024 VARIANT* in_args, VARIANT* out_args) {
1025 HRESULT hr = E_FAIL;
[email protected]37346bc2009-09-25 22:54:331026
[email protected]8ee65ba2011-04-12 20:53:231027 base::win::ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:331028
[email protected]8ee65ba2011-04-12 20:53:231029 base::win::ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite);
[email protected]bc2ff5192010-06-01 22:05:451030 if (!in_place_site.get() && m_spClientSite != NULL)
[email protected]37346bc2009-09-25 22:54:331031 in_place_site.QueryFrom(m_spClientSite);
[email protected]37346bc2009-09-25 22:54:331032
1033 if (in_place_site)
1034 hr = frame_cmd_target.QueryFrom(in_place_site);
[email protected]f7817822009-09-24 05:11:581035
[email protected]bc2ff5192010-06-01 22:05:451036 if (frame_cmd_target) {
[email protected]f7817822009-09-24 05:11:581037 hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt,
1038 in_args, out_args);
[email protected]bc2ff5192010-06-01 22:05:451039 }
[email protected]f7817822009-09-24 05:11:581040
1041 return hr;
1042}
[email protected]37346bc2009-09-25 22:54:331043
[email protected]c4e45b32010-07-28 21:15:151044bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url,
1045 const std::string& referrer) {
[email protected]d266ce82010-08-13 21:33:401046 DCHECK(!cf_url.gurl().is_empty());
[email protected]77700832010-04-27 00:06:031047
[email protected]242ceb032010-08-26 17:06:361048 if (!automation_client_.get()) {
1049 // http://code.google.com/p/chromium/issues/detail?id=52894
1050 // Still not sure how this happens.
1051 DLOG(ERROR) << "No automation client!";
1052 if (!Initialize()) {
1053 NOTREACHED() << "...and failed to start a new one >:(";
1054 return false;
1055 }
1056 }
1057
[email protected]93b792792011-06-07 23:00:011058 document_url_ = cf_url.gurl().spec();
1059
[email protected]d266ce82010-08-13 21:33:401060 url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str());
[email protected]c4e45b32010-07-28 21:15:151061 if (cf_url.attach_to_external_tab()) {
[email protected]c4e45b32010-07-28 21:15:151062 automation_client_->AttachExternalTab(cf_url.cookie());
[email protected]326d3b72011-03-29 20:38:241063 OnMoveWindow(cf_url.dimensions());
[email protected]d266ce82010-08-13 21:33:401064 } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(),
[email protected]6f8f31d2010-07-30 08:17:151065 referrer,
[email protected]354bcba2010-12-14 04:34:431066 this)) {
[email protected]6f8f31d2010-07-30 08:17:151067 DLOG(ERROR) << "Invalid URL: " << url_;
1068 Error(L"Invalid URL");
1069 url_.Reset();
1070 return false;
[email protected]37346bc2009-09-25 22:54:331071 }
1072
[email protected]3eb07da2010-02-01 19:48:361073 if (is_automation_client_reused_)
1074 return true;
[email protected]37346bc2009-09-25 22:54:331075
[email protected]bbfa9a12010-08-10 14:09:371076 automation_client_->SetUrlFetcher(url_fetcher_.get());
[email protected]701142a2010-08-31 20:57:071077 if (launch_params_) {
1078 return automation_client_->Initialize(this, launch_params_);
1079 } else {
[email protected]8103c7f2010-09-08 22:36:091080 std::wstring profile = UTF8ToWide(cf_url.profile_name());
1081 // If no profile was given, then make use of the host process's name.
1082 if (profile.empty())
1083 profile = GetHostProcessName(false);
1084 return InitializeAutomation(profile, L"", IsIEInPrivate(),
[email protected]9eeb35e2010-09-30 21:38:501085 false, cf_url.gurl(), GURL(referrer),
1086 false);
[email protected]701142a2010-08-31 20:57:071087 }
[email protected]37346bc2009-09-25 22:54:331088}
[email protected]1bb5f892009-10-06 01:44:571089
[email protected]355309e2010-03-15 17:01:341090HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1091 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:451092 DVLOG(1) << __FUNCTION__;
[email protected]355309e2010-03-15 17:01:341093 popup_allowed_ = false;
1094 if (in_args->vt == VT_I4 &&
1095 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1096 popup_allowed_ = true;
1097
1098 // Ask the yellow security band to change the text and icon and to remain
1099 // visible.
1100 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
[email protected]bbfa9a12010-08-10 14:09:371101 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
[email protected]355309e2010-03-15 17:01:341102 }
1103
[email protected]3eb8a70492010-12-03 21:32:191104 NavigationManager* mgr = NavigationManager::GetThreadInstance();
1105 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
1106
1107 // If ChromeFrame was activated on this page as a result of a document
1108 // received in response to a top level post, then we ask the user for
1109 // permission to repost and issue a navigation with the saved post data
1110 // which reinitates the whole sequence, i.e. the server receives the top
1111 // level post and chrome frame will be reactivated in response.
1112 if (mgr && mgr->post_data().type() != VT_EMPTY) {
1113 if (MessageBox(
1114 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING).c_str(),
1115 SimpleResourceLoader::Get(IDS_HTTP_POST_WARNING_TITLE).c_str(),
1116 MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
1117 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
1118 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1119 web_browser2.Receive());
1120 DCHECK(web_browser2);
1121 VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
1122 VARIANT flags = { VT_I4 };
1123 V_I4(&flags) = navNoHistory;
1124
1125 return web_browser2->Navigate2(base::win::ScopedVariant(url_).AsInput(),
1126 &flags,
1127 &empty,
1128 const_cast<VARIANT*>(&mgr->post_data()),
1129 const_cast<VARIANT*>(&mgr->headers()));
1130 } else {
1131 return S_OK;
1132 }
1133 }
1134
[email protected]355309e2010-03-15 17:01:341135 TabProxy* tab_proxy = GetTabProxy();
[email protected]bbfa9a12010-08-10 14:09:371136 if (tab_proxy) {
[email protected]355309e2010-03-15 17:01:341137 tab_proxy->ReloadAsync();
[email protected]bbfa9a12010-08-10 14:09:371138 } else {
1139 DLOG(ERROR) << "No automation proxy";
[email protected]242ceb032010-08-26 17:06:361140 DCHECK(automation_client_.get() != NULL) << "how did it get freed?";
[email protected]bbfa9a12010-08-10 14:09:371141 // The current url request manager (url_fetcher_) has been switched to
1142 // a stopping state so we need to reset it and get a new one for the new
1143 // automation server.
1144 ResetUrlRequestManager();
1145 url_fetcher_->set_frame_busting(false);
1146 // And now launch the current URL again. This starts a new server process.
[email protected]a22f7e02011-02-09 07:15:351147 DCHECK(navigation_info_->url.is_valid());
[email protected]bbfa9a12010-08-10 14:09:371148 ChromeFrameUrl cf_url;
[email protected]a22f7e02011-02-09 07:15:351149 cf_url.Parse(UTF8ToWide(navigation_info_->url.spec()));
1150 LaunchUrl(cf_url, navigation_info_->referrer.spec());
[email protected]bbfa9a12010-08-10 14:09:371151 }
[email protected]355309e2010-03-15 17:01:341152
1153 return S_OK;
1154}
1155
[email protected]1bb5f892009-10-06 01:44:571156HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1157 DWORD command_id,
1158 DWORD cmd_exec_opt,
1159 VARIANT* in_args,
1160 VARIANT* out_args) {
1161 if (!automation_client_.get()) {
[email protected]77700832010-04-27 00:06:031162 NOTREACHED() << "Invalid automation client";
[email protected]1bb5f892009-10-06 01:44:571163 return E_FAIL;
1164 }
1165
1166 switch (command_id) {
1167 case IDM_BASELINEFONT1:
1168 automation_client_->SetPageFontSize(SMALLEST_FONT);
1169 break;
1170
1171 case IDM_BASELINEFONT2:
1172 automation_client_->SetPageFontSize(SMALL_FONT);
1173 break;
1174
1175 case IDM_BASELINEFONT3:
1176 automation_client_->SetPageFontSize(MEDIUM_FONT);
1177 break;
1178
1179 case IDM_BASELINEFONT4:
1180 automation_client_->SetPageFontSize(LARGE_FONT);
1181 break;
1182
1183 case IDM_BASELINEFONT5:
1184 automation_client_->SetPageFontSize(LARGEST_FONT);
1185 break;
1186
1187 default:
1188 NOTREACHED() << "Invalid font size command: "
1189 << command_id;
1190 return E_FAIL;
1191 }
1192
1193 // Forward the command back to IEFrame with group set to
1194 // CGID_ExplorerBarDoc. This is probably needed to update the menu state to
1195 // indicate that the font size was set. This currently fails with error
1196 // 0x80040104.
1197 // TODO(iyengar)
1198 // Do some investigation into why this Exec call fails.
1199 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1200 return S_OK;
1201}
1202
[email protected]2f2afba2010-04-01 01:53:191203HRESULT ChromeActiveDocument::OnEncodingChange(const GUID* cmd_group_guid,
1204 DWORD command_id,
1205 DWORD cmd_exec_opt,
1206 VARIANT* in_args,
1207 VARIANT* out_args) {
1208 const struct EncodingMapData {
1209 DWORD ie_encoding_id;
1210 const char* chrome_encoding_name;
1211 } kEncodingTestDatas[] = {
1212#define DEFINE_ENCODING_MAP(encoding_name, id, chrome_name) \
1213 { encoding_name, chrome_name },
1214 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_MAP)
1215#undef DEFINE_ENCODING_MAP
1216 };
1217
1218 if (!automation_client_.get()) {
1219 NOTREACHED() << "Invalid automtion client";
1220 return E_FAIL;
1221 }
1222
[email protected]e9b35282010-06-02 16:43:191223 // Using ARRAYSIZE_UNSAFE in here is because we define the struct
1224 // EncodingMapData inside function.
[email protected]2f2afba2010-04-01 01:53:191225 const char* chrome_encoding_name = NULL;
1226 for (int i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
1227 const struct EncodingMapData* encoding_data = &kEncodingTestDatas[i];
1228 if (command_id == encoding_data->ie_encoding_id) {
1229 chrome_encoding_name = encoding_data->chrome_encoding_name;
1230 break;
1231 }
1232 }
1233 // Return E_FAIL when encountering invalid encoding id.
1234 if (!chrome_encoding_name)
1235 return E_FAIL;
1236
1237 TabProxy* tab = GetTabProxy();
1238 if (!tab) {
1239 NOTREACHED() << "Can not get TabProxy";
1240 return E_FAIL;
1241 }
1242
1243 if (chrome_encoding_name)
1244 tab->OverrideEncoding(chrome_encoding_name);
1245
1246 // Like we did on SetPageFontSize, we may forward the command back to IEFrame
1247 // to update the menu state to indicate that which encoding was set.
1248 // TODO(iyengar)
1249 // Do some investigation into why this Exec call fails.
1250 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1251 return S_OK;
1252}
1253
[email protected]f5494d42010-12-23 22:15:341254void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) {
[email protected]2b9a9f162010-10-19 20:30:451255 DVLOG(1) << __FUNCTION__ << " - offset:" << offset;
[email protected]a1800e82009-11-19 00:53:231256
[email protected]8ee65ba2011-04-12 20:53:231257 base::win::ScopedComPtr<IBrowserService> browser_service;
1258 base::win::ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:231259 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1260 travel_log.Receive());
1261
1262 if (browser_service && travel_log)
1263 travel_log->Travel(browser_service, offset);
1264}
1265
[email protected]326d3b72011-03-29 20:38:241266void ChromeActiveDocument::OnMoveWindow(const gfx::Rect& dimensions) {
[email protected]8ee65ba2011-04-12 20:53:231267 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]326d3b72011-03-29 20:38:241268 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1269 web_browser2.Receive());
1270 if (!web_browser2)
1271 return;
1272 DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions.width()
1273 << " height:" << dimensions.height();
1274 if (!dimensions.IsEmpty()) {
1275 web_browser2->put_MenuBar(VARIANT_FALSE);
1276 web_browser2->put_ToolBar(VARIANT_FALSE);
1277
1278 int width = dimensions.width();
1279 int height = dimensions.height();
1280 // Compute the size of the browser window given the desired size of the
1281 // content area. As per MSDN, the WebBrowser object returns an error from
1282 // this method. As a result the code below is best effort.
1283 web_browser2->ClientToWindow(&width, &height);
1284
1285 web_browser2->put_Width(width);
1286 web_browser2->put_Height(height);
1287 web_browser2->put_Left(dimensions.x());
1288 web_browser2->put_Top(dimensions.y());
1289 }
1290}
1291
[email protected]a1800e82009-11-19 00:53:231292HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1293 IBrowserService** browser_service, ITravelLog** travel_log) {
1294 DCHECK(browser_service || travel_log);
[email protected]8ee65ba2011-04-12 20:53:231295 base::win::ScopedComPtr<IBrowserService> browser_service_local;
[email protected]a1800e82009-11-19 00:53:231296 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1297 browser_service_local.Receive());
1298 if (!browser_service_local) {
1299 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1300 return hr;
[email protected]f9cc4c452009-10-13 14:56:381301 }
[email protected]a1800e82009-11-19 00:53:231302
1303 if (travel_log) {
1304 hr = browser_service_local->GetTravelLog(travel_log);
[email protected]5044da82010-10-27 01:09:161305 DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr;
[email protected]a1800e82009-11-19 00:53:231306 }
1307
1308 if (browser_service)
1309 *browser_service = browser_service_local.Detach();
1310
1311 return hr;
[email protected]f9cc4c452009-10-13 14:56:381312}
[email protected]a15d4a42010-02-17 08:21:351313
1314LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1315 HWND control_window,
1316 BOOL& bHandled) {
[email protected]8ee65ba2011-04-12 20:53:231317 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]a15d4a42010-02-17 08:21:351318 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1319 DCHECK(web_browser2);
1320
[email protected]bc2ff5192010-06-01 22:05:451321 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351322 web_browser2->GoForward();
[email protected]a15d4a42010-02-17 08:21:351323 return 0;
1324}
1325
1326LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1327 HWND control_window,
1328 BOOL& bHandled) {
[email protected]8ee65ba2011-04-12 20:53:231329 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]a15d4a42010-02-17 08:21:351330 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1331 DCHECK(web_browser2);
1332
[email protected]bc2ff5192010-06-01 22:05:451333 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351334 web_browser2->GoBack();
[email protected]a15d4a42010-02-17 08:21:351335 return 0;
1336}
1337
[email protected]80b5a8d2010-03-19 16:50:431338LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1339 LPARAM lparam,
1340 BOOL& handled) {
1341 if (!m_spClientSite)
1342 return 0;
1343
[email protected]8ee65ba2011-04-12 20:53:231344 base::win::ScopedComPtr<IWebBrowser2> web_browser2;
[email protected]80b5a8d2010-03-19 16:50:431345 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1346 web_browser2.Receive());
1347 if (!web_browser2) {
1348 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1349 return 0;
1350 }
1351
[email protected]8ee65ba2011-04-12 20:53:231352 base::win::ScopedComPtr<IShellBrowser> shell_browser;
[email protected]80b5a8d2010-03-19 16:50:431353 DoQueryService(SID_STopLevelBrowser, web_browser2,
1354 shell_browser.Receive());
1355 DCHECK(shell_browser.get() != NULL);
[email protected]8ee65ba2011-04-12 20:53:231356 base::win::ScopedComPtr<ITridentService2> trident_services;
[email protected]80b5a8d2010-03-19 16:50:431357 trident_services.QueryFrom(shell_browser);
[email protected]bc2ff5192010-06-01 22:05:451358 if (trident_services)
[email protected]80b5a8d2010-03-19 16:50:431359 trident_services->FirePrivacyImpactedStateChange(wparam);
[email protected]bc2ff5192010-06-01 22:05:451360 else
[email protected]80b5a8d2010-03-19 16:50:431361 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
[email protected]80b5a8d2010-03-19 16:50:431362 return 0;
1363}
[email protected]00aebd72010-07-16 14:44:321364
[email protected]723e5442010-07-21 17:36:051365LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam,
1366 LPARAM lparam,
1367 BOOL& handled) { // NO_LINT
1368 if (wparam)
1369 SetFocus();
1370 return 0;
1371}
1372
1373LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam,
1374 LPARAM lparam,
1375 BOOL& handled) { // NO_LINT
[email protected]e7ad9322010-08-02 20:41:291376 if (!ignore_setfocus_)
1377 GiveFocusToChrome(false);
[email protected]723e5442010-07-21 17:36:051378 return 0;
1379}
[email protected]7f860dd82010-08-09 23:18:051380
[email protected]342de552010-10-21 20:46:141381bool ChromeActiveDocument::IsNewNavigation(
[email protected]747bca12011-01-15 00:28:451382 const NavigationInfo& new_navigation_info, int flags) const {
[email protected]342de552010-10-21 20:46:141383 // A new navigation is typically an internal navigation which is initiated by
1384 // the renderer(WebKit). Condition 1 below has to be true along with the
1385 // any of the other conditions below.
[email protected]747bca12011-01-15 00:28:451386 // 1. The navigation notification flags passed in as the flags parameter
1387 // is not INVALIDATE_LOAD which indicates that the loading state of the
1388 // tab changed.
1389 // 2. The navigation index is greater than 0 which means that a top level
[email protected]342de552010-10-21 20:46:141390 // navigation was initiated on the current external tab.
[email protected]747bca12011-01-15 00:28:451391 // 3. The navigation type has changed.
1392 // 4. The url or the referrer are different.
1393 if (flags == TabContents::INVALIDATE_LOAD)
1394 return false;
1395
[email protected]342de552010-10-21 20:46:141396 if (new_navigation_info.navigation_index <= 0)
1397 return false;
1398
1399 if (new_navigation_info.navigation_index ==
[email protected]a22f7e02011-02-09 07:15:351400 navigation_info_->navigation_index)
[email protected]342de552010-10-21 20:46:141401 return false;
1402
[email protected]a22f7e02011-02-09 07:15:351403 if (new_navigation_info.navigation_type != navigation_info_->navigation_type)
[email protected]342de552010-10-21 20:46:141404 return true;
1405
[email protected]a22f7e02011-02-09 07:15:351406 if (new_navigation_info.url != navigation_info_->url)
[email protected]342de552010-10-21 20:46:141407 return true;
1408
[email protected]a22f7e02011-02-09 07:15:351409 if (new_navigation_info.referrer != navigation_info_->referrer)
[email protected]342de552010-10-21 20:46:141410 return true;
1411
1412 return false;
1413}