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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 6 7#include "chrome/browser/chrome_notification_types.h" 8#include "chrome/grit/generated_resources.h" 9#include "content/public/browser/navigation_controller.h" 10#include "content/public/browser/notification_source.h" 11#include "content/public/browser/web_contents.h" 12#include "ui/base/l10n/l10n_util.h" 13 14using content::NavigationController; 15using content::WebContents; 16 17TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate( 18 WebContents* web_contents) 19 : close_delegate_(NULL), 20 closing_(false) { 21 NavigationController* controller = &web_contents->GetController(); 22 registrar_.Add(this, content::NOTIFICATION_LOAD_START, 23 content::Source<NavigationController>(controller)); 24} 25 26TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() { 27 // If we end up here, the window has been closed, so make sure we don't close 28 // it again. 29 close_delegate_ = NULL; 30 // Make sure everything is cleaned up. 31 Cancel(); 32} 33 34void TabModalConfirmDialogDelegate::Cancel() { 35 if (closing_) 36 return; 37 // Make sure we won't do anything when another action occurs. 38 closing_ = true; 39 OnCanceled(); 40 CloseDialog(); 41} 42 43void TabModalConfirmDialogDelegate::Accept() { 44 if (closing_) 45 return; 46 // Make sure we won't do anything when another action occurs. 47 closing_ = true; 48 OnAccepted(); 49 CloseDialog(); 50} 51 52void TabModalConfirmDialogDelegate::Observe( 53 int type, 54 const content::NotificationSource& source, 55 const content::NotificationDetails& details) { 56 // Close the dialog if we load a page (because the action might not apply to 57 // the same page anymore). 58 DCHECK_EQ(content::NOTIFICATION_LOAD_START, type); 59 60 Close(); 61} 62 63void TabModalConfirmDialogDelegate::Close() { 64 if (closing_) 65 return; 66 // Make sure we won't do anything when another action occurs. 67 closing_ = true; 68 OnClosed(); 69 CloseDialog(); 70} 71 72void TabModalConfirmDialogDelegate::LinkClicked( 73 WindowOpenDisposition disposition) { 74 if (closing_) 75 return; 76 OnLinkClicked(disposition); 77} 78 79gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { 80 return NULL; 81} 82 83base::string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() { 84 return l10n_util::GetStringUTF16(IDS_OK); 85} 86 87base::string16 TabModalConfirmDialogDelegate::GetCancelButtonTitle() { 88 return l10n_util::GetStringUTF16(IDS_CANCEL); 89} 90 91base::string16 TabModalConfirmDialogDelegate::GetLinkText() const { 92 return base::string16(); 93} 94 95const char* TabModalConfirmDialogDelegate::GetAcceptButtonIcon() { 96 return NULL; 97} 98 99const char* TabModalConfirmDialogDelegate::GetCancelButtonIcon() { 100 return NULL; 101} 102 103void TabModalConfirmDialogDelegate::OnAccepted() { 104} 105 106void TabModalConfirmDialogDelegate::OnCanceled() { 107} 108 109void TabModalConfirmDialogDelegate::OnLinkClicked( 110 WindowOpenDisposition disposition) { 111} 112 113void TabModalConfirmDialogDelegate::OnClosed() { 114} 115 116void TabModalConfirmDialogDelegate::CloseDialog() { 117 if (close_delegate_) 118 close_delegate_->CloseDialog(); 119} 120