Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome_frame/chrome_active_document.cc

Issue 5998006: Clean up Automation and Chrome Frame IPC code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/chrome_active_document.h ('k') | chrome_frame/chrome_frame_activex.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implementation of ChromeActiveDocument 5 // Implementation of ChromeActiveDocument
6 #include "chrome_frame/chrome_active_document.h" 6 #include "chrome_frame/chrome_active_document.h"
7 7
8 #include <hlink.h> 8 #include <hlink.h>
9 #include <htiface.h> 9 #include <htiface.h>
10 #include <initguid.h> 10 #include <initguid.h>
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 in_place_frame_->SetActiveObject(in_place_active_object, NULL); 608 in_place_frame_->SetActiveObject(in_place_active_object, NULL);
609 if (in_place_ui_window) 609 if (in_place_ui_window)
610 in_place_ui_window->SetActiveObject(in_place_active_object, NULL); 610 in_place_ui_window->SetActiveObject(in_place_active_object, NULL);
611 } 611 }
612 } 612 }
613 } 613 }
614 m_spClientSite->ShowObject(); 614 m_spClientSite->ShowObject();
615 return S_OK; 615 return S_OK;
616 } 616 }
617 617
618 void ChromeActiveDocument::OnNavigationStateChanged(int tab_handle, int flags, 618 void ChromeActiveDocument::OnNavigationStateChanged(
619 const IPC::NavigationInfo& nav_info) { 619 int flags, const NavigationInfo& nav_info) {
620 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc. 620 // TODO(joshia): handle INVALIDATE_TAB,INVALIDATE_LOAD etc.
621 DVLOG(1) << __FUNCTION__ 621 DVLOG(1) << __FUNCTION__
622 << "\n Flags: " << flags 622 << "\n Flags: " << flags
623 << ", Url: " << nav_info.url 623 << ", Url: " << nav_info.url
624 << ", Title: " << nav_info.title 624 << ", Title: " << nav_info.title
625 << ", Type: " << nav_info.navigation_type 625 << ", Type: " << nav_info.navigation_type
626 << ", Relative Offset: " << nav_info.relative_offset 626 << ", Relative Offset: " << nav_info.relative_offset
627 << ", Index: " << nav_info.navigation_index; 627 << ", Index: " << nav_info.navigation_index;
628 628
629 UpdateNavigationState(nav_info); 629 UpdateNavigationState(nav_info);
630 } 630 }
631 631
632 void ChromeActiveDocument::OnUpdateTargetUrl(int tab_handle, 632 void ChromeActiveDocument::OnUpdateTargetUrl(
633 const std::wstring& new_target_url) { 633 const std::wstring& new_target_url) {
634 if (in_place_frame_) 634 if (in_place_frame_)
635 in_place_frame_->SetStatusText(new_target_url.c_str()); 635 in_place_frame_->SetStatusText(new_target_url.c_str());
636 } 636 }
637 637
638 bool IsFindAccelerator(const MSG& msg) { 638 bool IsFindAccelerator(const MSG& msg) {
639 // TODO(robertshield): This may not stand up to localization. Fix if this 639 // TODO(robertshield): This may not stand up to localization. Fix if this
640 // is the case. 640 // is the case.
641 return msg.message == WM_KEYDOWN && msg.wParam == 'F' && 641 return msg.message == WM_KEYDOWN && msg.wParam == 'F' &&
642 win_util::IsCtrlPressed() && 642 win_util::IsCtrlPressed() &&
643 !(win_util::IsAltPressed() || win_util::IsShiftPressed()); 643 !(win_util::IsAltPressed() || win_util::IsShiftPressed());
644 } 644 }
645 645
646 void ChromeActiveDocument::OnAcceleratorPressed(int tab_handle, 646 void ChromeActiveDocument::OnAcceleratorPressed(const MSG& accel_message) {
647 const MSG& accel_message) {
648 if (::TranslateAccelerator(m_hWnd, accelerator_table_, 647 if (::TranslateAccelerator(m_hWnd, accelerator_table_,
649 const_cast<MSG*>(&accel_message))) 648 const_cast<MSG*>(&accel_message)))
650 return; 649 return;
651 650
652 bool handled_accel = false; 651 bool handled_accel = false;
653 if (in_place_frame_ != NULL) { 652 if (in_place_frame_ != NULL) {
654 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW( 653 handled_accel = (S_OK == in_place_frame_->TranslateAcceleratorW(
655 const_cast<MSG*>(&accel_message), 0)); 654 const_cast<MSG*>(&accel_message), 0));
656 } 655 }
657 656
658 if (!handled_accel) { 657 if (!handled_accel) {
659 if (IsFindAccelerator(accel_message)) { 658 if (IsFindAccelerator(accel_message)) {
660 // Handle the showing of the find dialog explicitly. 659 // Handle the showing of the find dialog explicitly.
661 OnFindInPage(); 660 OnFindInPage();
662 } else { 661 } else {
663 BaseActiveX::OnAcceleratorPressed(tab_handle, accel_message); 662 BaseActiveX::OnAcceleratorPressed(accel_message);
664 } 663 }
665 } else { 664 } else {
666 DVLOG(1) << "IE handled accel key " << accel_message.wParam; 665 DVLOG(1) << "IE handled accel key " << accel_message.wParam;
667 } 666 }
668 } 667 }
669 668
670 void ChromeActiveDocument::OnTabbedOut(int tab_handle, bool reverse) { 669 void ChromeActiveDocument::OnTabbedOut(bool reverse) {
671 DVLOG(1) << __FUNCTION__; 670 DVLOG(1) << __FUNCTION__;
672 if (in_place_frame_) { 671 if (in_place_frame_) {
673 MSG msg = { NULL, WM_KEYDOWN, VK_TAB }; 672 MSG msg = { NULL, WM_KEYDOWN, VK_TAB };
674 in_place_frame_->TranslateAcceleratorW(&msg, 0); 673 in_place_frame_->TranslateAcceleratorW(&msg, 0);
675 } 674 }
676 } 675 }
677 676
678 void ChromeActiveDocument::OnDidNavigate(int tab_handle, 677 void ChromeActiveDocument::OnDidNavigate(const NavigationInfo& nav_info) {
679 const IPC::NavigationInfo& nav_info) {
680 DVLOG(1) << __FUNCTION__ << std::endl 678 DVLOG(1) << __FUNCTION__ << std::endl
681 << "Url: " << nav_info.url 679 << "Url: " << nav_info.url
682 << ", Title: " << nav_info.title 680 << ", Title: " << nav_info.title
683 << ", Type: " << nav_info.navigation_type 681 << ", Type: " << nav_info.navigation_type
684 << ", Relative Offset: " << nav_info.relative_offset 682 << ", Relative Offset: " << nav_info.relative_offset
685 << ", Index: " << nav_info.navigation_index; 683 << ", Index: " << nav_info.navigation_index;
686 684
687 CrashMetricsReporter::GetInstance()->IncrementMetric( 685 CrashMetricsReporter::GetInstance()->IncrementMetric(
688 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT); 686 CrashMetricsReporter::CHROME_FRAME_NAVIGATION_COUNT);
689 687
690 // This could be NULL if the active document instance is being destroyed. 688 // This could be NULL if the active document instance is being destroyed.
691 if (!m_spInPlaceSite) { 689 if (!m_spInPlaceSite) {
692 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning"; 690 DVLOG(1) << __FUNCTION__ << "m_spInPlaceSite is NULL. Returning";
693 return; 691 return;
694 } 692 }
695 693
696 UpdateNavigationState(nav_info); 694 UpdateNavigationState(nav_info);
697 } 695 }
698 696
699 void ChromeActiveDocument::OnCloseTab(int tab_handle) { 697 void ChromeActiveDocument::OnCloseTab() {
700 // Base class will fire DIChromeFrameEvents::onclose. 698 // Base class will fire DIChromeFrameEvents::onclose.
701 BaseActiveX::OnCloseTab(tab_handle); 699 BaseActiveX::OnCloseTab();
702 700
703 // Close the container window. 701 // Close the container window.
704 ScopedComPtr<IWebBrowser2> web_browser2; 702 ScopedComPtr<IWebBrowser2> web_browser2;
705 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); 703 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
706 if (web_browser2) 704 if (web_browser2)
707 web_browser2->Quit(); 705 web_browser2->Quit();
708 } 706 }
709 707
710 void ChromeActiveDocument::UpdateNavigationState( 708 void ChromeActiveDocument::UpdateNavigationState(
711 const IPC::NavigationInfo& new_navigation_info) { 709 const NavigationInfo& new_navigation_info) {
712 HRESULT hr = S_OK; 710 HRESULT hr = S_OK;
713 bool is_title_changed = (navigation_info_.title != new_navigation_info.title); 711 bool is_title_changed = (navigation_info_.title != new_navigation_info.title);
714 bool is_ssl_state_changed = 712 bool is_ssl_state_changed =
715 (navigation_info_.security_style != new_navigation_info.security_style) || 713 (navigation_info_.security_style != new_navigation_info.security_style) ||
716 (navigation_info_.displayed_insecure_content != 714 (navigation_info_.displayed_insecure_content !=
717 new_navigation_info.displayed_insecure_content) || 715 new_navigation_info.displayed_insecure_content) ||
718 (navigation_info_.ran_insecure_content != 716 (navigation_info_.ran_insecure_content !=
719 new_navigation_info.ran_insecure_content); 717 new_navigation_info.ran_insecure_content);
720 718
721 if (is_ssl_state_changed) { 719 if (is_ssl_state_changed) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 VARIANT* in_args, 910 VARIANT* in_args,
913 VARIANT* out_args) { 911 VARIANT* out_args) {
914 if (IsValid() && out_args) { 912 if (IsValid() && out_args) {
915 bool should_unload = true; 913 bool should_unload = true;
916 automation_client_->OnUnload(&should_unload); 914 automation_client_->OnUnload(&should_unload);
917 out_args->vt = VT_BOOL; 915 out_args->vt = VT_BOOL;
918 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE; 916 out_args->boolVal = should_unload ? VARIANT_TRUE : VARIANT_FALSE;
919 } 917 }
920 } 918 }
921 919
922 void ChromeActiveDocument::OnOpenURL(int tab_handle, 920 void ChromeActiveDocument::OnOpenURL(const GURL& url_to_open,
923 const GURL& url_to_open,
924 const GURL& referrer, 921 const GURL& referrer,
925 int open_disposition) { 922 int open_disposition) {
926 // If the disposition indicates that we should be opening the URL in the 923 // If the disposition indicates that we should be opening the URL in the
927 // current tab, then we can reuse the ChromeFrameAutomationClient instance 924 // current tab, then we can reuse the ChromeFrameAutomationClient instance
928 // maintained by the current ChromeActiveDocument instance. We cache this 925 // maintained by the current ChromeActiveDocument instance. We cache this
929 // instance so that it can be used by the new ChromeActiveDocument instance 926 // instance so that it can be used by the new ChromeActiveDocument instance
930 // which may be instantiated for handling the new URL. 927 // which may be instantiated for handling the new URL.
931 if (open_disposition == CURRENT_TAB) { 928 if (open_disposition == CURRENT_TAB) {
932 // Grab a reference to ensure that the document remains valid. 929 // Grab a reference to ensure that the document remains valid.
933 AddRef(); 930 AddRef();
934 g_active_doc_cache.Set(this); 931 g_active_doc_cache.Set(this);
935 } 932 }
936 933
937 BaseActiveX::OnOpenURL(tab_handle, url_to_open, referrer, open_disposition); 934 BaseActiveX::OnOpenURL(url_to_open, referrer, open_disposition);
938 } 935 }
939 936
940 void ChromeActiveDocument::OnAttachExternalTab(int tab_handle, 937 void ChromeActiveDocument::OnAttachExternalTab(
941 const IPC::AttachExternalTabParams& params) { 938 const AttachExternalTabParams& params) {
942 if (!automation_client_.get()) { 939 if (!automation_client_.get()) {
943 DLOG(WARNING) << "Invalid automation client instance"; 940 DLOG(WARNING) << "Invalid automation client instance";
944 return; 941 return;
945 } 942 }
946 DWORD flags = 0; 943 DWORD flags = 0;
947 if (params.user_gesture) 944 if (params.user_gesture)
948 flags = NWMF_USERREQUESTED; 945 flags = NWMF_USERREQUESTED;
949 else if (popup_allowed_) 946 else if (popup_allowed_)
950 flags = NWMF_USERALLOWED; 947 flags = NWMF_USERALLOWED;
951 948
952 HRESULT hr = S_OK; 949 HRESULT hr = S_OK;
953 if (popup_manager_) { 950 if (popup_manager_) {
954 const std::wstring& url_wide = UTF8ToWide(params.url.spec()); 951 const std::wstring& url_wide = UTF8ToWide(params.url.spec());
955 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_, 952 hr = popup_manager_->EvaluateNewWindow(url_wide.c_str(), NULL, url_,
956 NULL, FALSE, flags, 0); 953 NULL, FALSE, flags, 0);
957 } 954 }
958 // Allow popup 955 // Allow popup
959 if (hr == S_OK) { 956 if (hr == S_OK) {
960 BaseActiveX::OnAttachExternalTab(tab_handle, params); 957 BaseActiveX::OnAttachExternalTab(params);
961 return; 958 return;
962 } 959 }
963 960
964 automation_client_->BlockExternalTab(params.cookie); 961 automation_client_->BlockExternalTab(params.cookie);
965 } 962 }
966 963
967 bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) { 964 bool ChromeActiveDocument::PreProcessContextMenu(HMENU menu) {
968 ScopedComPtr<IBrowserService> browser_service; 965 ScopedComPtr<IBrowserService> browser_service;
969 ScopedComPtr<ITravelLog> travel_log; 966 ScopedComPtr<ITravelLog> travel_log;
970 GetBrowserServiceAndTravelLog(browser_service.Receive(), 967 GetBrowserServiceAndTravelLog(browser_service.Receive(),
971 travel_log.Receive()); 968 travel_log.Receive());
972 if (!browser_service || !travel_log) 969 if (!browser_service || !travel_log)
973 return true; 970 return true;
974 971
975 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND | 972 EnableMenuItem(menu, IDC_BACK, MF_BYCOMMAND |
976 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK, 973 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_BACK,
977 NULL)) ? 974 NULL)) ?
978 MF_ENABLED : MF_DISABLED)); 975 MF_ENABLED : MF_DISABLED));
979 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND | 976 EnableMenuItem(menu, IDC_FORWARD, MF_BYCOMMAND |
980 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE, 977 (SUCCEEDED(travel_log->GetTravelEntry(browser_service, TLOG_FORE,
981 NULL)) ? 978 NULL)) ?
982 MF_ENABLED : MF_DISABLED)); 979 MF_ENABLED : MF_DISABLED));
983 // Call base class (adds 'About' item) 980 // Call base class (adds 'About' item)
984 return BaseActiveX::PreProcessContextMenu(menu); 981 return BaseActiveX::PreProcessContextMenu(menu);
985 } 982 }
986 983
987 bool ChromeActiveDocument::HandleContextMenuCommand(UINT cmd, 984 bool ChromeActiveDocument::HandleContextMenuCommand(
988 const IPC::MiniContextMenuParams& params) { 985 UINT cmd, const MiniContextMenuParams& params) {
989 ScopedComPtr<IWebBrowser2> web_browser2; 986 ScopedComPtr<IWebBrowser2> web_browser2;
990 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive()); 987 DoQueryService(SID_SWebBrowserApp, m_spClientSite, web_browser2.Receive());
991 988
992 if (cmd == IDC_BACK) 989 if (cmd == IDC_BACK)
993 web_browser2->GoBack(); 990 web_browser2->GoBack();
994 else if (cmd == IDC_FORWARD) 991 else if (cmd == IDC_FORWARD)
995 web_browser2->GoForward(); 992 web_browser2->GoForward();
996 else if (cmd == IDC_RELOAD) 993 else if (cmd == IDC_RELOAD)
997 web_browser2->Refresh(); 994 web_browser2->Refresh();
998 else 995 else
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 tab->OverrideEncoding(chrome_encoding_name); 1223 tab->OverrideEncoding(chrome_encoding_name);
1227 1224
1228 // Like we did on SetPageFontSize, we may forward the command back to IEFrame 1225 // Like we did on SetPageFontSize, we may forward the command back to IEFrame
1229 // to update the menu state to indicate that which encoding was set. 1226 // to update the menu state to indicate that which encoding was set.
1230 // TODO(iyengar) 1227 // TODO(iyengar)
1231 // Do some investigation into why this Exec call fails. 1228 // Do some investigation into why this Exec call fails.
1232 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL); 1229 IEExec(&CGID_ExplorerBarDoc, command_id, cmd_exec_opt, NULL, NULL);
1233 return S_OK; 1230 return S_OK;
1234 } 1231 }
1235 1232
1236 void ChromeActiveDocument::OnGoToHistoryEntryOffset(int tab_handle, 1233 void ChromeActiveDocument::OnGoToHistoryEntryOffset(int offset) {
1237 int offset) {
1238 DVLOG(1) << __FUNCTION__ << " - offset:" << offset; 1234 DVLOG(1) << __FUNCTION__ << " - offset:" << offset;
1239 1235
1240 ScopedComPtr<IBrowserService> browser_service; 1236 ScopedComPtr<IBrowserService> browser_service;
1241 ScopedComPtr<ITravelLog> travel_log; 1237 ScopedComPtr<ITravelLog> travel_log;
1242 GetBrowserServiceAndTravelLog(browser_service.Receive(), 1238 GetBrowserServiceAndTravelLog(browser_service.Receive(),
1243 travel_log.Receive()); 1239 travel_log.Receive());
1244 1240
1245 if (browser_service && travel_log) 1241 if (browser_service && travel_log)
1246 travel_log->Travel(browser_service, offset); 1242 travel_log->Travel(browser_service, offset);
1247 } 1243 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 web_browser2->put_Height(dimensions_.height()); 1356 web_browser2->put_Height(dimensions_.height());
1361 web_browser2->put_Left(dimensions_.x()); 1357 web_browser2->put_Left(dimensions_.x());
1362 web_browser2->put_Top(dimensions_.y()); 1358 web_browser2->put_Top(dimensions_.y());
1363 1359
1364 dimensions_.set_height(0); 1360 dimensions_.set_height(0);
1365 dimensions_.set_width(0); 1361 dimensions_.set_width(0);
1366 } 1362 }
1367 } 1363 }
1368 1364
1369 bool ChromeActiveDocument::IsNewNavigation( 1365 bool ChromeActiveDocument::IsNewNavigation(
1370 const IPC::NavigationInfo& new_navigation_info) const { 1366 const NavigationInfo& new_navigation_info) const {
1371 // A new navigation is typically an internal navigation which is initiated by 1367 // A new navigation is typically an internal navigation which is initiated by
1372 // the renderer(WebKit). Condition 1 below has to be true along with the 1368 // the renderer(WebKit). Condition 1 below has to be true along with the
1373 // any of the other conditions below. 1369 // any of the other conditions below.
1374 // 1. The navigation index is greater than 0 which means that a top level 1370 // 1. The navigation index is greater than 0 which means that a top level
1375 // navigation was initiated on the current external tab. 1371 // navigation was initiated on the current external tab.
1376 // 2. The navigation type has changed. 1372 // 2. The navigation type has changed.
1377 // 3. The url or the referrer are different. 1373 // 3. The url or the referrer are different.
1378 if (new_navigation_info.navigation_index <= 0) 1374 if (new_navigation_info.navigation_index <= 0)
1379 return false; 1375 return false;
1380 1376
1381 if (new_navigation_info.navigation_index == 1377 if (new_navigation_info.navigation_index ==
1382 navigation_info_.navigation_index) 1378 navigation_info_.navigation_index)
1383 return false; 1379 return false;
1384 1380
1385 if (new_navigation_info.navigation_type != navigation_info_.navigation_type) 1381 if (new_navigation_info.navigation_type != navigation_info_.navigation_type)
1386 return true; 1382 return true;
1387 1383
1388 if (new_navigation_info.url != navigation_info_.url) 1384 if (new_navigation_info.url != navigation_info_.url)
1389 return true; 1385 return true;
1390 1386
1391 if (new_navigation_info.referrer != navigation_info_.referrer) 1387 if (new_navigation_info.referrer != navigation_info_.referrer)
1392 return true; 1388 return true;
1393 1389
1394 return false; 1390 return false;
1395 } 1391 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_active_document.h ('k') | chrome_frame/chrome_frame_activex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698