| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 3113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3124 return BrowserWindow::CreateBrowserWindow(this); | 3124 return BrowserWindow::CreateBrowserWindow(this); |
| 3125 } | 3125 } |
| 3126 | 3126 |
| 3127 /////////////////////////////////////////////////////////////////////////////// | 3127 /////////////////////////////////////////////////////////////////////////////// |
| 3128 // Browser, content::WebContentsDelegate implementation: | 3128 // Browser, content::WebContentsDelegate implementation: |
| 3129 | 3129 |
| 3130 WebContents* Browser::OpenURLFromTab(WebContents* source, | 3130 WebContents* Browser::OpenURLFromTab(WebContents* source, |
| 3131 const OpenURLParams& params) { | 3131 const OpenURLParams& params) { |
| 3132 browser::NavigateParams nav_params(this, params.url, params.transition); | 3132 browser::NavigateParams nav_params(this, params.url, params.transition); |
| 3133 nav_params.source_contents = GetTabContentsAt( | 3133 nav_params.source_contents = GetTabContentsAt( |
| 3134 tab_strip_model_->GetWrapperIndex(source)); | 3134 tab_strip_model_->GetIndexOfWebContents(source)); |
| 3135 nav_params.referrer = params.referrer; | 3135 nav_params.referrer = params.referrer; |
| 3136 nav_params.disposition = params.disposition; | 3136 nav_params.disposition = params.disposition; |
| 3137 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; | 3137 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 3138 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; | 3138 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3139 nav_params.user_gesture = true; | 3139 nav_params.user_gesture = true; |
| 3140 nav_params.override_encoding = params.override_encoding; | 3140 nav_params.override_encoding = params.override_encoding; |
| 3141 nav_params.is_renderer_initiated = params.is_renderer_initiated; | 3141 nav_params.is_renderer_initiated = params.is_renderer_initiated; |
| 3142 nav_params.transferred_global_request_id = | 3142 nav_params.transferred_global_request_id = |
| 3143 params.transferred_global_request_id; | 3143 params.transferred_global_request_id; |
| 3144 browser::Navigate(&nav_params); | 3144 browser::Navigate(&nav_params); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3205 blocked_content_tab_helper()-> | 3205 blocked_content_tab_helper()-> |
| 3206 AddPopup(new_tab_contents, initial_pos, user_gesture); | 3206 AddPopup(new_tab_contents, initial_pos, user_gesture); |
| 3207 return; | 3207 return; |
| 3208 } | 3208 } |
| 3209 | 3209 |
| 3210 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); | 3210 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); |
| 3211 } | 3211 } |
| 3212 | 3212 |
| 3213 browser::NavigateParams params(this, new_tab_contents); | 3213 browser::NavigateParams params(this, new_tab_contents); |
| 3214 params.source_contents = source ? | 3214 params.source_contents = source ? |
| 3215 GetTabContentsAt(tab_strip_model_->GetWrapperIndex(source)): NULL; | 3215 GetTabContentsAt(tab_strip_model_->GetIndexOfWebContents(source)): NULL; |
| 3216 params.disposition = disposition; | 3216 params.disposition = disposition; |
| 3217 params.window_bounds = initial_pos; | 3217 params.window_bounds = initial_pos; |
| 3218 params.window_action = browser::NavigateParams::SHOW_WINDOW; | 3218 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3219 params.user_gesture = user_gesture; | 3219 params.user_gesture = user_gesture; |
| 3220 browser::Navigate(¶ms); | 3220 browser::Navigate(¶ms); |
| 3221 } | 3221 } |
| 3222 | 3222 |
| 3223 void Browser::ActivateContents(WebContents* contents) { | 3223 void Browser::ActivateContents(WebContents* contents) { |
| 3224 ActivateTabAt(tab_strip_model_->GetWrapperIndex(contents), false); | 3224 ActivateTabAt(tab_strip_model_->GetIndexOfWebContents(contents), false); |
| 3225 window_->Activate(); | 3225 window_->Activate(); |
| 3226 } | 3226 } |
| 3227 | 3227 |
| 3228 void Browser::DeactivateContents(WebContents* contents) { | 3228 void Browser::DeactivateContents(WebContents* contents) { |
| 3229 window_->Deactivate(); | 3229 window_->Deactivate(); |
| 3230 } | 3230 } |
| 3231 | 3231 |
| 3232 void Browser::LoadingStateChanged(WebContents* source) { | 3232 void Browser::LoadingStateChanged(WebContents* source) { |
| 3233 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); | 3233 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); |
| 3234 window_->UpdateTitleBar(); | 3234 window_->UpdateTitleBar(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3261 void Browser::CloseContents(WebContents* source) { | 3261 void Browser::CloseContents(WebContents* source) { |
| 3262 if (is_attempting_to_close_browser_) { | 3262 if (is_attempting_to_close_browser_) { |
| 3263 // If we're trying to close the browser, just clear the state related to | 3263 // If we're trying to close the browser, just clear the state related to |
| 3264 // waiting for unload to fire. Don't actually try to close the tab as it | 3264 // waiting for unload to fire. Don't actually try to close the tab as it |
| 3265 // will go down the slow shutdown path instead of the fast path of killing | 3265 // will go down the slow shutdown path instead of the fast path of killing |
| 3266 // all the renderer processes. | 3266 // all the renderer processes. |
| 3267 ClearUnloadState(source, true); | 3267 ClearUnloadState(source, true); |
| 3268 return; | 3268 return; |
| 3269 } | 3269 } |
| 3270 | 3270 |
| 3271 int index = tab_strip_model_->GetWrapperIndex(source); | 3271 int index = tab_strip_model_->GetIndexOfWebContents(source); |
| 3272 if (index == TabStripModel::kNoTab) { | 3272 if (index == TabStripModel::kNoTab) { |
| 3273 NOTREACHED() << "CloseContents called for tab not in our strip"; | 3273 NOTREACHED() << "CloseContents called for tab not in our strip"; |
| 3274 return; | 3274 return; |
| 3275 } | 3275 } |
| 3276 tab_strip_model_->CloseTabContentsAt(index, | 3276 tab_strip_model_->CloseTabContentsAt(index, |
| 3277 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); | 3277 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
| 3278 } | 3278 } |
| 3279 | 3279 |
| 3280 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { | 3280 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
| 3281 if (!IsPopupOrPanel(source)) { | 3281 if (!IsPopupOrPanel(source)) { |
| 3282 NOTREACHED() << "moving invalid browser type"; | 3282 NOTREACHED() << "moving invalid browser type"; |
| 3283 return; | 3283 return; |
| 3284 } | 3284 } |
| 3285 window_->SetBounds(pos); | 3285 window_->SetBounds(pos); |
| 3286 } | 3286 } |
| 3287 | 3287 |
| 3288 void Browser::DetachContents(WebContents* source) { | 3288 void Browser::DetachContents(WebContents* source) { |
| 3289 int index = tab_strip_model_->GetWrapperIndex(source); | 3289 int index = tab_strip_model_->GetIndexOfWebContents(source); |
| 3290 if (index >= 0) | 3290 if (index >= 0) |
| 3291 tab_strip_model_->DetachTabContentsAt(index); | 3291 tab_strip_model_->DetachTabContentsAt(index); |
| 3292 } | 3292 } |
| 3293 | 3293 |
| 3294 bool Browser::IsPopupOrPanel(const WebContents* source) const { | 3294 bool Browser::IsPopupOrPanel(const WebContents* source) const { |
| 3295 // A non-tabbed BROWSER is an unconstrained popup. | 3295 // A non-tabbed BROWSER is an unconstrained popup. |
| 3296 return is_type_popup() || is_type_panel(); | 3296 return is_type_popup() || is_type_panel(); |
| 3297 } | 3297 } |
| 3298 | 3298 |
| 3299 bool Browser::CanReloadContents(WebContents* source) const { | 3299 bool Browser::CanReloadContents(WebContents* source) const { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3453 } | 3453 } |
| 3454 | 3454 |
| 3455 // If the download occurs in a new tab, close it. | 3455 // If the download occurs in a new tab, close it. |
| 3456 if (source->GetController().IsInitialNavigation() && tab_count() > 1) | 3456 if (source->GetController().IsInitialNavigation() && tab_count() > 1) |
| 3457 CloseContents(source); | 3457 CloseContents(source); |
| 3458 } | 3458 } |
| 3459 | 3459 |
| 3460 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { | 3460 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
| 3461 DCHECK(source); | 3461 DCHECK(source); |
| 3462 TabContents* tab_contents = GetTabContentsAt( | 3462 TabContents* tab_contents = GetTabContentsAt( |
| 3463 tab_strip_model_->GetWrapperIndex(source)); | 3463 tab_strip_model_->GetIndexOfWebContents(source)); |
| 3464 ViewSource(tab_contents); | 3464 ViewSource(tab_contents); |
| 3465 } | 3465 } |
| 3466 | 3466 |
| 3467 void Browser::ViewSourceForFrame(WebContents* source, | 3467 void Browser::ViewSourceForFrame(WebContents* source, |
| 3468 const GURL& frame_url, | 3468 const GURL& frame_url, |
| 3469 const std::string& frame_content_state) { | 3469 const std::string& frame_content_state) { |
| 3470 DCHECK(source); | 3470 DCHECK(source); |
| 3471 TabContents* tab_contents = GetTabContentsAt( | 3471 TabContents* tab_contents = GetTabContentsAt( |
| 3472 tab_strip_model_->GetWrapperIndex(source)); | 3472 tab_strip_model_->GetIndexOfWebContents(source)); |
| 3473 ViewSource(tab_contents, frame_url, frame_content_state); | 3473 ViewSource(tab_contents, frame_url, frame_content_state); |
| 3474 } | 3474 } |
| 3475 | 3475 |
| 3476 void Browser::ShowRepostFormWarningDialog(WebContents* source) { | 3476 void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
| 3477 browser::ShowTabModalConfirmDialog( | 3477 browser::ShowTabModalConfirmDialog( |
| 3478 new RepostFormWarningController(source), | 3478 new RepostFormWarningController(source), |
| 3479 TabContents::GetOwningTabContentsForWebContents(source)); | 3479 TabContents::GetOwningTabContentsForWebContents(source)); |
| 3480 } | 3480 } |
| 3481 | 3481 |
| 3482 bool Browser::ShouldAddNavigationToHistory( | 3482 bool Browser::ShouldAddNavigationToHistory( |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4542 web_app::IsValidUrl(contents->GetURL())); | 4542 web_app::IsValidUrl(contents->GetURL())); |
| 4543 #endif | 4543 #endif |
| 4544 window_->UpdateTitleBar(); | 4544 window_->UpdateTitleBar(); |
| 4545 } | 4545 } |
| 4546 } | 4546 } |
| 4547 | 4547 |
| 4548 // Updates that don't depend upon the selected state go here. | 4548 // Updates that don't depend upon the selected state go here. |
| 4549 if (flags & | 4549 if (flags & |
| 4550 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { | 4550 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
| 4551 tab_strip_model_->UpdateTabContentsStateAt( | 4551 tab_strip_model_->UpdateTabContentsStateAt( |
| 4552 tab_strip_model_->GetWrapperIndex(contents), | 4552 tab_strip_model_->GetIndexOfWebContents(contents), |
| 4553 TabStripModelObserver::ALL); | 4553 TabStripModelObserver::ALL); |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 // We don't need to process INVALIDATE_STATE, since that's not visible. | 4556 // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 4557 } | 4557 } |
| 4558 | 4558 |
| 4559 scheduled_updates_.clear(); | 4559 scheduled_updates_.clear(); |
| 4560 } | 4560 } |
| 4561 | 4561 |
| 4562 void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { | 4562 void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5173 if (contents && !allow_js_access) { | 5173 if (contents && !allow_js_access) { |
| 5174 contents->web_contents()->GetController().LoadURL( | 5174 contents->web_contents()->GetController().LoadURL( |
| 5175 target_url, | 5175 target_url, |
| 5176 content::Referrer(), | 5176 content::Referrer(), |
| 5177 content::PAGE_TRANSITION_LINK, | 5177 content::PAGE_TRANSITION_LINK, |
| 5178 std::string()); // No extra headers. | 5178 std::string()); // No extra headers. |
| 5179 } | 5179 } |
| 5180 | 5180 |
| 5181 return contents != NULL; | 5181 return contents != NULL; |
| 5182 } | 5182 } |
| OLD | NEW |