Chromium Code Reviews| 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 "athena/extensions/athena_javascript_dialog_manager_client.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "components/app_modal_dialogs/javascript_dialog_manager_client.h" | |
| 9 #include "components/app_modal_dialogs/views/javascript_app_modal_dialog_views.h " | |
| 10 #include "components/constrained_window/constrained_window_views.h" | |
|
Mr4D (OOO till 08-26)
2014/10/29 23:10:07
Are you sure you need this?
oshima
2014/10/31 00:37:50
Yes (:49)
Mr4D (OOO till 08-26)
2014/10/31 04:26:01
Acknowledged.
| |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "extensions/browser/process_manager.h" | |
| 13 #include "extensions/common/extension.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | |
| 15 | |
| 16 class JavaScriptAppModalDialog; | |
| 17 class NativeAppModalDialog; | |
| 18 | |
| 19 namespace athena { | |
| 20 | |
|
Mr4D (OOO till 08-26)
2014/10/29 23:10:07
No newline
oshima
2014/10/31 00:37:50
Done.
| |
| 21 namespace { | |
| 22 | |
| 23 // Returns the ProcessManager for the browser context from |web_contents|. | |
| 24 extensions::ProcessManager* GetExtensionsProcessManager( | |
| 25 content::WebContents* web_contents) { | |
| 26 return extensions::ProcessManager::Get(web_contents->GetBrowserContext()); | |
| 27 } | |
| 28 | |
| 29 // Returns the extension associated with |web_contents| or NULL if there is no | |
| 30 // associated extension (or extensions are not supported). | |
| 31 const extensions::Extension* GetExtensionForWebContents( | |
| 32 content::WebContents* web_contents) { | |
| 33 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
| 34 return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost()); | |
| 35 } | |
| 36 | |
| 37 class AthenaJavaScriptDialogManagerClient | |
| 38 : public JavaScriptDialogManagerClient { | |
| 39 public: | |
| 40 AthenaJavaScriptDialogManagerClient() {} | |
| 41 ~AthenaJavaScriptDialogManagerClient() override {} | |
| 42 | |
| 43 // JavaScriptDialogManagerClient: | |
| 44 NativeAppModalDialog* CreateNativeJavaScriptPrompt( | |
| 45 JavaScriptAppModalDialog* dialog, | |
| 46 gfx::NativeWindow parent_window) override { | |
| 47 JavaScriptAppModalDialogViews* d = | |
| 48 new JavaScriptAppModalDialogViews(dialog); | |
| 49 CreateWindowModalDialogViews(d, parent_window); | |
| 50 return d; | |
| 51 } | |
| 52 void IncrementLazyKeepaliveCount( | |
| 53 content::WebContents* web_contents) override { | |
| 54 const extensions::Extension* extension = | |
| 55 GetExtensionForWebContents(web_contents); | |
| 56 if (extension == nullptr) | |
| 57 return; | |
| 58 | |
| 59 DCHECK(web_contents); | |
| 60 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
| 61 if (pm) | |
| 62 pm->IncrementLazyKeepaliveCount(extension); | |
| 63 } | |
| 64 void DecrementLazyKeepaliveCount( | |
| 65 content::WebContents* web_contents) override { | |
| 66 const extensions::Extension* extension = | |
| 67 GetExtensionForWebContents(web_contents); | |
| 68 if (extension == nullptr) | |
| 69 return; | |
| 70 | |
| 71 DCHECK(web_contents); | |
| 72 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
| 73 if (pm) | |
| 74 pm->DecrementLazyKeepaliveCount(extension); | |
| 75 } | |
| 76 bool GetExtensionName(content::WebContents* web_contents, | |
| 77 const GURL& origin_url, | |
| 78 std::string* name_out) override { | |
| 79 const extensions::Extension* extension = | |
| 80 GetExtensionForWebContents(web_contents); | |
| 81 if (extension && | |
| 82 web_contents->GetLastCommittedURL().GetOrigin() == origin_url) { | |
| 83 *name_out = extension->name(); | |
| 84 return true; | |
| 85 } | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 DISALLOW_COPY_AND_ASSIGN(AthenaJavaScriptDialogManagerClient); | |
| 91 }; | |
| 92 | |
| 93 } // namespace | |
| 94 | |
| 95 void InstallJavaScriptDialogManagerClient() { | |
| 96 SetJavaScriptDialogManagerClient( | |
| 97 make_scoped_ptr(new AthenaJavaScriptDialogManagerClient)); | |
| 98 } | |
| 99 | |
| 100 void UninstallJavaScriptDialogManagerClient() { | |
| 101 SetJavaScriptDialogManagerClient(nullptr); | |
| 102 } | |
| 103 | |
| 104 } // namespace athena | |
| OLD | NEW |