| OLD | NEW |
| 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/macros.h" |
| 5 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 7 #include "chrome/browser/extensions/extension_install_prompt.h" | 8 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| 10 #include "chrome/browser/extensions/webstore_inline_installer.h" | 11 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 11 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 12 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 12 #include "chrome/browser/extensions/webstore_installer_test.h" | 13 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 13 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 14 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 kAppDomain, | 58 kAppDomain, |
| 58 kNonAppDomain) {} | 59 kNonAppDomain) {} |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 class ProgrammableInstallPrompt : public ExtensionInstallPrompt { | 62 class ProgrammableInstallPrompt : public ExtensionInstallPrompt { |
| 62 public: | 63 public: |
| 63 explicit ProgrammableInstallPrompt(WebContents* contents) | 64 explicit ProgrammableInstallPrompt(WebContents* contents) |
| 64 : ExtensionInstallPrompt(contents) | 65 : ExtensionInstallPrompt(contents) |
| 65 {} | 66 {} |
| 66 | 67 |
| 67 ~ProgrammableInstallPrompt() override {} | 68 ~ProgrammableInstallPrompt() override { g_done_callback = nullptr; } |
| 68 | 69 |
| 69 void ShowDialog( | 70 void ShowDialog( |
| 70 Delegate* delegate, | 71 const ExtensionInstallPrompt::DoneCallback& done_callback, |
| 71 const Extension* extension, | 72 const Extension* extension, |
| 72 const SkBitmap* icon, | 73 const SkBitmap* icon, |
| 73 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt, | 74 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt, |
| 74 scoped_ptr<const extensions::PermissionSet> custom_permissions, | 75 scoped_ptr<const extensions::PermissionSet> custom_permissions, |
| 75 const ShowDialogCallback& callback) override { | 76 const ShowDialogCallback& show_dialog_callback) override { |
| 76 delegate_ = delegate; | 77 done_callback_ = done_callback; |
| 78 g_done_callback = &done_callback_; |
| 77 } | 79 } |
| 78 | 80 |
| 79 static bool Ready() { | 81 static bool Ready() { return g_done_callback != nullptr; } |
| 80 return delegate_ != NULL; | |
| 81 } | |
| 82 | 82 |
| 83 static void Accept() { | 83 static void Accept() { |
| 84 delegate_->InstallUIProceed(); | 84 g_done_callback->Run(ExtensionInstallPrompt::Result::ACCEPTED); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static void Reject() { | 87 static void Reject() { |
| 88 delegate_->InstallUIAbort(true); | 88 g_done_callback->Run(ExtensionInstallPrompt::Result::USER_CANCELED); |
| 89 } | 89 } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 static Delegate* delegate_; | 92 static ExtensionInstallPrompt::DoneCallback* g_done_callback; |
| 93 |
| 94 ExtensionInstallPrompt::DoneCallback done_callback_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(ProgrammableInstallPrompt); |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; | 99 ExtensionInstallPrompt::DoneCallback* |
| 100 ProgrammableInstallPrompt::g_done_callback = nullptr; |
| 96 | 101 |
| 97 // Fake inline installer which creates a programmable prompt in place of | 102 // Fake inline installer which creates a programmable prompt in place of |
| 98 // the normal dialog UI. | 103 // the normal dialog UI. |
| 99 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { | 104 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { |
| 100 public: | 105 public: |
| 101 WebstoreInlineInstallerForTest(WebContents* contents, | 106 WebstoreInlineInstallerForTest(WebContents* contents, |
| 102 content::RenderFrameHost* host, | 107 content::RenderFrameHost* host, |
| 103 const std::string& extension_id, | 108 const std::string& extension_id, |
| 104 const GURL& requestor_url, | 109 const GURL& requestor_url, |
| 105 const Callback& callback) | 110 const Callback& callback) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, | 331 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, |
| 327 DownloadProgressListenerTest) { | 332 DownloadProgressListenerTest) { |
| 328 RunTest("download_progress_listener.html"); | 333 RunTest("download_progress_listener.html"); |
| 329 } | 334 } |
| 330 | 335 |
| 331 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { | 336 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { |
| 332 RunTest("both_listeners.html"); | 337 RunTest("both_listeners.html"); |
| 333 } | 338 } |
| 334 | 339 |
| 335 } // namespace extensions | 340 } // namespace extensions |
| OLD | NEW |