Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: extensions/components/javascript_dialog_extensions_client/javascript_dialog_extension_client_impl.cc

Issue 666533007: Move JavaScriptDialogManager, JavascriptAppModalDialogViews to components/app_modal_dialogs (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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* GetProcessManager(
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 = GetProcessManager(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 OnDialogOpened(content::WebContents* web_contents) override {
40 const Extension* extension = GetExtensionForWebContents(web_contents);
41 if (extension == nullptr)
42 return;
43
44 DCHECK(web_contents);
45 extensions::ProcessManager* pm = GetProcessManager(web_contents);
46 if (pm)
47 pm->IncrementLazyKeepaliveCount(extension);
48 }
49 void OnDialogClosed(content::WebContents* web_contents) override {
50 const Extension* extension = GetExtensionForWebContents(web_contents);
51 if (extension == nullptr)
52 return;
53
54 DCHECK(web_contents);
55 extensions::ProcessManager* pm = GetProcessManager(web_contents);
56 if (pm)
57 pm->DecrementLazyKeepaliveCount(extension);
58 }
59 bool GetExtensionName(content::WebContents* web_contents,
60 const GURL& origin_url,
61 std::string* name_out) override {
62 const Extension* extension = GetExtensionForWebContents(web_contents);
63 if (extension &&
64 web_contents->GetLastCommittedURL().GetOrigin() == origin_url) {
65 *name_out = extension->name();
66 return true;
67 }
68 return false;
69 }
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogExtensionsClientImpl);
73 };
74
75 } // namespace
76
77 void InstallJavaScriptDialogExtensionsClient() {
78 SetJavaScriptDialogExtensionsClient(
79 make_scoped_ptr(new JavaScriptDialogExtensionsClientImpl));
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698