Chromium Code Reviews| Index: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc |
| diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc |
| index b17dd6a14a8a4941702c0ac4d8e519720edd18b0..6d8190c96c20661939f028cbf8422ea340a50c64 100644 |
| --- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc |
| +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc |
| @@ -76,18 +76,18 @@ double MilliSecondsFromTime(const base::Time& time) { |
| // Dispatches events to the extension message service. |
| void DispatchEvent(BrowserContext* browser_context, |
| const char* event_name, |
| - const ListValue& args, |
| + base::Value* args, |
| const GURL& url) { |
| - std::string json_args; |
| - base::JSONWriter::Write(&args, &json_args); |
| - |
| extensions::EventFilteringInfo info; |
| info.SetURL(url); |
| + ListValue *event_args = new ListValue(); |
| + event_args->Append(args); |
| + |
| Profile* profile = Profile::FromBrowserContext(browser_context); |
| if (profile && profile->GetExtensionEventRouter()) { |
| profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| - event_name, json_args, profile, GURL(), info); |
| + event_name, event_args, profile, GURL(), info); |
| } |
| } |
| @@ -96,17 +96,15 @@ void DispatchOnBeforeNavigate(WebContents* web_contents, |
| int64 frame_id, |
| bool is_main_frame, |
| const GURL& validated_url) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| dict->SetString(keys::kUrlKey, validated_url.spec()); |
| dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| DispatchEvent(web_contents->GetBrowserContext(), |
| keys::kOnBeforeNavigate, |
| - args, |
| + dict, |
| validated_url); |
| } |
| @@ -118,7 +116,6 @@ void DispatchOnCommitted(const char* event_name, |
| bool is_main_frame, |
| const GURL& url, |
| content::PageTransition transition_type) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| dict->SetString(keys::kUrlKey, url.spec()); |
| @@ -137,9 +134,8 @@ void DispatchOnCommitted(const char* event_name, |
| qualifiers->Append(Value::CreateStringValue("from_address_bar")); |
| dict->Set(keys::kTransitionQualifiersKey, qualifiers); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| - DispatchEvent(web_contents->GetBrowserContext(), event_name, args, url); |
| + DispatchEvent(web_contents->GetBrowserContext(), event_name, dict, url); |
|
miket_OOO
2012/07/10 22:33:19
This CL would be prettier if dict were named args
|
| } |
| // Constructs and dispatches an onDOMContentLoaded event. |
| @@ -147,18 +143,16 @@ void DispatchOnDOMContentLoaded(WebContents* web_contents, |
| const GURL& url, |
| bool is_main_frame, |
| int64 frame_id) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kTabIdKey, |
| ExtensionTabUtil::GetTabId(web_contents)); |
| dict->SetString(keys::kUrlKey, url.spec()); |
| dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| DispatchEvent(web_contents->GetBrowserContext(), |
| keys::kOnDOMContentLoaded, |
| - args, |
| + dict, |
| url); |
| } |
| @@ -167,16 +161,14 @@ void DispatchOnCompleted(WebContents* web_contents, |
| const GURL& url, |
| bool is_main_frame, |
| int64 frame_id) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kTabIdKey, |
| ExtensionTabUtil::GetTabId(web_contents)); |
| dict->SetString(keys::kUrlKey, url.spec()); |
| dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| - DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, args, |
| + DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, dict, |
| url); |
| } |
| @@ -195,7 +187,6 @@ void DispatchOnCreatedNavigationTarget( |
| Profile::FromBrowserContext(target_web_contents->GetBrowserContext()), |
| false, NULL, NULL, NULL, NULL)); |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kSourceTabIdKey, |
| ExtensionTabUtil::GetTabId(web_contents)); |
| @@ -205,9 +196,8 @@ void DispatchOnCreatedNavigationTarget( |
| dict->SetInteger(keys::kTabIdKey, |
| ExtensionTabUtil::GetTabId(target_web_contents)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| - DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args, |
| + DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, dict, |
| target_url); |
| } |
| @@ -217,17 +207,15 @@ void DispatchOnErrorOccurred(WebContents* web_contents, |
| int64 frame_id, |
| bool is_main_frame, |
| int error_code) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| dict->SetString(keys::kUrlKey, url.spec()); |
| dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
| dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred, |
| - args, url); |
| + dict, url); |
| } |
| // Constructs and dispatches an onTabReplaced event. |
| @@ -235,16 +223,14 @@ void DispatchOnTabReplaced( |
| WebContents* old_web_contents, |
| BrowserContext* browser_context, |
| WebContents* new_web_contents) { |
| - ListValue args; |
| DictionaryValue* dict = new DictionaryValue(); |
| dict->SetInteger(keys::kReplacedTabIdKey, |
| ExtensionTabUtil::GetTabId(old_web_contents)); |
| dict->SetInteger(keys::kTabIdKey, |
| ExtensionTabUtil::GetTabId(new_web_contents)); |
| dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| - args.Append(dict); |
| - DispatchEvent(browser_context, keys::kOnTabReplaced, args, GURL()); |
| + DispatchEvent(browser_context, keys::kOnTabReplaced, dict, GURL()); |
| } |
| } // namespace |