diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-17 06:39:47 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-17 06:39:47 +0000 |
commit | 78d7191f68e49a61d16b5191d4e9040738f91265 (patch) | |
tree | 6abc17cd604787fe0171c057472e5c0165b4c93f /content/renderer | |
parent | b236c1c7bf750fecb04f4439e310f353dd713304 (diff) | |
download | chromium_src-78d7191f68e49a61d16b5191d4e9040738f91265.zip chromium_src-78d7191f68e49a61d16b5191d4e9040738f91265.tar.gz chromium_src-78d7191f68e49a61d16b5191d4e9040738f91265.tar.bz2 |
<webview> Move exit event to chrome
BUG=166165
Test=WebViewTest.Shim_*
TBR=cdn@chromium.org
Review URL: https://chromiumcodereview.appspot.com/18986009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r-- | content/renderer/browser_plugin/browser_plugin.cc | 68 | ||||
-rw-r--r-- | content/renderer/browser_plugin/browser_plugin.h | 4 | ||||
-rw-r--r-- | content/renderer/browser_plugin/browser_plugin_browsertest.cc | 80 |
3 files changed, 24 insertions, 128 deletions
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc index e2e9ee9..5a961ba 100644 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ b/content/renderer/browser_plugin/browser_plugin.cc @@ -55,24 +55,6 @@ namespace content { namespace { -static std::string TerminationStatusToString(base::TerminationStatus status) { - switch (status) { - case base::TERMINATION_STATUS_NORMAL_TERMINATION: - return "normal"; - case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: - case base::TERMINATION_STATUS_STILL_RUNNING: - return "abnormal"; - case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: - return "killed"; - case base::TERMINATION_STATUS_PROCESS_CRASHED: - return "crashed"; - case base::TERMINATION_STATUS_MAX_ENUM: - break; - } - NOTREACHED() << "Unknown Termination Status."; - return "unknown"; -} - static std::string GetInternalEventName(const char* event_name) { return base::StringPrintf("-internal-%s", event_name); } @@ -494,37 +476,17 @@ void BrowserPlugin::OnGuestContentWindowReady(int guest_instance_id, content_window_routing_id_ = content_window_routing_id; } -void BrowserPlugin::OnGuestGone(int guest_instance_id, - int process_id, - int status) { - // Set the BrowserPlugin in a crashed state before firing event listeners so - // that operations on the BrowserPlugin within listeners are aware that - // BrowserPlugin is in a crashed state. +void BrowserPlugin::OnGuestGone(int guest_instance_id) { guest_crashed_ = true; - // We fire the event listeners before painting the sad graphic to give the - // developer an opportunity to display an alternative overlay image on crash. - std::string termination_status = TerminationStatusToString( - static_cast<base::TerminationStatus>(status)); - std::map<std::string, base::Value*> props; - props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); - props[browser_plugin::kReason] = new base::StringValue(termination_status); - - // Event listeners may remove the BrowserPlugin from the document. If that - // happens, the BrowserPlugin will be scheduled for later deletion (see - // BrowserPlugin::destroy()). That will clear the container_ reference, - // but leave other member variables valid below. - TriggerEvent(browser_plugin::kEventExit, &props); - - // We won't paint the contents of the current backing store again so we might - // as well toss it out and save memory. - backing_store_.reset(); - // If the BrowserPlugin is scheduled to be deleted, then container_ will be - // NULL so we shouldn't attempt to access it. - if (container_) - container_->invalidate(); - // Turn off compositing so we can display the sad graphic. - EnableCompositing(false); + // Queue up showing the sad graphic to give content embedders an opportunity + // to fire their listeners and potentially overlay the webview with custom + // behavior. If the BrowserPlugin is destroyed in the meantime, then the + // task will not be executed. + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&BrowserPlugin::ShowSadGraphic, + weak_ptr_factory_.GetWeakPtr())); } void BrowserPlugin::OnGuestResponsive(int guest_instance_id, int process_id) { @@ -850,6 +812,18 @@ bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { return !HasGuestInstanceID(); } +void BrowserPlugin::ShowSadGraphic() { + // We won't paint the contents of the current backing store again so we might + // as well toss it out and save memory. + backing_store_.reset(); + // If the BrowserPlugin is scheduled to be deleted, then container_ will be + // NULL so we shouldn't attempt to access it. + if (container_) + container_->invalidate(); + // Turn off compositing so we can display the sad graphic. + EnableCompositing(false); +} + void BrowserPlugin::ParseAttributes() { // TODO(mthiesse): Handle errors here? std::string error; diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h index f1cebb7..b3e0f4b 100644 --- a/content/renderer/browser_plugin/browser_plugin.h +++ b/content/renderer/browser_plugin/browser_plugin.h @@ -240,6 +240,8 @@ class CONTENT_EXPORT BrowserPlugin : // Virtual to allow for mocking in tests. virtual float GetDeviceScaleFactor() const; + void ShowSadGraphic(); + // Parses the attributes of the browser plugin from the element's attributes // and sets them appropriately. void ParseAttributes(); @@ -323,7 +325,7 @@ class CONTENT_EXPORT BrowserPlugin : void OnCompositorFrameSwapped(const IPC::Message& message); void OnGuestContentWindowReady(int instance_id, int content_window_routing_id); - void OnGuestGone(int instance_id, int process_id, int status); + void OnGuestGone(int instance_id); void OnGuestResponsive(int instance_id, int process_id); void OnGuestUnresponsive(int instance_id, int process_id); // Requests permission from the embedder. diff --git a/content/renderer/browser_plugin/browser_plugin_browsertest.cc b/content/renderer/browser_plugin/browser_plugin_browsertest.cc index 2dcae6c..eb2e395 100644 --- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc +++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc @@ -376,57 +376,6 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) { } } -TEST_F(BrowserPluginTest, GuestCrash) { - LoadHTML(GetHTMLForBrowserPluginObject().c_str()); - - MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); - ASSERT_TRUE(browser_plugin); - - WebKit::WebCursorInfo cursor_info; - // Send an event and verify that the event is deported. - browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), - cursor_info); - EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( - BrowserPluginHostMsg_HandleInputEvent::ID)); - browser_plugin_manager()->sink().ClearMessages(); - - const char* kAddEventListener = - "var msg;" - "function exitListener(e) {" - " msg = JSON.parse(e.detail).reason;" - "}" - "document.getElementById('browserplugin')." - " addEventListener('-internal-exit', exitListener);"; - - ExecuteJavaScript(kAddEventListener); - - // Pretend that the guest has terminated normally. - { - BrowserPluginMsg_GuestGone msg( - 0, 0, base::TERMINATION_STATUS_NORMAL_TERMINATION); - browser_plugin->OnMessageReceived(msg); - } - - // Verify that our event listener has fired. - EXPECT_EQ("normal", ExecuteScriptAndReturnString("msg")); - - // Pretend that the guest has crashed. - { - BrowserPluginMsg_GuestGone msg( - 0, 0, base::TERMINATION_STATUS_PROCESS_CRASHED); - browser_plugin->OnMessageReceived(msg); - } - - // Verify that our event listener has fired. - EXPECT_EQ("crashed", ExecuteScriptAndReturnString("msg")); - - // Send an event and verify that events are no longer deported. - browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), - cursor_info); - EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( - BrowserPluginHostMsg_HandleInputEvent::ID)); -} - TEST_F(BrowserPluginTest, RemovePlugin) { LoadHTML(GetHTMLForBrowserPluginObject().c_str()); EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( @@ -591,35 +540,6 @@ TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { EXPECT_STREQ("storage", partition_value.c_str()); } -TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) { - LoadHTML(GetHTMLForBrowserPluginObject().c_str()); - - MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); - ASSERT_TRUE(browser_plugin); - int instance_id = browser_plugin->instance_id(); - - const char* kAddEventListener = - "function exitListener(e) {" - " if (JSON.parse(e.detail).reason == 'killed') {" - " var bp = document.getElementById('browserplugin');" - " bp.parentNode.removeChild(bp);" - " }" - "}" - "document.getElementById('browserplugin')." - " addEventListener('-internal-exit', exitListener);"; - - ExecuteJavaScript(kAddEventListener); - - // Pretend that the guest has crashed. - BrowserPluginMsg_GuestGone msg( - instance_id, 0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); - browser_plugin->OnMessageReceived(msg); - - ProcessPendingMessages(); - - EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); -} - TEST_F(BrowserPluginTest, AutoSizeAttributes) { std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, content::kBrowserPluginMimeType); |