Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698