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

Side by Side Diff: chrome/browser/extensions/webstore_inline_installer_browsertest.cc

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
7 #include "chrome/browser/extensions/extension_install_prompt.h" 7 #include "chrome/browser/extensions/extension_install_prompt.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/tab_helper.h" 9 #include "chrome/browser/extensions/tab_helper.h"
10 #include "chrome/browser/extensions/webstore_inline_installer.h" 10 #include "chrome/browser/extensions/webstore_inline_installer.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 kAppDomain, 57 kAppDomain,
58 kNonAppDomain) {} 58 kNonAppDomain) {}
59 }; 59 };
60 60
61 class ProgrammableInstallPrompt : public ExtensionInstallPrompt { 61 class ProgrammableInstallPrompt : public ExtensionInstallPrompt {
62 public: 62 public:
63 explicit ProgrammableInstallPrompt(WebContents* contents) 63 explicit ProgrammableInstallPrompt(WebContents* contents)
64 : ExtensionInstallPrompt(contents) 64 : ExtensionInstallPrompt(contents)
65 {} 65 {}
66 66
67 ~ProgrammableInstallPrompt() override {} 67 ~ProgrammableInstallPrompt() override { g_done_callback = nullptr; }
68 68
69 void ShowDialog( 69 void ShowDialog(
70 Delegate* delegate, 70 const ExtensionInstallPrompt::DoneCallback& done_callback,
71 const Extension* extension, 71 const Extension* extension,
72 const SkBitmap* icon, 72 const SkBitmap* icon,
73 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt, 73 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt,
74 scoped_ptr<const extensions::PermissionSet> custom_permissions, 74 scoped_ptr<const extensions::PermissionSet> custom_permissions,
75 const ShowDialogCallback& callback) override { 75 const ShowDialogCallback& show_dialog_callback) override {
76 delegate_ = delegate; 76 done_callback_ = done_callback;
77 g_done_callback = &done_callback_;
77 } 78 }
78 79
79 static bool Ready() { 80 static bool Ready() { return g_done_callback != nullptr; }
80 return delegate_ != NULL;
81 }
82 81
83 static void Accept() { 82 static void Accept() {
84 delegate_->InstallUIProceed(); 83 g_done_callback->Run(ExtensionInstallPrompt::Result::ACCEPTED);
85 } 84 }
86 85
87 static void Reject() { 86 static void Reject() {
88 delegate_->InstallUIAbort(true); 87 g_done_callback->Run(ExtensionInstallPrompt::Result::USER_CANCELED);
89 } 88 }
90 89
91 private: 90 private:
92 static Delegate* delegate_; 91 static ExtensionInstallPrompt::DoneCallback* g_done_callback;
92
93 ExtensionInstallPrompt::DoneCallback done_callback_;
94
95 DISALLOW_COPY_AND_ASSIGN(ProgrammableInstallPrompt);
Avi (use Gerrit) 2015/12/29 03:10:45 You know.
Devlin 2016/01/04 22:59:23 Done.
93 }; 96 };
94 97
95 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; 98 ExtensionInstallPrompt::DoneCallback*
99 ProgrammableInstallPrompt::g_done_callback = nullptr;
96 100
97 // Fake inline installer which creates a programmable prompt in place of 101 // Fake inline installer which creates a programmable prompt in place of
98 // the normal dialog UI. 102 // the normal dialog UI.
99 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { 103 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller {
100 public: 104 public:
101 WebstoreInlineInstallerForTest(WebContents* contents, 105 WebstoreInlineInstallerForTest(WebContents* contents,
102 content::RenderFrameHost* host, 106 content::RenderFrameHost* host,
103 const std::string& extension_id, 107 const std::string& extension_id,
104 const GURL& requestor_url, 108 const GURL& requestor_url,
105 const Callback& callback) 109 const Callback& callback)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, 330 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
327 DownloadProgressListenerTest) { 331 DownloadProgressListenerTest) {
328 RunTest("download_progress_listener.html"); 332 RunTest("download_progress_listener.html");
329 } 333 }
330 334
331 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { 335 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) {
332 RunTest("both_listeners.html"); 336 RunTest("both_listeners.html");
333 } 337 }
334 338
335 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698