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/app_modal_dialogs/javascript_app_modal_dialog.h" | 5 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
6 | 6 |
7 #include "chrome/browser/browser_shutdown.h" | 7 #include "chrome/browser/browser_shutdown.h" |
8 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 8 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_view.h" | 10 #include "content/public/browser/web_contents_view.h" |
11 #include "ui/base/text/text_elider.h" | 11 #include "ui/base/text/text_elider.h" |
12 | 12 |
13 #if defined(USE_AURA) | |
14 #include "ui/aura/root_window.h" | |
15 #endif | |
16 | |
17 using content::JavaScriptDialogCreator; | 13 using content::JavaScriptDialogCreator; |
18 using content::WebContents; | 14 using content::WebContents; |
19 | 15 |
20 namespace { | 16 namespace { |
21 | 17 |
22 // Control maximum sizes of various texts passed to us from javascript. | 18 // Control maximum sizes of various texts passed to us from javascript. |
23 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 19 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
24 // Two-dimensional eliding. Reformat the text of the message dialog | 20 // Two-dimensional eliding. Reformat the text of the message dialog |
25 // inserting line breaks because otherwise a single long line can overflow | 21 // inserting line breaks because otherwise a single long line can overflow |
26 // the message dialog (and crash/hang the GTK, depending on the version). | 22 // the message dialog (and crash/hang the GTK, depending on the version). |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 EnforceMaxTextSize(message_text, &message_text_); | 73 EnforceMaxTextSize(message_text, &message_text_); |
78 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); | 74 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); |
79 } | 75 } |
80 | 76 |
81 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { | 77 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { |
82 } | 78 } |
83 | 79 |
84 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { | 80 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { |
85 gfx::NativeWindow parent_window = | 81 gfx::NativeWindow parent_window = |
86 web_contents()->GetView()->GetTopLevelNativeWindow(); | 82 web_contents()->GetView()->GetTopLevelNativeWindow(); |
87 #if defined(USE_AURA) | |
88 if (!parent_window->GetRootWindow()) { | |
89 // When we are part of a WebContents that isn't actually being displayed on | |
90 // the screen, we can't actually attach to it. | |
91 parent_window = NULL; | |
92 } | |
93 #endif | |
94 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, | 83 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, |
95 parent_window); | 84 parent_window); |
96 } | 85 } |
97 | 86 |
98 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { | 87 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { |
99 return true; | 88 return true; |
100 } | 89 } |
101 | 90 |
102 void JavaScriptAppModalDialog::Invalidate() { | 91 void JavaScriptAppModalDialog::Invalidate() { |
103 if (!valid_) | 92 if (!valid_) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 144 |
156 callback_.Run(success, user_input); | 145 callback_.Run(success, user_input); |
157 | 146 |
158 extra_data_->last_javascript_message_dismissal_ = base::TimeTicks::Now(); | 147 extra_data_->last_javascript_message_dismissal_ = base::TimeTicks::Now(); |
159 extra_data_->suppress_javascript_messages_ = suppress_js_messages; | 148 extra_data_->suppress_javascript_messages_ = suppress_js_messages; |
160 | 149 |
161 // On Views, we can end up coming through this code path twice :(. | 150 // On Views, we can end up coming through this code path twice :(. |
162 // See crbug.com/63732. | 151 // See crbug.com/63732. |
163 valid_ = false; | 152 valid_ = false; |
164 } | 153 } |
OLD | NEW |