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 "extensions/components/javascript_dialog_extensions_client/javascript_d ialog_extension_client_impl.h" | |
6 | |
7 #include "components/app_modal_dialogs/javascript_dialog_extensions_client.h" | |
8 #include "components/app_modal_dialogs/javascript_dialog_manager.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 #include "extensions/browser/process_manager.h" | |
11 #include "extensions/common/extension.h" | |
12 #include "ui/gfx/native_widget_types.h" | |
13 | |
14 namespace { | |
15 | |
16 using extensions::Extension; | |
17 | |
18 // Returns the ProcessManager for the browser context from |web_contents|. | |
19 extensions::ProcessManager* GetExtensionsProcessManager( | |
20 content::WebContents* web_contents) { | |
21 return extensions::ProcessManager::Get(web_contents->GetBrowserContext()); | |
22 } | |
23 | |
24 // Returns the extension associated with |web_contents| or NULL if there is no | |
25 // associated extension (or extensions are not supported). | |
26 const Extension* GetExtensionForWebContents( | |
27 content::WebContents* web_contents) { | |
28 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
29 return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost()); | |
30 } | |
31 | |
32 class JavaScriptDialogExtensionsClientImpl | |
33 : public JavaScriptDialogExtensionsClient { | |
34 public: | |
35 JavaScriptDialogExtensionsClientImpl() {} | |
36 ~JavaScriptDialogExtensionsClientImpl() override {} | |
37 | |
38 // JavaScriptDialogExtensionsClient: | |
39 void IncrementLazyKeepaliveCount( | |
40 content::WebContents* web_contents) override; | |
msw
2014/11/05 03:53:56
nit: you can inline these definitions if the class
oshima
2014/11/05 21:42:19
Done.
oshima
2014/11/05 21:42:19
Done.
| |
41 void DecrementLazyKeepaliveCount( | |
42 content::WebContents* web_contents) override; | |
43 bool GetExtensionName(content::WebContents* web_contents, | |
44 const GURL& origin_url, | |
45 std::string* name_out) override; | |
46 | |
47 private: | |
48 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogExtensionsClientImpl); | |
49 }; | |
50 | |
51 void JavaScriptDialogExtensionsClientImpl::IncrementLazyKeepaliveCount( | |
52 content::WebContents* web_contents) { | |
53 const Extension* extension = GetExtensionForWebContents(web_contents); | |
54 if (extension == nullptr) | |
55 return; | |
56 | |
57 DCHECK(web_contents); | |
58 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
59 if (pm) | |
60 pm->IncrementLazyKeepaliveCount(extension); | |
61 } | |
62 | |
63 void JavaScriptDialogExtensionsClientImpl::DecrementLazyKeepaliveCount( | |
64 content::WebContents* web_contents) { | |
65 const Extension* extension = GetExtensionForWebContents(web_contents); | |
66 if (extension == nullptr) | |
67 return; | |
68 | |
69 DCHECK(web_contents); | |
70 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
71 if (pm) | |
72 pm->DecrementLazyKeepaliveCount(extension); | |
73 } | |
74 | |
75 bool JavaScriptDialogExtensionsClientImpl::GetExtensionName( | |
76 content::WebContents* web_contents, | |
77 const GURL& origin_url, | |
78 std::string* name_out) { | |
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 return false; | |
86 } | |
87 | |
88 } // namespace | |
89 | |
90 void InstallJavaScriptDialogExtensionsClient() { | |
91 SetJavaScriptDialogExtensionsClient( | |
92 make_scoped_ptr(new JavaScriptDialogExtensionsClientImpl)); | |
93 } | |
OLD | NEW |