blob: 2c9cba66351d1daa421755b1c72b8742142710df [file] [log] [blame]
[email protected]f7817822009-09-24 05:11:581// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// 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>
14#include <shobjidl.h>
15#include <tlogstg.h>
16#include <urlmon.h>
17#include <wininet.h>
18
19#include "base/command_line.h"
20#include "base/file_util.h"
21#include "base/logging.h"
22#include "base/path_service.h"
23#include "base/process_util.h"
24#include "base/registry.h"
25#include "base/scoped_variant_win.h"
26#include "base/string_tokenizer.h"
27#include "base/string_util.h"
28#include "base/thread.h"
29#include "base/thread_local.h"
30
31#include "grit/generated_resources.h"
32#include "chrome/browser/tab_contents/tab_contents.h"
33#include "chrome/common/chrome_constants.h"
34#include "chrome/common/navigation_types.h"
35#include "chrome/test/automation/browser_proxy.h"
36#include "chrome/test/automation/tab_proxy.h"
[email protected]b36a9f92009-10-19 17:34:5737#include "chrome_frame/bho.h"
[email protected]f7817822009-09-24 05:11:5838#include "chrome_frame/utils.h"
39
40const wchar_t kChromeAttachExternalTabPrefix[] = L"attach_external_tab";
41
42static const wchar_t kUseChromeNetworking[] = L"UseChromeNetworking";
[email protected]552fb6012010-02-03 17:24:2943static const wchar_t kHandleTopLevelRequests[] = L"HandleTopLevelRequests";
[email protected]f7817822009-09-24 05:11:5844
[email protected]a1800e82009-11-19 00:53:2345DEFINE_GUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0,
46 0x46);
47
48
[email protected]f7817822009-09-24 05:11:5849base::ThreadLocalPointer<ChromeActiveDocument> g_active_doc_cache;
50
51bool g_first_launch_by_process_ = true;
52
53ChromeActiveDocument::ChromeActiveDocument()
54 : first_navigation_(true),
[email protected]a15d4a42010-02-17 08:21:3555 is_automation_client_reused_(false),
[email protected]355309e2010-03-15 17:01:3456 popup_allowed_(false),
[email protected]a15d4a42010-02-17 08:21:3557 accelerator_table_(NULL) {
[email protected]3eb07da2010-02-01 19:48:3658 url_fetcher_.set_frame_busting(false);
[email protected]a1800e82009-11-19 00:53:2359 memset(&navigation_info_, 0, sizeof(navigation_info_));
[email protected]f7817822009-09-24 05:11:5860}
61
62HRESULT ChromeActiveDocument::FinalConstruct() {
63 // If we have a cached ChromeActiveDocument instance in TLS, then grab
64 // ownership of the cached document's automation client. This is an
65 // optimization to get Chrome active documents to load faster.
66 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
67 if (cached_document) {
68 DCHECK(automation_client_.get() == NULL);
[email protected]3148c0ae2010-03-11 18:06:0069 automation_client_.swap(cached_document->automation_client_);
[email protected]f7817822009-09-24 05:11:5870 DLOG(INFO) << "Reusing automation client instance from "
71 << cached_document;
72 DCHECK(automation_client_.get() != NULL);
[email protected]3eb07da2010-02-01 19:48:3673 automation_client_->Reinitialize(this, &url_fetcher_);
[email protected]f7817822009-09-24 05:11:5874 is_automation_client_reused_ = true;
75 } else {
76 // The FinalConstruct implementation in the ChromeFrameActivexBase class
77 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
78 // and initializes it, which would spawn a new Chrome process, etc.
79 // We don't want to be doing this if we have a cached document, whose
80 // automation client instance can be reused.
81 HRESULT hr = Base::FinalConstruct();
82 if (FAILED(hr))
83 return hr;
84 }
85
86 bool chrome_network = GetConfigBool(false, kUseChromeNetworking);
87 bool top_level_requests = GetConfigBool(true, kHandleTopLevelRequests);
88 automation_client_->set_use_chrome_network(chrome_network);
89 automation_client_->set_handle_top_level_requests(top_level_requests);
90
91 find_dialog_.Init(automation_client_.get());
92
93 enabled_commands_map_[OLECMDID_PRINT] = true;
94 enabled_commands_map_[OLECMDID_FIND] = true;
95 enabled_commands_map_[OLECMDID_CUT] = true;
96 enabled_commands_map_[OLECMDID_COPY] = true;
97 enabled_commands_map_[OLECMDID_PASTE] = true;
98 enabled_commands_map_[OLECMDID_SELECTALL] = true;
[email protected]673fd2c02010-02-04 23:10:0099 enabled_commands_map_[OLECMDID_SAVEAS] = true;
[email protected]a15d4a42010-02-17 08:21:35100
101 accelerator_table_ =
102 LoadAccelerators(GetModuleHandle(L"npchrome_frame.dll"),
103 MAKEINTRESOURCE(IDR_CHROME_FRAME_IE_FULL_TAB));
104 DCHECK(accelerator_table_ != NULL);
[email protected]f7817822009-09-24 05:11:58105 return S_OK;
106}
107
108ChromeActiveDocument::~ChromeActiveDocument() {
109 DLOG(INFO) << __FUNCTION__;
110 if (find_dialog_.IsWindow()) {
111 find_dialog_.DestroyWindow();
112 }
[email protected]3eb07da2010-02-01 19:48:36113 // ChromeFramePlugin
114 Base::Uninitialize();
[email protected]f7817822009-09-24 05:11:58115}
116
117// Override DoVerb
118STDMETHODIMP ChromeActiveDocument::DoVerb(LONG verb,
119 LPMSG msg,
120 IOleClientSite* active_site,
121 LONG index,
122 HWND parent_window,
123 LPCRECT pos) {
124 // IE will try and in-place activate us in some cases. This happens when
125 // the user opens a new IE window with a URL that has us as the DocObject.
126 // Here we refuse to be activated in-place and we will force IE to UIActivate
127 // us.
128 if (OLEIVERB_INPLACEACTIVATE == verb) {
129 return E_NOTIMPL;
130 }
131 // Check if we should activate as a docobject or not
132 // (client supports IOleDocumentSite)
133 if (doc_site_) {
134 switch (verb) {
[email protected]1bb5f892009-10-06 01:44:57135 case OLEIVERB_SHOW: {
136 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
137 doc_host_handler.QueryFrom(doc_site_);
138 if (doc_host_handler.get()) {
139 doc_host_handler->ShowUI(DOCHOSTUITYPE_BROWSE, this, this, NULL, NULL);
140 }
141 }
[email protected]f7817822009-09-24 05:11:58142 case OLEIVERB_OPEN:
143 case OLEIVERB_UIACTIVATE:
144 if (!m_bUIActive) {
145 return doc_site_->ActivateMe(NULL);
146 }
147 break;
148 }
149 }
150 return IOleObjectImpl<ChromeActiveDocument>::DoVerb(verb,
151 msg,
152 active_site,
153 index,
154 parent_window,
155 pos);
156}
157
[email protected]f7817822009-09-24 05:11:58158// Override IOleInPlaceActiveObjectImpl::OnDocWindowActivate
159STDMETHODIMP ChromeActiveDocument::OnDocWindowActivate(BOOL activate) {
160 DLOG(INFO) << __FUNCTION__;
161 return S_OK;
162}
163
164STDMETHODIMP ChromeActiveDocument::TranslateAccelerator(MSG* msg) {
165 DLOG(INFO) << __FUNCTION__;
166 if (msg == NULL)
167 return E_POINTER;
168
169 if (msg->message == WM_KEYDOWN && msg->wParam == VK_TAB) {
170 HWND focus = ::GetFocus();
171 if (focus != m_hWnd && !::IsChild(m_hWnd, focus)) {
172 // The call to SetFocus triggers a WM_SETFOCUS that makes the base class
173 // set focus to the correct element in Chrome.
174 ::SetFocus(m_hWnd);
175 return S_OK;
176 }
177 }
178
179 return S_FALSE;
180}
181// Override IPersistStorageImpl::IsDirty
182STDMETHODIMP ChromeActiveDocument::IsDirty() {
183 DLOG(INFO) << __FUNCTION__;
184 return S_FALSE;
185}
186
[email protected]b95f550f2009-11-19 05:35:22187void ChromeActiveDocument::OnAutomationServerReady() {
188 Base::OnAutomationServerReady();
189 Base::GiveFocusToChrome();
190}
191
[email protected]f7817822009-09-24 05:11:58192STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
193 IMoniker* moniker_name,
194 LPBC bind_context,
195 DWORD mode) {
196 if (NULL == moniker_name) {
197 return E_INVALIDARG;
198 }
[email protected]a1800e82009-11-19 00:53:23199
200 ScopedComPtr<IOleClientSite> client_site;
201 if (bind_context) {
202 ScopedComPtr<IUnknown> site;
203 bind_context->GetObjectParam(SZ_HTML_CLIENTSITE_OBJECTPARAM,
204 site.Receive());
205 if (site)
206 client_site.QueryFrom(site);
207 }
208
209 if (client_site) {
210 SetClientSite(client_site);
[email protected]b1c55638612010-03-08 16:26:11211 DoQueryService(IID_INewWindowManager, client_site,
212 popup_manager_.Receive());
[email protected]051236f2010-03-12 22:06:14213
214 // See if mshtml parsed the html header for us. If so, we need to
215 // clear the browser service flag that we use to indicate that this
216 // browser instance is navigating to a CF document.
217 ScopedComPtr<IBrowserService> browser_service;
218 DoQueryService(SID_SShellBrowser, client_site, browser_service.Receive());
219 if (browser_service) {
220 bool flagged = CheckForCFNavigation(browser_service, true);
221 DLOG_IF(INFO, flagged) << "Cleared flagged browser service";
222 }
[email protected]a1800e82009-11-19 00:53:23223 }
224
[email protected]051236f2010-03-12 22:06:14225 NavigationManager* mgr = NavigationManager::GetThreadInstance();
226 DCHECK(mgr);
[email protected]7e3544b2010-01-22 00:02:34227
228 // If the original URL contains an anchor, then the URL queried
229 // from the moniker does not contain the anchor. To workaround
230 // this we retrieve the URL from our BHO.
[email protected]38d3d422010-03-16 22:24:26231 std::wstring url(GetActualUrlFromMoniker(
232 moniker_name, bind_context,
233 mgr ? mgr->original_url_with_fragment() : std::wstring()));
234
[email protected]014c0332010-03-19 07:09:09235 scoped_refptr<RequestData> data;
[email protected]38d3d422010-03-16 22:24:26236 if (mgr) {
237 mgr->set_original_url_with_fragment(L"");
[email protected]014c0332010-03-19 07:09:09238 data = mgr->GetActiveRequestData(url.c_str());
[email protected]38d3d422010-03-16 22:24:26239 }
[email protected]051236f2010-03-12 22:06:14240
[email protected]051236f2010-03-12 22:06:14241 DLOG_IF(INFO, data) << "Got active request data";
242 DLOG_IF(WARNING, data.get() == NULL) << "NO active request data";
[email protected]f7817822009-09-24 05:11:58243
[email protected]37346bc2009-09-25 22:54:33244 // The is_new_navigation variable indicates if this a navigation initiated
245 // by typing in a URL for e.g. in the IE address bar, or from Chrome by
246 // a window.open call from javascript, in which case the current IE tab
247 // will attach to an existing ExternalTabContainer instance.
[email protected]f7817822009-09-24 05:11:58248 bool is_new_navigation = true;
[email protected]37346bc2009-09-25 22:54:33249 bool is_chrome_protocol = false;
[email protected]f7817822009-09-24 05:11:58250
[email protected]37346bc2009-09-25 22:54:33251 if (!ParseUrl(url, &is_new_navigation, &is_chrome_protocol, &url)) {
252 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
[email protected]f7817822009-09-24 05:11:58253 return E_INVALIDARG;
254 }
255
[email protected]37346bc2009-09-25 22:54:33256 if (!LaunchUrl(url, is_new_navigation)) {
257 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
258 return E_INVALIDARG;
[email protected]f7817822009-09-24 05:11:58259 }
260
[email protected]051236f2010-03-12 22:06:14261 if (!is_chrome_protocol && data) {
262 url_fetcher_.UseRequestDataForUrl(data, url);
[email protected]f7817822009-09-24 05:11:58263 }
264
[email protected]333590002010-03-05 18:49:21265 THREAD_SAFE_UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.FullTabLaunchType",
266 is_chrome_protocol, 0, 1, 2);
[email protected]f7817822009-09-24 05:11:58267 return S_OK;
268}
269
270STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
271 LPBC bind_context,
272 BOOL remember) {
273 return E_NOTIMPL;
274}
275
276STDMETHODIMP ChromeActiveDocument::SaveCompleted(IMoniker* moniker_name,
277 LPBC bind_context) {
278 return E_NOTIMPL;
279}
280
281STDMETHODIMP ChromeActiveDocument::GetCurMoniker(IMoniker** moniker_name) {
282 return E_NOTIMPL;
283}
284
285STDMETHODIMP ChromeActiveDocument::GetClassID(CLSID* class_id) {
286 if (NULL == class_id) {
287 return E_POINTER;
288 }
289 *class_id = GetObjectCLSID();
290 return S_OK;
291}
292
293STDMETHODIMP ChromeActiveDocument::QueryStatus(const GUID* cmd_group_guid,
294 ULONG number_of_commands,
295 OLECMD commands[],
296 OLECMDTEXT* command_text) {
297 DLOG(INFO) << __FUNCTION__;
298 for (ULONG command_index = 0; command_index < number_of_commands;
299 command_index++) {
300 DLOG(INFO) << "Command id = " << commands[command_index].cmdID;
301 if (enabled_commands_map_.find(commands[command_index].cmdID) !=
302 enabled_commands_map_.end()) {
303 commands[command_index].cmdf = OLECMDF_ENABLED;
304 }
305 }
306 return S_OK;
307}
308
309STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
310 DWORD command_id,
311 DWORD cmd_exec_opt,
312 VARIANT* in_args,
313 VARIANT* out_args) {
314 DLOG(INFO) << __FUNCTION__ << " Cmd id =" << command_id;
315 // Bail out if we have been uninitialized.
316 if (automation_client_.get() && automation_client_->tab()) {
317 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
318 in_args, out_args);
319 }
[email protected]e3200932009-10-09 21:33:03320 return OLECMDERR_E_NOTSUPPORTED;
[email protected]f7817822009-09-24 05:11:58321}
322
[email protected]a1800e82009-11-19 00:53:23323STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
324 IBindCtx* bind_context) {
325 // Read notes in ChromeActiveDocument::SaveHistory
326 DCHECK(stream);
327 LARGE_INTEGER offset = {0};
328 ULARGE_INTEGER cur_pos = {0};
329 STATSTG statstg = {0};
330
331 stream->Seek(offset, STREAM_SEEK_CUR, &cur_pos);
332 stream->Stat(&statstg, STATFLAG_NONAME);
333
334 DWORD url_size = statstg.cbSize.LowPart - cur_pos.LowPart;
335 ScopedBstr url_bstr;
336 DWORD bytes_read = 0;
337 stream->Read(url_bstr.AllocateBytes(url_size), url_size, &bytes_read);
338 std::wstring url(url_bstr);
339
340 bool is_new_navigation = true;
341 bool is_chrome_protocol = false;
342
343 if (!ParseUrl(url, &is_new_navigation, &is_chrome_protocol, &url)) {
344 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
345 return E_INVALIDARG;
346 }
347
348 if (!LaunchUrl(url, is_new_navigation)) {
349 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
350 return E_INVALIDARG;
351 }
352 return S_OK;
353}
354
355STDMETHODIMP ChromeActiveDocument::SaveHistory(IStream* stream) {
356 // TODO(sanjeevr): We need to fetch the entire list of navigation entries
357 // from Chrome and persist it in the stream. And in LoadHistory we need to
358 // pass this list back to Chrome which will recreate the list. This will allow
359 // Back-Forward navigation to anchors to work correctly when we navigate to a
360 // page outside of ChromeFrame and then come back.
361 if (!stream) {
362 NOTREACHED();
363 return E_INVALIDARG;
364 }
365
366 LARGE_INTEGER offset = {0};
367 ULARGE_INTEGER new_pos = {0};
368 DWORD written = 0;
369 std::wstring url = UTF8ToWide(navigation_info_.url.spec());
370 return stream->Write(url.c_str(), (url.length() + 1) * sizeof(wchar_t),
371 &written);
372}
373
374STDMETHODIMP ChromeActiveDocument::SetPositionCookie(DWORD position_cookie) {
375 int index = static_cast<int>(position_cookie);
376 navigation_info_.navigation_index = index;
377 automation_client_->NavigateToIndex(index);
378 return S_OK;
379}
380
381STDMETHODIMP ChromeActiveDocument::GetPositionCookie(DWORD* position_cookie) {
382 if (!position_cookie)
383 return E_INVALIDARG;
384
385 *position_cookie = navigation_info_.navigation_index;
386 return S_OK;
387}
388
[email protected]f7817822009-09-24 05:11:58389STDMETHODIMP ChromeActiveDocument::GetUrlForEvents(BSTR* url) {
390 if (NULL == url) {
391 return E_POINTER;
392 }
393 *url = ::SysAllocString(url_);
394 return S_OK;
395}
396
[email protected]a1800e82009-11-19 00:53:23397STDMETHODIMP ChromeActiveDocument::GetAddressBarUrl(BSTR* url) {
398 return GetUrlForEvents(url);
399}
400
[email protected]80b5a8d2010-03-19 16:50:43401STDMETHODIMP ChromeActiveDocument::Reset() {
402 next_privacy_record_ = privacy_info_.privacy_records.begin();
403 return S_OK;
404}
405
406STDMETHODIMP ChromeActiveDocument::GetSize(unsigned long* size) {
407 if (!size)
408 return E_POINTER;
409
410 *size = privacy_info_.privacy_records.size();
411 return S_OK;
412}
413
414STDMETHODIMP ChromeActiveDocument::GetPrivacyImpacted(BOOL* privacy_impacted) {
415 if (!privacy_impacted)
416 return E_POINTER;
417
418 *privacy_impacted = privacy_info_.privacy_impacted;
419 return S_OK;
420}
421
422STDMETHODIMP ChromeActiveDocument::Next(BSTR* url, BSTR* policy,
423 long* reserved, unsigned long* flags) {
424 if (!url || !policy || !flags)
425 return E_POINTER;
426
427 if (next_privacy_record_ == privacy_info_.privacy_records.end())
428 return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
429
430 *url = SysAllocString(next_privacy_record_->first.c_str());
431 *policy = SysAllocString(next_privacy_record_->second.policy_ref.c_str());
432 *flags = next_privacy_record_->second.flags;
433
434 next_privacy_record_++;
435 return S_OK;
436}
437
[email protected]f7817822009-09-24 05:11:58438HRESULT ChromeActiveDocument::IOleObject_SetClientSite(
439 IOleClientSite* client_site) {
440 if (client_site == NULL) {
441 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
442 if (cached_document) {
443 DCHECK(this == cached_document);
444 g_active_doc_cache.Set(NULL);
445 cached_document->Release();
446 }
[email protected]dda7d9c2009-11-11 23:01:47447
448 ScopedComPtr<IDocHostUIHandler> doc_host_handler;
[email protected]77059f72010-02-28 06:16:00449 if (doc_site_) {
450 doc_host_handler.QueryFrom(doc_site_);
451 }
[email protected]dda7d9c2009-11-11 23:01:47452
453 if (doc_host_handler.get()) {
454 doc_host_handler->HideUI();
455 }
456
457 doc_site_.Release();
458 in_place_frame_.Release();
[email protected]f7817822009-09-24 05:11:58459 }
[email protected]a1800e82009-11-19 00:53:23460
[email protected]80b5a8d2010-03-19 16:50:43461 if (client_site != m_spClientSite) {
[email protected]a1800e82009-11-19 00:53:23462 return Base::IOleObject_SetClientSite(client_site);
[email protected]80b5a8d2010-03-19 16:50:43463 }
[email protected]a1800e82009-11-19 00:53:23464
465 return S_OK;
[email protected]f7817822009-09-24 05:11:58466}
467
[email protected]f7817822009-09-24 05:11:58468HRESULT ChromeActiveDocument::ActiveXDocActivate(LONG verb) {
469 HRESULT hr = S_OK;
470 m_bNegotiatedWnd = TRUE;
471 if (!m_bInPlaceActive) {
472 hr = m_spInPlaceSite->CanInPlaceActivate();
473 if (FAILED(hr)) {
474 return hr;
475 }
476 m_spInPlaceSite->OnInPlaceActivate();
477 }
478 m_bInPlaceActive = TRUE;
479 // get location in the parent window,
480 // as well as some information about the parent
481 ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
482 frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
483 HWND parent_window = NULL;
484 if (m_spInPlaceSite->GetWindow(&parent_window) == S_OK) {
485 in_place_frame_.Release();
486 RECT position_rect = {0};
487 RECT clip_rect = {0};
488 m_spInPlaceSite->GetWindowContext(in_place_frame_.Receive(),
489 in_place_ui_window.Receive(),
490 &position_rect,
491 &clip_rect,
492 &frame_info_);
493 if (!m_bWndLess) {
494 if (IsWindow()) {
495 ::ShowWindow(m_hWnd, SW_SHOW);
496 SetFocus();
497 } else {
[email protected]c1d19582010-03-03 01:57:13498 m_hWnd = Create(parent_window, position_rect, 0, 0, WS_EX_CLIENTEDGE);
[email protected]f7817822009-09-24 05:11:58499 }
500 }
501 SetObjectRects(&position_rect, &clip_rect);
502 }
503
504 ScopedComPtr<IOleInPlaceActiveObject> in_place_active_object(this);
505
506 // Gone active by now, take care of UIACTIVATE
507 if (DoesVerbUIActivate(verb)) {
508 if (!m_bUIActive) {
509 m_bUIActive = TRUE;
510 hr = m_spInPlaceSite->OnUIActivate();
511 if (FAILED(hr)) {
512 return hr;
513 }
514 // set ourselves up in the host
515 if (in_place_active_object) {
516 if (in_place_frame_) {
517 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
518 }
519 if (in_place_ui_window) {
520 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
521 }
522 }
523 }
524 }
525 m_spClientSite->ShowObject();
[email protected]f7817822009-09-24 05:11:58526 return S_OK;
527}
528
529void ChromeActiveDocument::OnNavigationStateChanged(int tab_handle, int flags,
530 const IPC::NavigationInfo& nav_info) {
531 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
532 DLOG(INFO) << __FUNCTION__ << std::endl << " Flags: " << flags
533 << "Url: " << nav_info.url <<
534 ", Title: " << nav_info.title <<
535 ", Type: " << nav_info.navigation_type << ", Relative Offset: " <<
[email protected]62bb18dc12009-11-25 01:34:08536 nav_info.relative_offset << ", Index: " << nav_info.navigation_index;
[email protected]f7817822009-09-24 05:11:58537
538 UpdateNavigationState(nav_info);
539}
540
541void ChromeActiveDocument::OnUpdateTargetUrl(int tab_handle,
542 const std::wstring& new_target_url) {
543 if (in_place_frame_) {
544 in_place_frame_->SetStatusText(new_target_url.c_str());
545 }
546}
547
548bool IsFindAccelerator(const MSG& msg) {
549 // TODO(robertshield): This may not stand up to localization. Fix if this
550 // is the case.
551 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
552 win_util::IsCtrlPressed() &&
553 !(win_util::IsAltPressed() || win_util::IsShiftPressed());
554}
555
556void ChromeActiveDocument::OnAcceleratorPressed(int tab_handle,
557 const MSG& accel_message) {
[email protected]a15d4a42010-02-17 08:21:35558 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
559 const_cast<MSG*>(&accel_message)))
560 return;
561
[email protected]f7817822009-09-24 05:11:58562 bool handled_accel = false;
563 if (in_place_frame_ != NULL) {
564 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
565 const_cast<MSG*>(&accel_message), 0));
566 }
567
568 if (!handled_accel) {
569 if (IsFindAccelerator(accel_message)) {
570 // Handle the showing of the find dialog explicitly.
571 OnFindInPage();
[email protected]2b8fd322009-10-02 00:00:59572 } else {
573 Base::OnAcceleratorPressed(tab_handle, accel_message);
[email protected]f7817822009-09-24 05:11:58574 }
575 } else {
576 DLOG(INFO) << "IE handled accel key " << accel_message.wParam;
577 }
578}
579
580void ChromeActiveDocument::OnTabbedOut(int tab_handle, bool reverse) {
581 DLOG(INFO) << __FUNCTION__;
582 if (in_place_frame_) {
583 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
584 in_place_frame_->TranslateAcceleratorW(&msg, 0);
585 }
586}
587
588void ChromeActiveDocument::OnDidNavigate(int tab_handle,
589 const IPC::NavigationInfo& nav_info) {
590 DLOG(INFO) << __FUNCTION__ << std::endl << "Url: " << nav_info.url <<
591 ", Title: " << nav_info.title <<
592 ", Type: " << nav_info.navigation_type << ", Relative Offset: " <<
593 nav_info.relative_offset << ", Index: " << nav_info.navigation_index;
594
595 // This could be NULL if the active document instance is being destroyed.
596 if (!m_spInPlaceSite) {
597 DLOG(INFO) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
598 return;
599 }
600
601 UpdateNavigationState(nav_info);
602}
603
604void ChromeActiveDocument::UpdateNavigationState(
605 const IPC::NavigationInfo& new_navigation_info) {
[email protected]a1800e82009-11-19 00:53:23606 HRESULT hr = S_OK;
[email protected]f7817822009-09-24 05:11:58607 bool is_title_changed = (navigation_info_.title != new_navigation_info.title);
[email protected]f7817822009-09-24 05:11:58608 bool is_ssl_state_changed =
609 (navigation_info_.security_style != new_navigation_info.security_style) ||
610 (navigation_info_.has_mixed_content !=
611 new_navigation_info.has_mixed_content);
612
[email protected]f7817822009-09-24 05:11:58613 if (is_ssl_state_changed) {
614 int lock_status = SECURELOCK_SET_UNSECURE;
[email protected]a1800e82009-11-19 00:53:23615 switch (new_navigation_info.security_style) {
[email protected]f7817822009-09-24 05:11:58616 case SECURITY_STYLE_AUTHENTICATION_BROKEN:
617 lock_status = SECURELOCK_SET_SECUREUNKNOWNBIT;
618 break;
619 case SECURITY_STYLE_AUTHENTICATED:
[email protected]a1800e82009-11-19 00:53:23620 lock_status = new_navigation_info.has_mixed_content ?
[email protected]f7817822009-09-24 05:11:58621 SECURELOCK_SET_MIXED : SECURELOCK_SET_SECUREUNKNOWNBIT;
622 break;
623 default:
624 break;
625 }
626
627 ScopedVariant secure_lock_status(lock_status);
628 IEExec(&CGID_ShellDocView, INTERNAL_CMDID_SET_SSL_LOCK,
629 OLECMDEXECOPT_DODEFAULT, secure_lock_status.AsInput(), NULL);
630 }
631
[email protected]a1800e82009-11-19 00:53:23632 // Ideally all navigations should come to Chrome Frame so that we can call
633 // BeforeNavigate2 on installed BHOs and give them a chance to cancel the
634 // navigation. However, in practice what happens is as below:
635 // The very first navigation that happens in CF happens via a Load or a
636 // LoadHistory call. In this case, IE already has the correct information for
637 // its travel log as well address bar. For other internal navigations (navs
638 // that only happen within Chrome such as anchor navigations) we need to
639 // update IE's internal state after the fact. In the case of internal
640 // navigations, we notify the BHOs but ignore the should_cancel flag.
[email protected]6f526082010-01-28 19:36:58641
642 // Another case where we need to issue BeforeNavigate2 calls is as below:-
643 // We get notified after the fact, when navigations are initiated within
644 // Chrome via window.open calls. These navigations are handled by creating
645 // an external tab container within chrome and then connecting to it from IE.
646 // We still want to update the address bar/history, etc, to ensure that
647 // the special URL used by Chrome to indicate this is updated correctly.
648 bool is_internal_navigation = ((new_navigation_info.navigation_index > 0) &&
[email protected]a1800e82009-11-19 00:53:23649 (new_navigation_info.navigation_index !=
[email protected]6f526082010-01-28 19:36:58650 navigation_info_.navigation_index)) ||
651 StartsWith(static_cast<BSTR>(url_), kChromeAttachExternalTabPrefix,
652 false);
[email protected]f7817822009-09-24 05:11:58653
[email protected]a1800e82009-11-19 00:53:23654 if (new_navigation_info.url.is_valid()) {
655 url_.Allocate(UTF8ToWide(new_navigation_info.url.spec()).c_str());
[email protected]051236f2010-03-12 22:06:14656 NavigationManager* mgr = NavigationManager::GetThreadInstance();
657 DCHECK(mgr);
658 if (mgr) {
659 mgr->set_url(url_);
660 mgr->ReleaseRequestData();
661 }
[email protected]a1800e82009-11-19 00:53:23662 }
663
664 if (is_internal_navigation) {
665 ScopedComPtr<IDocObjectService> doc_object_svc;
[email protected]f7817822009-09-24 05:11:58666 ScopedComPtr<IWebBrowserEventsService> web_browser_events_svc;
[email protected]ae33d672010-03-04 21:58:06667
[email protected]f7817822009-09-24 05:11:58668 DoQueryService(__uuidof(web_browser_events_svc), m_spClientSite,
669 web_browser_events_svc.Receive());
[email protected]ae33d672010-03-04 21:58:06670
671 if (!web_browser_events_svc.get()) {
672 DoQueryService(SID_SShellBrowser, m_spClientSite,
673 doc_object_svc.Receive());
674 }
675
[email protected]62bb18dc12009-11-25 01:34:08676 // web_browser_events_svc can be NULL on IE6.
[email protected]f7817822009-09-24 05:11:58677 if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58678 VARIANT_BOOL should_cancel = VARIANT_FALSE;
679 web_browser_events_svc->FireBeforeNavigate2Event(&should_cancel);
[email protected]a1800e82009-11-19 00:53:23680 }
681
682 // We need to tell IE that we support navigation so that IE will query us
683 // for IPersistHistory and call GetPositionCookie to save our navigation
684 // index.
685 ScopedVariant html_window(static_cast<IUnknown*>(
686 static_cast<IHTMLWindow2*>(this)));
687 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
688 html_window.AsInput(), NULL);
689
690 // We pass the HLNF_INTERNALJUMP flag to INTERNAL_CMDID_FINALIZE_TRAVEL_LOG
691 // since we want to make IE treat all internal navigations within this page
692 // (including anchor navigations and subframe navigations) as anchor
693 // navigations. This will ensure that IE calls GetPositionCookie
694 // to save the current position cookie in the travel log and then call
695 // SetPositionCookie when the user hits Back/Forward to come back here.
696 ScopedVariant internal_navigation(HLNF_INTERNALJUMP);
697 IEExec(&CGID_Explorer, INTERNAL_CMDID_FINALIZE_TRAVEL_LOG, 0,
698 internal_navigation.AsInput(), NULL);
699
700 // We no longer need to lie to IE. If we lie persistently to IE, then
701 // IE reuses us for new navigations.
702 IEExec(&CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0, NULL, NULL);
703
704 if (doc_object_svc) {
705 // Now call the FireNavigateCompleteEvent which makes IE update the text
706 // in the address-bar.
707 doc_object_svc->FireNavigateComplete2(this, 0);
708 doc_object_svc->FireDocumentComplete(this, 0);
709 } else if (web_browser_events_svc) {
[email protected]f7817822009-09-24 05:11:58710 web_browser_events_svc->FireNavigateComplete2Event();
[email protected]a1800e82009-11-19 00:53:23711 web_browser_events_svc->FireDocumentCompleteEvent();
[email protected]f7817822009-09-24 05:11:58712 }
713 }
[email protected]37346bc2009-09-25 22:54:33714
[email protected]a1800e82009-11-19 00:53:23715 if (is_title_changed) {
716 ScopedVariant title(new_navigation_info.title.c_str());
717 IEExec(NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
718 title.AsInput(), NULL);
719 }
720
721 // It is important that we only update the navigation_info_ after we have
722 // finalized the travel log. This is because IE will ask for information
723 // such as navigation index when the travel log is finalized and we need
724 // supply the old index and not the new one.
725 navigation_info_ = new_navigation_info;
[email protected]37346bc2009-09-25 22:54:33726 // Update the IE zone here. Ideally we would like to do it when the active
727 // document is activated. However that does not work at times as the frame we
728 // get there is not the actual frame which handles the command.
729 IEExec(&CGID_Explorer, SBCMDID_MIXEDZONE, 0, NULL, NULL);
[email protected]f7817822009-09-24 05:11:58730}
731
732void ChromeActiveDocument::OnFindInPage() {
733 TabProxy* tab = GetTabProxy();
734 if (tab) {
735 if (!find_dialog_.IsWindow()) {
736 find_dialog_.Create(m_hWnd);
737 }
738
739 find_dialog_.ShowWindow(SW_SHOW);
740 }
741}
742
743void ChromeActiveDocument::OnViewSource() {
744 DCHECK(navigation_info_.url.is_valid());
745 std::string url_to_open = "view-source:";
746 url_to_open += navigation_info_.url.spec();
[email protected]b1c55638612010-03-08 16:26:11747 HostNavigate(GURL(url_to_open), GURL(), NEW_WINDOW);
[email protected]f7817822009-09-24 05:11:58748}
749
[email protected]37346bc2009-09-25 22:54:33750void ChromeActiveDocument::OnDetermineSecurityZone(const GUID* cmd_group_guid,
751 DWORD command_id,
752 DWORD cmd_exec_opt,
753 VARIANT* in_args,
754 VARIANT* out_args) {
[email protected]7c712c92010-03-24 17:29:22755 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
756 // Correct step is to use MapUrlToZone().
[email protected]37346bc2009-09-25 22:54:33757 if (out_args != NULL) {
758 out_args->vt = VT_UI4;
759 out_args->ulVal = URLZONE_INTERNET;
760 }
761}
762
[email protected]80b5a8d2010-03-19 16:50:43763void ChromeActiveDocument::OnDisplayPrivacyInfo() {
764 privacy_info_ = url_fetcher_.privacy_info();
765 Reset();
766 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
767}
768
[email protected]b36a9f92009-10-19 17:34:57769void ChromeActiveDocument::OnOpenURL(int tab_handle,
770 const GURL& url_to_open,
771 const GURL& referrer,
[email protected]f7817822009-09-24 05:11:58772 int open_disposition) {
773 // If the disposition indicates that we should be opening the URL in the
774 // current tab, then we can reuse the ChromeFrameAutomationClient instance
775 // maintained by the current ChromeActiveDocument instance. We cache this
776 // instance so that it can be used by the new ChromeActiveDocument instance
777 // which may be instantiated for handling the new URL.
778 if (open_disposition == CURRENT_TAB) {
779 // Grab a reference to ensure that the document remains valid.
780 AddRef();
781 g_active_doc_cache.Set(this);
782 }
783
[email protected]b36a9f92009-10-19 17:34:57784 Base::OnOpenURL(tab_handle, url_to_open, referrer, open_disposition);
[email protected]f7817822009-09-24 05:11:58785}
786
[email protected]b1c55638612010-03-08 16:26:11787void ChromeActiveDocument::OnAttachExternalTab(int tab_handle,
788 const IPC::AttachExternalTabParams& params) {
789 DWORD flags = 0;
790 if (params.user_gesture)
791 flags = NWMF_USERREQUESTED;
[email protected]355309e2010-03-15 17:01:34792 else if (popup_allowed_)
793 flags = NWMF_USERALLOWED;
[email protected]b1c55638612010-03-08 16:26:11794
795 HRESULT hr = S_OK;
796 if (popup_manager_) {
[email protected]355309e2010-03-15 17:01:34797 LPCWSTR popup_wnd_url = UTF8ToWide(params.url.spec()).c_str();
798 hr = popup_manager_->EvaluateNewWindow(popup_wnd_url, NULL, url_,
799 NULL, FALSE, flags, 0);
[email protected]b1c55638612010-03-08 16:26:11800 }
801 // Allow popup
802 if (hr == S_OK) {
803 Base::OnAttachExternalTab(tab_handle, params);
804 return;
805 }
806
807 automation_client_->BlockExternalTab(params.cookie);
808}
809
[email protected]f7817822009-09-24 05:11:58810bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
811 ScopedComPtr<IBrowserService> browser_service;
812 ScopedComPtr<ITravelLog> travel_log;
[email protected]a1800e82009-11-19 00:53:23813 GetBrowserServiceAndTravelLog(browser_service.Receive(),
814 travel_log.Receive());
815 if (!browser_service || !travel_log)
[email protected]f7817822009-09-24 05:11:58816 return true;
817
818 if (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK, NULL))) {
819 EnableMenuItem(menu, IDS_CONTENT_CONTEXT_BACK, MF_BYCOMMAND | MF_ENABLED);
820 } else {
821 EnableMenuItem(menu, IDS_CONTENT_CONTEXT_BACK, MF_BYCOMMAND | MFS_DISABLED);
822 }
823
[email protected]f7817822009-09-24 05:11:58824 if (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE, NULL))) {
825 EnableMenuItem(menu, IDS_CONTENT_CONTEXT_FORWARD,
826 MF_BYCOMMAND | MF_ENABLED);
827 } else {
828 EnableMenuItem(menu, IDS_CONTENT_CONTEXT_FORWARD,
829 MF_BYCOMMAND | MFS_DISABLED);
830 }
831
832 // Call base class (adds 'About' item)
833 return Base::PreProcessContextMenu(menu);
834}
835
[email protected]35f13ab2009-12-16 23:59:17836bool ChromeActiveDocument::HandleContextMenuCommand(UINT cmd,
837 const IPC::ContextMenuParams& params) {
[email protected]f7817822009-09-24 05:11:58838 ScopedComPtr<IWebBrowser2> web_browser2;
839 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
840
841 switch (cmd) {
842 case IDS_CONTENT_CONTEXT_BACK:
843 web_browser2->GoBack();
844 break;
845
846 case IDS_CONTENT_CONTEXT_FORWARD:
847 web_browser2->GoForward();
848 break;
849
850 case IDS_CONTENT_CONTEXT_RELOAD:
851 web_browser2->Refresh();
852 break;
853
854 default:
[email protected]35f13ab2009-12-16 23:59:17855 return Base::HandleContextMenuCommand(cmd, params);
[email protected]f7817822009-09-24 05:11:58856 }
857
858 return true;
859}
860
861HRESULT ChromeActiveDocument::IEExec(const GUID* cmd_group_guid,
862 DWORD command_id, DWORD cmd_exec_opt,
863 VARIANT* in_args, VARIANT* out_args) {
864 HRESULT hr = E_FAIL;
[email protected]37346bc2009-09-25 22:54:33865
[email protected]f7817822009-09-24 05:11:58866 ScopedComPtr<IOleCommandTarget> frame_cmd_target;
[email protected]37346bc2009-09-25 22:54:33867
868 ScopedComPtr<IOleInPlaceSite> in_place_site(m_spInPlaceSite);
[email protected]6ebfda422009-11-12 23:30:54869 if (!in_place_site.get() && m_spClientSite != NULL) {
[email protected]37346bc2009-09-25 22:54:33870 in_place_site.QueryFrom(m_spClientSite);
871 }
872
873 if (in_place_site)
874 hr = frame_cmd_target.QueryFrom(in_place_site);
[email protected]f7817822009-09-24 05:11:58875
876 if (frame_cmd_target)
877 hr = frame_cmd_target->Exec(cmd_group_guid, command_id, cmd_exec_opt,
878 in_args, out_args);
879
880 return hr;
881}
[email protected]37346bc2009-09-25 22:54:33882
[email protected]7c712c92010-03-24 17:29:22883unsigned long ChromeActiveDocument::MapUrlToZone(const wchar_t* url) {
884 unsigned long zone = URLZONE_INVALID;
[email protected]37346bc2009-09-25 22:54:33885 if (security_manager_.get() == NULL) {
886 HRESULT hr = CoCreateInstance(
887 CLSID_InternetSecurityManager,
888 NULL,
889 CLSCTX_ALL,
890 IID_IInternetSecurityManager,
891 reinterpret_cast<void**>(security_manager_.Receive()));
892
893 if (FAILED(hr)) {
894 NOTREACHED() << __FUNCTION__
895 << " Failed to create InternetSecurityManager. Error: 0x%x"
896 << hr;
[email protected]7c712c92010-03-24 17:29:22897 return zone;
[email protected]37346bc2009-09-25 22:54:33898 }
899 }
900
[email protected]7c712c92010-03-24 17:29:22901 security_manager_->MapUrlToZone(url, &zone, 0);
902 return zone;
[email protected]37346bc2009-09-25 22:54:33903}
904
905bool ChromeActiveDocument::ParseUrl(const std::wstring& url,
906 bool* is_new_navigation,
907 bool* is_chrome_protocol,
908 std::wstring* parsed_url) {
909 if (!is_new_navigation || !is_chrome_protocol|| !parsed_url) {
910 NOTREACHED() << __FUNCTION__ << " Invalid arguments";
911 return false;
912 }
913
914 std::wstring initial_url = url;
915
916 *is_chrome_protocol = StartsWith(initial_url, kChromeProtocolPrefix,
917 false);
918
919 *is_new_navigation = true;
920
921 if (*is_chrome_protocol) {
922 initial_url.erase(0, lstrlen(kChromeProtocolPrefix));
923 *is_new_navigation =
924 !StartsWith(initial_url, kChromeAttachExternalTabPrefix, false);
925 }
926
[email protected]10bf1a72009-10-01 16:00:21927 if (!IsValidUrlScheme(initial_url, is_privileged_)) {
[email protected]37346bc2009-09-25 22:54:33928 DLOG(WARNING) << __FUNCTION__ << " Disallowing navigation to url: "
929 << url;
930 return false;
931 }
932
[email protected]7c712c92010-03-24 17:29:22933 if (URLZONE_UNTRUSTED == MapUrlToZone(initial_url.c_str())) {
[email protected]37346bc2009-09-25 22:54:33934 DLOG(WARNING) << __FUNCTION__
935 << " Disallowing navigation to restricted url: "
936 << initial_url;
937 return false;
938 }
939
[email protected]552fb6012010-02-03 17:24:29940 if (*is_chrome_protocol) {
941 // Allow chrome protocol (gcf:) if -
942 // - explicitly enabled using registry
943 // - for gcf:attach_external_tab
944 // - for gcf:about and gcf:view-source
945 GURL crack_url(initial_url);
946 bool allow_gcf_protocol = !*is_new_navigation ||
947 GetConfigBool(false, kEnableGCFProtocol) ||
948 crack_url.SchemeIs(chrome::kAboutScheme) ||
949 crack_url.SchemeIs(chrome::kViewSourceScheme);
950 if (!allow_gcf_protocol)
951 return false;
952 }
953
[email protected]37346bc2009-09-25 22:54:33954 *parsed_url = initial_url;
955 return true;
956}
957
958bool ChromeActiveDocument::LaunchUrl(const std::wstring& url,
959 bool is_new_navigation) {
[email protected]6f526082010-01-28 19:36:58960 url_.Reset(::SysAllocString(url.c_str()));
961
[email protected]37346bc2009-09-25 22:54:33962 if (!is_new_navigation) {
963 WStringTokenizer tokenizer(url, L"&");
964 // Skip over kChromeAttachExternalTabPrefix
965 tokenizer.GetNext();
966
[email protected]b1c55638612010-03-08 16:26:11967 uint64 external_tab_cookie = 0;
968 if (tokenizer.GetNext()) {
969 wchar_t* end_ptr = 0;
970 external_tab_cookie = _wcstoui64(tokenizer.token().c_str(), &end_ptr, 10);
971 }
[email protected]37346bc2009-09-25 22:54:33972
973 if (external_tab_cookie == 0) {
974 NOTREACHED() << "invalid url for attach tab: " << url;
975 return false;
976 }
977
978 automation_client_->AttachExternalTab(external_tab_cookie);
979 } else {
980 // Initiate navigation before launching chrome so that the url will be
981 // cached and sent with launch settings.
[email protected]62bb18dc12009-11-25 01:34:08982 if (url_.Length()) {
983 std::string utf8_url;
984 WideToUTF8(url_, url_.Length(), &utf8_url);
[email protected]b36a9f92009-10-19 17:34:57985
[email protected]62bb18dc12009-11-25 01:34:08986 std::string referrer;
[email protected]051236f2010-03-12 22:06:14987 NavigationManager* mgr = NavigationManager::GetThreadInstance();
988 if (mgr)
989 referrer = mgr->referrer();
[email protected]a1800e82009-11-19 00:53:23990
[email protected]62bb18dc12009-11-25 01:34:08991 if (!automation_client_->InitiateNavigation(utf8_url,
992 referrer,
993 is_privileged_)) {
994 DLOG(ERROR) << "Invalid URL: " << url;
995 Error(L"Invalid URL");
996 url_.Reset();
997 return false;
[email protected]37346bc2009-09-25 22:54:33998 }
[email protected]62bb18dc12009-11-25 01:34:08999
1000 DLOG(INFO) << "Url is " << url_;
[email protected]37346bc2009-09-25 22:54:331001 }
1002 }
1003
[email protected]3eb07da2010-02-01 19:48:361004 if (is_automation_client_reused_)
1005 return true;
[email protected]37346bc2009-09-25 22:54:331006
[email protected]3eb07da2010-02-01 19:48:361007 automation_client_->SetUrlFetcher(&url_fetcher_);
1008
[email protected]3921d1952010-03-23 20:51:011009 if (InitializeAutomation(GetHostProcessName(false), L"", IsIEInPrivate()))
[email protected]3eb07da2010-02-01 19:48:361010 return true;
1011
1012 return false;
[email protected]37346bc2009-09-25 22:54:331013}
[email protected]1bb5f892009-10-06 01:44:571014
[email protected]355309e2010-03-15 17:01:341015
1016HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1017 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
1018 popup_allowed_ = false;
1019 if (in_args->vt == VT_I4 &&
1020 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1021 popup_allowed_ = true;
1022
1023 // Ask the yellow security band to change the text and icon and to remain
1024 // visible.
1025 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
1026 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
1027 }
1028
1029 TabProxy* tab_proxy = GetTabProxy();
1030 if (tab_proxy)
1031 tab_proxy->ReloadAsync();
1032
1033 return S_OK;
1034}
1035
1036
[email protected]1bb5f892009-10-06 01:44:571037HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1038 DWORD command_id,
1039 DWORD cmd_exec_opt,
1040 VARIANT* in_args,
1041 VARIANT* out_args) {
1042 if (!automation_client_.get()) {
1043 NOTREACHED() << "Invalid automtion client";
1044 return E_FAIL;
1045 }
1046
1047 switch (command_id) {
1048 case IDM_BASELINEFONT1:
1049 automation_client_->SetPageFontSize(SMALLEST_FONT);
1050 break;
1051
1052 case IDM_BASELINEFONT2:
1053 automation_client_->SetPageFontSize(SMALL_FONT);
1054 break;
1055
1056 case IDM_BASELINEFONT3:
1057 automation_client_->SetPageFontSize(MEDIUM_FONT);
1058 break;
1059
1060 case IDM_BASELINEFONT4:
1061 automation_client_->SetPageFontSize(LARGE_FONT);
1062 break;
1063
1064 case IDM_BASELINEFONT5:
1065 automation_client_->SetPageFontSize(LARGEST_FONT);
1066 break;
1067
1068 default:
1069 NOTREACHED() << "Invalid font size command: "
1070 << command_id;
1071 return E_FAIL;
1072 }
1073
1074 // Forward the command back to IEFrame with group set to
1075 // CGID_ExplorerBarDoc. This is probably needed to update the menu state to
1076 // indicate that the font size was set. This currently fails with error
1077 // 0x80040104.
1078 // TODO(iyengar)
1079 // Do some investigation into why this Exec call fails.
1080 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1081 return S_OK;
1082}
1083
[email protected]f9cc4c452009-10-13 14:56:381084void ChromeActiveDocument::OnGoToHistoryEntryOffset(int tab_handle,
1085 int offset) {
[email protected]a1800e82009-11-19 00:53:231086 DLOG(INFO) << __FUNCTION__ << " - offset:" << offset;
1087
[email protected]f9cc4c452009-10-13 14:56:381088 ScopedComPtr<IBrowserService> browser_service;
[email protected]a1800e82009-11-19 00:53:231089 ScopedComPtr<ITravelLog> travel_log;
1090 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1091 travel_log.Receive());
1092
1093 if (browser_service && travel_log)
1094 travel_log->Travel(browser_service, offset);
1095}
1096
1097HRESULT ChromeActiveDocument::GetBrowserServiceAndTravelLog(
1098 IBrowserService** browser_service, ITravelLog** travel_log) {
1099 DCHECK(browser_service || travel_log);
1100 ScopedComPtr<IBrowserService> browser_service_local;
1101 HRESULT hr = DoQueryService(SID_SShellBrowser, m_spClientSite,
1102 browser_service_local.Receive());
1103 if (!browser_service_local) {
1104 NOTREACHED() << "DoQueryService for IBrowserService failed: " << hr;
1105 return hr;
[email protected]f9cc4c452009-10-13 14:56:381106 }
[email protected]a1800e82009-11-19 00:53:231107
1108 if (travel_log) {
1109 hr = browser_service_local->GetTravelLog(travel_log);
1110 DLOG_IF(INFO, !travel_log) << "browser_service->GetTravelLog failed: "
1111 << hr;
1112 }
1113
1114 if (browser_service)
1115 *browser_service = browser_service_local.Detach();
1116
1117 return hr;
[email protected]f9cc4c452009-10-13 14:56:381118}
[email protected]a15d4a42010-02-17 08:21:351119
1120LRESULT ChromeActiveDocument::OnForward(WORD notify_code, WORD id,
1121 HWND control_window,
1122 BOOL& bHandled) {
1123 ScopedComPtr<IWebBrowser2> web_browser2;
1124 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1125 DCHECK(web_browser2);
1126
1127 if (web_browser2) {
1128 web_browser2->GoForward();
1129 }
1130 return 0;
1131}
1132
1133LRESULT ChromeActiveDocument::OnBack(WORD notify_code, WORD id,
1134 HWND control_window,
1135 BOOL& bHandled) {
1136 ScopedComPtr<IWebBrowser2> web_browser2;
1137 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
1138 DCHECK(web_browser2);
1139
1140 if (web_browser2) {
1141 web_browser2->GoBack();
1142 }
1143 return 0;
1144}
1145
[email protected]80b5a8d2010-03-19 16:50:431146LRESULT ChromeActiveDocument::OnFirePrivacyChange(UINT message, WPARAM wparam,
1147 LPARAM lparam,
1148 BOOL& handled) {
1149 if (!m_spClientSite)
1150 return 0;
1151
1152 ScopedComPtr<IWebBrowser2> web_browser2;
1153 DoQueryService(SID_SWebBrowserApp, m_spClientSite,
1154 web_browser2.Receive());
1155 if (!web_browser2) {
1156 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1157 return 0;
1158 }
1159
1160 ScopedComPtr<IShellBrowser> shell_browser;
1161 DoQueryService(SID_STopLevelBrowser, web_browser2,
1162 shell_browser.Receive());
1163 DCHECK(shell_browser.get() != NULL);
1164 ScopedComPtr<ITridentService2> trident_services;
1165 trident_services.QueryFrom(shell_browser);
1166 if (trident_services) {
1167 trident_services->FirePrivacyImpactedStateChange(wparam);
1168 } else {
1169 NOTREACHED() << "Failed to retrieve IWebBrowser2 interface.";
1170 }
1171 return 0;
1172}
1173