Index: chrome/browser/extensions/browser_event_router.cc |
diff --git a/chrome/browser/extensions/browser_event_router.cc b/chrome/browser/extensions/browser_event_router.cc |
index c407d6caf557ff9c4e47867a5556dbf3671fdf53..83347cbb9acf9f55ff020429fed77b14604b7692 100644 |
--- a/chrome/browser/extensions/browser_event_router.cc |
+++ b/chrome/browser/extensions/browser_event_router.cc |
@@ -184,20 +184,17 @@ void BrowserEventRouter::TabInsertedAt(TabContents* contents, |
return; |
} |
- ListValue args; |
- args.Append(Value::CreateIntegerValue(tab_id)); |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateIntegerValue(tab_id)); |
DictionaryValue* object_args = new DictionaryValue(); |
object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( |
ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( |
index)); |
- args.Append(object_args); |
+ args->Append(object_args); |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
- |
- DispatchEvent(contents->profile(), events::kOnTabAttached, json_args, |
+ DispatchEvent(contents->profile(), events::kOnTabAttached, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
@@ -207,8 +204,8 @@ void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) { |
return; |
} |
- ListValue args; |
- args.Append(Value::CreateIntegerValue( |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateIntegerValue( |
ExtensionTabUtil::GetTabId(contents->web_contents()))); |
DictionaryValue* object_args = new DictionaryValue(); |
@@ -216,12 +213,9 @@ void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) { |
ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( |
index)); |
- args.Append(object_args); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ args->Append(object_args); |
- DispatchEvent(contents->profile(), events::kOnTabDetached, json_args, |
+ DispatchEvent(contents->profile(), events::kOnTabDetached, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
@@ -230,18 +224,15 @@ void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
int index) { |
int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); |
- ListValue args; |
- args.Append(Value::CreateIntegerValue(tab_id)); |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateIntegerValue(tab_id)); |
DictionaryValue* object_args = new DictionaryValue(); |
object_args->SetBoolean(tab_keys::kWindowClosing, |
tab_strip_model->closing_all()); |
- args.Append(object_args); |
+ args->Append(object_args); |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
- |
- DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args, |
+ DispatchEvent(contents->profile(), events::kOnTabRemoved, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
int removed_count = tab_entries_.erase(tab_id); |
@@ -254,33 +245,29 @@ void BrowserEventRouter::ActiveTabChanged(TabContents* old_contents, |
TabContents* new_contents, |
int index, |
bool user_gesture) { |
- ListValue args; |
+ scoped_ptr<ListValue> args(new ListValue()); |
int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); |
- args.Append(Value::CreateIntegerValue(tab_id)); |
+ args->Append(Value::CreateIntegerValue(tab_id)); |
DictionaryValue* object_args = new DictionaryValue(); |
object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); |
- args.Append(object_args); |
+ args->Append(object_args); |
// The onActivated event replaced onActiveChanged and onSelectionChanged. The |
// deprecated events take two arguments: tabId, {windowId}. |
- std::string old_json_args; |
- base::JSONWriter::Write(&args, &old_json_args); |
- |
- // The onActivated event takes one argument: {windowId, tabId}. |
- std::string new_json_args; |
- args.Remove(0, NULL); |
- object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
- base::JSONWriter::Write(&args, &new_json_args); |
- |
Profile* profile = new_contents->profile(); |
EventRouter::UserGestureState gesture = user_gesture ? |
EventRouter::USER_GESTURE_ENABLED : EventRouter::USER_GESTURE_NOT_ENABLED; |
- DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args, |
- gesture); |
- DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args, gesture); |
- DispatchEvent(profile, events::kOnTabActivated, new_json_args, gesture); |
+ DispatchEvent(profile, events::kOnTabSelectionChanged, |
+ scoped_ptr<ListValue>(args->DeepCopy()), gesture); |
+ DispatchEvent(profile, events::kOnTabActiveChanged, |
+ scoped_ptr<ListValue>(args->DeepCopy()), gesture); |
+ |
+ // The onActivated event takes one argument: {windowId, tabId}. |
+ args->Remove(0, NULL); |
+ object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
+ DispatchEvent(profile, events::kOnTabActivated, args.Pass(), gesture); |
} |
void BrowserEventRouter::TabSelectionChanged( |
@@ -299,31 +286,29 @@ void BrowserEventRouter::TabSelectionChanged( |
all->Append(Value::CreateIntegerValue(tab_id)); |
} |
- ListValue args; |
+ scoped_ptr<ListValue> args(new ListValue()); |
DictionaryValue* select_info = new DictionaryValue(); |
select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
select_info->Set(tab_keys::kTabIdsKey, all); |
- args.Append(select_info); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ args->Append(select_info); |
// The onHighlighted event replaced onHighlightChanged. |
Profile* profile = tab_strip_model->profile(); |
- DispatchEvent(profile, events::kOnTabHighlightChanged, json_args, |
+ DispatchEvent(profile, events::kOnTabHighlightChanged, |
+ scoped_ptr<ListValue>(args->DeepCopy()), |
EventRouter::USER_GESTURE_UNKNOWN); |
- DispatchEvent(profile, events::kOnTabHighlighted, json_args, |
+ DispatchEvent(profile, events::kOnTabHighlighted, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
void BrowserEventRouter::TabMoved(TabContents* contents, |
int from_index, |
int to_index) { |
- ListValue args; |
- args.Append(Value::CreateIntegerValue( |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateIntegerValue( |
ExtensionTabUtil::GetTabId(contents->web_contents()))); |
DictionaryValue* object_args = new DictionaryValue(); |
@@ -333,12 +318,9 @@ void BrowserEventRouter::TabMoved(TabContents* contents, |
from_index)); |
object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( |
to_index)); |
- args.Append(object_args); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ args->Append(object_args); |
- DispatchEvent(contents->profile(), events::kOnTabMoved, json_args, |
+ DispatchEvent(contents->profile(), events::kOnTabMoved, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
@@ -360,38 +342,40 @@ void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { |
void BrowserEventRouter::DispatchEvent( |
Profile* profile, |
const char* event_name, |
- const std::string& json_args, |
+ scoped_ptr<ListValue> args, |
EventRouter::UserGestureState user_gesture) { |
if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
return; |
profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
- event_name, json_args, profile, GURL(), user_gesture); |
+ event_name, args.Pass(), profile, GURL(), user_gesture); |
} |
void BrowserEventRouter::DispatchEventToExtension( |
Profile* profile, |
const std::string& extension_id, |
const char* event_name, |
- const std::string& json_args, |
+ scoped_ptr<ListValue> event_args, |
EventRouter::UserGestureState user_gesture) { |
if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
return; |
profile->GetExtensionEventRouter()->DispatchEventToExtension( |
- extension_id, event_name, json_args, profile, GURL(), user_gesture); |
+ extension_id, event_name, event_args.Pass(), profile, GURL(), |
+ user_gesture); |
} |
void BrowserEventRouter::DispatchEventsAcrossIncognito( |
Profile* profile, |
const char* event_name, |
- const std::string& json_args, |
- const std::string& cross_incognito_args) { |
+ scoped_ptr<ListValue> event_args, |
+ scoped_ptr<ListValue> cross_incognito_args) { |
if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
return; |
profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito( |
- event_name, json_args, profile, cross_incognito_args, GURL()); |
+ event_name, event_args.Pass(), profile, cross_incognito_args.Pass(), |
+ GURL()); |
} |
void BrowserEventRouter::DispatchEventWithTab( |
@@ -404,16 +388,14 @@ void BrowserEventRouter::DispatchEventWithTab( |
if (!profile_->IsSameProfile(profile)) |
return; |
- ListValue args; |
- args.Append(ExtensionTabUtil::CreateTabValueActive( |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(ExtensionTabUtil::CreateTabValueActive( |
web_contents, active)); |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
if (!extension_id.empty()) { |
- DispatchEventToExtension(profile, extension_id, event_name, json_args, |
+ DispatchEventToExtension(profile, extension_id, event_name, args.Pass(), |
user_gesture); |
} else { |
- DispatchEvent(profile, event_name, json_args, user_gesture); |
+ DispatchEvent(profile, event_name, args.Pass(), user_gesture); |
} |
} |
@@ -422,13 +404,10 @@ void BrowserEventRouter::DispatchSimpleBrowserEvent( |
if (!profile_->IsSameProfile(profile)) |
return; |
- ListValue args; |
- args.Append(Value::CreateIntegerValue(window_id)); |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateIntegerValue(window_id)); |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
- |
- DispatchEvent(profile, event_name, json_args, |
+ DispatchEvent(profile, event_name, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
@@ -439,22 +418,19 @@ void BrowserEventRouter::DispatchTabUpdatedEvent( |
// The state of the tab (as seen from the extension point of view) has |
// changed. Send a notification to the extension. |
- ListValue args; |
+ scoped_ptr<ListValue> args(new ListValue()); |
// First arg: The id of the tab that changed. |
- args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
+ args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
// Second arg: An object containing the changes to the tab state. |
- args.Append(changed_properties); |
+ args->Append(changed_properties); |
// Third arg: An object containing the state of the tab. |
- args.Append(ExtensionTabUtil::CreateTabValue(contents)); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ args->Append(ExtensionTabUtil::CreateTabValue(contents)); |
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
- DispatchEvent(profile, events::kOnTabUpdated, json_args, |
+ DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), |
EventRouter::USER_GESTURE_UNKNOWN); |
} |
@@ -523,19 +499,16 @@ void BrowserEventRouter::DispatchOldPageActionEvent( |
int tab_id, |
const std::string& url, |
int button) { |
- ListValue args; |
- args.Append(Value::CreateStringValue(page_action_id)); |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateStringValue(page_action_id)); |
DictionaryValue* data = new DictionaryValue(); |
data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); |
data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); |
- args.Append(data); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ args->Append(data); |
- DispatchEventToExtension(profile, extension_id, "pageActions", json_args, |
+ DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass(), |
EventRouter::USER_GESTURE_ENABLED); |
} |
@@ -580,15 +553,13 @@ void BrowserEventRouter::ScriptBadgeExecuted( |
void BrowserEventRouter::CommandExecuted(Profile* profile, |
const std::string& extension_id, |
const std::string& command) { |
- ListValue args; |
- args.Append(Value::CreateStringValue(command)); |
- std::string json_args; |
- base::JSONWriter::Write(&args, &json_args); |
+ scoped_ptr<ListValue> args(new ListValue()); |
+ args->Append(Value::CreateStringValue(command)); |
DispatchEventToExtension(profile, |
extension_id, |
"experimental.commands.onCommand", |
- json_args, |
+ args.Pass(), |
EventRouter::USER_GESTURE_ENABLED); |
} |