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

Side by Side Diff: chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc

Issue 17500003: Close web contents modal dialogs on content load start (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compilation fixes, change "inhibit" variable names Created 7 years, 5 months 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
OLDNEW
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/webui/tab_modal_confirm_dialog_webui.h" 5 #include "chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 17 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "components/web_modal/web_contents_modal_dialog_manager.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_ui_data_source.h" 22 #include "content/public/browser/web_ui_data_source.h"
22 #include "grit/browser_resources.h" 23 #include "grit/browser_resources.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
27 #include "ui/webui/web_ui_util.h" 28 #include "ui/webui/web_ui_util.h"
28 29
29 using content::WebContents; 30 using content::WebContents;
30 using content::WebUIMessageHandler; 31 using content::WebUIMessageHandler;
32 using web_modal::WebContentsModalDialogManager;
31 33
32 // static 34 // static
33 TabModalConfirmDialog* TabModalConfirmDialog::Create( 35 TabModalConfirmDialog* TabModalConfirmDialog::Create(
34 TabModalConfirmDialogDelegate* delegate, 36 TabModalConfirmDialogDelegate* delegate,
35 content::WebContents* web_contents) { 37 content::WebContents* web_contents) {
36 return new TabModalConfirmDialogWebUI(delegate, web_contents); 38 return new TabModalConfirmDialogWebUI(delegate, web_contents);
37 } 39 }
38 40
39 const int kDialogWidth = 400; 41 const int kDialogWidth = 400;
40 const int kDialogHeight = 120; 42 const int kDialogHeight = 120;
41 43
42 TabModalConfirmDialogWebUI::TabModalConfirmDialogWebUI( 44 TabModalConfirmDialogWebUI::TabModalConfirmDialogWebUI(
43 TabModalConfirmDialogDelegate* delegate, 45 TabModalConfirmDialogDelegate* delegate,
44 WebContents* web_contents) 46 WebContents* web_contents)
45 : delegate_(delegate) { 47 : web_contents_(web_contents),
48 delegate_(delegate) {
46 Profile* profile = 49 Profile* profile =
47 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 50 Profile::FromBrowserContext(web_contents->GetBrowserContext());
48 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( 51 content::WebUIDataSource* data_source = content::WebUIDataSource::Create(
49 chrome::kChromeUITabModalConfirmDialogHost); 52 chrome::kChromeUITabModalConfirmDialogHost);
50 data_source->SetDefaultResource(IDR_TAB_MODAL_CONFIRM_DIALOG_HTML); 53 data_source->SetDefaultResource(IDR_TAB_MODAL_CONFIRM_DIALOG_HTML);
51 data_source->DisableContentSecurityPolicy(); 54 data_source->DisableContentSecurityPolicy();
52 content::WebUIDataSource::Add(profile, data_source); 55 content::WebUIDataSource::Add(profile, data_source);
53 56
54 constrained_web_dialog_delegate_ = 57 constrained_web_dialog_delegate_ =
55 CreateConstrainedWebDialog(profile, this, NULL, web_contents); 58 CreateConstrainedWebDialog(profile, this, NULL, web_contents);
56 delegate_->set_close_delegate(this); 59 delegate_->set_operations_delegate(this);
57 } 60 }
58 61
59 ui::ModalType TabModalConfirmDialogWebUI::GetDialogModalType() const { 62 ui::ModalType TabModalConfirmDialogWebUI::GetDialogModalType() const {
60 return ui::MODAL_TYPE_WINDOW; 63 return ui::MODAL_TYPE_WINDOW;
61 } 64 }
62 65
63 string16 TabModalConfirmDialogWebUI::GetDialogTitle() const { 66 string16 TabModalConfirmDialogWebUI::GetDialogTitle() const {
64 return delegate_->GetTitle(); 67 return delegate_->GetTitle();
65 } 68 }
66 69
(...skipping 21 matching lines...) Expand all
88 91
89 void TabModalConfirmDialogWebUI::OnDialogClosed( 92 void TabModalConfirmDialogWebUI::OnDialogClosed(
90 const std::string& json_retval) { 93 const std::string& json_retval) {
91 bool accepted = false; 94 bool accepted = false;
92 if (!json_retval.empty()) { 95 if (!json_retval.empty()) {
93 scoped_ptr<Value> value(base::JSONReader::Read(json_retval)); 96 scoped_ptr<Value> value(base::JSONReader::Read(json_retval));
94 if (!value.get() || !value->GetAsBoolean(&accepted)) 97 if (!value.get() || !value->GetAsBoolean(&accepted))
95 NOTREACHED() << "Missing or unreadable response from dialog"; 98 NOTREACHED() << "Missing or unreadable response from dialog";
96 } 99 }
97 100
98 delegate_->set_close_delegate(NULL); 101 delegate_->set_operations_delegate(NULL);
99 if (accepted) 102 if (accepted)
100 delegate_->Accept(); 103 delegate_->Accept();
101 else 104 else
102 delegate_->Cancel(); 105 delegate_->Cancel();
103 } 106 }
104 107
105 void TabModalConfirmDialogWebUI::OnCloseContents(WebContents* source, 108 void TabModalConfirmDialogWebUI::OnCloseContents(WebContents* source,
106 bool* out_close_dialog) {} 109 bool* out_close_dialog) {}
107 110
108 bool TabModalConfirmDialogWebUI::ShouldShowDialogTitle() const { 111 bool TabModalConfirmDialogWebUI::ShouldShowDialogTitle() const {
109 return true; 112 return true;
110 } 113 }
111 114
112 TabModalConfirmDialogWebUI::~TabModalConfirmDialogWebUI() {} 115 TabModalConfirmDialogWebUI::~TabModalConfirmDialogWebUI() {}
113 116
114 void TabModalConfirmDialogWebUI::AcceptTabModalDialog() { 117 void TabModalConfirmDialogWebUI::AcceptTabModalDialog() {
115 } 118 }
116 119
117 void TabModalConfirmDialogWebUI::CancelTabModalDialog() { 120 void TabModalConfirmDialogWebUI::CancelTabModalDialog() {
118 } 121 }
119 122
120 void TabModalConfirmDialogWebUI::CloseDialog() { 123 void TabModalConfirmDialogWebUI::CloseDialog() {
121 constrained_web_dialog_delegate_->OnDialogCloseFromWebUI(); 124 constrained_web_dialog_delegate_->OnDialogCloseFromWebUI();
122 } 125 }
126
127 void TabModalConfirmDialogWebUI::SetPreventCloseOnLoadStart(bool prevent) {
128 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager =
129 WebContentsModalDialogManager::FromWebContents(web_contents_);
130 web_contents_modal_dialog_manager->SetPreventCloseOnLoadStart(
131 constrained_web_dialog_delegate_->GetNativeDialog(),
132 prevent);
133 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.h ('k') | components/web_modal/web_contents_modal_dialog_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698