Revert "Unrevert 119770 - "Event pages: remember events that the page registered for,"

Original CL:
Add support for broadcasted events.

Add an extension.onInstalled event that is run when the event page first
starts."

Fixed ASAN bug with previous incarnation.

Reason for revert:
Some WebstoreInlineInstallTest tests have started failing. Might be this CL.

TBR=aa
BUG=81752, 112391
TEST=no

Review URL: https://chromiumcodereview.appspot.com/9350006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120678 0039d316-1c4b-4281-b951-d872f2087c98
parent a278944d
......@@ -50,15 +50,6 @@ class ExtensionEventRouter : public content::NotificationObserver {
content::RenderProcessHost* process,
const std::string& extension_id);
// Add or remove the extension as having a lazy background page that listens
// to the event. The difference from the above methods is that these will be
// remembered even after the process goes away. We use this list to decide
// which extension pages to load when dispatching an event.
void AddLazyEventListener(const std::string& event_name,
const std::string& extension_id);
void RemoveLazyEventListener(const std::string& event_name,
const std::string& extension_id);
// Returns true if there is at least one listener for the given event.
bool HasEventListener(const std::string& event_name);
......@@ -114,25 +105,15 @@ class ExtensionEventRouter : public content::NotificationObserver {
// Shared by DispatchEvent*. If |extension_id| is empty, the event is
// broadcast.
// An event that just came off the pending list may not be delayed again.
void DispatchEventImpl(const std::string& extension_id,
const linked_ptr<ExtensionEvent>& event,
void DispatchEventImpl(const linked_ptr<ExtensionEvent>& event,
bool was_pending);
// Ensures that all non-persistent background pages that are interested in the
// given event are loaded, and queues the event if the page is not ready yet.
// If |extension_id| is non-empty, we load only that extension's page
// (assuming it is interested in the event).
void LoadLazyBackgroundPagesForEvent(
const std::string& extension_id,
const linked_ptr<ExtensionEvent>& event);
// Dispatch may be delayed if the extension has a lazy background page.
bool CanDispatchEventNow(const Extension* extension);
bool CanDispatchEventNow(const std::string& extension_id);
// Store the event so that it can be dispatched (in order received)
// when the background page is done loading.
void AppendEvent(const std::string& extension_id,
const linked_ptr<ExtensionEvent>& event);
void AppendEvent(const linked_ptr<ExtensionEvent>& event);
void DispatchPendingEvents(const std::string& extension_id);
private:
......@@ -154,11 +135,6 @@ class ExtensionEventRouter : public content::NotificationObserver {
typedef std::map<std::string, std::set<EventListener> > ListenerMap;
ListenerMap listeners_;
// Keeps track of all the non-persistent background pages that are listening
// to events.
// TODO(mpcomplete): save to disk.
ListenerMap lazy_listeners_;
// A map between an extension id and the queue of events pending
// the load of it's background page.
typedef std::vector<linked_ptr<ExtensionEvent> > PendingEventsList;
......
......@@ -340,6 +340,10 @@ void ExtensionHost::DidStopLoading() {
#endif
}
if (notify) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::Source<Profile>(profile_),
content::Details<ExtensionHost>(this));
if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
since_created_.Elapsed());
......@@ -355,13 +359,6 @@ void ExtensionHost::DidStopLoading() {
} else if (extension_host_type_ == chrome::VIEW_TYPE_APP_SHELL) {
UMA_HISTOGRAM_TIMES("Extensions.ShellLoadTime", since_created_.Elapsed());
}
// Send the notification last, because it might result in this being
// deleted.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::Source<Profile>(profile_),
content::Details<ExtensionHost>(this));
}
}
......
......@@ -35,10 +35,6 @@ using content::OpenURLParams;
using content::Referrer;
using content::SiteInstance;
namespace events {
const char kOnInstalled[] = "experimental.extension.onInstalled";
}; // namespace events
namespace {
// Incognito profiles use this process manager. It is mostly a shim that decides
......@@ -71,14 +67,9 @@ class IncognitoExtensionProcessManager : public ExtensionProcessManager {
static void CreateBackgroundHostForExtensionLoad(
ExtensionProcessManager* manager, const Extension* extension) {
if (extension->has_background_page()) {
if (extension->background_page_persists()) {
manager->CreateBackgroundHost(extension, extension->GetBackgroundURL());
} else {
// TODO(mpcomplete): Only call this on install once we persist event
// registration. Also call this for regular background pages.
manager->DispatchExtensionInstalledEvent(extension);
}
if (extension->has_background_page() &&
extension->background_page_persists()) {
manager->CreateBackgroundHost(extension, extension->GetBackgroundURL());
}
}
......@@ -418,14 +409,6 @@ void ExtensionProcessManager::CloseBackgroundHosts() {
}
}
void ExtensionProcessManager::DispatchExtensionInstalledEvent(
const Extension* extension) {
ExtensionEventRouter* router = GetProfile()->GetExtensionEventRouter();
router->AddLazyEventListener(events::kOnInstalled, extension->id());
router->DispatchEventToExtension(
extension->id(), events::kOnInstalled, "[]", NULL, GURL());
}
//
// IncognitoExtensionProcessManager
//
......
......@@ -93,10 +93,6 @@ class ExtensionProcessManager : public content::NotificationObserver {
// lazy background pages are enabled).
void OnExtensionIdle(const std::string& extension_id);
// Dispatch an event to the extension to let it know it was just installed.
// TODO(mpcomplete): Temporary until we implement persistent event registry.
void DispatchExtensionInstalledEvent(const Extension* extension);
typedef std::set<ExtensionHost*> ExtensionHostSet;
typedef ExtensionHostSet::const_iterator const_iterator;
const_iterator begin() const { return all_hosts_.begin(); }
......
......@@ -19,26 +19,6 @@
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
namespace {
// Helper class to wait for a lazy background page to load and close again.
class LazyBackgroundObserver {
public:
LazyBackgroundObserver()
: page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::NotificationService::AllSources()),
page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources()) {
}
void Wait() {
page_created_.Wait();
page_closed_.Wait();
}
private:
ui_test_utils::WindowedNotificationObserver page_created_;
ui_test_utils::WindowedNotificationObserver page_closed_;
};
} // namespace
class LazyBackgroundPageApiTest : public ExtensionApiTest {
public:
void SetUpCommandLine(CommandLine* command_line) {
......@@ -53,10 +33,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
ASSERT_TRUE(LoadExtension(extdir));
// Lazy Background Page doesn't exist yet.
// Note: We actually loaded and destroyed the page to dispatch the onInstalled
// event. LoadExtension waits for the load to finish, after which onInstalled
// is dispatched. Since the extension isn't listening to it, we immediately
// tear it down again.
ExtensionProcessManager* pm =
browser()->profile()->GetExtensionProcessManager();
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
......@@ -64,9 +40,15 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
// Observe background page being created and closed after
// the browser action is clicked.
LazyBackgroundObserver page_complete;
ui_test_utils::WindowedNotificationObserver bg_pg_created(
chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::NotificationService::AllSources());
ui_test_utils::WindowedNotificationObserver bg_pg_closed(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
BrowserActionTestUtil(browser()).Press(0);
page_complete.Wait();
bg_pg_created.Wait();
bg_pg_closed.Wait();
// Background page created a new tab before it closed.
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
......@@ -89,22 +71,26 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
// Observe background page being created and closed after
// the browser action is clicked.
LazyBackgroundObserver page_complete;
ui_test_utils::WindowedNotificationObserver bg_pg_created(
chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::NotificationService::AllSources());
ui_test_utils::WindowedNotificationObserver bg_pg_closed(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
BrowserActionTestUtil(browser()).Press(0);
page_complete.Wait();
bg_pg_created.Wait();
bg_pg_closed.Wait();
// Background page is closed after creating a new tab.
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
EXPECT_EQ(num_tabs_before + 1, browser()->tab_count());
}
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
ASSERT_TRUE(StartTestServer());
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
BroadcastEvent) {
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
AppendASCII("broadcast_event");
const Extension* extension = LoadExtension(extdir);
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(extdir));
// Lazy Background Page doesn't exist yet.
ExtensionProcessManager* pm =
......@@ -114,38 +100,17 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
GetLocationBarForTesting()->PageActionVisibleCount();
// Open a tab to a URL that will trigger the page action to show.
LazyBackgroundObserver page_complete;
ui_test_utils::WindowedNotificationObserver page_action_changed(
chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
content::NotificationService::AllSources());
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL("files/extensions/test_file.html"));
page_complete.Wait();
// stegosaurus.html doesn't actually exist but that doesn't seem to matter.
GURL stego_url = GURL("stegosaurus.html");
ui_test_utils::NavigateToURL(browser(), stego_url);
// New page action is never shown because background page is never created.
// TODO(tessamac): Implement! Broadcast events (like tab updates) should
// cause lazy background pages to be created.
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
// Page action is shown.
page_action_changed.Wait();
EXPECT_EQ(num_page_actions + 1,
EXPECT_EQ(num_page_actions, // should be + 1
browser()->window()->GetLocationBar()->
GetLocationBarForTesting()->PageActionVisibleCount());
}
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) {
LazyBackgroundObserver page_complete;
ResultCatcher catcher;
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
AppendASCII("on_installed");
const Extension* extension = LoadExtension(extdir);
ASSERT_TRUE(extension);
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
page_complete.Wait();
// Lazy Background Page has been shut down.
ExtensionProcessManager* pm =
browser()->profile()->GetExtensionProcessManager();
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
GetLocationBarForTesting()->PageActionVisibleCount());
}
// TODO: background page with timer.
......
......@@ -86,10 +86,6 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddListener, OnExtensionAddListener)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveListener,
OnExtensionRemoveListener)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddLazyListener,
OnExtensionAddLazyListener)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveLazyListener,
OnExtensionRemoveLazyListener)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExtensionIdle, OnExtensionIdle)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExtensionEventAck, OnExtensionEventAck)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel)
......@@ -137,8 +133,6 @@ void ChromeRenderMessageFilter::OverrideThreadForMessage(
#endif
case ExtensionHostMsg_AddListener::ID:
case ExtensionHostMsg_RemoveListener::ID:
case ExtensionHostMsg_AddLazyListener::ID:
case ExtensionHostMsg_RemoveLazyListener::ID:
case ExtensionHostMsg_ExtensionIdle::ID:
case ExtensionHostMsg_ExtensionEventAck::ID:
case ExtensionHostMsg_CloseChannel::ID:
......@@ -347,20 +341,6 @@ void ChromeRenderMessageFilter::OnExtensionRemoveListener(
event_name, process, extension_id);
}
void ChromeRenderMessageFilter::OnExtensionAddLazyListener(
const std::string& extension_id, const std::string& event_name) {
if (profile_->GetExtensionEventRouter())
profile_->GetExtensionEventRouter()->AddLazyEventListener(
event_name, extension_id);
}
void ChromeRenderMessageFilter::OnExtensionRemoveLazyListener(
const std::string& extension_id, const std::string& event_name) {
if (profile_->GetExtensionEventRouter())
profile_->GetExtensionEventRouter()->RemoveLazyEventListener(
event_name, extension_id);
}
void ChromeRenderMessageFilter::OnExtensionIdle(
const std::string& extension_id) {
if (profile_->GetExtensionProcessManager())
......
......@@ -101,10 +101,6 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
const std::string& event_name);
void OnExtensionRemoveListener(const std::string& extension_id,
const std::string& event_name);
void OnExtensionAddLazyListener(const std::string& extension_id,
const std::string& event_name);
void OnExtensionRemoveLazyListener(const std::string& extension_id,
const std::string& event_name);
void OnExtensionIdle(const std::string& extension_id);
void OnExtensionEventAck(const std::string& extension_id);
void OnExtensionCloseChannel(int port_id);
......
......@@ -25,7 +25,6 @@
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_CLEAR" file="extensions\api\experimental.clear.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_DNS" file="extensions\api\experimental.dns.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_DOWNLOADS" file="extensions\api\experimental.downloads.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_EXTENSIONS" file="extensions\api\experimental.extension.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_INFOBARS" file="extensions\api\experimental.infobars.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_UI" file="extensions\api\experimental.input.ui.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD" file="extensions\api\experimental.input.virtualKeyboard.json" type="BINDATA" />
......
[
{
"namespace": "experimental.extension",
"events": [
{
"name": "onInstalled",
"type": "function",
"description": "Fired when the extension is first installed.",
"parameters": [
]
}
]
}
]
......@@ -90,7 +90,6 @@ ExtensionAPI::ExtensionAPI() {
IDR_EXTENSION_API_JSON_EXPERIMENTAL_CLEAR,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_DNS,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_DOWNLOADS,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_EXTENSIONS,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_INFOBARS,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_UI,
IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD,
......
......@@ -239,7 +239,6 @@ on the following experimental APIs:
<a href="experimental.clear.html">experimental.clear</a></li><li>
<a href="experimental.devtools.audits.html">experimental.devtools.audits</a></li><li>
<a href="experimental.devtools.console.html">experimental.devtools.console</a></li><li>
<a href="experimental.extension.html">experimental.extension</a></li><li>
<a href="experimental.infobars.html">experimental.infobars</a></li><li>
<a href="experimental.speechInput.html">experimental.speechInput</a></li>
</ul>
......
......@@ -36,7 +36,6 @@ var MODULE_SCHEMAS = [
'../api/experimental.clear.json',
'../api/experimental.dns.json',
'../api/experimental.downloads.json',
'../api/experimental.extension.json',
'../api/experimental.infobars.json',
'../api/experimental.input.ui.json',
'../api/experimental.input.virtualKeyboard.json',
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -270,18 +270,6 @@ IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveListener,
std::string /* extension_id */,
std::string /* name */)
// Notify the browser that the given extension added a listener to an event from
// a lazy background page.
IPC_MESSAGE_CONTROL2(ExtensionHostMsg_AddLazyListener,
std::string /* extension_id */,
std::string /* name */)
// Notify the browser that the given extension is no longer interested in
// receiving the given event from a lazy background page.
IPC_MESSAGE_CONTROL2(ExtensionHostMsg_RemoveLazyListener,
std::string /* extension_id */,
std::string /* name */)
// Notify the browser that the extension is idle so it's lazy background page
// can be closed.
IPC_MESSAGE_CONTROL1(ExtensionHostMsg_ExtensionIdle,
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -91,20 +91,10 @@ class ExtensionImpl : public ChromeV8Extension {
if (!v8_extension->CheckCurrentContextAccessToExtensionAPI(event_name))
return v8::Undefined();
const ::Extension* extension = v8_extension->extension_dispatcher()->
extensions()->GetByID(context->extension_id());
if (++listener_counts[event_name] == 1) {
content::RenderThread::Get()->Send(
new ExtensionHostMsg_AddListener(context->extension_id(),
event_name));
// TODO(mpcomplete): restrict this to the bg page only.
// TODO(mpcomplete): figure out proper time to call RemoveLazyListener.
if (extension && !extension->background_page_persists()) {
content::RenderThread::Get()->Send(
new ExtensionHostMsg_AddLazyListener(context->extension_id(),
event_name));
}
}
}
......@@ -127,7 +117,6 @@ class ExtensionImpl : public ChromeV8Extension {
EventListenerCounts& listener_counts =
GetListenerCounts(context->extension_id());
std::string event_name(*v8::String::AsciiValue(args[0]));
if (--listener_counts[event_name] == 0) {
content::RenderThread::Get()->Send(
new ExtensionHostMsg_RemoveListener(context->extension_id(),
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.url.search("test_file.html") > -1)
// TODO: look for 'stegosaurus' in the page contents.
if (tab.url.search("stegosaurus") > -1)
chrome.pageAction.show(tabId);
else
chrome.pageAction.hide(tabId);
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.experimental.extension.onInstalled.addListener(function() {
chrome.test.notifyPass();
});
{
"name": "Lazy BG onInstalled test",
"description": "Test that the onInstalled event is handled properly",
"version": "1",
"manifest_version": 2,
"permissions": ["tabs", "experimental"],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
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