summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 06:18:01 +0000
committerfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 06:18:01 +0000
commitfcf5a7a76685e63dc5520c57d335f685697dbda6 (patch)
tree975bbba4cf45d0837a0a579944100082f7e4ff0e
parent9e70b5725059f16de3d39f4e4937d1e7d8dfc6cb (diff)
downloadchromium_src-fcf5a7a76685e63dc5520c57d335f685697dbda6.zip
chromium_src-fcf5a7a76685e63dc5520c57d335f685697dbda6.tar.gz
chromium_src-fcf5a7a76685e63dc5520c57d335f685697dbda6.tar.bz2
<webview>: Move responsive/unresponsive events from content to chrome
BUG=166165 TBR=cdn@chromium.org for deleting IPCs in browser_plugin_messages.h Review URL: https://chromiumcodereview.appspot.com/18716002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213772 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/guestview/webview/webview_constants.cc2
-rw-r--r--chrome/browser/guestview/webview/webview_constants.h6
-rw-r--r--chrome/browser/guestview/webview/webview_guest.cc16
-rw-r--r--chrome/browser/guestview/webview/webview_guest.h2
-rw-r--r--chrome/renderer/resources/extensions/web_view.js10
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.cc14
-rw-r--r--content/browser/browser_plugin/browser_plugin_host_browsertest.cc62
-rw-r--r--content/common/browser_plugin/browser_plugin_messages.h12
-rw-r--r--content/public/browser/browser_plugin_guest_delegate.h6
-rw-r--r--content/renderer/browser_plugin/browser_plugin.cc16
-rw-r--r--content/test/data/browser_plugin_embedder_guest_unresponsive.html31
11 files changed, 43 insertions, 134 deletions
diff --git a/chrome/browser/guestview/webview/webview_constants.cc b/chrome/browser/guestview/webview/webview_constants.cc
index b80b635..2611a7d 100644
--- a/chrome/browser/guestview/webview/webview_constants.cc
+++ b/chrome/browser/guestview/webview/webview_constants.cc
@@ -16,6 +16,8 @@ const char kEventLoadCommit[] = "webview.onLoadCommit";
const char kEventLoadRedirect[] = "webview.onLoadRedirect";
const char kEventLoadStart[] = "webview.onLoadStart";
const char kEventLoadStop[] = "webview.onLoadStop";
+const char kEventResponsive[] = "webview.onResponsive";
+const char kEventUnresponsive[] = "webview.onUnresponsive";
// Parameters/properties on events.
const char kLevel[] = "level";
diff --git a/chrome/browser/guestview/webview/webview_constants.h b/chrome/browser/guestview/webview/webview_constants.h
index e8ce5a4..59532f2 100644
--- a/chrome/browser/guestview/webview/webview_constants.h
+++ b/chrome/browser/guestview/webview/webview_constants.h
@@ -19,11 +19,13 @@ extern const char kEventLoadCommit[];
extern const char kEventLoadRedirect[];
extern const char kEventLoadStart[];
extern const char kEventLoadStop[];
+extern const char kEventResponsive[];
+extern const char kEventUnresponsive[];
// Parameters/properties on events.
-extern const char kMessage[];
extern const char kLevel[];
extern const char kLine[];
+extern const char kMessage[];
extern const char kNewURL[];
extern const char kOldURL[];
extern const char kProcessId[];
@@ -35,8 +37,6 @@ extern const char kInternalCurrentEntryIndex[];
extern const char kInternalEntryCount[];
extern const char kInternalProcessId[];
-// Parameters/properties on events.
-
} // namespace webview
#endif // CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_CONSTANTS_H_
diff --git a/chrome/browser/guestview/webview/webview_guest.cc b/chrome/browser/guestview/webview/webview_guest.cc
index 71a4e6c..9bd93895 100644
--- a/chrome/browser/guestview/webview/webview_guest.cc
+++ b/chrome/browser/guestview/webview/webview_guest.cc
@@ -160,6 +160,22 @@ bool WebViewGuest::HandleKeyboardEvent(
return false;
}
+// TODO(fsamuel): Find a reliable way to test the 'responsive' and
+// 'unresponsive' events.
+void WebViewGuest::RendererResponsive() {
+ scoped_ptr<DictionaryValue> args(new DictionaryValue());
+ args->SetInteger(webview::kProcessId,
+ guest_web_contents()->GetRenderProcessHost()->GetID());
+ DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass()));
+}
+
+void WebViewGuest::RendererUnresponsive() {
+ scoped_ptr<DictionaryValue> args(new DictionaryValue());
+ args->SetInteger(webview::kProcessId,
+ guest_web_contents()->GetRenderProcessHost()->GetID());
+ DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass()));
+}
+
void WebViewGuest::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
diff --git a/chrome/browser/guestview/webview/webview_guest.h b/chrome/browser/guestview/webview/webview_guest.h
index 5f63ecd..a13e306 100644
--- a/chrome/browser/guestview/webview/webview_guest.h
+++ b/chrome/browser/guestview/webview/webview_guest.h
@@ -48,6 +48,8 @@ class WebViewGuest : public GuestView,
virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE;
virtual bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
+ virtual void RendererResponsive() OVERRIDE;
+ virtual void RendererUnresponsive() OVERRIDE;
// NotificationObserver implementation.
virtual void Observe(int type,
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
index 2d1a083b..6b4d3c9 100644
--- a/chrome/renderer/resources/extensions/web_view.js
+++ b/chrome/renderer/resources/extensions/web_view.js
@@ -15,9 +15,7 @@ var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight',
'minwidth', 'maxheight', 'maxwidth'];
var WEB_VIEW_EVENTS = {
- 'responsive' : ['processId'],
'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'],
- 'unresponsive' : ['processId']
};
var createEvent = function(name) {
@@ -69,6 +67,14 @@ var WEB_VIEW_EXT_EVENTS = {
'loadstop': {
evt: createEvent('webview.onLoadStop'),
fields: []
+ },
+ 'responsive': {
+ evt: createEvent('webview.onResponsive'),
+ fields: ['processId']
+ },
+ 'unresponsive': {
+ evt: createEvent('webview.onUnresponsive'),
+ fields: ['processId']
}
};
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index ca1ae40..067833e 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -731,19 +731,17 @@ void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents,
}
void BrowserPluginGuest::RendererUnresponsive(WebContents* source) {
- int process_id =
- GetWebContents()->GetRenderProcessHost()->GetID();
- SendMessageToEmbedder(
- new BrowserPluginMsg_GuestUnresponsive(instance_id(), process_id));
RecordAction(UserMetricsAction("BrowserPlugin.Guest.Hung"));
+ if (!delegate_)
+ return;
+ delegate_->RendererUnresponsive();
}
void BrowserPluginGuest::RendererResponsive(WebContents* source) {
- int process_id =
- GetWebContents()->GetRenderProcessHost()->GetID();
- SendMessageToEmbedder(
- new BrowserPluginMsg_GuestResponsive(instance_id(), process_id));
RecordAction(UserMetricsAction("BrowserPlugin.Guest.Responsive"));
+ if (!delegate_)
+ return;
+ delegate_->RendererResponsive();
}
void BrowserPluginGuest::RunFileChooser(WebContents* web_contents,
diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
index a1c0613..5e6d887f 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -377,68 +377,6 @@ class BrowserPluginHostTest : public ContentBrowserTest {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest);
};
-// This test loads a guest that has a busy loop, and therefore it hangs the
-// guest.
-//
-// Disabled on Windows and Linux since it is flaky. crbug.com/164812
-// THIS TEST IS ALWAYS FLAKY. DO NOT ENABLE AGAIN WITHOUT REWRITING.
-#if defined(OS_WIN) || defined(OS_LINUX)
-#define MAYBE_GuestUnresponsive DISABLED_GuestUnresponsive
-#else
-#define MAYBE_GuestUnresponsive GuestUnresponsive
-#endif
-IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest,
- MAYBE_GuestUnresponsive) {
- // Override the hang timeout for guest to be very small.
- content::BrowserPluginGuest::set_factory_for_testing(
- TestShortHangTimeoutGuestFactory::GetInstance());
- const char kEmbedderURL[] =
- "/browser_plugin_embedder_guest_unresponsive.html";
- StartBrowserPluginTest(
- kEmbedderURL, kHTMLForGuestBusyLoop, true, std::string());
- // Wait until the busy loop starts.
- {
- const string16 expected_title = ASCIIToUTF16("start");
- content::TitleWatcher title_watcher(test_guest()->web_contents(),
- expected_title);
- // Hang the guest for a length of time.
- int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds();
- ExecuteSyncJSFunction(
- test_guest()->web_contents()->GetRenderViewHost(),
- base::StringPrintf("StartPauseMs(%d);", spin_time).c_str());
-
- string16 actual_title = title_watcher.WaitAndGetTitle();
- EXPECT_EQ(expected_title, actual_title);
- }
- {
- const string16 expected_title = ASCIIToUTF16("done");
- content::TitleWatcher title_watcher(test_embedder()->web_contents(),
- expected_title);
-
- // Send a mouse event to the guest.
- SimulateMouseClick(test_embedder()->web_contents(), 0,
- WebKit::WebMouseEvent::ButtonLeft);
-
- string16 actual_title = title_watcher.WaitAndGetTitle();
- EXPECT_EQ(expected_title, actual_title);
- }
-
- // Verify that the embedder has received the 'unresponsive' and 'responsive'
- // events.
- RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
- test_embedder()->web_contents()->GetRenderViewHost());
- scoped_ptr<base::Value> value =
- content::ExecuteScriptAndGetValue(rvh, "unresponsiveCalled");
- bool result = false;
- ASSERT_TRUE(value->GetAsBoolean(&result));
- EXPECT_TRUE(result);
-
- value = content::ExecuteScriptAndGetValue(rvh, "responsiveCalled");
- result = false;
- ASSERT_TRUE(value->GetAsBoolean(&result));
- EXPECT_TRUE(result);
-}
-
// This test ensures that if guest isn't there and we resize the guest (from
// js), it remembers the size correctly.
//
diff --git a/content/common/browser_plugin/browser_plugin_messages.h b/content/common/browser_plugin/browser_plugin_messages.h
index 6d3556a..5c921ac 100644
--- a/content/common/browser_plugin/browser_plugin_messages.h
+++ b/content/common/browser_plugin/browser_plugin_messages.h
@@ -312,18 +312,6 @@ IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestContentWindowReady,
IPC_MESSAGE_CONTROL1(BrowserPluginMsg_GuestGone,
int /* instance_id */)
-// When the guest is unresponsive, the browser process informs the embedder
-// through this message.
-IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestUnresponsive,
- int /* instance_id */,
- int /* process_id */)
-
-// When the guest begins responding again, the browser process informs the
-// embedder through this message.
-IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestResponsive,
- int /* instance_id */,
- int /* process_id */)
-
// When the user tabs to the end of the tab stops of a guest, the browser
// process informs the embedder to tab out of the browser plugin.
IPC_MESSAGE_CONTROL2(BrowserPluginMsg_AdvanceFocus,
diff --git a/content/public/browser/browser_plugin_guest_delegate.h b/content/public/browser/browser_plugin_guest_delegate.h
index a9003ad..df98e4f 100644
--- a/content/public/browser/browser_plugin_guest_delegate.h
+++ b/content/public/browser/browser_plugin_guest_delegate.h
@@ -35,6 +35,12 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate {
virtual void GuestProcessGone(base::TerminationStatus status) {}
virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
+
+ // Notification that the guest is no longer hung.
+ virtual void RendererResponsive() {}
+
+ // Notification that the guest is hung.
+ virtual void RendererUnresponsive() {}
};
} // namespace content
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 4483c58..835a24e 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -148,8 +148,6 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady,
OnGuestContentWindowReady)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone)
- IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive)
- IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestPermission, OnRequestPermission)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock)
@@ -485,18 +483,6 @@ void BrowserPlugin::OnGuestGone(int guest_instance_id) {
weak_ptr_factory_.GetWeakPtr()));
}
-void BrowserPlugin::OnGuestResponsive(int guest_instance_id, int process_id) {
- std::map<std::string, base::Value*> props;
- props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id);
- TriggerEvent(browser_plugin::kEventResponsive, &props);
-}
-
-void BrowserPlugin::OnGuestUnresponsive(int guest_instance_id, int process_id) {
- std::map<std::string, base::Value*> props;
- props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id);
- TriggerEvent(browser_plugin::kEventUnresponsive, &props);
-}
-
void BrowserPlugin::OnRequestPermission(
int guest_instance_id,
BrowserPluginPermissionType permission_type,
@@ -1168,8 +1154,6 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin(
case BrowserPluginMsg_CompositorFrameSwapped::ID:
case BrowserPluginMsg_GuestContentWindowReady::ID:
case BrowserPluginMsg_GuestGone::ID:
- case BrowserPluginMsg_GuestResponsive::ID:
- case BrowserPluginMsg_GuestUnresponsive::ID:
case BrowserPluginMsg_RequestPermission::ID:
case BrowserPluginMsg_SetCursor::ID:
case BrowserPluginMsg_SetMouseLock::ID:
diff --git a/content/test/data/browser_plugin_embedder_guest_unresponsive.html b/content/test/data/browser_plugin_embedder_guest_unresponsive.html
deleted file mode 100644
index f6e819b..0000000
--- a/content/test/data/browser_plugin_embedder_guest_unresponsive.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<script type="text/javascript">
-var unresponsiveCalled = false;
-var responsiveCalled = false;
-function SetSrc(src) {
- plugin = document.getElementById('plugin');
- plugin.src = src;
-}
-function GuestUnresponsive(evt) {
- unresponsiveCalled = true;
-}
-
-function GuestResponsive(evt) {
- responsiveCalled = true;
- document.title = "done";
-}
-</script>
-
-<!-- The plugin size is same as the browser's size -->
-<object id="plugin"
- tabindex="0"
- type="application/browser-plugin"
- style="height: 100%; width: 100%; border: 0px"></object>
-
-<script>
- var plugin = document.getElementById('plugin');
- plugin.addEventListener('-internal-unresponsive', GuestUnresponsive);
- plugin.addEventListener('-internal-responsive', GuestResponsive);
- plugin.addEventListener('-internal-instanceid-allocated', function(e) {
- plugin['-internal-attach']({});
- });
-</script>