| Index: chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
|
| diff --git a/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc b/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3040406183e7a9210b73ebb3ceb790a2145abfa3
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.h"
|
| +
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +#if defined(ENABLE_EXTENSIONS)
|
| +#include "extensions/browser/process_manager.h"
|
| +#include "extensions/common/extension.h"
|
| +
|
| +using extensions::Extension;
|
| +#endif // defined(ENABLE_EXTENSIONS)
|
| +
|
| +namespace {
|
| +
|
| +#if defined(ENABLE_EXTENSIONS)
|
| +// Returns the ProcessManager for the browser context from |web_contents|.
|
| +extensions::ProcessManager* GetExtensionsProcessManager(
|
| + content::WebContents* web_contents) {
|
| + return extensions::ProcessManager::Get(web_contents->GetBrowserContext());
|
| +}
|
| +
|
| +// Returns the extension associated with |web_contents| or NULL if there is no
|
| +// associated extension (or extensions are not supported).
|
| +const Extension* GetExtensionForWebContents(
|
| + content::WebContents* web_contents) {
|
| + extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
|
| + return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost());
|
| +}
|
| +#endif // defined(ENABLE_EXTENSIONS)
|
| +
|
| +} // namespace
|
| +
|
| +ChromeJavaScriptDialogManagerClient::ChromeJavaScriptDialogManagerClient() {}
|
| +ChromeJavaScriptDialogManagerClient::~ChromeJavaScriptDialogManagerClient() {}
|
| +
|
| +NativeAppModalDialog*
|
| +ChromeJavaScriptDialogManagerClient::CreateNativeJavaScriptPrompt(
|
| + JavaScriptAppModalDialog* dialog,
|
| + gfx::NativeWindow parent_window) {
|
| + return CreateChromeNativeJavaScriptPrompt(dialog, parent_window);
|
| +}
|
| +
|
| +void ChromeJavaScriptDialogManagerClient::IncrementLazyKeepaliveCount(
|
| + content::WebContents* web_contents) {
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + const Extension* extension = GetExtensionForWebContents(web_contents);
|
| + if (extension == nullptr)
|
| + return;
|
| +
|
| + DCHECK(web_contents);
|
| + extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
|
| + if (pm)
|
| + pm->IncrementLazyKeepaliveCount(extension);
|
| +#endif // defined(ENABLE_EXTENSIONS)
|
| +}
|
| +
|
| +void ChromeJavaScriptDialogManagerClient::DecrementLazyKeepaliveCount(
|
| + content::WebContents* web_contents) {
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + const Extension* extension = GetExtensionForWebContents(web_contents);
|
| + if (extension == nullptr)
|
| + return;
|
| +
|
| + DCHECK(web_contents);
|
| + extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
|
| + if (pm)
|
| + pm->DecrementLazyKeepaliveCount(extension);
|
| +#endif // defined(ENABLE_EXTENSIONS)
|
| +}
|
| +
|
| +bool ChromeJavaScriptDialogManagerClient::GetExtensionName(
|
| + content::WebContents* web_contents,
|
| + const GURL& origin_url,
|
| + std::string* name_out) {
|
| +#if defined(ENABLE_EXTENSIONS)
|
| + const Extension* extension = GetExtensionForWebContents(web_contents);
|
| + if (extension &&
|
| + web_contents->GetLastCommittedURL().GetOrigin() == origin_url) {
|
| + *name_out = extension->name();
|
| + return true;
|
| + }
|
| +#endif // defined(ENABLE_EXTENSIONS)
|
| + return false;
|
| +}
|
|
|