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 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 void Browser::ShowFindBar() { | 1572 void Browser::ShowFindBar() { |
1573 GetFindBarController()->Show(); | 1573 GetFindBarController()->Show(); |
1574 } | 1574 } |
1575 | 1575 |
1576 void Browser::ShowPageInfo(content::WebContents* web_contents, | 1576 void Browser::ShowPageInfo(content::WebContents* web_contents, |
1577 const GURL& url, | 1577 const GURL& url, |
1578 const SSLStatus& ssl, | 1578 const SSLStatus& ssl, |
1579 bool show_history) { | 1579 bool show_history) { |
1580 Profile* profile = Profile::FromBrowserContext( | 1580 Profile* profile = Profile::FromBrowserContext( |
1581 web_contents->GetBrowserContext()); | 1581 web_contents->GetBrowserContext()); |
1582 TabContents* tab_contents = | 1582 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
1583 TabContents::GetOwningTabContentsForWebContents(web_contents); | |
1584 | 1583 |
1585 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1584 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1586 switches::kEnableWebsiteSettings)) { | 1585 switches::kEnableWebsiteSettings)) { |
1587 window()->ShowWebsiteSettings( | 1586 window()->ShowWebsiteSettings( |
1588 profile, tab_contents, url, ssl, show_history); | 1587 profile, tab_contents, url, ssl, show_history); |
1589 } else { | 1588 } else { |
1590 window()->ShowPageInfo(profile, url, ssl, show_history); | 1589 window()->ShowPageInfo(profile, url, ssl, show_history); |
1591 } | 1590 } |
1592 } | 1591 } |
1593 | 1592 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 // them. Once they have fired, we'll get a message back saying whether | 2228 // them. Once they have fired, we'll get a message back saying whether |
2230 // to proceed closing the page or not, which sends us back to this method | 2229 // to proceed closing the page or not, which sends us back to this method |
2231 // with the NeedToFireBeforeUnload bit cleared. | 2230 // with the NeedToFireBeforeUnload bit cleared. |
2232 contents->GetRenderViewHost()->FirePageBeforeUnload(false); | 2231 contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
2233 return true; | 2232 return true; |
2234 } | 2233 } |
2235 return false; | 2234 return false; |
2236 } | 2235 } |
2237 | 2236 |
2238 // static | 2237 // static |
2239 void Browser::JSOutOfMemoryHelper(WebContents* tab) { | 2238 void Browser::JSOutOfMemoryHelper(WebContents* web_contents) { |
2240 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents( | 2239 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
2241 tab); | |
2242 if (!tab_contents) | 2240 if (!tab_contents) |
2243 return; | 2241 return; |
2244 | 2242 |
2245 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); | 2243 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
2246 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 2244 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
2247 infobar_helper, | 2245 infobar_helper, |
2248 NULL, | 2246 NULL, |
2249 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), | 2247 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
2250 true)); | 2248 true)); |
2251 } | 2249 } |
2252 | 2250 |
2253 // static | 2251 // static |
2254 void Browser::RegisterProtocolHandlerHelper(WebContents* tab, | 2252 void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents, |
2255 const std::string& protocol, | 2253 const std::string& protocol, |
2256 const GURL& url, | 2254 const GURL& url, |
2257 const string16& title, | 2255 const string16& title, |
2258 bool user_gesture) { | 2256 bool user_gesture) { |
2259 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents( | 2257 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
2260 tab); | |
2261 if (!tab_contents || tab_contents->profile()->IsOffTheRecord()) | 2258 if (!tab_contents || tab_contents->profile()->IsOffTheRecord()) |
2262 return; | 2259 return; |
2263 | 2260 |
2264 ProtocolHandler handler = | 2261 ProtocolHandler handler = |
2265 ProtocolHandler::CreateProtocolHandler(protocol, url, title); | 2262 ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
2266 | 2263 |
2267 ProtocolHandlerRegistry* registry = | 2264 ProtocolHandlerRegistry* registry = |
2268 tab_contents->profile()->GetProtocolHandlerRegistry(); | 2265 tab_contents->profile()->GetProtocolHandlerRegistry(); |
2269 | 2266 |
2270 if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { | 2267 if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { |
(...skipping 16 matching lines...) Expand all Loading... |
2287 break; | 2284 break; |
2288 } | 2285 } |
2289 } | 2286 } |
2290 | 2287 |
2291 if (rph_delegate != NULL) | 2288 if (rph_delegate != NULL) |
2292 infobar_helper->AddInfoBar(rph_delegate); | 2289 infobar_helper->AddInfoBar(rph_delegate); |
2293 } | 2290 } |
2294 } | 2291 } |
2295 | 2292 |
2296 // static | 2293 // static |
2297 void Browser::FindReplyHelper(WebContents* tab, | 2294 void Browser::FindReplyHelper(WebContents* web_contents, |
2298 int request_id, | 2295 int request_id, |
2299 int number_of_matches, | 2296 int number_of_matches, |
2300 const gfx::Rect& selection_rect, | 2297 const gfx::Rect& selection_rect, |
2301 int active_match_ordinal, | 2298 int active_match_ordinal, |
2302 bool final_update) { | 2299 bool final_update) { |
2303 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents( | 2300 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
2304 tab); | |
2305 if (!tab_contents || !tab_contents->find_tab_helper()) | 2301 if (!tab_contents || !tab_contents->find_tab_helper()) |
2306 return; | 2302 return; |
2307 | 2303 |
2308 tab_contents->find_tab_helper()->HandleFindReply(request_id, | 2304 tab_contents->find_tab_helper()->HandleFindReply(request_id, |
2309 number_of_matches, | 2305 number_of_matches, |
2310 selection_rect, | 2306 selection_rect, |
2311 active_match_ordinal, | 2307 active_match_ordinal, |
2312 final_update); | 2308 final_update); |
2313 } | 2309 } |
2314 | 2310 |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3166 WindowOpenDisposition disposition, | 3162 WindowOpenDisposition disposition, |
3167 const gfx::Rect& initial_pos, | 3163 const gfx::Rect& initial_pos, |
3168 bool user_gesture) { | 3164 bool user_gesture) { |
3169 // No code for this yet. | 3165 // No code for this yet. |
3170 DCHECK(disposition != SAVE_TO_DISK); | 3166 DCHECK(disposition != SAVE_TO_DISK); |
3171 // Can't create a new contents for the current tab - invalid case. | 3167 // Can't create a new contents for the current tab - invalid case. |
3172 DCHECK(disposition != CURRENT_TAB); | 3168 DCHECK(disposition != CURRENT_TAB); |
3173 | 3169 |
3174 TabContents* source_tab_contents = NULL; | 3170 TabContents* source_tab_contents = NULL; |
3175 BlockedContentTabHelper* source_blocked_content = NULL; | 3171 BlockedContentTabHelper* source_blocked_content = NULL; |
3176 TabContents* new_tab_contents = | 3172 TabContents* new_tab_contents = TabContents::FromWebContents(new_contents); |
3177 TabContents::GetOwningTabContentsForWebContents(new_contents); | |
3178 if (!new_tab_contents) { | 3173 if (!new_tab_contents) { |
3179 new_tab_contents = new TabContents(new_contents); | 3174 new_tab_contents = new TabContents(new_contents); |
3180 } | 3175 } |
3181 if (source) { | 3176 if (source) { |
3182 source_tab_contents = | 3177 source_tab_contents = TabContents::FromWebContents(source); |
3183 TabContents::GetOwningTabContentsForWebContents(source); | |
3184 source_blocked_content = source_tab_contents->blocked_content_tab_helper(); | 3178 source_blocked_content = source_tab_contents->blocked_content_tab_helper(); |
3185 } | 3179 } |
3186 | 3180 |
3187 if (source_tab_contents) { | 3181 if (source_tab_contents) { |
3188 // Handle blocking of all contents. | 3182 // Handle blocking of all contents. |
3189 if (source_blocked_content->all_contents_blocked()) { | 3183 if (source_blocked_content->all_contents_blocked()) { |
3190 source_blocked_content->AddTabContents(new_tab_contents, | 3184 source_blocked_content->AddTabContents(new_tab_contents, |
3191 disposition, | 3185 disposition, |
3192 initial_pos, | 3186 initial_pos, |
3193 user_gesture); | 3187 user_gesture); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3241 GetActiveTabContents()->core_tab_helper()->GetStatusText()); | 3235 GetActiveTabContents()->core_tab_helper()->GetStatusText()); |
3242 } | 3236 } |
3243 | 3237 |
3244 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { | 3238 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { |
3245 // Schedule a shortcut update when web application info is available if | 3239 // Schedule a shortcut update when web application info is available if |
3246 // last committed entry is not NULL. Last committed entry could be NULL | 3240 // last committed entry is not NULL. Last committed entry could be NULL |
3247 // when an interstitial page is injected (e.g. bad https certificate, | 3241 // when an interstitial page is injected (e.g. bad https certificate, |
3248 // malware site etc). When this happens, we abort the shortcut update. | 3242 // malware site etc). When this happens, we abort the shortcut update. |
3249 NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); | 3243 NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); |
3250 if (entry) { | 3244 if (entry) { |
3251 TabContents::GetOwningTabContentsForWebContents(source)-> | 3245 TabContents::FromWebContents(source)-> |
3252 extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); | 3246 extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); |
3253 } else { | 3247 } else { |
3254 pending_web_app_action_ = NONE; | 3248 pending_web_app_action_ = NONE; |
3255 } | 3249 } |
3256 } | 3250 } |
3257 } | 3251 } |
3258 } | 3252 } |
3259 | 3253 |
3260 void Browser::CloseContents(WebContents* source) { | 3254 void Browser::CloseContents(WebContents* source) { |
3261 if (is_attempting_to_close_browser_) { | 3255 if (is_attempting_to_close_browser_) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3343 } | 3337 } |
3344 | 3338 |
3345 void Browser::ConvertContentsToApplication(WebContents* contents) { | 3339 void Browser::ConvertContentsToApplication(WebContents* contents) { |
3346 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); | 3340 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); |
3347 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 3341 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
3348 | 3342 |
3349 DetachContents(contents); | 3343 DetachContents(contents); |
3350 Browser* app_browser = Browser::CreateWithParams( | 3344 Browser* app_browser = Browser::CreateWithParams( |
3351 Browser::CreateParams::CreateForApp( | 3345 Browser::CreateParams::CreateForApp( |
3352 TYPE_POPUP, app_name, gfx::Rect(), profile_)); | 3346 TYPE_POPUP, app_name, gfx::Rect(), profile_)); |
3353 TabContents* tab_contents = | 3347 TabContents* tab_contents = TabContents::FromWebContents(contents); |
3354 TabContents::GetOwningTabContentsForWebContents(contents); | |
3355 if (!tab_contents) | 3348 if (!tab_contents) |
3356 tab_contents = new TabContents(contents); | 3349 tab_contents = new TabContents(contents); |
3357 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); | 3350 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); |
3358 | 3351 |
3359 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 3352 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
3360 contents->GetRenderViewHost()->SyncRendererPrefs(); | 3353 contents->GetRenderViewHost()->SyncRendererPrefs(); |
3361 app_browser->window()->Show(); | 3354 app_browser->window()->Show(); |
3362 } | 3355 } |
3363 | 3356 |
3364 gfx::Rect Browser::GetRootWindowResizerRect() const { | 3357 gfx::Rect Browser::GetRootWindowResizerRect() const { |
3365 return window_->GetRootWindowResizerRect(); | 3358 return window_->GetRootWindowResizerRect(); |
3366 } | 3359 } |
3367 | 3360 |
3368 void Browser::BeforeUnloadFired(WebContents* tab, | 3361 void Browser::BeforeUnloadFired(WebContents* web_contents, |
3369 bool proceed, | 3362 bool proceed, |
3370 bool* proceed_to_fire_unload) { | 3363 bool* proceed_to_fire_unload) { |
3371 if (!is_attempting_to_close_browser_) { | 3364 if (!is_attempting_to_close_browser_) { |
3372 *proceed_to_fire_unload = proceed; | 3365 *proceed_to_fire_unload = proceed; |
3373 if (!proceed) | 3366 if (!proceed) |
3374 tab->SetClosedByUserGesture(false); | 3367 web_contents->SetClosedByUserGesture(false); |
3375 return; | 3368 return; |
3376 } | 3369 } |
3377 | 3370 |
3378 if (!proceed) { | 3371 if (!proceed) { |
3379 CancelWindowClose(); | 3372 CancelWindowClose(); |
3380 *proceed_to_fire_unload = false; | 3373 *proceed_to_fire_unload = false; |
3381 tab->SetClosedByUserGesture(false); | 3374 web_contents->SetClosedByUserGesture(false); |
3382 return; | 3375 return; |
3383 } | 3376 } |
3384 | 3377 |
3385 if (RemoveFromSet(&tabs_needing_before_unload_fired_, tab)) { | 3378 if (RemoveFromSet(&tabs_needing_before_unload_fired_, web_contents)) { |
3386 // Now that beforeunload has fired, put the tab on the queue to fire | 3379 // Now that beforeunload has fired, put the tab on the queue to fire |
3387 // unload. | 3380 // unload. |
3388 tabs_needing_unload_fired_.insert(tab); | 3381 tabs_needing_unload_fired_.insert(web_contents); |
3389 ProcessPendingTabs(); | 3382 ProcessPendingTabs(); |
3390 // We want to handle firing the unload event ourselves since we want to | 3383 // We want to handle firing the unload event ourselves since we want to |
3391 // fire all the beforeunload events before attempting to fire the unload | 3384 // fire all the beforeunload events before attempting to fire the unload |
3392 // events should the user cancel closing the browser. | 3385 // events should the user cancel closing the browser. |
3393 *proceed_to_fire_unload = false; | 3386 *proceed_to_fire_unload = false; |
3394 return; | 3387 return; |
3395 } | 3388 } |
3396 | 3389 |
3397 *proceed_to_fire_unload = true; | 3390 *proceed_to_fire_unload = true; |
3398 } | 3391 } |
(...skipping 12 matching lines...) Expand all Loading... |
3411 void Browser::RenderWidgetShowing() { | 3404 void Browser::RenderWidgetShowing() { |
3412 window_->DisableInactiveFrame(); | 3405 window_->DisableInactiveFrame(); |
3413 } | 3406 } |
3414 | 3407 |
3415 int Browser::GetExtraRenderViewHeight() const { | 3408 int Browser::GetExtraRenderViewHeight() const { |
3416 return window_->GetExtraRenderViewHeight(); | 3409 return window_->GetExtraRenderViewHeight(); |
3417 } | 3410 } |
3418 | 3411 |
3419 void Browser::OnStartDownload(WebContents* source, | 3412 void Browser::OnStartDownload(WebContents* source, |
3420 content::DownloadItem* download) { | 3413 content::DownloadItem* download) { |
3421 TabContents* tab_contents = | 3414 TabContents* tab_contents = TabContents::FromWebContents(source); |
3422 TabContents::GetOwningTabContentsForWebContents(source); | |
3423 TabContents* constrained = GetConstrainingTabContents(tab_contents); | 3415 TabContents* constrained = GetConstrainingTabContents(tab_contents); |
3424 if (constrained != tab_contents) { | 3416 if (constrained != tab_contents) { |
3425 // Download in a constrained popup is shown in the tab that opened it. | 3417 // Download in a constrained popup is shown in the tab that opened it. |
3426 WebContents* constrained_tab = constrained->web_contents(); | 3418 WebContents* constrained_tab = constrained->web_contents(); |
3427 constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); | 3419 constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); |
3428 return; | 3420 return; |
3429 } | 3421 } |
3430 | 3422 |
3431 if (!window()) | 3423 if (!window()) |
3432 return; | 3424 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3468 const std::string& frame_content_state) { | 3460 const std::string& frame_content_state) { |
3469 DCHECK(source); | 3461 DCHECK(source); |
3470 TabContents* tab_contents = GetTabContentsAt( | 3462 TabContents* tab_contents = GetTabContentsAt( |
3471 tab_strip_model_->GetIndexOfWebContents(source)); | 3463 tab_strip_model_->GetIndexOfWebContents(source)); |
3472 ViewSource(tab_contents, frame_url, frame_content_state); | 3464 ViewSource(tab_contents, frame_url, frame_content_state); |
3473 } | 3465 } |
3474 | 3466 |
3475 void Browser::ShowRepostFormWarningDialog(WebContents* source) { | 3467 void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
3476 browser::ShowTabModalConfirmDialog( | 3468 browser::ShowTabModalConfirmDialog( |
3477 new RepostFormWarningController(source), | 3469 new RepostFormWarningController(source), |
3478 TabContents::GetOwningTabContentsForWebContents(source)); | 3470 TabContents::FromWebContents(source)); |
3479 } | 3471 } |
3480 | 3472 |
3481 bool Browser::ShouldAddNavigationToHistory( | 3473 bool Browser::ShouldAddNavigationToHistory( |
3482 const history::HistoryAddPageArgs& add_page_args, | 3474 const history::HistoryAddPageArgs& add_page_args, |
3483 content::NavigationType navigation_type) { | 3475 content::NavigationType navigation_type) { |
3484 // Don't update history if running as app. | 3476 // Don't update history if running as app. |
3485 return !IsApplication(); | 3477 return !IsApplication(); |
3486 } | 3478 } |
3487 | 3479 |
3488 bool Browser::ShouldCreateWebContents( | 3480 bool Browser::ShouldCreateWebContents( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3523 content::Source<Profile>(profile_), | 3515 content::Source<Profile>(profile_), |
3524 content::Details<RetargetingDetails>(&details)); | 3516 content::Details<RetargetingDetails>(&details)); |
3525 } | 3517 } |
3526 | 3518 |
3527 void Browser::ContentRestrictionsChanged(WebContents* source) { | 3519 void Browser::ContentRestrictionsChanged(WebContents* source) { |
3528 UpdateCommandsForContentRestrictionState(); | 3520 UpdateCommandsForContentRestrictionState(); |
3529 } | 3521 } |
3530 | 3522 |
3531 void Browser::RendererUnresponsive(WebContents* source) { | 3523 void Browser::RendererUnresponsive(WebContents* source) { |
3532 // Ignore hangs if print preview is open. | 3524 // Ignore hangs if print preview is open. |
3533 TabContents* tab_contents = | 3525 TabContents* tab_contents = TabContents::FromWebContents(source); |
3534 TabContents::GetOwningTabContentsForWebContents(source); | |
3535 if (tab_contents) { | 3526 if (tab_contents) { |
3536 printing::PrintPreviewTabController* controller = | 3527 printing::PrintPreviewTabController* controller = |
3537 printing::PrintPreviewTabController::GetInstance(); | 3528 printing::PrintPreviewTabController::GetInstance(); |
3538 if (controller) { | 3529 if (controller) { |
3539 TabContents* preview_tab = | 3530 TabContents* preview_tab = |
3540 controller->GetPrintPreviewForTab(tab_contents); | 3531 controller->GetPrintPreviewForTab(tab_contents); |
3541 if (preview_tab && preview_tab != tab_contents) { | 3532 if (preview_tab && preview_tab != tab_contents) { |
3542 return; | 3533 return; |
3543 } | 3534 } |
3544 } | 3535 } |
3545 } | 3536 } |
3546 | 3537 |
3547 browser::ShowHungRendererDialog(source); | 3538 browser::ShowHungRendererDialog(source); |
3548 } | 3539 } |
3549 | 3540 |
3550 void Browser::RendererResponsive(WebContents* source) { | 3541 void Browser::RendererResponsive(WebContents* source) { |
3551 browser::HideHungRendererDialog(source); | 3542 browser::HideHungRendererDialog(source); |
3552 } | 3543 } |
3553 | 3544 |
3554 void Browser::WorkerCrashed(WebContents* source) { | 3545 void Browser::WorkerCrashed(WebContents* source) { |
3555 TabContents* tab_contents = | 3546 TabContents* tab_contents = TabContents::FromWebContents(source); |
3556 TabContents::GetOwningTabContentsForWebContents(source); | |
3557 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); | 3547 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
3558 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( | 3548 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
3559 infobar_helper, | 3549 infobar_helper, |
3560 NULL, | 3550 NULL, |
3561 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), | 3551 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
3562 true)); | 3552 true)); |
3563 } | 3553 } |
3564 | 3554 |
3565 void Browser::DidNavigateMainFramePostCommit(WebContents* tab) { | 3555 void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
3566 if (tab == GetActiveWebContents()) | 3556 if (web_contents == GetActiveWebContents()) |
3567 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 3557 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
3568 } | 3558 } |
3569 | 3559 |
3570 void Browser::DidNavigateToPendingEntry(WebContents* tab) { | 3560 void Browser::DidNavigateToPendingEntry(WebContents* web_contents) { |
3571 if (tab == GetActiveWebContents()) | 3561 if (web_contents == GetActiveWebContents()) |
3572 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 3562 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
3573 } | 3563 } |
3574 | 3564 |
3575 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { | 3565 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
3576 return GetJavaScriptDialogCreatorInstance(); | 3566 return GetJavaScriptDialogCreatorInstance(); |
3577 } | 3567 } |
3578 | 3568 |
3579 content::ColorChooser* Browser::OpenColorChooser(WebContents* tab, | 3569 content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents, |
3580 int color_chooser_id, | 3570 int color_chooser_id, |
3581 SkColor color) { | 3571 SkColor color) { |
3582 #if defined(OS_WIN) | 3572 #if defined(OS_WIN) |
3583 // On Windows, only create a color chooser if one doesn't exist, because we | 3573 // On Windows, only create a color chooser if one doesn't exist, because we |
3584 // can't close the old color chooser dialog. | 3574 // can't close the old color chooser dialog. |
3585 if (!color_chooser_.get()) | 3575 if (!color_chooser_.get()) |
3586 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, tab, | 3576 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 3577 web_contents, |
3587 color)); | 3578 color)); |
3588 #else | 3579 #else |
3589 if (color_chooser_.get()) | 3580 if (color_chooser_.get()) |
3590 color_chooser_->End(); | 3581 color_chooser_->End(); |
3591 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, tab, | 3582 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 3583 web_contents, |
3592 color)); | 3584 color)); |
3593 #endif | 3585 #endif |
3594 return color_chooser_.get(); | 3586 return color_chooser_.get(); |
3595 } | 3587 } |
3596 | 3588 |
3597 void Browser::DidEndColorChooser() { | 3589 void Browser::DidEndColorChooser() { |
3598 color_chooser_.reset(); | 3590 color_chooser_.reset(); |
3599 } | 3591 } |
3600 | 3592 |
3601 void Browser::RunFileChooser(WebContents* tab, | 3593 void Browser::RunFileChooser(WebContents* web_contents, |
3602 const content::FileChooserParams& params) { | 3594 const content::FileChooserParams& params) { |
3603 FileSelectHelper::RunFileChooser(tab, params); | 3595 FileSelectHelper::RunFileChooser(web_contents, params); |
3604 } | 3596 } |
3605 | 3597 |
3606 void Browser::EnumerateDirectory(WebContents* tab, | 3598 void Browser::EnumerateDirectory(WebContents* web_contents, |
3607 int request_id, | 3599 int request_id, |
3608 const FilePath& path) { | 3600 const FilePath& path) { |
3609 FileSelectHelper::EnumerateDirectory(tab, request_id, path); | 3601 FileSelectHelper::EnumerateDirectory(web_contents, request_id, path); |
3610 } | 3602 } |
3611 | 3603 |
3612 void Browser::ToggleFullscreenModeForTab(WebContents* tab, | 3604 void Browser::ToggleFullscreenModeForTab(WebContents* web_contents, |
3613 bool enter_fullscreen) { | 3605 bool enter_fullscreen) { |
3614 fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); | 3606 fullscreen_controller_->ToggleFullscreenModeForTab(web_contents, |
| 3607 enter_fullscreen); |
3615 } | 3608 } |
3616 | 3609 |
3617 bool Browser::IsFullscreenForTabOrPending(const WebContents* tab) const { | 3610 bool Browser::IsFullscreenForTabOrPending( |
3618 return fullscreen_controller_->IsFullscreenForTabOrPending(tab); | 3611 const WebContents* web_contents) const { |
| 3612 return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents); |
3619 } | 3613 } |
3620 | 3614 |
3621 void Browser::JSOutOfMemory(WebContents* tab) { | 3615 void Browser::JSOutOfMemory(WebContents* web_contents) { |
3622 JSOutOfMemoryHelper(tab); | 3616 JSOutOfMemoryHelper(web_contents); |
3623 } | 3617 } |
3624 | 3618 |
3625 void Browser::RegisterProtocolHandler(WebContents* tab, | 3619 void Browser::RegisterProtocolHandler(WebContents* web_contents, |
3626 const std::string& protocol, | 3620 const std::string& protocol, |
3627 const GURL& url, | 3621 const GURL& url, |
3628 const string16& title, | 3622 const string16& title, |
3629 bool user_gesture) { | 3623 bool user_gesture) { |
3630 RegisterProtocolHandlerHelper(tab, protocol, url, title, user_gesture); | 3624 RegisterProtocolHandlerHelper( |
| 3625 web_contents, protocol, url, title, user_gesture); |
3631 } | 3626 } |
3632 | 3627 |
3633 void Browser::RegisterIntentHandler( | 3628 void Browser::RegisterIntentHandler( |
3634 WebContents* tab, | 3629 WebContents* web_contents, |
3635 const webkit_glue::WebIntentServiceData& data, | 3630 const webkit_glue::WebIntentServiceData& data, |
3636 bool user_gesture) { | 3631 bool user_gesture) { |
3637 RegisterIntentHandlerHelper(tab, data, user_gesture); | 3632 RegisterIntentHandlerHelper(web_contents, data, user_gesture); |
3638 } | 3633 } |
3639 | 3634 |
3640 void Browser::WebIntentDispatch( | 3635 void Browser::WebIntentDispatch( |
3641 WebContents* tab, content::WebIntentsDispatcher* intents_dispatcher) { | 3636 WebContents* web_contents, |
| 3637 content::WebIntentsDispatcher* intents_dispatcher) { |
3642 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) | 3638 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) |
3643 return; | 3639 return; |
3644 | 3640 |
3645 UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); | 3641 UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); |
3646 | 3642 |
3647 TabContents* tab_contents = | 3643 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
3648 TabContents::GetOwningTabContentsForWebContents(tab); | |
3649 tab_contents->web_intent_picker_controller()->SetIntentsDispatcher( | 3644 tab_contents->web_intent_picker_controller()->SetIntentsDispatcher( |
3650 intents_dispatcher); | 3645 intents_dispatcher); |
3651 tab_contents->web_intent_picker_controller()->ShowDialog( | 3646 tab_contents->web_intent_picker_controller()->ShowDialog( |
3652 intents_dispatcher->GetIntent().action, | 3647 intents_dispatcher->GetIntent().action, |
3653 intents_dispatcher->GetIntent().type); | 3648 intents_dispatcher->GetIntent().type); |
3654 } | 3649 } |
3655 | 3650 |
3656 void Browser::UpdatePreferredSize(WebContents* source, | 3651 void Browser::UpdatePreferredSize(WebContents* source, |
3657 const gfx::Size& pref_size) { | 3652 const gfx::Size& pref_size) { |
3658 window_->UpdatePreferredSize(source, pref_size); | 3653 window_->UpdatePreferredSize(source, pref_size); |
3659 } | 3654 } |
3660 | 3655 |
3661 void Browser::ResizeDueToAutoResize(WebContents* source, | 3656 void Browser::ResizeDueToAutoResize(WebContents* source, |
3662 const gfx::Size& new_size) { | 3657 const gfx::Size& new_size) { |
3663 window_->ResizeDueToAutoResize(source, new_size); | 3658 window_->ResizeDueToAutoResize(source, new_size); |
3664 } | 3659 } |
3665 | 3660 |
3666 void Browser::FindReply(WebContents* tab, | 3661 void Browser::FindReply(WebContents* web_contents, |
3667 int request_id, | 3662 int request_id, |
3668 int number_of_matches, | 3663 int number_of_matches, |
3669 const gfx::Rect& selection_rect, | 3664 const gfx::Rect& selection_rect, |
3670 int active_match_ordinal, | 3665 int active_match_ordinal, |
3671 bool final_update) { | 3666 bool final_update) { |
3672 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3667 FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect, |
3673 active_match_ordinal, final_update); | 3668 active_match_ordinal, final_update); |
3674 } | 3669 } |
3675 | 3670 |
3676 void Browser::RequestToLockMouse(WebContents* tab, | 3671 void Browser::RequestToLockMouse(WebContents* web_contents, |
3677 bool user_gesture, | 3672 bool user_gesture, |
3678 bool last_unlocked_by_target) { | 3673 bool last_unlocked_by_target) { |
3679 fullscreen_controller_->RequestToLockMouse(tab, | 3674 fullscreen_controller_->RequestToLockMouse(web_contents, |
3680 user_gesture, | 3675 user_gesture, |
3681 last_unlocked_by_target); | 3676 last_unlocked_by_target); |
3682 } | 3677 } |
3683 | 3678 |
3684 void Browser::LostMouseLock() { | 3679 void Browser::LostMouseLock() { |
3685 fullscreen_controller_->LostMouseLock(); | 3680 fullscreen_controller_->LostMouseLock(); |
3686 } | 3681 } |
3687 | 3682 |
3688 /////////////////////////////////////////////////////////////////////////////// | 3683 /////////////////////////////////////////////////////////////////////////////// |
3689 // Browser, CoreTabHelperDelegate implementation: | 3684 // Browser, CoreTabHelperDelegate implementation: |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4615 if (HasCompletedUnloadProcessing()) { | 4610 if (HasCompletedUnloadProcessing()) { |
4616 // We've finished all the unload events and can proceed to close the | 4611 // We've finished all the unload events and can proceed to close the |
4617 // browser. | 4612 // browser. |
4618 OnWindowClosing(); | 4613 OnWindowClosing(); |
4619 return; | 4614 return; |
4620 } | 4615 } |
4621 | 4616 |
4622 // Process beforeunload tabs first. When that queue is empty, process | 4617 // Process beforeunload tabs first. When that queue is empty, process |
4623 // unload tabs. | 4618 // unload tabs. |
4624 if (!tabs_needing_before_unload_fired_.empty()) { | 4619 if (!tabs_needing_before_unload_fired_.empty()) { |
4625 WebContents* tab = *(tabs_needing_before_unload_fired_.begin()); | 4620 WebContents* web_contents = *(tabs_needing_before_unload_fired_.begin()); |
4626 // Null check render_view_host here as this gets called on a PostTask and | 4621 // Null check render_view_host here as this gets called on a PostTask and |
4627 // the tab's render_view_host may have been nulled out. | 4622 // the tab's render_view_host may have been nulled out. |
4628 if (tab->GetRenderViewHost()) { | 4623 if (web_contents->GetRenderViewHost()) { |
4629 tab->GetRenderViewHost()->FirePageBeforeUnload(false); | 4624 web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
4630 } else { | 4625 } else { |
4631 ClearUnloadState(tab, true); | 4626 ClearUnloadState(web_contents, true); |
4632 } | 4627 } |
4633 } else if (!tabs_needing_unload_fired_.empty()) { | 4628 } else if (!tabs_needing_unload_fired_.empty()) { |
4634 // We've finished firing all beforeunload events and can proceed with unload | 4629 // We've finished firing all beforeunload events and can proceed with unload |
4635 // events. | 4630 // events. |
4636 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting | 4631 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
4637 // somewhere around here so that we have accurate measurements of shutdown | 4632 // somewhere around here so that we have accurate measurements of shutdown |
4638 // time. | 4633 // time. |
4639 // TODO(ojan): We can probably fire all the unload events in parallel and | 4634 // TODO(ojan): We can probably fire all the unload events in parallel and |
4640 // get a perf benefit from that in the cases where the tab hangs in it's | 4635 // get a perf benefit from that in the cases where the tab hangs in it's |
4641 // unload handler or takes a long time to page in. | 4636 // unload handler or takes a long time to page in. |
4642 WebContents* tab = *(tabs_needing_unload_fired_.begin()); | 4637 WebContents* web_contents = *(tabs_needing_unload_fired_.begin()); |
4643 // Null check render_view_host here as this gets called on a PostTask and | 4638 // Null check render_view_host here as this gets called on a PostTask and |
4644 // the tab's render_view_host may have been nulled out. | 4639 // the tab's render_view_host may have been nulled out. |
4645 if (tab->GetRenderViewHost()) { | 4640 if (web_contents->GetRenderViewHost()) { |
4646 tab->GetRenderViewHost()->ClosePage(); | 4641 web_contents->GetRenderViewHost()->ClosePage(); |
4647 } else { | 4642 } else { |
4648 ClearUnloadState(tab, true); | 4643 ClearUnloadState(web_contents, true); |
4649 } | 4644 } |
4650 } else { | 4645 } else { |
4651 NOTREACHED(); | 4646 NOTREACHED(); |
4652 } | 4647 } |
4653 } | 4648 } |
4654 | 4649 |
4655 bool Browser::HasCompletedUnloadProcessing() const { | 4650 bool Browser::HasCompletedUnloadProcessing() const { |
4656 return is_attempting_to_close_browser_ && | 4651 return is_attempting_to_close_browser_ && |
4657 tabs_needing_before_unload_fired_.empty() && | 4652 tabs_needing_before_unload_fired_.empty() && |
4658 tabs_needing_unload_fired_.empty(); | 4653 tabs_needing_unload_fired_.empty(); |
(...skipping 13 matching lines...) Expand all Loading... |
4672 content::Source<Browser>(this), | 4667 content::Source<Browser>(this), |
4673 content::NotificationService::NoDetails()); | 4668 content::NotificationService::NoDetails()); |
4674 | 4669 |
4675 // Inform TabCloseableStateWatcher that closing of window has been canceled. | 4670 // Inform TabCloseableStateWatcher that closing of window has been canceled. |
4676 TabCloseableStateWatcher* watcher = | 4671 TabCloseableStateWatcher* watcher = |
4677 g_browser_process->tab_closeable_state_watcher(); | 4672 g_browser_process->tab_closeable_state_watcher(); |
4678 if (watcher) | 4673 if (watcher) |
4679 watcher->OnWindowCloseCanceled(this); | 4674 watcher->OnWindowCloseCanceled(this); |
4680 } | 4675 } |
4681 | 4676 |
4682 bool Browser::RemoveFromSet(UnloadListenerSet* set, WebContents* tab) { | 4677 bool Browser::RemoveFromSet(UnloadListenerSet* set, WebContents* web_contents) { |
4683 DCHECK(is_attempting_to_close_browser_); | 4678 DCHECK(is_attempting_to_close_browser_); |
4684 | 4679 |
4685 UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); | 4680 UnloadListenerSet::iterator iter = |
| 4681 std::find(set->begin(), set->end(), web_contents); |
4686 if (iter != set->end()) { | 4682 if (iter != set->end()) { |
4687 set->erase(iter); | 4683 set->erase(iter); |
4688 return true; | 4684 return true; |
4689 } | 4685 } |
4690 return false; | 4686 return false; |
4691 } | 4687 } |
4692 | 4688 |
4693 void Browser::ClearUnloadState(WebContents* tab, bool process_now) { | 4689 void Browser::ClearUnloadState(WebContents* web_contents, bool process_now) { |
4694 // Closing of browser could be canceled (via IsClosingPermitted) between the | 4690 // Closing of browser could be canceled (via IsClosingPermitted) between the |
4695 // time when request was initiated and when this method is called, so check | 4691 // time when request was initiated and when this method is called, so check |
4696 // for is_attempting_to_close_browser_ flag before proceeding. | 4692 // for is_attempting_to_close_browser_ flag before proceeding. |
4697 if (is_attempting_to_close_browser_) { | 4693 if (is_attempting_to_close_browser_) { |
4698 RemoveFromSet(&tabs_needing_before_unload_fired_, tab); | 4694 RemoveFromSet(&tabs_needing_before_unload_fired_, web_contents); |
4699 RemoveFromSet(&tabs_needing_unload_fired_, tab); | 4695 RemoveFromSet(&tabs_needing_unload_fired_, web_contents); |
4700 if (process_now) { | 4696 if (process_now) { |
4701 ProcessPendingTabs(); | 4697 ProcessPendingTabs(); |
4702 } else { | 4698 } else { |
4703 MessageLoop::current()->PostTask( | 4699 MessageLoop::current()->PostTask( |
4704 FROM_HERE, | 4700 FROM_HERE, |
4705 base::Bind(&Browser::ProcessPendingTabs, weak_factory_.GetWeakPtr())); | 4701 base::Bind(&Browser::ProcessPendingTabs, weak_factory_.GetWeakPtr())); |
4706 } | 4702 } |
4707 } | 4703 } |
4708 } | 4704 } |
4709 | 4705 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4830 OpenURL(OpenURLParams( | 4826 OpenURL(OpenURLParams( |
4831 entry->GetURL(), Referrer(), disposition, | 4827 entry->GetURL(), Referrer(), disposition, |
4832 content::PAGE_TRANSITION_RELOAD, false)); | 4828 content::PAGE_TRANSITION_RELOAD, false)); |
4833 return; | 4829 return; |
4834 } | 4830 } |
4835 | 4831 |
4836 // As this is caused by a user action, give the focus to the page. | 4832 // As this is caused by a user action, give the focus to the page. |
4837 // | 4833 // |
4838 // Also notify RenderViewHostDelegate of the user gesture; this is | 4834 // Also notify RenderViewHostDelegate of the user gesture; this is |
4839 // normally done in Browser::Navigate, but a reload bypasses Navigate. | 4835 // normally done in Browser::Navigate, but a reload bypasses Navigate. |
4840 WebContents* tab = GetOrCloneTabForDisposition(disposition); | 4836 WebContents* web_contents = GetOrCloneTabForDisposition(disposition); |
4841 tab->UserGestureDone(); | 4837 web_contents->UserGestureDone(); |
4842 if (!tab->FocusLocationBarByDefault()) | 4838 if (!web_contents->FocusLocationBarByDefault()) |
4843 tab->Focus(); | 4839 web_contents->Focus(); |
4844 if (ignore_cache) | 4840 if (ignore_cache) |
4845 tab->GetController().ReloadIgnoringCache(true); | 4841 web_contents->GetController().ReloadIgnoringCache(true); |
4846 else | 4842 else |
4847 tab->GetController().Reload(true); | 4843 web_contents->GetController().Reload(true); |
4848 } | 4844 } |
4849 | 4845 |
4850 WebContents* Browser::GetOrCloneTabForDisposition( | 4846 WebContents* Browser::GetOrCloneTabForDisposition( |
4851 WindowOpenDisposition disposition) { | 4847 WindowOpenDisposition disposition) { |
4852 TabContents* current_tab = GetActiveTabContents(); | 4848 TabContents* current_tab = GetActiveTabContents(); |
4853 switch (disposition) { | 4849 switch (disposition) { |
4854 case NEW_FOREGROUND_TAB: | 4850 case NEW_FOREGROUND_TAB: |
4855 case NEW_BACKGROUND_TAB: { | 4851 case NEW_BACKGROUND_TAB: { |
4856 current_tab = current_tab->Clone(); | 4852 current_tab = current_tab->Clone(); |
4857 tab_strip_model_->AddTabContents( | 4853 tab_strip_model_->AddTabContents( |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5172 if (contents && !allow_js_access) { | 5168 if (contents && !allow_js_access) { |
5173 contents->web_contents()->GetController().LoadURL( | 5169 contents->web_contents()->GetController().LoadURL( |
5174 target_url, | 5170 target_url, |
5175 content::Referrer(), | 5171 content::Referrer(), |
5176 content::PAGE_TRANSITION_LINK, | 5172 content::PAGE_TRANSITION_LINK, |
5177 std::string()); // No extra headers. | 5173 std::string()); // No extra headers. |
5178 } | 5174 } |
5179 | 5175 |
5180 return contents != NULL; | 5176 return contents != NULL; |
5181 } | 5177 } |
OLD | NEW |