OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/app_modal_dialogs/chrome_javascript_dialog_manager_c
lient.h" |
| 6 |
| 7 #include "content/public/browser/web_contents.h" |
| 8 |
| 9 #if defined(ENABLE_EXTENSIONS) |
| 10 #include "extensions/browser/process_manager.h" |
| 11 #include "extensions/common/extension.h" |
| 12 |
| 13 using extensions::Extension; |
| 14 #endif // defined(ENABLE_EXTENSIONS) |
| 15 |
| 16 namespace { |
| 17 |
| 18 #if defined(ENABLE_EXTENSIONS) |
| 19 // Returns the ProcessManager for the browser context from |web_contents|. |
| 20 extensions::ProcessManager* GetExtensionsProcessManager( |
| 21 content::WebContents* web_contents) { |
| 22 return extensions::ProcessManager::Get(web_contents->GetBrowserContext()); |
| 23 } |
| 24 |
| 25 // Returns the extension associated with |web_contents| or NULL if there is no |
| 26 // associated extension (or extensions are not supported). |
| 27 const Extension* GetExtensionForWebContents( |
| 28 content::WebContents* web_contents) { |
| 29 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
| 30 return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost()); |
| 31 } |
| 32 #endif // defined(ENABLE_EXTENSIONS) |
| 33 |
| 34 } // namespace |
| 35 |
| 36 ChromeJavaScriptDialogManagerClient::ChromeJavaScriptDialogManagerClient() {} |
| 37 ChromeJavaScriptDialogManagerClient::~ChromeJavaScriptDialogManagerClient() {} |
| 38 |
| 39 NativeAppModalDialog* |
| 40 ChromeJavaScriptDialogManagerClient::CreateNativeJavaScriptPrompt( |
| 41 JavaScriptAppModalDialog* dialog, |
| 42 gfx::NativeWindow parent_window) { |
| 43 return CreateChromeNativeJavaScriptPrompt(dialog, parent_window); |
| 44 } |
| 45 |
| 46 void ChromeJavaScriptDialogManagerClient::IncrementLazyKeepaliveCount( |
| 47 content::WebContents* web_contents) { |
| 48 #if defined(ENABLE_EXTENSIONS) |
| 49 const Extension* extension = GetExtensionForWebContents(web_contents); |
| 50 if (extension == nullptr) |
| 51 return; |
| 52 |
| 53 DCHECK(web_contents); |
| 54 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
| 55 if (pm) |
| 56 pm->IncrementLazyKeepaliveCount(extension); |
| 57 #endif // defined(ENABLE_EXTENSIONS) |
| 58 } |
| 59 |
| 60 void ChromeJavaScriptDialogManagerClient::DecrementLazyKeepaliveCount( |
| 61 content::WebContents* web_contents) { |
| 62 #if defined(ENABLE_EXTENSIONS) |
| 63 const Extension* extension = GetExtensionForWebContents(web_contents); |
| 64 if (extension == nullptr) |
| 65 return; |
| 66 |
| 67 DCHECK(web_contents); |
| 68 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); |
| 69 if (pm) |
| 70 pm->DecrementLazyKeepaliveCount(extension); |
| 71 #endif // defined(ENABLE_EXTENSIONS) |
| 72 } |
| 73 |
| 74 bool ChromeJavaScriptDialogManagerClient::GetExtensionName( |
| 75 content::WebContents* web_contents, |
| 76 const GURL& origin_url, |
| 77 std::string* name_out) { |
| 78 #if defined(ENABLE_EXTENSIONS) |
| 79 const Extension* extension = GetExtensionForWebContents(web_contents); |
| 80 if (extension && |
| 81 web_contents->GetLastCommittedURL().GetOrigin() == origin_url) { |
| 82 *name_out = extension->name(); |
| 83 return true; |
| 84 } |
| 85 #endif // defined(ENABLE_EXTENSIONS) |
| 86 return false; |
| 87 } |
OLD | NEW |