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

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

Issue 21372006: Revert 212329 "Reland "Close web contents modal dialogs on conte..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 4 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"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_ui_data_source.h" 21 #include "content/public/browser/web_ui_data_source.h"
23 #include "grit/browser_resources.h" 22 #include "grit/browser_resources.h"
24 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/size.h" 26 #include "ui/gfx/size.h"
28 #include "ui/webui/web_ui_util.h" 27 #include "ui/webui/web_ui_util.h"
29 28
30 using content::WebContents; 29 using content::WebContents;
31 using content::WebUIMessageHandler; 30 using content::WebUIMessageHandler;
32 using web_modal::WebContentsModalDialogManager;
33 31
34 // static 32 // static
35 TabModalConfirmDialog* TabModalConfirmDialog::Create( 33 TabModalConfirmDialog* TabModalConfirmDialog::Create(
36 TabModalConfirmDialogDelegate* delegate, 34 TabModalConfirmDialogDelegate* delegate,
37 content::WebContents* web_contents) { 35 content::WebContents* web_contents) {
38 return new TabModalConfirmDialogWebUI(delegate, web_contents); 36 return new TabModalConfirmDialogWebUI(delegate, web_contents);
39 } 37 }
40 38
41 const int kDialogWidth = 400; 39 const int kDialogWidth = 400;
42 const int kDialogHeight = 120; 40 const int kDialogHeight = 120;
43 41
44 TabModalConfirmDialogWebUI::TabModalConfirmDialogWebUI( 42 TabModalConfirmDialogWebUI::TabModalConfirmDialogWebUI(
45 TabModalConfirmDialogDelegate* delegate, 43 TabModalConfirmDialogDelegate* delegate,
46 WebContents* web_contents) 44 WebContents* web_contents)
47 : web_contents_(web_contents), 45 : delegate_(delegate) {
48 delegate_(delegate) {
49 Profile* profile = 46 Profile* profile =
50 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 47 Profile::FromBrowserContext(web_contents->GetBrowserContext());
51 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( 48 content::WebUIDataSource* data_source = content::WebUIDataSource::Create(
52 chrome::kChromeUITabModalConfirmDialogHost); 49 chrome::kChromeUITabModalConfirmDialogHost);
53 data_source->SetDefaultResource(IDR_TAB_MODAL_CONFIRM_DIALOG_HTML); 50 data_source->SetDefaultResource(IDR_TAB_MODAL_CONFIRM_DIALOG_HTML);
54 data_source->DisableContentSecurityPolicy(); 51 data_source->DisableContentSecurityPolicy();
55 content::WebUIDataSource::Add(profile, data_source); 52 content::WebUIDataSource::Add(profile, data_source);
56 53
57 constrained_web_dialog_delegate_ = 54 constrained_web_dialog_delegate_ =
58 CreateConstrainedWebDialog(profile, this, NULL, web_contents); 55 CreateConstrainedWebDialog(profile, this, NULL, web_contents);
59 delegate_->set_operations_delegate(this); 56 delegate_->set_close_delegate(this);
60 } 57 }
61 58
62 ui::ModalType TabModalConfirmDialogWebUI::GetDialogModalType() const { 59 ui::ModalType TabModalConfirmDialogWebUI::GetDialogModalType() const {
63 return ui::MODAL_TYPE_WINDOW; 60 return ui::MODAL_TYPE_WINDOW;
64 } 61 }
65 62
66 string16 TabModalConfirmDialogWebUI::GetDialogTitle() const { 63 string16 TabModalConfirmDialogWebUI::GetDialogTitle() const {
67 return delegate_->GetTitle(); 64 return delegate_->GetTitle();
68 } 65 }
69 66
(...skipping 21 matching lines...) Expand all
91 88
92 void TabModalConfirmDialogWebUI::OnDialogClosed( 89 void TabModalConfirmDialogWebUI::OnDialogClosed(
93 const std::string& json_retval) { 90 const std::string& json_retval) {
94 bool accepted = false; 91 bool accepted = false;
95 if (!json_retval.empty()) { 92 if (!json_retval.empty()) {
96 scoped_ptr<Value> value(base::JSONReader::Read(json_retval)); 93 scoped_ptr<Value> value(base::JSONReader::Read(json_retval));
97 if (!value.get() || !value->GetAsBoolean(&accepted)) 94 if (!value.get() || !value->GetAsBoolean(&accepted))
98 NOTREACHED() << "Missing or unreadable response from dialog"; 95 NOTREACHED() << "Missing or unreadable response from dialog";
99 } 96 }
100 97
101 delegate_->set_operations_delegate(NULL); 98 delegate_->set_close_delegate(NULL);
102 if (accepted) 99 if (accepted)
103 delegate_->Accept(); 100 delegate_->Accept();
104 else 101 else
105 delegate_->Cancel(); 102 delegate_->Cancel();
106 } 103 }
107 104
108 void TabModalConfirmDialogWebUI::OnCloseContents(WebContents* source, 105 void TabModalConfirmDialogWebUI::OnCloseContents(WebContents* source,
109 bool* out_close_dialog) {} 106 bool* out_close_dialog) {}
110 107
111 bool TabModalConfirmDialogWebUI::ShouldShowDialogTitle() const { 108 bool TabModalConfirmDialogWebUI::ShouldShowDialogTitle() const {
112 return true; 109 return true;
113 } 110 }
114 111
115 TabModalConfirmDialogWebUI::~TabModalConfirmDialogWebUI() {} 112 TabModalConfirmDialogWebUI::~TabModalConfirmDialogWebUI() {}
116 113
117 void TabModalConfirmDialogWebUI::AcceptTabModalDialog() { 114 void TabModalConfirmDialogWebUI::AcceptTabModalDialog() {
118 } 115 }
119 116
120 void TabModalConfirmDialogWebUI::CancelTabModalDialog() { 117 void TabModalConfirmDialogWebUI::CancelTabModalDialog() {
121 } 118 }
122 119
123 void TabModalConfirmDialogWebUI::CloseDialog() { 120 void TabModalConfirmDialogWebUI::CloseDialog() {
124 constrained_web_dialog_delegate_->OnDialogCloseFromWebUI(); 121 constrained_web_dialog_delegate_->OnDialogCloseFromWebUI();
125 } 122 }
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

Powered by Google App Engine
This is Rietveld 408576698