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

Unified Diff: chrome/browser/extensions/extension_omnibox_api.cc

Issue 2078021: First pass at experimental omnibox API. There are plenty of rough edges and (Closed)
Patch Set: no prefer_keyword Created 10 years, 7 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/extension_omnibox_api.cc
diff --git a/chrome/browser/extensions/extension_omnibox_api.cc b/chrome/browser/extensions/extension_omnibox_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b526d76240d4f1a8adb27b0cec07c1751ee5988
--- /dev/null
+++ b/chrome/browser/extensions/extension_omnibox_api.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/extensions/extension_omnibox_api.h"
+
+#include "base/json/json_writer.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_message_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/notification_service.h"
+
+namespace events {
+const char kOnInputChanged[] = "experimental.omnibox.onInputChanged/";
+const char kOnInputEntered[] = "experimental.omnibox.onInputEntered/";
+}; // namespace events
+
+// static
+bool ExtensionOmniboxEventRouter::OnInputChanged(
+ Profile* profile, const std::string& extension_id,
+ const std::string& input, int suggest_id) {
+ std::string event_name = events::kOnInputChanged + extension_id;
+ if (!profile->GetExtensionMessageService()->HasEventListener(event_name))
+ return false;
+
+ ListValue args;
+ args.Set(0, Value::CreateStringValue(input));
+ args.Set(1, Value::CreateIntegerValue(suggest_id));
+ std::string json_args;
+ base::JSONWriter::Write(&args, false, &json_args);
+
+ profile->GetExtensionMessageService()->DispatchEventToRenderers(
+ event_name, json_args, profile->IsOffTheRecord(), GURL());
+ return true;
+}
+
+// static
+void ExtensionOmniboxEventRouter::OnInputEntered(
+ Profile* profile, const std::string& extension_id,
+ const std::string& input) {
+ std::string event_name = events::kOnInputEntered + extension_id;
+
+ ListValue args;
+ args.Set(0, Value::CreateStringValue(input));
+ std::string json_args;
+ base::JSONWriter::Write(&args, false, &json_args);
+
+ profile->GetExtensionMessageService()->DispatchEventToRenderers(
+ event_name, json_args, profile->IsOffTheRecord(), GURL());
+}
+
+bool OmniboxSendSuggestionsFunction::RunImpl() {
+ int request_id;
+ ListValue* suggestions_value;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &request_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
+
+ ExtensionOmniboxSuggestions details(request_id, suggestions_value);
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY,
+ Source<Profile>(profile_),
+ Details<ExtensionOmniboxSuggestions>(&details));
+
+ return true;
+}
+
« no previous file with comments | « chrome/browser/extensions/extension_omnibox_api.h ('k') | chrome/browser/extensions/extension_omnibox_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698