blob: 3635d4e7645f195f6b7df013738a8c3d835de816 [file] [log] [blame]
[email protected]f17a0ee2010-05-17 17:38:471// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Implementation of ChromeActiveDocument
6#include "chrome_frame/chrome_active_document.h"
7
8#include <hlink.h>
9#include <htiface.h>
[email protected]a1800e82009-11-19 00:53:2310#include <initguid.h>
[email protected]f7817822009-09-24 05:11:5811#include <mshtmcid.h>
12#include <shdeprecated.h>
13#include <shlguid.h>
[email protected]48dc9e12010-08-26 19:49:5714#include <shlobj.h>
[email protected]f7817822009-09-24 05:11:5815#include <shobjidl.h>
16#include <tlogstg.h>
17#include <urlmon.h>
18#include <wininet.h>
19
20#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5021#include "base/debug/trace_event.h"
[email protected]f7817822009-09-24 05:11:5822#include "base/file_util.h"
23#include "base/logging.h"
24#include "base/path_service.h"
25#include "base/process_util.h"
[email protected]f7817822009-09-24 05:11:5826#include "base/string_tokenizer.h"
27#include "base/string_util.h"
[email protected]34b99632011-01-01 01:01:0628#include "base/threading/thread.h"
[email protected]1357c322010-12-30 22:18:5629#include "base/threading/thread_local.h"
[email protected]252cad62010-08-18 18:33:5730#include "base/utf_string_conversions.h"
[email protected]965722ff2010-10-20 15:50:3031#include "base/win/scoped_variant.h"
[email protected]a8e20582010-12-31 17:18:5032#include "base/win/win_util.h"
[email protected]f7817822009-09-24 05:11:5833#include "grit/generated_resources.h"
[email protected]1a3aba82010-11-08 23:52:5434#include "chrome/app/chrome_command_ids.h"
[email protected]cccd3762010-11-12 18:40:0135#include "chrome/app/chrome_dll_resource.h"
[email protected]747bca12011-01-15 00:28:4536#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]a22f7e02011-02-09 07:15:3537#include "chrome/common/automation_messages.h"
[email protected]f7817822009-09-24 05:11:5838#include "chrome/common/chrome_constants.h"
39#include "chrome/common/navigation_types.h"
[email protected]7f860dd82010-08-09 23:18:0540#include "chrome/common/page_zoom.h"
[email protected]f7817822009-09-24 05:11:5841#include "chrome/test/automation/browser_proxy.h"
42#include "chrome/test/automation/tab_proxy.h"
[email protected]b36a9f92009-10-19 17:34:5743#include "chrome_frame/bho.h"
[email protected]29c32f902010-04-20 23:27:2944#include "chrome_frame/bind_context_info.h"
[email protected]5ae94d22010-07-21 19:55:3645#include "chrome_frame/buggy_bho_handling.h"
[email protected]9607f6a82010-06-12 17:24:4146#include "chrome_frame/crash_reporting/crash_metrics.h"
[email protected]f7817822009-09-24 05:11:5847#include "chrome_frame/utils.h"
48
[email protected]a1800e82009-11-19 00:53:2349DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
50 0x46);
51
[email protected]f7817822009-09-24 05:11:5852base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache;
53
54bool g_first_launch_by_process_ = true;
55
[email protected]2f2afba2010-04-01 01:53:1956const DWORD kIEEncodingIdArray[] = {
57#define DEFINE_ENCODING_ID_ARRAY(encoding_name, id, chrome_name) encoding_name,
58 INTERNAL_IE_ENCODINGMENU_IDS(DEFINE_ENCODING_ID_ARRAY)
59#undef DEFINE_ENCODING_ID_ARRAY
60 0 // The Last data must be 0 to indicate the end of the encoding id array.
61};
62
[email protected]f7817822009-09-24 05:11:5863ChromeActiveDocument::ChromeActiveDocument()
[email protected]a22f7e02011-02-09 07:15:3564 : navigation_info_(new NavigationInfo()),
65 first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3566 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3467 popup_allowed_(false),
[email protected]c4e45b32010-07-28 21:15:1568 accelerator_table_(NULL) {
[email protected]04e3f352010-05-10 13:48:2469 TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, "");
70
[email protected]bbfa9a12010-08-10 14:09:3771 url_fetcher_->set_frame_busting(false);
[email protected]a22f7e02011-02-09 07:15:3572 memset(navigation_info_.get(), 0, sizeof(NavigationInfo));
[email protected]f7817822009-09-24 05:11:5873}
74
75HRESULT ChromeActiveDocument::FinalConstruct() {
76 // If we have a cached ChromeActiveDocument instance in TLS, then grab
77 // ownership of the cached document's automation client. This is an
78 // optimization to get Chrome active documents to load faster.
79 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
[email protected]58174a72010-05-05 21:30:3080 if (cached_document && cached_document->IsValid()) {
[email protected]3eb8a70492010-12-03 21:32:1981 SetResourceModule();
[email protected]f7817822009-09-24 05:11:5882 DCHECK(automation_client_.get() == NULL);
[email protected]3148c0ae2010-03-11 18:06:0083 automation_client_.swap(cached_document->automation_client_);
[email protected]2b9a9f162010-10-19 20:30:4584 DVLOG(1) << "Reusing automation client instance from " << cached_document;
[email protected]f7817822009-09-24 05:11:5885 DCHECK(automation_client_.get() != NULL);
[email protected]bbfa9a12010-08-10 14:09:3786 automation_client_->Reinitialize(this, url_fetcher_.get());
[email protected]f7817822009-09-24 05:11:5887 is_automation_client_reused_ = true;
[email protected]b5811052010-08-21 01:37:2988 OnAutomationServerReady();
[email protected]f7817822009-09-24 05:11:5889 } else {
90 // The FinalConstruct implementation in the ChromeFrameActivexBase class
91 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
92 // and initializes it, which would spawn a new Chrome process, etc.
93 // We don't want to be doing this if we have a cached document, whose
94 // automation client instance can be reused.
[email protected]97965e12010-04-09 00:51:1095 HRESULT hr = BaseActiveX::FinalConstruct();
[email protected]f7817822009-09-24 05:11:5896 if (FAILED(hr))
97 return hr;
98 }
99
[email protected]e1081d92010-09-10 20:29:11100 InitializeAutomationSettings();
[email protected]8f56e612010-09-09 17:03:14101
[email protected]f7817822009-09-24 05:11:58102 find_dialog_.Init(automation_client_.get());
103
[email protected]6fd1a7a2010-07-26 22:09:46104 OLECMDF flags = static_cast<OLECMDF>(OLECMDF_ENABLED | OLECMDF_SUPPORTED);
105
106 null_group_commands_map_[OLECMDID_PRINT] = flags;
107 null_group_commands_map_[OLECMDID_FIND] = flags;
108 null_group_commands_map_[OLECMDID_CUT] = flags;
109 null_group_commands_map_[OLECMDID_COPY] = flags;
110 null_group_commands_map_[OLECMDID_PASTE] = flags;
111 null_group_commands_map_[OLECMDID_SELECTALL] = flags;
112 null_group_commands_map_[OLECMDID_SAVEAS] = flags;
113
114 mshtml_group_commands_map_[IDM_BASELINEFONT1] = flags;
115 mshtml_group_commands_map_[IDM_BASELINEFONT2] = flags;
116 mshtml_group_commands_map_[IDM_BASELINEFONT3] = flags;
117 mshtml_group_commands_map_[IDM_BASELINEFONT4] = flags;
118 mshtml_group_commands_map_[IDM_BASELINEFONT5] = flags;
[email protected]b2529722010-12-01 02:49:07119 mshtml_group_commands_map_[IDM_VIEWSOURCE] = flags;
[email protected]a15d4a42010-02-17 08:21:35120
[email protected]3c6f8e12010-03-24 21:58:21121 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
[email protected]a15d4a42010-02-17 08:21:35122 accelerator_table_ =
[email protected]3c6f8e12010-03-24 21:58:21123 LoadAccelerators(this_module,
[email protected]a15d4a42010-02-17 08:21:35124 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
125 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58126 return S_OK;
127}
128
129ChromeActiveDocument::~ChromeActiveDocument() {
[email protected]2b9a9f162010-10-19 20:30:45130 DVLOG(1) << __FUNCTION__;
[email protected]bc2ff5192010-06-01 22:05:45131 if (find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58132 find_dialog_.DestroyWindow();
[email protected]3eb07da2010-02-01 19:48:36133 // ChromeFramePlugin
[email protected]97965e12010-04-09 00:51:10134 BaseActiveX::Uninitialize();
[email protected]04e3f352010-05-10 13:48:24135
136 TRACE_EVENT_END("chromeframe.createactivedocument", this, "");
[email protected]f7817822009-09-24 05:11:58137}
138
139// Override DoVerb
140STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
141 LPMSG msg,
142 IOleClientSite* active_site,
143 LONG index,
144 HWND parent_window,
145 LPCRECT pos) {
146 // IE will try and in-place activate us in some cases. This happens when
147 // the user opens a new IE window with a URL that has us as the DocObject.
148 // Here we refuse to be activated in-place and we will force IE to UIActivate
149 // us.
[email protected]bc2ff5192010-06-01 22:05:45150 if (OLEIVERB_INPLACEACTIVATE == verb)
[email protected]23b33612010-11-09 23:47:01151 return OLEOBJ_E_INVALIDVERB;
[email protected]f7817822009-09-24 05:11:58152 // Check if we should activate as a docobject or not
153 // (client supports IOleDocumentSite)
154 if (doc_site_) {
155 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57156 case OLEIVERB_SHOW: {
157 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
158 doc_host_handler.QueryFrom(doc_site_);
[email protected]bc2ff5192010-06-01 22:05:45159 if (doc_host_handler.get())
[email protected]1bb5f892009-10-06 01:44:57160 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
[email protected]1bb5f892009-10-06 01:44:57161 }
[email protected]f7817822009-09-24 05:11:58162 case OLEIVERB_OPEN:
163 case OLEIVERB_UIACTIVATE:
[email protected]bc2ff5192010-06-01 22:05:45164 if (!m_bUIActive)
[email protected]f7817822009-09-24 05:11:58165 return doc_site_->ActivateMe(NULL);
[email protected]f7817822009-09-24 05:11:58166 break;
167 }
168 }
169 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
170 msg,
171 active_site,
172 index,
173 parent_window,
174 pos);
175}
176
[email protected]f7817822009-09-24 05:11:58177// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
178STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
[email protected]2b9a9f162010-10-19 20:30:45179 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58180 return S_OK;
181}
182
183STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
[email protected]2b9a9f162010-10-19 20:30:45184 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58185 if (msg == NULL)
186 return E_POINTER;
187
188 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
189 HWND focus = ::GetFocus();
190 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
191 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
192 // set focus to the correct element in Chrome.
193 ::SetFocus(m_hWnd);
194 return S_OK;
195 }
196 }
197
198 return S_FALSE;
199}
200// Override IPersistStorageImpl::IsDirty
201STDMETHODIMP ChromeActiveDocument::IsDirty() {
[email protected]2b9a9f162010-10-19 20:30:45202 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58203 return S_FALSE;
204}
205
[email protected]b95f550f2009-11-19 05:35:22206void ChromeActiveDocument::OnAutomationServerReady() {
[email protected]97965e12010-04-09 00:51:10207 BaseActiveX::OnAutomationServerReady();
[email protected]1fd45692010-04-19 21:01:18208 BaseActiveX::GiveFocusToChrome(true);
[email protected]b95f550f2009-11-19 05:35:22209}
210
[email protected]f7817822009-09-24 05:11:58211STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
212 IMoniker* moniker_name,
213 LPBC bind_context,
214 DWORD mode) {
[email protected]bc2ff5192010-06-01 22:05:45215 if (NULL == moniker_name)
[email protected]f7817822009-09-24 05:11:58216 return E_INVALIDARG;
[email protected]a1800e82009-11-19 00:53:23217
218 ScopedComPtr<IOleClientSite> client_site;
219 if (bind_context) {
220 ScopedComPtr<IUnknown> site;
221 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
222 site.Receive());
223 if (site)
224 client_site.QueryFrom(site);
225 }
226
227 if (client_site) {
228 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11229 DoQueryService(IID_INewWindowManager, client_site,
230 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14231
232 // See if mshtml parsed the html header for us. If so, we need to
233 // clear the browser service flag that we use to indicate that this
234 // browser instance is navigating to a CF document.
235 ScopedComPtr<IBrowserService> browser_service;
236 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
237 if (browser_service) {
238 bool flagged = CheckForCFNavigation(browser_service, true);
[email protected]5044da82010-10-27 01:09:16239 DVLOG_IF(1, flagged) << "Cleared flagged browser service";
[email protected]051236f2010-03-12 22:06:14240 }
[email protected]a1800e82009-11-19 00:53:23241 }
242
[email protected]051236f2010-03-12 22:06:14243 NavigationManager* mgr = NavigationManager::GetThreadInstance();
[email protected]21b4e6d2010-07-14 18:19:59244 DLOG_IF(ERROR, !mgr) << "Couldn't get instance of NavigationManager";
[email protected]7e3544b2010-01-22 00:02:34245
[email protected]29c32f902010-04-20 23:27:29246 std::wstring url;
247
[email protected]77d7aee2010-05-14 20:31:55248 ScopedComPtr<BindContextInfo> info;
249 BindContextInfo::FromBindContext(bind_context, info.Receive());
[email protected]29c32f902010-04-20 23:27:29250 DCHECK(info);
[email protected]4f45d4582011-02-22 23:27:27251 if (info && !info->GetUrl().empty()) {
252 url = info->GetUrl();
[email protected]df0846a52011-02-23 03:29:58253 if (mgr) {
254 // If the original URL contains an anchor, then the URL queried
255 // from the protocol sink wrapper does not contain the anchor. To
256 // workaround this we retrieve the anchor from the navigation manager
257 // and append it to the url retrieved from the protocol sink wrapper.
258 GURL url_for_anchor(mgr->url());
259 if (url_for_anchor.has_ref()) {
260 url += L"#";
261 url += UTF8ToWide(url_for_anchor.ref());
262 }
263 }
[email protected]29c32f902010-04-20 23:27:29264 } else {
265 // If the original URL contains an anchor, then the URL queried
266 // from the moniker does not contain the anchor. To workaround
267 // this we retrieve the URL from our BHO.
268 url = GetActualUrlFromMoniker(moniker_name, bind_context,
269 mgr ? mgr->url(): std::wstring());
270 }
[email protected]051236f2010-03-12 22:06:14271
[email protected]c4e45b32010-07-28 21:15:15272 ChromeFrameUrl cf_url;
273 if (!cf_url.Parse(url)) {
[email protected]37346bc2009-09-25 22:54:33274 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58275 return E_INVALIDARG;
276 }
277
[email protected]bbfa9a12010-08-10 14:09:37278 std::string referrer(mgr ? mgr->referrer() : EmptyString());
[email protected]d8e13512010-09-22 17:02:58279 RendererType renderer_type = cf_url.is_chrome_protocol() ?
280 RENDERER_TYPE_CHROME_GCF_PROTOCOL : RENDERER_TYPE_UNDETERMINED;
[email protected]bbfa9a12010-08-10 14:09:37281
[email protected]aaf124502010-07-17 04:02:58282 // With CTransaction patch we have more robust way to grab the referrer for
283 // each top-level-switch-to-CF request by peeking at our sniffing data
[email protected]d8e13512010-09-22 17:02:58284 // object that lives inside the bind context. We also remember the reason
285 // we're rendering the document in Chrome.
[email protected]aaf124502010-07-17 04:02:58286 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
287 scoped_refptr<ProtData> prot_data = info->get_prot_data();
[email protected]d8e13512010-09-22 17:02:58288 if (prot_data) {
[email protected]aaf124502010-07-17 04:02:58289 referrer = prot_data->referrer();
[email protected]d8e13512010-09-22 17:02:58290 renderer_type = prot_data->renderer_type();
291 }
[email protected]aaf124502010-07-17 04:02:58292 }
293
[email protected]62ce09732010-09-03 18:32:04294 // For gcf: URLs allow only about and view-source schemes to pass through for
295 // further inspection.
296 bool is_safe_scheme = cf_url.gurl().SchemeIs(chrome::kAboutScheme) ||
297 cf_url.gurl().SchemeIs(chrome::kViewSourceScheme);
298 if (cf_url.is_chrome_protocol() && !is_safe_scheme &&
299 !GetConfigBool(false, kAllowUnsafeURLs)) {
300 DLOG(ERROR) << __FUNCTION__ << " gcf: not allowed:" << url;
301 return E_INVALIDARG;
302 }
303
[email protected]c4e45b32010-07-28 21:15:15304 if (!LaunchUrl(cf_url, referrer)) {
[email protected]d266ce82010-08-13 21:33:40305 DLOG(ERROR) << __FUNCTION__ << " Failed to launch url:" << url;
[email protected]37346bc2009-09-25 22:54:33306 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58307 }
308
[email protected]c4e45b32010-07-28 21:15:15309 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
[email protected]d266ce82010-08-13 21:33:40310 url_fetcher_->SetInfoForUrl(url.c_str(), moniker_name, bind_context);
[email protected]f7817822009-09-24 05:11:58311
[email protected]d8e13512010-09-22 17:02:58312 // Log a metric indicating why GCF is rendering in Chrome.
313 // (Note: we only track the renderer type when using the CTransaction patch.
314 // When the code for the browser service patch and for the moniker patch is
315 // removed, this conditional can also go away.)
316 if (RENDERER_TYPE_UNDETERMINED != renderer_type) {
317 THREAD_SAFE_UMA_LAUNCH_TYPE_COUNT(renderer_type);
318 }
319
[email protected]f7817822009-09-24 05:11:58320 return S_OK;
321}
322
323STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
324 LPBC bind_context,
325 BOOL remember) {
326 return E_NOTIMPL;
327}
328
329STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
330 LPBC bind_context) {
331 return E_NOTIMPL;
332}
333
334STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
335 return E_NOTIMPL;
336}
337
338STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
[email protected]bc2ff5192010-06-01 22:05:45339 if (NULL == class_id)
[email protected]f7817822009-09-24 05:11:58340 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58341 *class_id = GetObjectCLSID();
342 return S_OK;
343}
344
345STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
346 ULONG number_of_commands,
347 OLECMD commands[],
348 OLECMDTEXT* command_text) {
[email protected]2b9a9f162010-10-19 20:30:45349 DVLOG(1) << __FUNCTION__;
[email protected]b509ec82010-04-13 16:53:06350
[email protected]6fd1a7a2010-07-26 22:09:46351 CommandStatusMap* command_map = NULL;
[email protected]b509ec82010-04-13 16:53:06352
[email protected]6fd1a7a2010-07-26 22:09:46353 if (cmd_group_guid) {
354 if (IsEqualGUID(*cmd_group_guid, GUID_NULL)) {
355 command_map = &null_group_commands_map_;
356 } else if (IsEqualGUID(*cmd_group_guid, CGID_MSHTML)) {
357 command_map = &mshtml_group_commands_map_;
358 } else if (IsEqualGUID(*cmd_group_guid, CGID_Explorer)) {
359 command_map = &explorer_group_commands_map_;
360 } else if (IsEqualGUID(*cmd_group_guid, CGID_ShellDocView)) {
361 command_map = &shdoc_view_group_commands_map_;
362 }
363 } else {
364 command_map = &null_group_commands_map_;
365 }
366
367 if (!command_map) {
[email protected]2b9a9f162010-10-19 20:30:45368 DVLOG(1) << "unsupported command group: " << GuidToString(*cmd_group_guid);
[email protected]b509ec82010-04-13 16:53:06369 return OLECMDERR_E_NOTSUPPORTED;
370 }
371
[email protected]f7817822009-09-24 05:11:58372 for (ULONG command_index = 0; command_index < number_of_commands;
373 command_index++) {
[email protected]2b9a9f162010-10-19 20:30:45374 DVLOG(1) << "Command id = " << commands[command_index].cmdID;
[email protected]6fd1a7a2010-07-26 22:09:46375 CommandStatusMap::iterator index =
376 command_map->find(commands[command_index].cmdID);
377 if (index != command_map->end())
378 commands[command_index].cmdf = index->second;
[email protected]f7817822009-09-24 05:11:58379 }
380 return S_OK;
381}
382
383STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
384 DWORD command_id,
385 DWORD cmd_exec_opt,
386 VARIANT* in_args,
387 VARIANT* out_args) {
[email protected]2b9a9f162010-10-19 20:30:45388 DVLOG(1) << __FUNCTION__ << " Cmd id =" << command_id;
[email protected]f7817822009-09-24 05:11:58389 // Bail out if we have been uninitialized.
390 if (automation_client_.get() && automation_client_->tab()) {
391 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
392 in_args, out_args);
[email protected]bbfa9a12010-08-10 14:09:37393 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
394 // If the automation server has crashed and the user is refreshing the
395 // page, let OnRefreshPage attempt to recover.
396 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
[email protected]f7817822009-09-24 05:11:58397 }
[email protected]bbfa9a12010-08-10 14:09:37398
[email protected]e3200932009-10-09 21:33:03399 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58400}
401
[email protected]a1800e82009-11-19 00:53:23402STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
403 IBindCtx* bind_context) {
404 // Read notes in ChromeActiveDocument::SaveHistory
405 DCHECK(stream);
406 LARGE_INTEGER offset = {0};
407 ULARGE_INTEGER cur_pos = {0};
408 STATSTG statstg = {0};
409
410 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
411 stream->Stat(&statstg, STATFLAG_NONAME);
412
413 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
[email protected]965722ff2010-10-20 15:50:30414 base::win::ScopedBstr url_bstr;
[email protected]a1800e82009-11-19 00:53:23415 DWORD bytes_read = 0;
416 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
417 std::wstring url(url_bstr);
418
[email protected]c4e45b32010-07-28 21:15:15419 ChromeFrameUrl cf_url;
420 if (!cf_url.Parse(url)) {
[email protected]a1800e82009-11-19 00:53:23421 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
422 return E_INVALIDARG;
423 }
424
[email protected]c5cbf4e2010-07-15 21:48:25425 const std::string& referrer = EmptyString();
[email protected]c4e45b32010-07-28 21:15:15426 if (!LaunchUrl(cf_url, referrer)) {
[email protected]a1800e82009-11-19 00:53:23427 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
428 return E_INVALIDARG;
429 }
430 return S_OK;
431}
432
433STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
434 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
435 // from Chrome and persist it in the stream. And in LoadHistory we need to
436 // pass this list back to Chrome which will recreate the list. This will allow
437 // Back-Forward navigation to anchors to work correctly when we navigate to a
438 // page outside of ChromeFrame and then come back.
439 if (!stream) {
440 NOTREACHED();
441 return E_INVALIDARG;
442 }
443
444 LARGE_INTEGER offset = {0};
445 ULARGE_INTEGER new_pos = {0};
446 DWORD written = 0;
[email protected]a22f7e02011-02-09 07:15:35447 std::wstring url = UTF8ToWide(navigation_info_->url.spec());
[email protected]a1800e82009-11-19 00:53:23448 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
449 &written);
450}
451
452STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
[email protected]77700832010-04-27 00:06:03453 if (automation_client_.get()) {
454 int index = static_cast<int>(position_cookie);
[email protected]a22f7e02011-02-09 07:15:35455 navigation_info_->navigation_index = index;
[email protected]77700832010-04-27 00:06:03456 automation_client_->NavigateToIndex(index);
457 } else {
458 DLOG(WARNING) << "Invalid automation client instance";
459 }
[email protected]a1800e82009-11-19 00:53:23460 return S_OK;
461}
462
463STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
464 if (!position_cookie)
465 return E_INVALIDARG;
466
[email protected]a22f7e02011-02-09 07:15:35467 *position_cookie = navigation_info_->navigation_index;
[email protected]a1800e82009-11-19 00:53:23468 return S_OK;
469}
470
[email protected]f7817822009-09-24 05:11:58471STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
[email protected]bc2ff5192010-06-01 22:05:45472 if (NULL == url)
[email protected]f7817822009-09-24 05:11:58473 return E_POINTER;
[email protected]f7817822009-09-24 05:11:58474 *url = ::SysAllocString(url_);
475 return S_OK;
476}
477
[email protected]a1800e82009-11-19 00:53:23478STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
479 return GetUrlForEvents(url);
480}
481
[email protected]80b5a8d2010-03-19 16:50:43482STDMETHODIMP ChromeActiveDocument::Reset() {
483 next_privacy_record_ = privacy_info_.privacy_records.begin();
484 return S_OK;
485}
486
[email protected]00aebd72010-07-16 14:44:32487STDMETHODIMP ChromeActiveDocument::GetSize(DWORD* size) {
[email protected]80b5a8d2010-03-19 16:50:43488 if (!size)
489 return E_POINTER;
490
491 *size = privacy_info_.privacy_records.size();
492 return S_OK;
493}
494
495STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
496 if (!privacy_impacted)
497 return E_POINTER;
498
499 *privacy_impacted = privacy_info_.privacy_impacted;
500 return S_OK;
501}
502
503STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
[email protected]00aebd72010-07-16 14:44:32504 LONG* reserved, DWORD* flags) {
[email protected]80b5a8d2010-03-19 16:50:43505 if (!url || !policy || !flags)
506 return E_POINTER;
507
508 if (next_privacy_record_ == privacy_info_.privacy_records.end())
509 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
510
511 *url = SysAllocString(next_privacy_record_->first.c_str());
512 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
513 *flags = next_privacy_record_->second.flags;
514
515 next_privacy_record_++;
516 return S_OK;
517}
518
[email protected]354bcba2010-12-14 04:34:43519bool ChromeActiveDocument::IsSchemeAllowed(const GURL& url) {
520 bool allowed = BaseActiveX::IsSchemeAllowed(url);
521 if (allowed)
522 return true;
523
524 if (url.SchemeIs(chrome::kAboutScheme)) {
525 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutPluginsURL))
526 return true;
527 }
528 return false;
529}
530
[email protected]3eafbfb92010-08-02 16:54:22531HRESULT ChromeActiveDocument::GetInPlaceFrame(
532 IOleInPlaceFrame** in_place_frame) {
533 DCHECK(in_place_frame);
534 if (in_place_frame_) {
535 *in_place_frame = in_place_frame_.get();
536 (*in_place_frame)->AddRef();
537 return S_OK;
538 } else {
539 return S_FALSE;
540 }
541}
542
[email protected]f7817822009-09-24 05:11:58543HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
544 IOleClientSite* client_site) {
545 if (client_site == NULL) {
546 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
547 if (cached_document) {
548 DCHECK(this == cached_document);
549 g_active_doc_cache.Set(NULL);
550 cached_document->Release();
551 }
[email protected]dda7d9c2009-11-11 23:01:47552
553 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]bc2ff5192010-06-01 22:05:45554 if (doc_site_)
[email protected]77059f72010-02-28 06:16:00555 doc_host_handler.QueryFrom(doc_site_);
[email protected]dda7d9c2009-11-11 23:01:47556
[email protected]bc2ff5192010-06-01 22:05:45557 if (doc_host_handler.get())
[email protected]dda7d9c2009-11-11 23:01:47558 doc_host_handler->HideUI();
[email protected]dda7d9c2009-11-11 23:01:47559
560 doc_site_.Release();
[email protected]f7817822009-09-24 05:11:58561 }
[email protected]a1800e82009-11-19 00:53:23562
[email protected]bc2ff5192010-06-01 22:05:45563 if (client_site != m_spClientSite)
[email protected]97965e12010-04-09 00:51:10564 return BaseActiveX::IOleObject_SetClientSite(client_site);
[email protected]a1800e82009-11-19 00:53:23565
566 return S_OK;
[email protected]f7817822009-09-24 05:11:58567}
568
[email protected]f7817822009-09-24 05:11:58569HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
570 HRESULT hr = S_OK;
571 m_bNegotiatedWnd = TRUE;
572 if (!m_bInPlaceActive) {
573 hr = m_spInPlaceSite->CanInPlaceActivate();
[email protected]bc2ff5192010-06-01 22:05:45574 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58575 return hr;
[email protected]f7817822009-09-24 05:11:58576 m_spInPlaceSite->OnInPlaceActivate();
577 }
578 m_bInPlaceActive = TRUE;
579 // get location in the parent window,
580 // as well as some information about the parent
581 ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
582 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
583 HWND parent_window = NULL;
584 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
585 in_place_frame_.Release();
586 RECT position_rect = {0};
587 RECT clip_rect = {0};
588 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
589 in_place_ui_window.Receive(),
590 &position_rect,
591 &clip_rect,
592 &frame_info_);
593 if (!m_bWndLess) {
594 if (IsWindow()) {
595 ::ShowWindow(m_hWnd, SW_SHOW);
596 SetFocus();
597 } else {
[email protected]fca446b92011-02-18 20:44:06598 m_hWnd = Create(parent_window, position_rect);
[email protected]dd4beb522010-07-13 18:18:14599 if (!IsWindow()) {
600 // This might happen if the automation server couldn't be
601 // instantiated. If so, a NOTREACHED() will have already been hit.
602 DLOG(ERROR) << "Failed to create Ax window";
603 return AtlHresultFromLastError();
604 }
[email protected]f7817822009-09-24 05:11:58605 }
[email protected]7f860dd82010-08-09 23:18:05606 SetWindowDimensions();
[email protected]f7817822009-09-24 05:11:58607 }
608 SetObjectRects(&position_rect, &clip_rect);
609 }
610
611 ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
612
613 // Gone active by now, take care of UIACTIVATE
614 if (DoesVerbUIActivate(verb)) {
615 if (!m_bUIActive) {
616 m_bUIActive = TRUE;
617 hr = m_spInPlaceSite->OnUIActivate();
[email protected]bc2ff5192010-06-01 22:05:45618 if (FAILED(hr))
[email protected]f7817822009-09-24 05:11:58619 return hr;
[email protected]f7817822009-09-24 05:11:58620 // set ourselves up in the host
621 if (in_place_active_object) {
[email protected]bc2ff5192010-06-01 22:05:45622 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58623 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
[email protected]bc2ff5192010-06-01 22:05:45624 if (in_place_ui_window)
[email protected]f7817822009-09-24 05:11:58625 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
[email protected]f7817822009-09-24 05:11:58626 }
627 }
628 }
629 m_spClientSite->ShowObject();
630 return S_OK;
631}
632
[email protected]f5494d42010-12-23 22:15:34633void ChromeActiveDocument::OnNavigationStateChanged(
634 int flags, const NavigationInfo& nav_info) {
[email protected]f7817822009-09-24 05:11:58635 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
[email protected]2b9a9f162010-10-19 20:30:45636 DVLOG(1) << __FUNCTION__
637 << "\n Flags: " << flags
638 << ", Url: " << nav_info.url
639 << ", Title: " << nav_info.title
640 << ", Type: " << nav_info.navigation_type
641 << ", Relative Offset: " << nav_info.relative_offset
642 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58643
[email protected]747bca12011-01-15 00:28:45644 UpdateNavigationState(nav_info, flags);
[email protected]f7817822009-09-24 05:11:58645}
646
[email protected]f5494d42010-12-23 22:15:34647void ChromeActiveDocument::OnUpdateTargetUrl(
[email protected]f7817822009-09-24 05:11:58648 const std::wstring& new_target_url) {
[email protected]bc2ff5192010-06-01 22:05:45649 if (in_place_frame_)
[email protected]f7817822009-09-24 05:11:58650 in_place_frame_->SetStatusText(new_target_url.c_str());
[email protected]f7817822009-09-24 05:11:58651}
652
653bool IsFindAccelerator(const MSG& msg) {
654 // TODO(robertshield): This may not stand up to localization. Fix if this
655 // is the case.
656 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
[email protected]a8e20582010-12-31 17:18:50657 base::win::IsCtrlPressed() &&
658 !(base::win::IsAltPressed() || base::win::IsShiftPressed());
[email protected]f7817822009-09-24 05:11:58659}
660
[email protected]f5494d42010-12-23 22:15:34661void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35662 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
663 const_cast<MSG*>(&accel_message)))
664 return;
665
[email protected]f7817822009-09-24 05:11:58666 bool handled_accel = false;
667 if (in_place_frame_ != NULL) {
668 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
669 const_cast<MSG*>(&accel_message), 0));
670 }
671
672 if (!handled_accel) {
673 if (IsFindAccelerator(accel_message)) {
674 // Handle the showing of the find dialog explicitly.
675 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59676 } else {
[email protected]f5494d42010-12-23 22:15:34677 BaseActiveX::OnAcceleratorPressed(accel_message);
[email protected]f7817822009-09-24 05:11:58678 }
679 } else {
[email protected]2b9a9f162010-10-19 20:30:45680 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
[email protected]f7817822009-09-24 05:11:58681 }
682}
683
[email protected]f5494d42010-12-23 22:15:34684void ChromeActiveDocument::OnTabbedOut(bool reverse) {
[email protected]2b9a9f162010-10-19 20:30:45685 DVLOG(1) << __FUNCTION__;
[email protected]f7817822009-09-24 05:11:58686 if (in_place_frame_) {
687 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
688 in_place_frame_->TranslateAcceleratorW(&msg, 0);
689 }
690}
691
[email protected]f5494d42010-12-23 22:15:34692void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
[email protected]2b9a9f162010-10-19 20:30:45693 DVLOG(1) << __FUNCTION__ << std::endl
694 << "Url: " << nav_info.url
695 << ", Title: " << nav_info.title
696 << ", Type: " << nav_info.navigation_type
697 << ", Relative Offset: " << nav_info.relative_offset
698 << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58699
[email protected]897b26272010-06-11 02:23:44700 CrashMetricsReporter::GetInstance()->IncrementMetric(
701 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
702
[email protected]f7817822009-09-24 05:11:58703 // This could be NULL if the active document instance is being destroyed.
704 if (!m_spInPlaceSite) {
[email protected]2b9a9f162010-10-19 20:30:45705 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
[email protected]f7817822009-09-24 05:11:58706 return;
707 }
708
[email protected]747bca12011-01-15 00:28:45709 UpdateNavigationState(nav_info, 0);
[email protected]f7817822009-09-24 05:11:58710}
711
[email protected]f5494d42010-12-23 22:15:34712void ChromeActiveDocument::OnCloseTab() {
[email protected]2f1793ea2010-10-27 17:32:51713 // Base class will fire DIChromeFrameEvents::onclose.
[email protected]f5494d42010-12-23 22:15:34714 BaseActiveX::OnCloseTab();
[email protected]2f1793ea2010-10-27 17:32:51715
716 // Close the container window.
[email protected]e16dd1672010-06-07 21:40:29717 ScopedComPtr<IWebBrowser2> web_browser2;
718 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
719 if (web_browser2)
720 web_browser2->Quit();
721}
722
[email protected]f7817822009-09-24 05:11:58723void ChromeActiveDocument::UpdateNavigationState(
[email protected]747bca12011-01-15 00:28:45724 const NavigationInfo& new_navigation_info, int flags) {
[email protected]a1800e82009-11-19 00:53:23725 HRESULT hr = S_OK;
[email protected]a22f7e02011-02-09 07:15:35726 bool is_title_changed =
727 (navigation_info_->title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58728 bool is_ssl_state_changed =
[email protected]a22f7e02011-02-09 07:15:35729 (navigation_info_->security_style !=
730 new_navigation_info.security_style) ||
731 (navigation_info_->displayed_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48732 new_navigation_info.displayed_insecure_content) ||
[email protected]a22f7e02011-02-09 07:15:35733 (navigation_info_->ran_insecure_content !=
[email protected]b4e75c12010-05-18 18:28:48734 new_navigation_info.ran_insecure_content);
[email protected]f7817822009-09-24 05:11:58735
[email protected]f7817822009-09-24 05:11:58736 if (is_ssl_state_changed) {
737 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23738 switch (new_navigation_info.security_style) {
[email protected]f7817822009-09-24 05:11:58739 case SECURITY_STYLE_AUTHENTICATED:
[email protected]b4e75c12010-05-18 18:28:48740 lock_status = new_navigation_info.displayed_insecure_content ?
[email protected]f7817822009-09-24 05:11:58741 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
742 break;
743 default:
744 break;
745 }
746
[email protected]965722ff2010-10-20 15:50:30747 base::win::ScopedVariant secure_lock_status(lock_status);
[email protected]f7817822009-09-24 05:11:58748 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
749 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
750 }
751
[email protected]a17930d82011-02-11 23:12:35752 // A number of poorly written bho's crash in their event sink callbacks if
753 // chrome frame is the currently loaded document. This is because they expect
754 // chrome frame to implement interfaces like IHTMLDocument, etc. We patch the
755 // event sink's of these bho's and don't invoke the event sink if chrome
756 // frame is the currently loaded document.
757 if (GetConfigBool(true, kEnableBuggyBhoIntercept)) {
758 ScopedComPtr<IWebBrowser2> wb2;
759 DoQueryService(SID_SWebBrowserApp, m_spClientSite, wb2.Receive());
760 if (wb2 && buggy_bho::BuggyBhoTls::GetInstance()) {
761 buggy_bho::BuggyBhoTls::GetInstance()->PatchBuggyBHOs(wb2);
762 }
763 }
764
[email protected]a1800e82009-11-19 00:53:23765 // Ideally all navigations should come to Chrome Frame so that we can call
766 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
767 // navigation. However, in practice what happens is as below:
768 // The very first navigation that happens in CF happens via a Load or a
769 // LoadHistory call. In this case, IE already has the correct information for
770 // its travel log as well address bar. For other internal navigations (navs
771 // that only happen within Chrome such as anchor navigations) we need to
772 // update IE's internal state after the fact. In the case of internal
773 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58774
775 // Another case where we need to issue BeforeNavigate2 calls is as below:-
776 // We get notified after the fact, when navigations are initiated within
777 // Chrome via window.open calls. These navigations are handled by creating
778 // an external tab container within chrome and then connecting to it from IE.
779 // We still want to update the address bar/history, etc, to ensure that
780 // the special URL used by Chrome to indicate this is updated correctly.
[email protected]d266ce82010-08-13 21:33:40781 ChromeFrameUrl cf_url;
782 bool is_attach_external_tab_url = cf_url.Parse(std::wstring(url_)) &&
783 cf_url.attach_to_external_tab();
[email protected]342de552010-10-21 20:46:14784
785 bool is_internal_navigation =
[email protected]747bca12011-01-15 00:28:45786 IsNewNavigation(new_navigation_info, flags) || is_attach_external_tab_url;
[email protected]f7817822009-09-24 05:11:58787
[email protected]bc2ff5192010-06-01 22:05:45788 if (new_navigation_info.url.is_valid())
[email protected]38939de2010-05-13 02:32:06789 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]38939de2010-05-13 02:32:06790
[email protected]a1800e82009-11-19 00:53:23791 if (is_internal_navigation) {
792 ScopedComPtr<IDocObjectService> doc_object_svc;
[email protected]f7817822009-09-24 05:11:58793 ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06794
[email protected]f7817822009-09-24 05:11:58795 DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite,
796 web_browser_events_svc.Receive());
[email protected]ae33d672010-03-04 21:58:06797
798 if (!web_browser_events_svc.get()) {
799 DoQueryService(SID_SShellBrowser, m_spClientSite,
800 doc_object_svc.Receive());
801 }
802
[email protected]62bb18dc12009-11-25 01:34:08803 // web_browser_events_svc can be NULL on IE6.
[email protected]f7817822009-09-24 05:11:58804 if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58805 VARIANT_BOOL should_cancel = VARIANT_FALSE;
806 web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel);
[email protected]33bd26d2010-08-31 05:05:03807 } else if (doc_object_svc) {
808 BOOL should_cancel = FALSE;
809 doc_object_svc->FireBeforeNavigate2(NULL, url_, 0, NULL, NULL, 0,
810 NULL, FALSE, &should_cancel);
[email protected]a1800e82009-11-19 00:53:23811 }
812
813 // We need to tell IE that we support navigation so that IE will query us
814 // for IPersistHistory and call GetPositionCookie to save our navigation
815 // index.
[email protected]965722ff2010-10-20 15:50:30816 base::win::ScopedVariant html_window(static_cast<IUnknown*>(
[email protected]a1800e82009-11-19 00:53:23817 static_cast<IHTMLWindow2*>(this)));
818 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
819 html_window.AsInput(), NULL);
820
821 // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG
822 // since we want to make IE treat all internal navigations within this page
823 // (including anchor navigations and subframe navigations) as anchor
824 // navigations. This will ensure that IE calls GetPositionCookie
825 // to save the current position cookie in the travel log and then call
826 // SetPositionCookie when the user hits Back/Forward to come back here.
[email protected]965722ff2010-10-20 15:50:30827 base::win::ScopedVariant internal_navigation(HLNF_INTERNALJUMP);
[email protected]a1800e82009-11-19 00:53:23828 IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0,
829 internal_navigation.AsInput(), NULL);
830
831 // We no longer need to lie to IE. If we lie persistently to IE, then
832 // IE reuses us for new navigations.
833 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL);
834
835 if (doc_object_svc) {
836 // Now call the FireNavigateCompleteEvent which makes IE update the text
837 // in the address-bar.
838 doc_object_svc->FireNavigateComplete2(this, 0);
[email protected]5ae94d22010-07-21 19:55:36839 doc_object_svc->FireDocumentComplete(this, 0);
[email protected]a1800e82009-11-19 00:53:23840 } else if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58841 web_browser_events_svc->FireNavigateComplete2Event();
[email protected]5ae94d22010-07-21 19:55:36842 web_browser_events_svc->FireDocumentCompleteEvent();
[email protected]f7817822009-09-24 05:11:58843 }
844 }
[email protected]37346bc2009-09-25 22:54:33845
[email protected]a1800e82009-11-19 00:53:23846 if (is_title_changed) {
[email protected]965722ff2010-10-20 15:50:30847 base::win::ScopedVariant title(new_navigation_info.title.c_str());
[email protected]a1800e82009-11-19 00:53:23848 IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
849 title.AsInput(), NULL);
850 }
851
852 // It is important that we only update the navigation_info_ after we have
853 // finalized the travel log. This is because IE will ask for information
854 // such as navigation index when the travel log is finalized and we need
855 // supply the old index and not the new one.
[email protected]a22f7e02011-02-09 07:15:35856 *navigation_info_ = new_navigation_info;
[email protected]37346bc2009-09-25 22:54:33857 // Update the IE zone here. Ideally we would like to do it when the active
858 // document is activated. However that does not work at times as the frame we
859 // get there is not the actual frame which handles the command.
860 IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL);
[email protected]f7817822009-09-24 05:11:58861}
862
863void ChromeActiveDocument::OnFindInPage() {
864 TabProxy* tab = GetTabProxy();
865 if (tab) {
[email protected]bc2ff5192010-06-01 22:05:45866 if (!find_dialog_.IsWindow())
[email protected]f7817822009-09-24 05:11:58867 find_dialog_.Create(m_hWnd);
[email protected]f7817822009-09-24 05:11:58868
869 find_dialog_.ShowWindow(SW_SHOW);
870 }
871}
872
873void ChromeActiveDocument::OnViewSource() {
[email protected]a22f7e02011-02-09 07:15:35874 DCHECK(navigation_info_->url.is_valid());
[email protected]76e7da22010-06-18 22:44:49875 HostNavigate(GURL(chrome::kViewSourceScheme + std::string(":") +
[email protected]a22f7e02011-02-09 07:15:35876 navigation_info_->url.spec()), GURL(), NEW_WINDOW);
[email protected]f7817822009-09-24 05:11:58877}
878
[email protected]37346bc2009-09-25 22:54:33879void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid,
880 DWORD command_id,
881 DWORD cmd_exec_opt,
882 VARIANT* in_args,
883 VARIANT* out_args) {
[email protected]7c712c92010-03-24 17:29:22884 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
885 // Correct step is to use MapUrlToZone().
[email protected]37346bc2009-09-25 22:54:33886 if (out_args != NULL) {
887 out_args->vt = VT_UI4;
888 out_args->ulVal = URLZONE_INTERNET;
889 }
890}
891
[email protected]80b5a8d2010-03-19 16:50:43892void ChromeActiveDocument::OnDisplayPrivacyInfo() {
[email protected]bbfa9a12010-08-10 14:09:37893 privacy_info_ = url_fetcher_->privacy_info();
[email protected]80b5a8d2010-03-19 16:50:43894 Reset();
895 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
896}
897
[email protected]7f860dd82010-08-09 23:18:05898void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid,
899 DWORD command_id,
900 DWORD cmd_exec_opt,
901 VARIANT* in_args,
902 VARIANT* out_args) {
903 if (out_args != NULL) {
904 out_args->vt = VT_I4;
905 out_args->lVal = 0;
906 }
907}
908
909void ChromeActiveDocument::OnSetZoomRange(const GUID* cmd_group_guid,
910 DWORD command_id,
911 DWORD cmd_exec_opt,
912 VARIANT* in_args,
913 VARIANT* out_args) {
914 const int kZoomIn = 125;
915 const int kZoomOut = 75;
916
917 if (in_args && V_VT(in_args) == VT_I4 && IsValid()) {
918 if (in_args->lVal == kZoomIn) {
919 automation_client_->SetZoomLevel(PageZoom::ZOOM_IN);
920 } else if (in_args->lVal == kZoomOut) {
921 automation_client_->SetZoomLevel(PageZoom::ZOOM_OUT);
922 } else {
923 DLOG(WARNING) << "Unsupported zoom level:" << in_args->lVal;
924 }
925 }
926}
927
[email protected]d9d8f0c2010-09-17 21:47:16928void ChromeActiveDocument::OnUnload(const GUID* cmd_group_guid,
929 DWORD command_id,
930 DWORD cmd_exec_opt,
931 VARIANT* in_args,
932 VARIANT* out_args) {
933 if (IsValid() && out_args) {
934 bool should_unload = true;
935 automation_client_->OnUnload(&should_unload);
936 out_args->vt = VT_BOOL;
937 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
938 }
939}
940
[email protected]f5494d42010-12-23 22:15:34941void ChromeActiveDocument::OnOpenURL(const GURL& url_to_open,
[email protected]b36a9f92009-10-19 17:34:57942 const GURL& referrer,
[email protected]f7817822009-09-24 05:11:58943 int open_disposition) {
944 // If the disposition indicates that we should be opening the URL in the
945 // current tab, then we can reuse the ChromeFrameAutomationClient instance
946 // maintained by the current ChromeActiveDocument instance. We cache this
947 // instance so that it can be used by the new ChromeActiveDocument instance
948 // which may be instantiated for handling the new URL.
949 if (open_disposition == CURRENT_TAB) {
950 // Grab a reference to ensure that the document remains valid.
951 AddRef();
952 g_active_doc_cache.Set(this);
953 }
954
[email protected]f5494d42010-12-23 22:15:34955 BaseActiveX::OnOpenURL(url_to_open, referrer, open_disposition);
[email protected]f7817822009-09-24 05:11:58956}
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) {
986 ScopedComPtr<IBrowserService> browser_service;
987 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]f7817822009-09-24 05:11:581007 ScopedComPtr<IWebBrowser2> web_browser2;
1008 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]f7817822009-09-24 05:11:581027 ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:331028
1029 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]d266ce82010-08-13 21:33:401058 url_.Allocate(UTF8ToWide(cf_url.gurl().spec()).c_str());
[email protected]c4e45b32010-07-28 21:15:151059 if (cf_url.attach_to_external_tab()) {
1060 dimensions_ = cf_url.dimensions();
1061 automation_client_->AttachExternalTab(cf_url.cookie());
[email protected]7f860dd82010-08-09 23:18:051062 SetWindowDimensions();
[email protected]d266ce82010-08-13 21:33:401063 } else if (!automation_client_->InitiateNavigation(cf_url.gurl().spec(),
[email protected]6f8f31d2010-07-30 08:17:151064 referrer,
[email protected]354bcba2010-12-14 04:34:431065 this)) {
[email protected]6f8f31d2010-07-30 08:17:151066 DLOG(ERROR) << "Invalid URL: " << url_;
1067 Error(L"Invalid URL");
1068 url_.Reset();
1069 return false;
[email protected]37346bc2009-09-25 22:54:331070 }
1071
[email protected]3eb07da2010-02-01 19:48:361072 if (is_automation_client_reused_)
1073 return true;
[email protected]37346bc2009-09-25 22:54:331074
[email protected]bbfa9a12010-08-10 14:09:371075 automation_client_->SetUrlFetcher(url_fetcher_.get());
[email protected]701142a2010-08-31 20:57:071076 if (launch_params_) {
1077 return automation_client_->Initialize(this, launch_params_);
1078 } else {
[email protected]8103c7f2010-09-08 22:36:091079 std::wstring profile = UTF8ToWide(cf_url.profile_name());
1080 // If no profile was given, then make use of the host process's name.
1081 if (profile.empty())
1082 profile = GetHostProcessName(false);
1083 return InitializeAutomation(profile, L"", IsIEInPrivate(),
[email protected]9eeb35e2010-09-30 21:38:501084 false, cf_url.gurl(), GURL(referrer),
1085 false);
[email protected]701142a2010-08-31 20:57:071086 }
[email protected]37346bc2009-09-25 22:54:331087}
[email protected]1bb5f892009-10-06 01:44:571088
[email protected]355309e2010-03-15 17:01:341089
1090HRESULT 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]f9cc4c452009-10-13 14:56:381257 ScopedComPtr<IBrowserService> browser_service;
[email protected]a1800e82009-11-19 00:53:231258 ScopedComPtr<ITravelLog> travel_log;
1259 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1260 travel_log.Receive());
1261
1262 if (browser_service && travel_log)
1263 travel_log->Travel(browser_service, offset);
1264}
1265
1266HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1267 IBrowserService** browser_service, ITravelLog** travel_log) {
1268 DCHECK(browser_service || travel_log);
1269 ScopedComPtr<IBrowserService> browser_service_local;
1270 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1271 browser_service_local.Receive());
1272 if (!browser_service_local) {
1273 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1274 return hr;
[email protected]f9cc4c452009-10-13 14:56:381275 }
[email protected]a1800e82009-11-19 00:53:231276
1277 if (travel_log) {
1278 hr = browser_service_local->GetTravelLog(travel_log);
[email protected]5044da82010-10-27 01:09:161279 DVLOG_IF(1, !travel_log) << "browser_service->GetTravelLog failed: " << hr;
[email protected]a1800e82009-11-19 00:53:231280 }
1281
1282 if (browser_service)
1283 *browser_service = browser_service_local.Detach();
1284
1285 return hr;
[email protected]f9cc4c452009-10-13 14:56:381286}
[email protected]a15d4a42010-02-17 08:21:351287
1288LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1289 HWND control_window,
1290 BOOL& bHandled) {
1291 ScopedComPtr<IWebBrowser2> web_browser2;
1292 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1293 DCHECK(web_browser2);
1294
[email protected]bc2ff5192010-06-01 22:05:451295 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351296 web_browser2->GoForward();
[email protected]a15d4a42010-02-17 08:21:351297 return 0;
1298}
1299
1300LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1301 HWND control_window,
1302 BOOL& bHandled) {
1303 ScopedComPtr<IWebBrowser2> web_browser2;
1304 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1305 DCHECK(web_browser2);
1306
[email protected]bc2ff5192010-06-01 22:05:451307 if (web_browser2)
[email protected]a15d4a42010-02-17 08:21:351308 web_browser2->GoBack();
[email protected]a15d4a42010-02-17 08:21:351309 return 0;
1310}
1311
[email protected]80b5a8d2010-03-19 16:50:431312LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1313 LPARAM lparam,
1314 BOOL& handled) {
1315 if (!m_spClientSite)
1316 return 0;
1317
1318 ScopedComPtr<IWebBrowser2> web_browser2;
1319 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1320 web_browser2.Receive());
1321 if (!web_browser2) {
1322 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1323 return 0;
1324 }
1325
1326 ScopedComPtr<IShellBrowser> shell_browser;
1327 DoQueryService(SID_STopLevelBrowser, web_browser2,
1328 shell_browser.Receive());
1329 DCHECK(shell_browser.get() != NULL);
1330 ScopedComPtr<ITridentService2> trident_services;
1331 trident_services.QueryFrom(shell_browser);
[email protected]bc2ff5192010-06-01 22:05:451332 if (trident_services)
[email protected]80b5a8d2010-03-19 16:50:431333 trident_services->FirePrivacyImpactedStateChange(wparam);
[email protected]bc2ff5192010-06-01 22:05:451334 else
[email protected]80b5a8d2010-03-19 16:50:431335 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
[email protected]80b5a8d2010-03-19 16:50:431336 return 0;
1337}
[email protected]00aebd72010-07-16 14:44:321338
[email protected]723e5442010-07-21 17:36:051339LRESULT ChromeActiveDocument::OnShowWindow(UINT message, WPARAM wparam,
1340 LPARAM lparam,
1341 BOOL& handled) { // NO_LINT
1342 if (wparam)
1343 SetFocus();
1344 return 0;
1345}
1346
1347LRESULT ChromeActiveDocument::OnSetFocus(UINT message, WPARAM wparam,
1348 LPARAM lparam,
1349 BOOL& handled) { // NO_LINT
[email protected]e7ad9322010-08-02 20:41:291350 if (!ignore_setfocus_)
1351 GiveFocusToChrome(false);
[email protected]723e5442010-07-21 17:36:051352 return 0;
1353}
[email protected]7f860dd82010-08-09 23:18:051354
1355void ChromeActiveDocument::SetWindowDimensions() {
1356 ScopedComPtr<IWebBrowser2> web_browser2;
1357 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1358 web_browser2.Receive());
1359 if (!web_browser2)
1360 return;
[email protected]2b9a9f162010-10-19 20:30:451361 DVLOG(1) << "this:" << this << "\ndimensions: width:" << dimensions_.width()
1362 << " height:" << dimensions_.height();
[email protected]7f860dd82010-08-09 23:18:051363 if (!dimensions_.IsEmpty()) {
[email protected]73b18972010-11-18 01:35:461364 web_browser2->put_MenuBar(VARIANT_FALSE);
1365 web_browser2->put_ToolBar(VARIANT_FALSE);
1366
1367 int width = dimensions_.width();
1368 int height = dimensions_.height();
1369 // Compute the size of the browser window given the desired size of the
1370 // content area. As per MSDN, the WebBrowser object returns an error from
1371 // this method. As a result the code below is best effort.
1372 if (SUCCEEDED(web_browser2->ClientToWindow(&width, &height))) {
1373 dimensions_.set_width(width);
1374 dimensions_.set_height(height);
1375 }
[email protected]7f860dd82010-08-09 23:18:051376 web_browser2->put_Width(dimensions_.width());
1377 web_browser2->put_Height(dimensions_.height());
1378 web_browser2->put_Left(dimensions_.x());
1379 web_browser2->put_Top(dimensions_.y());
[email protected]7f860dd82010-08-09 23:18:051380
1381 dimensions_.set_height(0);
1382 dimensions_.set_width(0);
1383 }
1384}
[email protected]342de552010-10-21 20:46:141385
1386bool ChromeActiveDocument::IsNewNavigation(
[email protected]747bca12011-01-15 00:28:451387 const NavigationInfo& new_navigation_info, int flags) const {
[email protected]342de552010-10-21 20:46:141388 // A new navigation is typically an internal navigation which is initiated by
1389 // the renderer(WebKit). Condition 1 below has to be true along with the
1390 // any of the other conditions below.
[email protected]747bca12011-01-15 00:28:451391 // 1. The navigation notification flags passed in as the flags parameter
1392 // is not INVALIDATE_LOAD which indicates that the loading state of the
1393 // tab changed.
1394 // 2. The navigation index is greater than 0 which means that a top level
[email protected]342de552010-10-21 20:46:141395 // navigation was initiated on the current external tab.
[email protected]747bca12011-01-15 00:28:451396 // 3. The navigation type has changed.
1397 // 4. The url or the referrer are different.
1398 if (flags == TabContents::INVALIDATE_LOAD)
1399 return false;
1400
[email protected]342de552010-10-21 20:46:141401 if (new_navigation_info.navigation_index <= 0)
1402 return false;
1403
1404 if (new_navigation_info.navigation_index ==
[email protected]a22f7e02011-02-09 07:15:351405 navigation_info_->navigation_index)
[email protected]342de552010-10-21 20:46:141406 return false;
1407
[email protected]a22f7e02011-02-09 07:15:351408 if (new_navigation_info.navigation_type != navigation_info_->navigation_type)
[email protected]342de552010-10-21 20:46:141409 return true;
1410
[email protected]a22f7e02011-02-09 07:15:351411 if (new_navigation_info.url != navigation_info_->url)
[email protected]342de552010-10-21 20:46:141412 return true;
1413
[email protected]a22f7e02011-02-09 07:15:351414 if (new_navigation_info.referrer != navigation_info_->referrer)
[email protected]342de552010-10-21 20:46:141415 return true;
1416
1417 return false;
1418}