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_dialog_manager.h" | 5 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
14 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 14 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
15 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 15 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
16 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 16 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
20 #include "content/public/common/javascript_message_type.h" | 20 #include "content/public/common/javascript_message_type.h" |
21 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
Lei Zhang
2014/08/22 22:39:50
You should #ifdef these two files to flush out any
| |
22 #include "extensions/browser/process_manager.h" | 22 #include "extensions/browser/process_manager.h" |
23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 | 26 |
27 using content::BrowserContext; | 27 using content::BrowserContext; |
28 using content::JavaScriptDialogManager; | 28 using content::JavaScriptDialogManager; |
29 using content::WebContents; | 29 using content::WebContents; |
30 using extensions::Extension; | 30 using extensions::Extension; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 #if defined(ENABLE_EXTENSIONS) | |
34 // Returns the ProcessManager for the browser context from |web_contents|. | 35 // Returns the ProcessManager for the browser context from |web_contents|. |
35 extensions::ProcessManager* GetExtensionsProcessManager( | 36 extensions::ProcessManager* GetExtensionsProcessManager( |
36 WebContents* web_contents) { | 37 WebContents* web_contents) { |
37 #if defined(ENABLE_EXTENSIONS) | |
38 return extensions::ExtensionSystem::Get( | 38 return extensions::ExtensionSystem::Get( |
39 web_contents->GetBrowserContext())->process_manager(); | 39 web_contents->GetBrowserContext())->process_manager(); |
40 #else | |
41 return NULL; | |
42 #endif // defined(ENABLE_EXTENSIONS) | |
43 } | 40 } |
41 #endif // ENABLE_EXTENSIONS | |
44 | 42 |
45 // Returns the extension associated with |web_contents| or NULL if there is no | 43 // Returns the extension associated with |web_contents| or NULL if there is no |
46 // associated extension (or extensions are not supported). | 44 // associated extension (or extensions are not supported). |
47 const Extension* GetExtensionForWebContents(WebContents* web_contents) { | 45 const Extension* GetExtensionForWebContents(WebContents* web_contents) { |
48 #if defined(ENABLE_EXTENSIONS) | 46 #if defined(ENABLE_EXTENSIONS) |
49 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | 47 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
50 return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost()); | 48 return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost()); |
51 #else | 49 #else |
52 return NULL; | 50 return NULL; |
53 #endif // defined(ENABLE_EXTENSIONS) | 51 #endif // ENABLE_EXTENSIONS |
Lei Zhang
2014/08/22 22:39:50
nit: I think most people do // defined(FOO)
David Yen
2014/08/22 23:03:58
Done.
| |
54 } | 52 } |
55 | 53 |
56 // Keeps an |extension| from shutting down its lazy background page. If an | 54 // Keeps an |extension| from shutting down its lazy background page. If an |
57 // extension opens a dialog its lazy background page must stay alive until the | 55 // extension opens a dialog its lazy background page must stay alive until the |
58 // dialog closes. | 56 // dialog closes. |
59 void IncrementLazyKeepaliveCount(const Extension* extension, | 57 void IncrementLazyKeepaliveCount(const Extension* extension, |
60 WebContents* web_contents) { | 58 WebContents* web_contents) { |
59 #if defined(ENABLE_EXTENSIONS) | |
msw
2014/08/22 22:36:10
I'm actually not sure what build errors you'd see
David Yen
2014/08/22 23:05:52
Even though technically it can never be called, th
| |
61 DCHECK(extension); | 60 DCHECK(extension); |
62 DCHECK(web_contents); | 61 DCHECK(web_contents); |
63 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | 62 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
64 if (pm) | 63 if (pm) |
65 pm->IncrementLazyKeepaliveCount(extension); | 64 pm->IncrementLazyKeepaliveCount(extension); |
65 #endif // ENABLE_EXTENSIONS | |
66 } | 66 } |
67 | 67 |
68 // Allows an |extension| to shut down its lazy background page after a dialog | 68 // Allows an |extension| to shut down its lazy background page after a dialog |
69 // closes (if nothing else is keeping it open). | 69 // closes (if nothing else is keeping it open). |
70 void DecrementLazyKeepaliveCount(const Extension* extension, | 70 void DecrementLazyKeepaliveCount(const Extension* extension, |
71 WebContents* web_contents) { | 71 WebContents* web_contents) { |
72 #if defined(ENABLE_EXTENSIONS) | |
72 DCHECK(extension); | 73 DCHECK(extension); |
73 DCHECK(web_contents); | 74 DCHECK(web_contents); |
74 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | 75 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
75 if (pm) | 76 if (pm) |
76 pm->DecrementLazyKeepaliveCount(extension); | 77 pm->DecrementLazyKeepaliveCount(extension); |
78 #endif // ENABLE_EXTENSIONS | |
77 } | 79 } |
78 | 80 |
79 class ChromeJavaScriptDialogManager : public JavaScriptDialogManager { | 81 class ChromeJavaScriptDialogManager : public JavaScriptDialogManager { |
80 public: | 82 public: |
81 static ChromeJavaScriptDialogManager* GetInstance(); | 83 static ChromeJavaScriptDialogManager* GetInstance(); |
82 | 84 |
83 virtual void RunJavaScriptDialog( | 85 virtual void RunJavaScriptDialog( |
84 WebContents* web_contents, | 86 WebContents* web_contents, |
85 const GURL& origin_url, | 87 const GURL& origin_url, |
86 const std::string& accept_lang, | 88 const std::string& accept_lang, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 chrome::kJavaScriptMessageExpectedDelay)) { | 176 chrome::kJavaScriptMessageExpectedDelay)) { |
175 display_suppress_checkbox = true; | 177 display_suppress_checkbox = true; |
176 } else { | 178 } else { |
177 display_suppress_checkbox = false; | 179 display_suppress_checkbox = false; |
178 } | 180 } |
179 | 181 |
180 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 182 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
181 base::string16 dialog_title = | 183 base::string16 dialog_title = |
182 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 184 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
183 | 185 |
184 const Extension* extension = GetExtensionForWebContents(web_contents); | 186 const Extension* extension = GetExtensionForWebContents(web_contents); |
Lei Zhang
2014/08/22 22:39:50
As I mentioned on the other CL, maybe pull all the
David Yen
2014/08/22 23:03:58
Done.
| |
185 if (extension) | 187 if (extension) |
186 IncrementLazyKeepaliveCount(extension, web_contents); | 188 IncrementLazyKeepaliveCount(extension, web_contents); |
187 | 189 |
188 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 190 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
189 web_contents, | 191 web_contents, |
190 &javascript_dialog_extra_data_, | 192 &javascript_dialog_extra_data_, |
191 dialog_title, | 193 dialog_title, |
192 message_type, | 194 message_type, |
193 message_text, | 195 message_text, |
194 default_prompt_text, | 196 default_prompt_text, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 DecrementLazyKeepaliveCount(extension, web_contents); | 315 DecrementLazyKeepaliveCount(extension, web_contents); |
314 | 316 |
315 callback.Run(success, user_input); | 317 callback.Run(success, user_input); |
316 } | 318 } |
317 | 319 |
318 } // namespace | 320 } // namespace |
319 | 321 |
320 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { | 322 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
321 return ChromeJavaScriptDialogManager::GetInstance(); | 323 return ChromeJavaScriptDialogManager::GetInstance(); |
322 } | 324 } |
OLD | NEW |