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( | |
Yoyo Zhou
2014/11/06 01:05:03
nit: I'd drop the Extensions from this function na
| |
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 { | |
41 const Extension* extension = GetExtensionForWebContents(web_contents); | |
42 if (extension == nullptr) | |
43 return; | |
44 | |
45 DCHECK(web_contents); | |
46 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
47 if (pm) | |
48 pm->IncrementLazyKeepaliveCount(extension); | |
49 } | |
50 void DecrementLazyKeepaliveCount( | |
51 content::WebContents* web_contents) override { | |
52 const Extension* extension = GetExtensionForWebContents(web_contents); | |
53 if (extension == nullptr) | |
54 return; | |
55 | |
56 DCHECK(web_contents); | |
57 extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents); | |
58 if (pm) | |
59 pm->DecrementLazyKeepaliveCount(extension); | |
60 } | |
61 bool GetExtensionName(content::WebContents* web_contents, | |
62 const GURL& origin_url, | |
63 std::string* name_out) override { | |
64 const Extension* extension = GetExtensionForWebContents(web_contents); | |
65 if (extension && | |
66 web_contents->GetLastCommittedURL().GetOrigin() == origin_url) { | |
67 *name_out = extension->name(); | |
68 return true; | |
69 } | |
70 return false; | |
71 } | |
72 | |
73 private: | |
74 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogExtensionsClientImpl); | |
75 }; | |
76 | |
77 } // namespace | |
78 | |
79 void InstallJavaScriptDialogExtensionsClient() { | |
80 SetJavaScriptDialogExtensionsClient( | |
81 make_scoped_ptr(new JavaScriptDialogExtensionsClientImpl)); | |
82 } | |
OLD | NEW |