Commit 8926e857 authored by raymes's avatar raymes Committed by Commit bot

Hookup the plugin placeholder to the Flash permission prompt

This hooks up the plugin placeholder to the Flash permission prompt
such that the prompt is displayed when the placeholder is clicked.

BUG=641615
TBR=calamity

Review-Url: https://codereview.chromium.org/2385033002
Cr-Commit-Position: refs/heads/master@{#423070}
parent 64b2c16c
......@@ -642,7 +642,7 @@ void HandleFlashDownloadActionOnUIThread(int render_process_id,
return;
WebContents* web_contents =
WebContents::FromRenderFrameHost(render_frame_host);
FlashDownloadInterception::InterceptFlashDownloadNavigation(web_contents);
FlashDownloadInterception::ShowRunFlashPrompt(web_contents);
}
#endif // defined(ENABLE_PLUGINS)
......
......@@ -158,7 +158,6 @@ class SiteEngagementScore {
FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary);
FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset);
friend class ChromePluginServiceFilterTest;
friend class FlashPermissionBrowserTest;
friend class ImportantSitesUtilTest;
friend class SiteEngagementHelperTest;
friend class SiteEngagementScoreTest;
......
......@@ -30,8 +30,7 @@ void PermissionsBrowserTest::SetUpOnMainThread() {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
embedded_test_server()->GetURL(test_url()));
ui_test_utils::NavigateToURL(browser(), GetTestUrl());
}
void PermissionsBrowserTest::TearDownOnMainThread() {
......@@ -51,6 +50,10 @@ content::WebContents* PermissionsBrowserTest::GetWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
GURL PermissionsBrowserTest::GetTestUrl() {
return embedded_test_server()->GetURL(test_url());
}
void PermissionsBrowserTest::CommonFailsBeforeRequesting() {
EXPECT_EQ(0, prompt_factory()->total_request_count());
// Dismiss any prompts if they are shown when using the feature.
......@@ -63,8 +66,8 @@ void PermissionsBrowserTest::CommonFailsIfDismissed() {
prompt_factory()->set_response_type(PermissionRequestManager::DISMISS);
TriggerPrompt();
EXPECT_EQ(1, prompt_factory()->total_request_count());
EXPECT_FALSE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
}
void PermissionsBrowserTest::CommonFailsIfBlocked() {
......@@ -72,8 +75,8 @@ void PermissionsBrowserTest::CommonFailsIfBlocked() {
prompt_factory()->set_response_type(PermissionRequestManager::DENY_ALL);
TriggerPrompt();
EXPECT_EQ(1, prompt_factory()->total_request_count());
EXPECT_FALSE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
}
void PermissionsBrowserTest::CommonSucceedsIfAllowed() {
......@@ -81,6 +84,6 @@ void PermissionsBrowserTest::CommonSucceedsIfAllowed() {
prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
TriggerPrompt();
EXPECT_EQ(1, prompt_factory()->total_request_count());
EXPECT_TRUE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
}
......@@ -46,6 +46,8 @@ class PermissionsBrowserTest : public InProcessBrowserTest {
content::WebContents* GetWebContents();
GURL GetTestUrl();
// Common tests that should be called by subclasses.
void CommonFailsBeforeRequesting();
void CommonFailsIfDismissed();
......
......@@ -34,21 +34,21 @@ void DoNothing(blink::mojom::PermissionStatus result) {}
bool InterceptNavigation(
content::WebContents* source,
const navigation_interception::NavigationParams& params) {
FlashDownloadInterception::InterceptFlashDownloadNavigation(source);
FlashDownloadInterception::ShowRunFlashPrompt(source);
return true;
}
} // namespace
// static
void FlashDownloadInterception::InterceptFlashDownloadNavigation(
content::WebContents* source) {
void FlashDownloadInterception::ShowRunFlashPrompt(
content::WebContents* web_contents) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PermissionManager* manager = PermissionManager::Get(
Profile::FromBrowserContext(source->GetBrowserContext()));
Profile::FromBrowserContext(web_contents->GetBrowserContext()));
manager->RequestPermission(
content::PermissionType::FLASH, source->GetMainFrame(),
source->GetLastCommittedURL(), true, base::Bind(&DoNothing));
content::PermissionType::FLASH, web_contents->GetMainFrame(),
web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing));
}
// static
......
......@@ -23,7 +23,7 @@ class GURL;
// Chrome already ships with it. Note that this is an UI thread class.
class FlashDownloadInterception {
public:
static void InterceptFlashDownloadNavigation(content::WebContents* source);
static void ShowRunFlashPrompt(content::WebContents* web_contents);
static bool ShouldStopFlashDownloadAction(
HostContentSettingsMap* host_content_settings_map,
const GURL& source_url,
......@@ -34,7 +34,7 @@ class FlashDownloadInterception {
content::NavigationHandle* handle);
private:
DISALLOW_COPY_AND_ASSIGN(FlashDownloadInterception);
DISALLOW_IMPLICIT_CONSTRUCTORS(FlashDownloadInterception);
};
#endif // CHROME_BROWSER_PLUGINS_FLASH_DOWNLOAD_INTERCEPTION_H_
......@@ -2,14 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/engagement/site_engagement_score.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "chrome/browser/permissions/permissions_browsertest.h"
#include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/ppapi_test_utils.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "url/gurl.h"
class FlashPermissionBrowserTest : public PermissionsBrowserTest {
public:
......@@ -20,27 +24,43 @@ class FlashPermissionBrowserTest : public PermissionsBrowserTest {
// PermissionsBrowserTest
void SetUpCommandLine(base::CommandLine* command_line) override {
PermissionsBrowserTest::SetUpCommandLine(command_line);
ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line));
feature_list_.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
// Set a high engagement threshhold so it doesn't interfere with testing the
// permission.
command_line->AppendSwitchASCII(switches::kEnableFeatures,
"PreferHtmlOverPlugins<Study1");
command_line->AppendSwitchASCII(switches::kForceFieldTrials,
"Study1/Enabled/");
command_line->AppendSwitchASCII(
switches::kForceFieldTrialParams,
"Study1.Enabled:engagement_threshold_for_flash/100");
}
void SetUpOnMainThread() override {
SiteEngagementScore::SetParamValuesForTesting();
PermissionsBrowserTest::SetUpOnMainThread();
}
void TriggerPrompt() override {
if (prompt_factory()->response_type() ==
PermissionRequestManager::ACCEPT_ALL) {
// If the prompt will be allowed, we need to wait for the page to refresh.
content::TestNavigationManager observer(GetWebContents(), GetTestUrl());
EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
observer.WaitForNavigationFinished();
} else {
EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
}
}
bool FeatureUsageSucceeds() override {
// Flash won't be enabled until the page is refreshed.
// Wait until the page is refreshed before testing whether flash is enabled
// or disabled.
ui_test_utils::NavigateToURL(browser(),
GetWebContents()->GetLastCommittedURL());
return RunScriptReturnBool("flashIsEnabled();");
// If either flash with or without fallback content runs successfully it
// indicates the feature is at least partly working, which could imply a
// faulty permission.
return RunScriptReturnBool("flashIsEnabled();") ||
RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();");
}
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
......@@ -65,6 +85,22 @@ IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) {
prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();"));
EXPECT_TRUE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
}
IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
TriggerPromptViaPluginPlaceholder) {
EXPECT_EQ(0, prompt_factory()->total_request_count());
EXPECT_FALSE(FeatureUsageSucceeds());
prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
// We need to simulate a mouse click to trigger the placeholder to prompt.
content::TestNavigationManager observer(GetWebContents(), GetTestUrl());
content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */,
blink::WebMouseEvent::Button::Left,
gfx::Point(50, 50));
observer.WaitForNavigationFinished();
EXPECT_TRUE(FeatureUsageSucceeds());
EXPECT_EQ(1, prompt_factory()->total_request_count());
}
......@@ -17,6 +17,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/plugins/flash_download_interception.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/browser/plugins/plugin_infobar_delegates.h"
#include "chrome/browser/profiles/profile.h"
......@@ -33,6 +34,7 @@
#include "components/infobars/core/infobar_delegate.h"
#include "components/infobars/core/simple_alert_infobar_delegate.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
......@@ -454,7 +456,9 @@ void PluginObserver::OnOpenAboutPlugins() {
}
void PluginObserver::OnShowFlashPermissionBubble() {
// TODO(tommycli): Show a permission bubble for the associated tab.
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
FlashDownloadInterception::ShowRunFlashPrompt(web_contents());
}
void PluginObserver::OnCouldNotLoadPlugin(const base::FilePath& plugin_path) {
......
......@@ -41,6 +41,10 @@ class MockPermissionPromptFactory {
response_type_ = type;
}
PermissionRequestManager::AutoResponseType response_type() {
return response_type_;
}
// If the current view is visible.
bool is_visible();
// Number of times |Show| was called on any bubble.
......
......@@ -11,23 +11,33 @@
window.domAutomationController.send(true);
}
function flashIsEnabled() {
var plugin = document.getElementById('flash-object');
function flashIsEnabledForPlugin(plugin) {
plugin.addEventListener('message', function handleEvent(event) {
if (event.data.source === 'getPowerSaverStatusResponse') {
plugin.removeEventListener('message', handleEvent);
window.domAutomationController.send(true);
}
});
if (plugin.postMessage) {
if (plugin.postMessage)
plugin.postMessage('getPowerSaverStatus');
} else {
else
window.domAutomationController.send(false);
}
function flashIsEnabled() {
flashIsEnabledForPlugin(document.getElementById('flash-object'));
}
function flashIsEnabledForPluginWithoutFallback() {
flashIsEnabledForPlugin(
document.getElementById('flash-object-no-fallback'));
}
</script>
<body>
<object id="flash-object" name="plugin" data="test.swf"
<object id="flash-object-no-fallback" data="test.swf"
type="application/x-shockwave-flash" width="400" height="100">
</object>
<object id="flash-object" data="test.swf"
type="application/x-shockwave-flash" width="400" height="100">
Flash not supported.
<br>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment