| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/common/automation_messages.h" | 35 #include "chrome/common/automation_messages.h" |
| 36 #include "chrome/common/chrome_constants.h" | 36 #include "chrome/common/chrome_constants.h" |
| 37 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
| 38 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
| 39 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 40 #include "content/browser/load_notification_details.h" | 40 #include "content/browser/load_notification_details.h" |
| 41 #include "content/browser/renderer_host/render_view_host.h" | 41 #include "content/browser/renderer_host/render_view_host.h" |
| 42 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 42 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 43 #include "content/browser/tab_contents/navigation_details.h" | 43 #include "content/browser/tab_contents/navigation_details.h" |
| 44 #include "content/browser/tab_contents/provisional_load_details.h" | 44 #include "content/browser/tab_contents/provisional_load_details.h" |
| 45 #include "content/browser/tab_contents/tab_contents.h" |
| 45 #include "content/public/browser/intents_host.h" | 46 #include "content/public/browser/intents_host.h" |
| 46 #include "content/public/browser/native_web_keyboard_event.h" | 47 #include "content/public/browser/native_web_keyboard_event.h" |
| 47 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/common/bindings_policy.h" | 49 #include "content/public/common/bindings_policy.h" |
| 49 #include "content/public/common/frame_navigate_params.h" | 50 #include "content/public/common/frame_navigate_params.h" |
| 50 #include "content/public/common/page_transition_types.h" | 51 #include "content/public/common/page_transition_types.h" |
| 51 #include "content/public/common/page_zoom.h" | 52 #include "content/public/common/page_zoom.h" |
| 52 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 53 #include "grit/locale_settings.h" | 54 #include "grit/locale_settings.h" |
| 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 NOTREACHED(); | 161 NOTREACHED(); |
| 161 return false; | 162 return false; |
| 162 } | 163 } |
| 163 | 164 |
| 164 // TODO(jcampan): limit focus traversal to contents. | 165 // TODO(jcampan): limit focus traversal to contents. |
| 165 | 166 |
| 166 prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this)); | 167 prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this)); |
| 167 | 168 |
| 168 if (existing_contents) { | 169 if (existing_contents) { |
| 169 tab_contents_.reset(existing_contents); | 170 tab_contents_.reset(existing_contents); |
| 170 tab_contents_->controller().set_browser_context(profile); | 171 tab_contents_->tab_contents()->controller().set_browser_context(profile); |
| 171 } else { | 172 } else { |
| 172 TabContents* new_contents = new TabContents(profile, NULL, MSG_ROUTING_NONE, | 173 TabContents* new_contents = new TabContents(profile, NULL, MSG_ROUTING_NONE, |
| 173 NULL, NULL); | 174 NULL, NULL); |
| 174 tab_contents_.reset(new TabContentsWrapper(new_contents)); | 175 tab_contents_.reset(new TabContentsWrapper(new_contents)); |
| 175 } | 176 } |
| 176 | 177 |
| 177 if (!infobars_enabled) | 178 if (!infobars_enabled) |
| 178 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); | 179 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); |
| 179 | 180 |
| 180 tab_contents_->tab_contents()->set_delegate(this); | 181 tab_contents_->tab_contents()->set_delegate(this); |
| 181 | 182 |
| 182 tab_contents_->tab_contents()-> | 183 tab_contents_->tab_contents()-> |
| 183 GetMutableRendererPrefs()->browser_handles_top_level_requests = | 184 GetMutableRendererPrefs()->browser_handles_top_level_requests = |
| 184 handle_top_level_requests; | 185 handle_top_level_requests; |
| 185 | 186 |
| 186 if (!existing_contents) { | 187 if (!existing_contents) { |
| 187 tab_contents_->render_view_host()->AllowBindings( | 188 tab_contents_->tab_contents()->render_view_host()->AllowBindings( |
| 188 content::BINDINGS_POLICY_EXTERNAL_HOST); | 189 content::BINDINGS_POLICY_EXTERNAL_HOST); |
| 189 } | 190 } |
| 190 | 191 |
| 191 NavigationController* controller = &tab_contents_->controller(); | 192 NavigationController* controller = |
| 193 &tab_contents_->tab_contents()->controller(); |
| 192 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 194 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 193 content::Source<NavigationController>(controller)); | 195 content::Source<NavigationController>(controller)); |
| 194 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 196 registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 195 content::Source<NavigationController>(controller)); | 197 content::Source<NavigationController>(controller)); |
| 196 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 198 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 197 content::Source<NavigationController>(controller)); | 199 content::Source<NavigationController>(controller)); |
| 198 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 200 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 199 content::Source<TabContents>(tab_contents_->tab_contents())); | 201 content::Source<TabContents>(tab_contents_->tab_contents())); |
| 200 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 202 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| 201 content::NotificationService::AllSources()); | 203 content::NotificationService::AllSources()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 229 | 231 |
| 230 LoadAccelerators(); | 232 LoadAccelerators(); |
| 231 SetupExternalTabView(); | 233 SetupExternalTabView(); |
| 232 tab_contents_->blocked_content_tab_helper()->set_delegate(this); | 234 tab_contents_->blocked_content_tab_helper()->set_delegate(this); |
| 233 return true; | 235 return true; |
| 234 } | 236 } |
| 235 | 237 |
| 236 void ExternalTabContainer::Uninitialize() { | 238 void ExternalTabContainer::Uninitialize() { |
| 237 registrar_.RemoveAll(); | 239 registrar_.RemoveAll(); |
| 238 if (tab_contents_.get()) { | 240 if (tab_contents_.get()) { |
| 239 UnregisterRenderViewHost(tab_contents_->render_view_host()); | 241 UnregisterRenderViewHost(tab_contents_->tab_contents()->render_view_host()); |
| 240 | 242 |
| 241 if (GetWidget()->GetRootView()) | 243 if (GetWidget()->GetRootView()) |
| 242 GetWidget()->GetRootView()->RemoveAllChildViews(true); | 244 GetWidget()->GetRootView()->RemoveAllChildViews(true); |
| 243 | 245 |
| 244 content::NotificationService::current()->Notify( | 246 content::NotificationService::current()->Notify( |
| 245 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, | 247 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, |
| 246 content::Source<NavigationController>(&tab_contents_->controller()), | 248 content::Source<NavigationController>( |
| 249 &tab_contents_->tab_contents()->controller()), |
| 247 content::Details<ExternalTabContainer>(this)); | 250 content::Details<ExternalTabContainer>(this)); |
| 248 | 251 |
| 249 tab_contents_.reset(NULL); | 252 tab_contents_.reset(NULL); |
| 250 } | 253 } |
| 251 | 254 |
| 252 if (focus_manager_) { | 255 if (focus_manager_) { |
| 253 focus_manager_->UnregisterAccelerators(this); | 256 focus_manager_->UnregisterAccelerators(this); |
| 254 focus_manager_ = NULL; | 257 focus_manager_ = NULL; |
| 255 } | 258 } |
| 256 | 259 |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 tab_handle_, commit->http_status_code, commit->entry->url())); | 813 tab_handle_, commit->http_status_code, commit->entry->url())); |
| 811 | 814 |
| 812 ignore_next_load_notification_ = true; | 815 ignore_next_load_notification_ = true; |
| 813 } else { | 816 } else { |
| 814 NavigationInfo navigation_info; | 817 NavigationInfo navigation_info; |
| 815 // When the previous entry index is invalid, it will be -1, which | 818 // When the previous entry index is invalid, it will be -1, which |
| 816 // will still make the computation come out right (navigating to the | 819 // will still make the computation come out right (navigating to the |
| 817 // 0th entry will be +1). | 820 // 0th entry will be +1). |
| 818 if (InitNavigationInfo(&navigation_info, commit->type, | 821 if (InitNavigationInfo(&navigation_info, commit->type, |
| 819 commit->previous_entry_index - | 822 commit->previous_entry_index - |
| 820 tab_contents_->controller().last_committed_entry_index())) | 823 tab_contents_->tab_contents()-> |
| 824 controller().last_committed_entry_index())) |
| 821 automation_->Send(new AutomationMsg_DidNavigate(tab_handle_, | 825 automation_->Send(new AutomationMsg_DidNavigate(tab_handle_, |
| 822 navigation_info)); | 826 navigation_info)); |
| 823 } | 827 } |
| 824 break; | 828 break; |
| 825 } | 829 } |
| 826 case content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR: { | 830 case content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR: { |
| 827 const ProvisionalLoadDetails* load_details = | 831 const ProvisionalLoadDetails* load_details = |
| 828 content::Details<ProvisionalLoadDetails>(details).ptr(); | 832 content::Details<ProvisionalLoadDetails>(details).ptr(); |
| 829 automation_->Send(new AutomationMsg_NavigationFailed( | 833 automation_->Send(new AutomationMsg_NavigationFailed( |
| 830 tab_handle_, load_details->error_code(), load_details->url())); | 834 tab_handle_, load_details->error_code(), load_details->url())); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 msg.wParam = wparam; | 935 msg.wParam = wparam; |
| 932 msg.lParam = lparam; | 936 msg.lParam = lparam; |
| 933 automation_->Send(new AutomationMsg_HandleAccelerator(tab_handle_, msg)); | 937 automation_->Send(new AutomationMsg_HandleAccelerator(tab_handle_, msg)); |
| 934 return true; | 938 return true; |
| 935 } | 939 } |
| 936 | 940 |
| 937 bool ExternalTabContainer::InitNavigationInfo(NavigationInfo* nav_info, | 941 bool ExternalTabContainer::InitNavigationInfo(NavigationInfo* nav_info, |
| 938 content::NavigationType nav_type, | 942 content::NavigationType nav_type, |
| 939 int relative_offset) { | 943 int relative_offset) { |
| 940 DCHECK(nav_info); | 944 DCHECK(nav_info); |
| 941 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); | 945 NavigationEntry* entry = |
| 946 tab_contents_->tab_contents()->controller().GetActiveEntry(); |
| 942 // If this is very early in the game then we may not have an entry. | 947 // If this is very early in the game then we may not have an entry. |
| 943 if (!entry) | 948 if (!entry) |
| 944 return false; | 949 return false; |
| 945 | 950 |
| 946 nav_info->navigation_type = nav_type; | 951 nav_info->navigation_type = nav_type; |
| 947 nav_info->relative_offset = relative_offset; | 952 nav_info->relative_offset = relative_offset; |
| 948 nav_info->navigation_index = | 953 nav_info->navigation_index = |
| 949 tab_contents_->controller().GetCurrentEntryIndex(); | 954 tab_contents_->tab_contents()->controller().GetCurrentEntryIndex(); |
| 950 nav_info->url = entry->url(); | 955 nav_info->url = entry->url(); |
| 951 nav_info->referrer = entry->referrer().url; | 956 nav_info->referrer = entry->referrer().url; |
| 952 nav_info->title = UTF16ToWideHack(entry->title()); | 957 nav_info->title = UTF16ToWideHack(entry->title()); |
| 953 if (nav_info->title.empty()) | 958 if (nav_info->title.empty()) |
| 954 nav_info->title = UTF8ToWide(nav_info->url.spec()); | 959 nav_info->title = UTF8ToWide(nav_info->url.spec()); |
| 955 | 960 |
| 956 nav_info->security_style = entry->ssl().security_style(); | 961 nav_info->security_style = entry->ssl().security_style(); |
| 957 nav_info->displayed_insecure_content = | 962 nav_info->displayed_insecure_content = |
| 958 entry->ssl().displayed_insecure_content(); | 963 entry->ssl().displayed_insecure_content(); |
| 959 nav_info->ran_insecure_content = entry->ssl().ran_insecure_content(); | 964 nav_info->ran_insecure_content = entry->ssl().ran_insecure_content(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 987 bool ExternalTabContainer::DrawInfoBarArrows(int* x) const { | 992 bool ExternalTabContainer::DrawInfoBarArrows(int* x) const { |
| 988 return false; | 993 return false; |
| 989 } | 994 } |
| 990 | 995 |
| 991 bool ExternalTabContainer::AcceleratorPressed( | 996 bool ExternalTabContainer::AcceleratorPressed( |
| 992 const ui::Accelerator& accelerator) { | 997 const ui::Accelerator& accelerator) { |
| 993 std::map<ui::Accelerator, int>::const_iterator iter = | 998 std::map<ui::Accelerator, int>::const_iterator iter = |
| 994 accelerator_table_.find(accelerator); | 999 accelerator_table_.find(accelerator); |
| 995 DCHECK(iter != accelerator_table_.end()); | 1000 DCHECK(iter != accelerator_table_.end()); |
| 996 | 1001 |
| 997 if (!tab_contents_.get() || !tab_contents_->render_view_host()) { | 1002 if (!tab_contents_.get() || |
| 1003 !tab_contents_->tab_contents()->render_view_host()) { |
| 998 NOTREACHED(); | 1004 NOTREACHED(); |
| 999 return false; | 1005 return false; |
| 1000 } | 1006 } |
| 1001 | 1007 |
| 1002 RenderViewHost* host = tab_contents_->render_view_host(); | 1008 RenderViewHost* host = tab_contents_->tab_contents()->render_view_host(); |
| 1003 int command_id = iter->second; | 1009 int command_id = iter->second; |
| 1004 switch (command_id) { | 1010 switch (command_id) { |
| 1005 case IDC_ZOOM_PLUS: | 1011 case IDC_ZOOM_PLUS: |
| 1006 host->Zoom(content::PAGE_ZOOM_IN); | 1012 host->Zoom(content::PAGE_ZOOM_IN); |
| 1007 break; | 1013 break; |
| 1008 case IDC_ZOOM_NORMAL: | 1014 case IDC_ZOOM_NORMAL: |
| 1009 host->Zoom(content::PAGE_ZOOM_RESET); | 1015 host->Zoom(content::PAGE_ZOOM_RESET); |
| 1010 break; | 1016 break; |
| 1011 case IDC_ZOOM_MINUS: | 1017 case IDC_ZOOM_MINUS: |
| 1012 host->Zoom(content::PAGE_ZOOM_OUT); | 1018 host->Zoom(content::PAGE_ZOOM_OUT); |
| 1013 break; | 1019 break; |
| 1014 case IDC_DEV_TOOLS: | 1020 case IDC_DEV_TOOLS: |
| 1015 DevToolsWindow::ToggleDevToolsWindow( | 1021 DevToolsWindow::ToggleDevToolsWindow( |
| 1016 tab_contents_->render_view_host(), DEVTOOLS_TOGGLE_ACTION_NONE); | 1022 tab_contents_->tab_contents()->render_view_host(), |
| 1023 DEVTOOLS_TOGGLE_ACTION_NONE); |
| 1017 break; | 1024 break; |
| 1018 case IDC_DEV_TOOLS_CONSOLE: | 1025 case IDC_DEV_TOOLS_CONSOLE: |
| 1019 DevToolsWindow::ToggleDevToolsWindow( | 1026 DevToolsWindow::ToggleDevToolsWindow( |
| 1020 tab_contents_->render_view_host(), | 1027 tab_contents_->tab_contents()->render_view_host(), |
| 1021 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); | 1028 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 1022 break; | 1029 break; |
| 1023 case IDC_DEV_TOOLS_INSPECT: | 1030 case IDC_DEV_TOOLS_INSPECT: |
| 1024 DevToolsWindow::ToggleDevToolsWindow( | 1031 DevToolsWindow::ToggleDevToolsWindow( |
| 1025 tab_contents_->render_view_host(), | 1032 tab_contents_->tab_contents()->render_view_host(), |
| 1026 DEVTOOLS_TOGGLE_ACTION_INSPECT); | 1033 DEVTOOLS_TOGGLE_ACTION_INSPECT); |
| 1027 break; | 1034 break; |
| 1028 default: | 1035 default: |
| 1029 NOTREACHED() << "Unsupported accelerator: " << command_id; | 1036 NOTREACHED() << "Unsupported accelerator: " << command_id; |
| 1030 return false; | 1037 return false; |
| 1031 } | 1038 } |
| 1032 return true; | 1039 return true; |
| 1033 } | 1040 } |
| 1034 | 1041 |
| 1035 void ExternalTabContainer::Navigate(const GURL& url, const GURL& referrer) { | 1042 void ExternalTabContainer::Navigate(const GURL& url, const GURL& referrer) { |
| 1036 if (!tab_contents_.get()) { | 1043 if (!tab_contents_.get()) { |
| 1037 NOTREACHED(); | 1044 NOTREACHED(); |
| 1038 return; | 1045 return; |
| 1039 } | 1046 } |
| 1040 | 1047 |
| 1041 TRACE_EVENT_BEGIN_ETW("ExternalTabContainer::Navigate", 0, url.spec()); | 1048 TRACE_EVENT_BEGIN_ETW("ExternalTabContainer::Navigate", 0, url.spec()); |
| 1042 | 1049 |
| 1043 tab_contents_->controller().LoadURL( | 1050 tab_contents_->tab_contents()->controller().LoadURL( |
| 1044 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), | 1051 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), |
| 1045 content::PAGE_TRANSITION_START_PAGE, std::string()); | 1052 content::PAGE_TRANSITION_START_PAGE, std::string()); |
| 1046 } | 1053 } |
| 1047 | 1054 |
| 1048 bool ExternalTabContainer::OnGoToEntryOffset(int offset) { | 1055 bool ExternalTabContainer::OnGoToEntryOffset(int offset) { |
| 1049 if (load_requests_via_automation_) { | 1056 if (load_requests_via_automation_) { |
| 1050 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( | 1057 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( |
| 1051 tab_handle_, offset)); | 1058 tab_handle_, offset)); |
| 1052 return false; | 1059 return false; |
| 1053 } | 1060 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 accelerator_table_[accelerator] = accelerators[i].cmd; | 1093 accelerator_table_[accelerator] = accelerators[i].cmd; |
| 1087 | 1094 |
| 1088 // Also register with the focus manager. | 1095 // Also register with the focus manager. |
| 1089 if (focus_manager_) | 1096 if (focus_manager_) |
| 1090 focus_manager_->RegisterAccelerator(accelerator, this); | 1097 focus_manager_->RegisterAccelerator(accelerator, this); |
| 1091 } | 1098 } |
| 1092 } | 1099 } |
| 1093 | 1100 |
| 1094 void ExternalTabContainer::OnReinitialize() { | 1101 void ExternalTabContainer::OnReinitialize() { |
| 1095 if (load_requests_via_automation_) { | 1102 if (load_requests_via_automation_) { |
| 1096 RenderViewHost* rvh = tab_contents_->render_view_host(); | 1103 RenderViewHost* rvh = tab_contents_->tab_contents()->render_view_host(); |
| 1097 if (rvh) { | 1104 if (rvh) { |
| 1098 AutomationResourceMessageFilter::ResumePendingRenderView( | 1105 AutomationResourceMessageFilter::ResumePendingRenderView( |
| 1099 rvh->process()->GetID(), rvh->routing_id(), | 1106 rvh->process()->GetID(), rvh->routing_id(), |
| 1100 tab_handle_, automation_resource_message_filter_); | 1107 tab_handle_, automation_resource_message_filter_); |
| 1101 } | 1108 } |
| 1102 } | 1109 } |
| 1103 | 1110 |
| 1104 NavigationStateChanged(tab_contents(), 0); | 1111 NavigationStateChanged(tab_contents(), 0); |
| 1105 ServicePendingOpenURLRequests(); | 1112 ServicePendingOpenURLRequests(); |
| 1106 } | 1113 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 if (params.disposition == CURRENT_TAB) { | 1178 if (params.disposition == CURRENT_TAB) { |
| 1172 DCHECK(route_all_top_level_navigations_); | 1179 DCHECK(route_all_top_level_navigations_); |
| 1173 forward_params.disposition = NEW_FOREGROUND_TAB; | 1180 forward_params.disposition = NEW_FOREGROUND_TAB; |
| 1174 } | 1181 } |
| 1175 TabContents* new_contents = | 1182 TabContents* new_contents = |
| 1176 ExternalTabContainer::OpenURLFromTab(source, forward_params); | 1183 ExternalTabContainer::OpenURLFromTab(source, forward_params); |
| 1177 // support only one navigation for a dummy tab before it is killed. | 1184 // support only one navigation for a dummy tab before it is killed. |
| 1178 ::DestroyWindow(GetNativeView()); | 1185 ::DestroyWindow(GetNativeView()); |
| 1179 return new_contents; | 1186 return new_contents; |
| 1180 } | 1187 } |
| OLD | NEW |