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

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: Build fix. 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 906294a4a4de0088ffa6056668c3052ca62ffff5..7ad5933fb68bae95f622bf84a4f6208f9e793f8b 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
@@ -74,11 +74,14 @@ double MilliSecondsFromTime(const base::Time& time) {
// Dispatches events to the extension message service.
void DispatchEvent(BrowserContext* browser_context,
const char* event_name,
- const std::string& json_args) {
+ base::Value* args) {
+ 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());
+ event_name, event_args, profile, GURL());
}
}
@@ -87,19 +90,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);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
DispatchEvent(web_contents->GetBrowserContext(),
keys::kOnBeforeNavigate,
- json_args);
+ dict);
}
// Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
@@ -110,7 +109,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());
@@ -129,11 +127,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);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- DispatchEvent(web_contents->GetBrowserContext(), event_name, json_args);
+ DispatchEvent(web_contents->GetBrowserContext(), event_name, dict);
}
// Constructs and dispatches an onDOMContentLoaded event.
@@ -141,20 +136,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);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
DispatchEvent(web_contents->GetBrowserContext(),
keys::kOnDOMContentLoaded,
- json_args);
+ dict);
}
// Constructs and dispatches an onCompleted event.
@@ -162,19 +153,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);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- DispatchEvent(web_contents->GetBrowserContext(),
- keys::kOnCompleted, json_args);
+ DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, dict);
}
// Constructs and dispatches an onCreatedNavigationTarget event.
@@ -192,7 +178,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));
@@ -202,12 +187,8 @@ void DispatchOnCreatedNavigationTarget(
dict->SetInteger(keys::kTabIdKey,
ExtensionTabUtil::GetTabId(target_web_contents));
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
- args.Append(dict);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
- DispatchEvent(
- browser_context, keys::kOnCreatedNavigationTarget, json_args);
+ DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, dict);
}
// Constructs and dispatches an onErrorOccurred event.
@@ -216,20 +197,16 @@ 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);
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
DispatchEvent(web_contents->GetBrowserContext(),
keys::kOnErrorOccurred,
- json_args);
+ dict);
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698