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

Side by Side Diff: chrome/browser/external_tab_container_win.cc

Issue 5998006: Clean up Automation and Chrome Frame IPC code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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/browser/external_tab_container_win.h ('k') | chrome/common/automation_messages.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 #include "chrome/browser/external_tab_container_win.h" 5 #include "chrome/browser/external_tab_container_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/view_prop.h" 10 #include "app/view_prop.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 337
338 switch (disposition) { 338 switch (disposition) {
339 case CURRENT_TAB: 339 case CURRENT_TAB:
340 case SINGLETON_TAB: 340 case SINGLETON_TAB:
341 case NEW_FOREGROUND_TAB: 341 case NEW_FOREGROUND_TAB:
342 case NEW_BACKGROUND_TAB: 342 case NEW_BACKGROUND_TAB:
343 case NEW_POPUP: 343 case NEW_POPUP:
344 case NEW_WINDOW: 344 case NEW_WINDOW:
345 case SAVE_TO_DISK: 345 case SAVE_TO_DISK:
346 if (automation_) { 346 if (automation_) {
347 automation_->Send(new AutomationMsg_OpenURL(0, tab_handle_, 347 automation_->Send(new AutomationMsg_OpenURL(tab_handle_,
348 url, referrer, 348 url, referrer,
349 disposition)); 349 disposition));
350 // TODO(ananta) 350 // TODO(ananta)
351 // We should populate other fields in the 351 // We should populate other fields in the
352 // ViewHostMsg_FrameNavigate_Params structure. Another option could be 352 // ViewHostMsg_FrameNavigate_Params structure. Another option could be
353 // to refactor the UpdateHistoryForNavigation function in TabContents. 353 // to refactor the UpdateHistoryForNavigation function in TabContents.
354 ViewHostMsg_FrameNavigate_Params params; 354 ViewHostMsg_FrameNavigate_Params params;
355 params.referrer = referrer; 355 params.referrer = referrer;
356 params.url = url; 356 params.url = url;
357 params.page_id = -1; 357 params.page_id = -1;
358 params.transition = PageTransition::LINK; 358 params.transition = PageTransition::LINK;
359 359
360 NavigationController::LoadCommittedDetails details; 360 NavigationController::LoadCommittedDetails details;
361 details.did_replace_entry = false; 361 details.did_replace_entry = false;
362 362
363 scoped_refptr<history::HistoryAddPageArgs> add_page_args( 363 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
364 tab_contents_->CreateHistoryAddPageArgs(url, details, params)); 364 tab_contents_->CreateHistoryAddPageArgs(url, details, params));
365 tab_contents_->UpdateHistoryForNavigation(add_page_args); 365 tab_contents_->UpdateHistoryForNavigation(add_page_args);
366 } 366 }
367 break; 367 break;
368 default: 368 default:
369 NOTREACHED(); 369 NOTREACHED();
370 break; 370 break;
371 } 371 }
372 } 372 }
373 373
374 void ExternalTabContainer::NavigationStateChanged(const TabContents* source, 374 void ExternalTabContainer::NavigationStateChanged(const TabContents* source,
375 unsigned changed_flags) { 375 unsigned changed_flags) {
376 if (automation_) { 376 if (automation_) {
377 IPC::NavigationInfo nav_info; 377 NavigationInfo nav_info;
378 if (InitNavigationInfo(&nav_info, NavigationType::NAV_IGNORE, 0)) 378 if (InitNavigationInfo(&nav_info, NavigationType::NAV_IGNORE, 0))
379 automation_->Send(new AutomationMsg_NavigationStateChanged( 379 automation_->Send(new AutomationMsg_NavigationStateChanged(
380 0, tab_handle_, changed_flags, nav_info)); 380 tab_handle_, changed_flags, nav_info));
381 } 381 }
382 } 382 }
383 383
384 void ExternalTabContainer::AddNewContents(TabContents* source, 384 void ExternalTabContainer::AddNewContents(TabContents* source,
385 TabContents* new_contents, 385 TabContents* new_contents,
386 WindowOpenDisposition disposition, 386 WindowOpenDisposition disposition,
387 const gfx::Rect& initial_pos, 387 const gfx::Rect& initial_pos,
388 bool user_gesture) { 388 bool user_gesture) {
389 if (!automation_) { 389 if (!automation_) {
390 DCHECK(pending_); 390 DCHECK(pending_);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 true, 425 true,
426 route_all_top_level_navigations_); 426 route_all_top_level_navigations_);
427 427
428 if (result) { 428 if (result) {
429 if (route_all_top_level_navigations_) { 429 if (route_all_top_level_navigations_) {
430 return; 430 return;
431 } 431 }
432 uintptr_t cookie = reinterpret_cast<uintptr_t>(new_container.get()); 432 uintptr_t cookie = reinterpret_cast<uintptr_t>(new_container.get());
433 pending_tabs_.Get()[cookie] = new_container; 433 pending_tabs_.Get()[cookie] = new_container;
434 new_container->set_pending(true); 434 new_container->set_pending(true);
435 IPC::AttachExternalTabParams attach_params_; 435 AttachExternalTabParams attach_params_;
436 attach_params_.cookie = static_cast<uint64>(cookie); 436 attach_params_.cookie = static_cast<uint64>(cookie);
437 attach_params_.dimensions = initial_pos; 437 attach_params_.dimensions = initial_pos;
438 attach_params_.user_gesture = user_gesture; 438 attach_params_.user_gesture = user_gesture;
439 attach_params_.disposition = disposition; 439 attach_params_.disposition = disposition;
440 attach_params_.profile_name = WideToUTF8( 440 attach_params_.profile_name = WideToUTF8(
441 tab_contents()->profile()->GetPath().DirName().BaseName().value()); 441 tab_contents()->profile()->GetPath().DirName().BaseName().value());
442 automation_->Send(new AutomationMsg_AttachExternalTab(0, 442 automation_->Send(new AutomationMsg_AttachExternalTab(
443 tab_handle_, attach_params_)); 443 tab_handle_, attach_params_));
444 } else { 444 } else {
445 NOTREACHED(); 445 NOTREACHED();
446 } 446 }
447 } 447 }
448 448
449 void ExternalTabContainer::TabContentsCreated(TabContents* new_contents) { 449 void ExternalTabContainer::TabContentsCreated(TabContents* new_contents) {
450 RenderViewHost* rvh = new_contents->render_view_host(); 450 RenderViewHost* rvh = new_contents->render_view_host();
451 DCHECK(rvh != NULL); 451 DCHECK(rvh != NULL);
452 452
(...skipping 19 matching lines...) Expand all
472 void ExternalTabContainer::CloseContents(TabContents* source) { 472 void ExternalTabContainer::CloseContents(TabContents* source) {
473 if (!automation_) 473 if (!automation_)
474 return; 474 return;
475 475
476 if (unload_reply_message_) { 476 if (unload_reply_message_) {
477 AutomationMsg_RunUnloadHandlers::WriteReplyParams(unload_reply_message_, 477 AutomationMsg_RunUnloadHandlers::WriteReplyParams(unload_reply_message_,
478 true); 478 true);
479 automation_->Send(unload_reply_message_); 479 automation_->Send(unload_reply_message_);
480 unload_reply_message_ = NULL; 480 unload_reply_message_ = NULL;
481 } else { 481 } else {
482 automation_->Send(new AutomationMsg_CloseExternalTab(0, tab_handle_)); 482 automation_->Send(new AutomationMsg_CloseExternalTab(tab_handle_));
483 } 483 }
484 } 484 }
485 485
486 void ExternalTabContainer::MoveContents(TabContents* source, 486 void ExternalTabContainer::MoveContents(TabContents* source,
487 const gfx::Rect& pos) { 487 const gfx::Rect& pos) {
488 } 488 }
489 489
490 void ExternalTabContainer::URLStarredChanged(TabContents* source, 490 void ExternalTabContainer::URLStarredChanged(TabContents* source,
491 bool starred) { 491 bool starred) {
492 } 492 }
493 493
494 void ExternalTabContainer::UpdateTargetURL(TabContents* source, 494 void ExternalTabContainer::UpdateTargetURL(TabContents* source,
495 const GURL& url) { 495 const GURL& url) {
496 if (automation_) { 496 if (automation_) {
497 std::wstring url_string = CA2W(url.spec().c_str()); 497 std::wstring url_string = CA2W(url.spec().c_str());
498 automation_->Send( 498 automation_->Send(
499 new AutomationMsg_UpdateTargetUrl(0, tab_handle_, url_string)); 499 new AutomationMsg_UpdateTargetUrl(tab_handle_, url_string));
500 } 500 }
501 } 501 }
502 502
503 void ExternalTabContainer::ContentsZoomChange(bool zoom_in) { 503 void ExternalTabContainer::ContentsZoomChange(bool zoom_in) {
504 } 504 }
505 505
506 void ExternalTabContainer::ToolbarSizeChanged(TabContents* source, 506 void ExternalTabContainer::ToolbarSizeChanged(TabContents* source,
507 bool finished) { 507 bool finished) {
508 } 508 }
509 509
510 void ExternalTabContainer::ForwardMessageToExternalHost( 510 void ExternalTabContainer::ForwardMessageToExternalHost(
511 const std::string& message, const std::string& origin, 511 const std::string& message, const std::string& origin,
512 const std::string& target) { 512 const std::string& target) {
513 if (automation_) { 513 if (automation_) {
514 automation_->Send( 514 automation_->Send(new AutomationMsg_ForwardMessageToExternalHost(
515 new AutomationMsg_ForwardMessageToExternalHost(0, tab_handle_, 515 tab_handle_, message, origin, target));
516 message, origin, target));
517 } 516 }
518 } 517 }
519 518
520 bool ExternalTabContainer::IsExternalTabContainer() const { 519 bool ExternalTabContainer::IsExternalTabContainer() const {
521 return true; 520 return true;
522 } 521 }
523 522
524 gfx::NativeWindow ExternalTabContainer::GetFrameNativeWindow() { 523 gfx::NativeWindow ExternalTabContainer::GetFrameNativeWindow() {
525 return hwnd(); 524 return hwnd();
526 } 525 }
527 526
528 bool ExternalTabContainer::TakeFocus(bool reverse) { 527 bool ExternalTabContainer::TakeFocus(bool reverse) {
529 if (automation_) { 528 if (automation_) {
530 automation_->Send(new AutomationMsg_TabbedOut(0, tab_handle_, 529 automation_->Send(new AutomationMsg_TabbedOut(tab_handle_,
531 win_util::IsShiftPressed())); 530 win_util::IsShiftPressed()));
532 } 531 }
533 532
534 return true; 533 return true;
535 } 534 }
536 535
537 bool ExternalTabContainer::CanDownload(int request_id) { 536 bool ExternalTabContainer::CanDownload(int request_id) {
538 if (load_requests_via_automation_) { 537 if (load_requests_via_automation_) {
539 if (automation_) { 538 if (automation_) {
540 // In case the host needs to show UI that needs to take the focus. 539 // In case the host needs to show UI that needs to take the focus.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 614 }
616 external_context_menu_.reset( 615 external_context_menu_.reset(
617 new RenderViewContextMenuViews(tab_contents(), params)); 616 new RenderViewContextMenuViews(tab_contents(), params));
618 external_context_menu_->SetExternal(); 617 external_context_menu_->SetExternal();
619 external_context_menu_->Init(); 618 external_context_menu_->Init();
620 external_context_menu_->UpdateMenuItemStates(); 619 external_context_menu_->UpdateMenuItemStates();
621 620
622 POINT screen_pt = { params.x, params.y }; 621 POINT screen_pt = { params.x, params.y };
623 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); 622 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1);
624 623
625 IPC::MiniContextMenuParams ipc_params( 624 MiniContextMenuParams ipc_params(
626 screen_pt.x, 625 screen_pt.x,
627 screen_pt.y, 626 screen_pt.y,
628 params.link_url, 627 params.link_url,
629 params.unfiltered_link_url, 628 params.unfiltered_link_url,
630 params.src_url, 629 params.src_url,
631 params.page_url, 630 params.page_url,
632 params.frame_url); 631 params.frame_url);
633 632
634 bool rtl = base::i18n::IsRTL(); 633 bool rtl = base::i18n::IsRTL();
635 automation_->Send( 634 automation_->Send(
636 new AutomationMsg_ForwardContextMenuToExternalHost(0, tab_handle_, 635 new AutomationMsg_ForwardContextMenuToExternalHost(tab_handle_,
637 external_context_menu_->GetMenuHandle(), 636 external_context_menu_->GetMenuHandle(),
638 rtl ? TPM_RIGHTALIGN : TPM_LEFTALIGN, ipc_params)); 637 rtl ? TPM_RIGHTALIGN : TPM_LEFTALIGN, ipc_params));
639 638
640 return true; 639 return true;
641 } 640 }
642 641
643 bool ExternalTabContainer::ExecuteContextMenuCommand(int command) { 642 bool ExternalTabContainer::ExecuteContextMenuCommand(int command) {
644 if (!external_context_menu_.get()) { 643 if (!external_context_menu_.get()) {
645 NOTREACHED(); 644 NOTREACHED();
646 return false; 645 return false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 static const int kHttpClientErrorStart = 400; 720 static const int kHttpClientErrorStart = 400;
722 static const int kHttpServerErrorEnd = 510; 721 static const int kHttpServerErrorEnd = 510;
723 722
724 switch (type.value) { 723 switch (type.value) {
725 case NotificationType::LOAD_STOP: { 724 case NotificationType::LOAD_STOP: {
726 const LoadNotificationDetails* load = 725 const LoadNotificationDetails* load =
727 Details<LoadNotificationDetails>(details).ptr(); 726 Details<LoadNotificationDetails>(details).ptr();
728 if (load != NULL && PageTransition::IsMainFrame(load->origin())) { 727 if (load != NULL && PageTransition::IsMainFrame(load->origin())) {
729 TRACE_EVENT_END("ExternalTabContainer::Navigate", 0, 728 TRACE_EVENT_END("ExternalTabContainer::Navigate", 0,
730 load->url().spec()); 729 load->url().spec());
731 automation_->Send(new AutomationMsg_TabLoaded(0, tab_handle_, 730 automation_->Send(new AutomationMsg_TabLoaded(tab_handle_,
732 load->url())); 731 load->url()));
733 } 732 }
734 break; 733 break;
735 } 734 }
736 case NotificationType::NAV_ENTRY_COMMITTED: { 735 case NotificationType::NAV_ENTRY_COMMITTED: {
737 if (ignore_next_load_notification_) { 736 if (ignore_next_load_notification_) {
738 ignore_next_load_notification_ = false; 737 ignore_next_load_notification_ = false;
739 return; 738 return;
740 } 739 }
741 740
742 const NavigationController::LoadCommittedDetails* commit = 741 const NavigationController::LoadCommittedDetails* commit =
743 Details<NavigationController::LoadCommittedDetails>(details).ptr(); 742 Details<NavigationController::LoadCommittedDetails>(details).ptr();
744 743
745 if (commit->http_status_code >= kHttpClientErrorStart && 744 if (commit->http_status_code >= kHttpClientErrorStart &&
746 commit->http_status_code <= kHttpServerErrorEnd) { 745 commit->http_status_code <= kHttpServerErrorEnd) {
747 automation_->Send(new AutomationMsg_NavigationFailed( 746 automation_->Send(new AutomationMsg_NavigationFailed(
748 0, tab_handle_, commit->http_status_code, commit->entry->url())); 747 tab_handle_, commit->http_status_code, commit->entry->url()));
749 748
750 ignore_next_load_notification_ = true; 749 ignore_next_load_notification_ = true;
751 } else { 750 } else {
752 IPC::NavigationInfo navigation_info; 751 NavigationInfo navigation_info;
753 // When the previous entry index is invalid, it will be -1, which 752 // When the previous entry index is invalid, it will be -1, which
754 // will still make the computation come out right (navigating to the 753 // will still make the computation come out right (navigating to the
755 // 0th entry will be +1). 754 // 0th entry will be +1).
756 if (InitNavigationInfo(&navigation_info, commit->type, 755 if (InitNavigationInfo(&navigation_info, commit->type,
757 commit->previous_entry_index - 756 commit->previous_entry_index -
758 tab_contents_->controller().last_committed_entry_index())) 757 tab_contents_->controller().last_committed_entry_index()))
759 automation_->Send(new AutomationMsg_DidNavigate(0, tab_handle_, 758 automation_->Send(new AutomationMsg_DidNavigate(tab_handle_,
760 navigation_info)); 759 navigation_info));
761 } 760 }
762 break; 761 break;
763 } 762 }
764 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: { 763 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: {
765 const ProvisionalLoadDetails* load_details = 764 const ProvisionalLoadDetails* load_details =
766 Details<ProvisionalLoadDetails>(details).ptr(); 765 Details<ProvisionalLoadDetails>(details).ptr();
767 automation_->Send(new AutomationMsg_NavigationFailed( 766 automation_->Send(new AutomationMsg_NavigationFailed(
768 0, tab_handle_, load_details->error_code(), load_details->url())); 767 tab_handle_, load_details->error_code(), load_details->url()));
769 768
770 ignore_next_load_notification_ = true; 769 ignore_next_load_notification_ = true;
771 break; 770 break;
772 } 771 }
773 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { 772 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: {
774 if (load_requests_via_automation_) { 773 if (load_requests_via_automation_) {
775 RenderViewHost* rvh = Details<RenderViewHost>(details).ptr(); 774 RenderViewHost* rvh = Details<RenderViewHost>(details).ptr();
776 RegisterRenderViewHostForAutomation(rvh, false); 775 RegisterRenderViewHostForAutomation(rvh, false);
777 } 776 }
778 break; 777 break;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 852
854 // Send this keystroke to the external host as it could be processed as an 853 // Send this keystroke to the external host as it could be processed as an
855 // accelerator there. If the host does not handle this accelerator, it will 854 // accelerator there. If the host does not handle this accelerator, it will
856 // reflect the accelerator back to us via the ProcessUnhandledAccelerator 855 // reflect the accelerator back to us via the ProcessUnhandledAccelerator
857 // method. 856 // method.
858 MSG msg = {0}; 857 MSG msg = {0};
859 msg.hwnd = window; 858 msg.hwnd = window;
860 msg.message = message; 859 msg.message = message;
861 msg.wParam = wparam; 860 msg.wParam = wparam;
862 msg.lParam = lparam; 861 msg.lParam = lparam;
863 automation_->Send(new AutomationMsg_HandleAccelerator(0, tab_handle_, msg)); 862 automation_->Send(new AutomationMsg_HandleAccelerator(tab_handle_, msg));
864 return true; 863 return true;
865 } 864 }
866 865
867 bool ExternalTabContainer::InitNavigationInfo(IPC::NavigationInfo* nav_info, 866 bool ExternalTabContainer::InitNavigationInfo(NavigationInfo* nav_info,
868 NavigationType::Type nav_type, 867 NavigationType::Type nav_type,
869 int relative_offset) { 868 int relative_offset) {
870 DCHECK(nav_info); 869 DCHECK(nav_info);
871 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); 870 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
872 // If this is very early in the game then we may not have an entry. 871 // If this is very early in the game then we may not have an entry.
873 if (!entry) 872 if (!entry)
874 return false; 873 return false;
875 874
876 nav_info->navigation_type = nav_type; 875 nav_info->navigation_type = nav_type;
877 nav_info->relative_offset = relative_offset; 876 nav_info->relative_offset = relative_offset;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 982
984 TRACE_EVENT_BEGIN("ExternalTabContainer::Navigate", 0, url.spec()); 983 TRACE_EVENT_BEGIN("ExternalTabContainer::Navigate", 0, url.spec());
985 984
986 tab_contents_->controller().LoadURL(url, referrer, 985 tab_contents_->controller().LoadURL(url, referrer,
987 PageTransition::START_PAGE); 986 PageTransition::START_PAGE);
988 } 987 }
989 988
990 bool ExternalTabContainer::OnGoToEntryOffset(int offset) { 989 bool ExternalTabContainer::OnGoToEntryOffset(int offset) {
991 if (load_requests_via_automation_) { 990 if (load_requests_via_automation_) {
992 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( 991 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset(
993 0, tab_handle_, offset)); 992 tab_handle_, offset));
994 return false; 993 return false;
995 } 994 }
996 995
997 return true; 996 return true;
998 } 997 }
999 998
1000 void ExternalTabContainer::LoadAccelerators() { 999 void ExternalTabContainer::LoadAccelerators() {
1001 HACCEL accelerator_table = AtlLoadAccelerators(IDR_CHROMEFRAME); 1000 HACCEL accelerator_table = AtlLoadAccelerators(IDR_CHROMEFRAME);
1002 DCHECK(accelerator_table); 1001 DCHECK(accelerator_table);
1003 1002
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 1112
1114 if (disposition == CURRENT_TAB) { 1113 if (disposition == CURRENT_TAB) {
1115 DCHECK(route_all_top_level_navigations_); 1114 DCHECK(route_all_top_level_navigations_);
1116 disposition = NEW_FOREGROUND_TAB; 1115 disposition = NEW_FOREGROUND_TAB;
1117 } 1116 }
1118 ExternalTabContainer::OpenURLFromTab(source, url, referrer, disposition, 1117 ExternalTabContainer::OpenURLFromTab(source, url, referrer, disposition,
1119 transition); 1118 transition);
1120 // support only one navigation for a dummy tab before it is killed. 1119 // support only one navigation for a dummy tab before it is killed.
1121 ::DestroyWindow(GetNativeView()); 1120 ::DestroyWindow(GetNativeView());
1122 } 1121 }
OLDNEW
« no previous file with comments | « chrome/browser/external_tab_container_win.h ('k') | chrome/common/automation_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698